Skip to content

Commit

Permalink
TransactionBuilder - sequenceNumber is now always a BigInteger
Browse files Browse the repository at this point in the history
  • Loading branch information
zulucrypto committed Sep 22, 2018
1 parent a7d25da commit 304fe45
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions src/Transaction/TransactionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,20 +380,16 @@ public function toXdr()
{
$bytes = '';

// todo: $sequenceNumber should always be a BigInteger
if ($this->sequenceNumber) {
$sequenceNumber = $this->sequenceNumber->toString();
}
else {
$sequenceNumber = $this->generateSequenceNumber();
if (!$this->sequenceNumber) {
$this->sequenceNumber = $this->generateSequenceNumber();
}

// Account ID (36 bytes)
$bytes .= $this->accountId->toXdr();
// Fee (4 bytes)
$bytes .= XdrEncoder::unsignedInteger($this->getFee());
// Sequence number (8 bytes)
$bytes .= XdrEncoder::unsignedInteger64($sequenceNumber);
$bytes .= XdrEncoder::unsignedBigInteger64($this->sequenceNumber);

// Time Bounds are optional
if ($this->timeBounds->isEmpty()) {
Expand Down Expand Up @@ -525,25 +521,7 @@ protected function generateSequenceNumber()
throw new \ErrorException(sprintf('Account not found: %s', $this->accountId->getAccountIdString()));
}

try {
return $this->apiClient
->getAccount($this->accountId->getAccountIdString())
->getSequence() + 1
;
} catch (HorizonException $e) {
$e->getTraceAsString();

print "**************\n" . $e->getTraceAsString() . "\n****************\n";

throw new \ErrorException(
sprintf('Could not get sequence number for %s, does this account exist?', $this->accountId->getAccountIdString()),
$e->getCode(),
$e->getSeverity(),
__FILE__,
__LINE__,
$e
);
}
return $account->getSequenceAsBigInteger()->add(new BigInteger(1));
}

protected function ensureApiClient()
Expand Down Expand Up @@ -601,6 +579,10 @@ public function getSequenceNumber()
*/
public function setSequenceNumber($sequenceNumber)
{
if (!is_a($sequenceNumber, 'phpseclib\Math\BigInteger')) {
$sequenceNumber = new BigInteger($sequenceNumber);
}

$this->sequenceNumber = $sequenceNumber;

return $this;
Expand Down

0 comments on commit 304fe45

Please sign in to comment.