-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for BumpSequenceOperation and result
- Loading branch information
1 parent
8941f89
commit 7395221
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/** | ||
* Adds a new signer to an existing account | ||
*/ | ||
|
||
|
||
require '../vendor/autoload.php'; | ||
|
||
use \ZuluCrypto\StellarSdk\Keypair; | ||
use \ZuluCrypto\StellarSdk\Server; | ||
use \phpseclib\Math\BigInteger; | ||
|
||
|
||
$server = Server::testNet(); | ||
|
||
// GCP6IHMHWRCF5TQ4ZP6TVIRNDZD56W42F42VHYWMVDGDAND75YGAHHBQ | ||
$currentAccount = Keypair::newFromSeed('SCEDMZ7DUEOUGRQWEXHXEXISQ2NAWI5IDXRHYWT2FHTYLIQOSUK5FX2E'); | ||
|
||
|
||
// Submit to the network | ||
$server->buildTransaction($currentAccount->getPublicKey()) | ||
->bumpSequenceTo(new BigInteger('47061756253569030')) | ||
->submit($currentAccount->getSecret()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
|
||
namespace ZuluCrypto\StellarSdk\Model; | ||
|
||
|
||
use phpseclib\Math\BigInteger; | ||
use ZuluCrypto\StellarSdk\XdrModel\Operation\BumpSequenceOp; | ||
|
||
class BumpSequenceOperation extends Operation | ||
{ | ||
/** | ||
* @var BigInteger | ||
*/ | ||
protected $bumpTo; | ||
|
||
/** | ||
* @param array $rawData | ||
* @return BumpSequenceOp | ||
*/ | ||
public static function fromRawResponseData($rawData) | ||
{ | ||
$object = new BumpSequenceOp($rawData['id'], $rawData['type']); | ||
|
||
$object->loadFromRawResponseData($rawData); | ||
|
||
return $object; | ||
} | ||
|
||
/** | ||
* @param $id | ||
* @param $type | ||
*/ | ||
public function __construct($id, $type) | ||
{ | ||
parent::__construct($id, Operation::TYPE_BUMP_SEQUENCE); | ||
} | ||
|
||
/** | ||
* @param $rawData | ||
*/ | ||
public function loadFromRawResponseData($rawData) | ||
{ | ||
parent::loadFromRawResponseData($rawData); | ||
|
||
$this->bumpTo = new BigInteger($rawData['bump_to']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
|
||
namespace ZuluCrypto\StellarSdk\XdrModel; | ||
|
||
|
||
use ZuluCrypto\StellarSdk\Xdr\XdrBuffer; | ||
|
||
class BumpSequenceResult extends OperationResult | ||
{ | ||
// https://github.com/stellar/stellar-core/blob/master/src/xdr/Stellar-transaction.x#L675 | ||
const BAD_SEQ = 'bump_sequence_bad_seq'; // "bumpTo" is not within bounds | ||
|
||
/** | ||
* @deprecated Do not call this method directly. Instead, use OperationResult::fromXdr | ||
* | ||
* @param XdrBuffer $xdr | ||
* @return OperationResult|PaymentResult | ||
* @throws \ErrorException | ||
*/ | ||
public static function fromXdr(XdrBuffer $xdr) | ||
{ | ||
$model = new BumpSequenceResult(); | ||
|
||
$rawErrorCode = $xdr->readInteger(); | ||
$errorCodeMap = [ | ||
'0' => 'success', | ||
'-1' => static::BAD_SEQ, | ||
]; | ||
if (!isset($errorCodeMap[$rawErrorCode])) { | ||
throw new \ErrorException(sprintf('Unknown error code %s', $rawErrorCode)); | ||
} | ||
|
||
// Do not store the "success" error code | ||
if ($errorCodeMap[$rawErrorCode] !== 'success') { | ||
$model->errorCode = $errorCodeMap[$rawErrorCode]; | ||
} | ||
|
||
return $model; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters