Skip to content

Commit

Permalink
implemented BumpSequenceOp
Browse files Browse the repository at this point in the history
  • Loading branch information
zulucrypto committed Mar 31, 2018
1 parent 5007960 commit b30dad9
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/XdrModel/Operation/BumpSequenceOp.php
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;
}
}
4 changes: 4 additions & 0 deletions src/XdrModel/Operation/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ abstract class Operation implements XdrEncodableInterface
const TYPE_ACCOUNT_MERGE = 8;
const TYPE_INFLATION = 9;
const TYPE_MANAGE_DATA = 10;
const TYPE_BUMP_SEQUENCE = 11;

/**
* @var AccountId
Expand Down Expand Up @@ -151,6 +152,9 @@ public static function fromXdr(XdrBuffer $xdr)
case Operation::TYPE_MANAGE_DATA:
$model = ManageDataOp::fromXdr($xdr);
break;
case Operation::TYPE_BUMP_SEQUENCE:
$model = BumpSequenceOp::fromXdr($xdr);
break;
default:
throw new \InvalidArgumentException(sprintf('unrecognized operation type %s', $type));
}
Expand Down
25 changes: 25 additions & 0 deletions tests/Unit/XdrModel/Operation/BumpSequenceOpTest.php
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());
}
}

0 comments on commit b30dad9

Please sign in to comment.