-
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.
- Loading branch information
Showing
9 changed files
with
231 additions
and
3 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
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
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,67 @@ | ||
<?php | ||
|
||
|
||
namespace ZuluCrypto\StellarSdk\XdrModel\Operation; | ||
|
||
|
||
use phpseclib\Math\BigInteger; | ||
use ZuluCrypto\StellarSdk\Keypair; | ||
use ZuluCrypto\StellarSdk\Xdr\XdrBuffer; | ||
use ZuluCrypto\StellarSdk\Xdr\XdrEncoder; | ||
use ZuluCrypto\StellarSdk\XdrModel\AccountId; | ||
|
||
class BumpSequenceOp extends Operation | ||
{ | ||
|
||
/** @var BigInteger */ | ||
protected $bumpTo; | ||
|
||
public function __construct(BigInteger $bumpTo, $sourceAccountId = null) | ||
{ | ||
parent::__construct(Operation::TYPE_BUMP_SEQUENCE, $sourceAccountId); | ||
|
||
$this->bumpTo = $bumpTo; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function toXdr() | ||
{ | ||
$bytes = parent::toXdr(); | ||
|
||
$bytes .= XdrEncoder::unsignedBigInteger64($this->bumpTo); | ||
|
||
return $bytes; | ||
} | ||
|
||
/** | ||
* NOTE: This only parses the XDR that's specific to this operation and cannot | ||
* load a full Operation | ||
* | ||
* @deprecated Do not call this directly, instead call Operation::fromXdr() | ||
* @param XdrBuffer $xdr | ||
* @return BumpSequenceOp | ||
* @throws \ErrorException | ||
*/ | ||
public static function fromXdr(XdrBuffer $xdr) | ||
{ | ||
return new BumpSequenceOp($xdr->readBigInteger()); | ||
} | ||
|
||
/** | ||
* @return BigInteger | ||
*/ | ||
public function getBumpTo() | ||
{ | ||
return $this->bumpTo; | ||
} | ||
|
||
/** | ||
* @param BigInteger $bumpTo | ||
*/ | ||
public function setBumpTo($bumpTo) | ||
{ | ||
$this->bumpTo = $bumpTo; | ||
} | ||
} |
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,64 @@ | ||
<?php | ||
|
||
|
||
namespace ZuluCrypto\StellarSdk\Test\HardwareWallet; | ||
|
||
|
||
use phpseclib\Math\BigInteger; | ||
use ZuluCrypto\StellarSdk\Keypair; | ||
use ZuluCrypto\StellarSdk\Test\Util\HardwareWalletIntegrationTest; | ||
|
||
class BumpSequenceOpTest extends HardwareWalletIntegrationTest | ||
{ | ||
/** | ||
* @group requires-hardwarewallet | ||
*/ | ||
public function testSimpleBumpSequence() | ||
{ | ||
$sourceKeypair = Keypair::newFromMnemonic($this->mnemonic); | ||
|
||
$bumpTo = new BigInteger(1234567890); | ||
|
||
$transaction = $this->horizonServer | ||
->buildTransaction($sourceKeypair) | ||
->setSequenceNumber(new BigInteger(4294967296)) | ||
->bumpSequenceTo($bumpTo); | ||
|
||
$knownSignature = $transaction->signWith($this->privateKeySigner); | ||
|
||
$this->manualVerificationOutput(join(PHP_EOL, [ | ||
' Bump Sequence: basic', | ||
' Source: ' . $sourceKeypair->getPublicKey(), | ||
' Bump To: ' . $bumpTo->toString(), | ||
])); | ||
$hardwareSignature = $transaction->signWith($this->horizonServer->getSigningProvider()); | ||
|
||
$this->assertEquals($knownSignature->toBase64(), $hardwareSignature->toBase64()); | ||
} | ||
|
||
/** | ||
* @group requires-hardwarewallet | ||
*/ | ||
public function testMaxBumpSequence() | ||
{ | ||
$sourceKeypair = Keypair::newFromMnemonic($this->mnemonic); | ||
|
||
$bumpTo = new BigInteger('9223372036854775807'); | ||
|
||
$transaction = $this->horizonServer | ||
->buildTransaction($sourceKeypair) | ||
->setSequenceNumber(new BigInteger(4294967296)) | ||
->bumpSequenceTo($bumpTo); | ||
|
||
$knownSignature = $transaction->signWith($this->privateKeySigner); | ||
|
||
$this->manualVerificationOutput(join(PHP_EOL, [ | ||
' Bump Sequence: max', | ||
' Source: ' . $sourceKeypair->getPublicKey(), | ||
' Bump To: ' . $bumpTo->toString(), | ||
])); | ||
$hardwareSignature = $transaction->signWith($this->horizonServer->getSigningProvider()); | ||
|
||
$this->assertEquals($knownSignature->toBase64(), $hardwareSignature->toBase64()); | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
|
||
namespace ZuluCrypto\StellarSdk\Test\Unit\XdrModel\Operation; | ||
|
||
|
||
use phpseclib\Math\BigInteger; | ||
use PHPUnit\Framework\TestCase; | ||
use ZuluCrypto\StellarSdk\Xdr\XdrBuffer; | ||
use ZuluCrypto\StellarSdk\XdrModel\Operation\BumpSequenceOp; | ||
use ZuluCrypto\StellarSdk\XdrModel\Operation\Operation; | ||
|
||
class BumpSequenceOpTest extends TestCase | ||
{ | ||
public function testFromXdr() | ||
{ | ||
$source = new BumpSequenceOp(new BigInteger('1234567890')); | ||
|
||
/** @var BumpSequenceOp $parsed */ | ||
$parsed = Operation::fromXdr(new XdrBuffer($source->toXdr())); | ||
|
||
$this->assertTrue($parsed instanceof BumpSequenceOp); | ||
$this->assertEquals($source->getBumpTo()->toString(), $parsed->getBumpTo()->toString()); | ||
} | ||
} |
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