Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsobries committed Oct 24, 2024
1 parent 1b26027 commit 3352037
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
12 changes: 5 additions & 7 deletions src/Transactions/Deserializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class Deserializer

/**
* Create a new deserializer instance.
*
* @param object $serialized
*/
public function __construct(string $serialized)
{
Expand Down Expand Up @@ -51,10 +49,6 @@ public function deserialize(): Transaction

$this->deserializeSignatures($transaction->data);

if (! isset($transaction->data['amount'])) {
$transaction->data['amount'] = '0';
}

$transaction->data['id'] = Hash::sha256($transaction->serialize())->getHex();

return $transaction;
Expand All @@ -63,11 +57,15 @@ public function deserialize(): Transaction
private function deserializeCommon(array &$data): void
{
$this->buffer->skip(1);

$data['version'] = $this->buffer->readUInt8();
$data['network'] = $this->buffer->readUInt8();
$data['typeGroup'] = $this->buffer->readUInt32();
$data['type'] = $this->buffer->readUInt16();
$data['nonce'] = strval($this->buffer->readUInt64());
$data['senderPublicKey'] = $this->buffer->readHex(33 * 2);
$data['gasPrice'] = $this->buffer->readUInt256();
$data['fee'] = $this->buffer->readUInt256();
$data['amount'] = '0';
}

private function deserializeSignatures(array &$data): void
Expand Down
12 changes: 3 additions & 9 deletions src/Transactions/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,15 @@ public function serializeSignatures(ByteBuffer $buffer, array $options): void

private function serializeCommon(ByteBuffer $buffer): void
{
$this->transaction->data['version'] = $this->transaction->data['version'] ?? 0x01;

if (! isset($this->transaction->data['typeGroup'])) {
$this->transaction->data['typeGroup'] = TypeGroup::CORE;
}

$buffer->writeUInt8(0xff);
$buffer->writeUInt8($this->transaction->data['version']);
$buffer->writeUInt8($this->transaction->data['version'] ?? 0x01);
$buffer->writeUInt8($this->transaction->data['network'] ?? Network::version());

$buffer->writeUint32($this->transaction->data['typeGroup']);
$buffer->writeUint32($this->transaction->data['typeGroup'] ?? TypeGroup::CORE);
$buffer->writeUint16($this->transaction->data['type']);
$buffer->writeUint64(+$this->transaction->data['nonce']);

if (isset($this->transaction->data['senderPublicKey'])) {
if ($this->transaction->data['senderPublicKey']) {
$buffer->writeHex($this->transaction->data['senderPublicKey']);
}

Expand Down
16 changes: 8 additions & 8 deletions tests/Unit/Transactions/Builder/EvmCallBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public function it_should_sign_it_with_a_passphrase()
$fixture = $this->getTransactionFixture('evm_call', 'evm-sign');

$builder = EvmCallBuilder::new()
->withFee($fixture['data']['fee'])
->withNonce($fixture['data']['nonce'])
->withNetwork(30)
->fee($fixture['data']['fee'])
->nonce($fixture['data']['nonce'])
->network(30)
->payload($fixture['data']['asset']['evmCall']['payload'])
->withGasLimit($fixture['data']['asset']['evmCall']['gasLimit'])
->gasLimit($fixture['data']['asset']['evmCall']['gasLimit'])
->sign($this->passphrase);

$this->assertTrue($builder->verify());
Expand All @@ -34,11 +34,11 @@ public function it_should_sign_it_with_a_passphrase_and_contract()
$fixture = $this->getTransactionFixture('evm_call', 'evm-with-contract');

$builder = EvmCallBuilder::new()
->withFee($fixture['data']['fee'])
->withNonce($fixture['data']['nonce'])
->withNetwork(30)
->fee($fixture['data']['fee'])
->nonce($fixture['data']['nonce'])
->network(30)
->payload($fixture['data']['asset']['evmCall']['payload'])
->withGasLimit($fixture['data']['asset']['evmCall']['gasLimit'])
->gasLimit($fixture['data']['asset']['evmCall']['gasLimit'])
// RecipientId is the contractId
->recipient($fixture['data']['recipientId'])
->sign($this->passphrase);
Expand Down

0 comments on commit 3352037

Please sign in to comment.