diff --git a/src/Transactions/Deserializer.php b/src/Transactions/Deserializer.php index 984f410..afb8ee4 100644 --- a/src/Transactions/Deserializer.php +++ b/src/Transactions/Deserializer.php @@ -15,8 +15,6 @@ class Deserializer /** * Create a new deserializer instance. - * - * @param object $serialized */ public function __construct(string $serialized) { @@ -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; @@ -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 diff --git a/src/Transactions/Serializer.php b/src/Transactions/Serializer.php index 3b1f024..09aea41 100644 --- a/src/Transactions/Serializer.php +++ b/src/Transactions/Serializer.php @@ -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']); } diff --git a/tests/Unit/Transactions/Builder/EvmCallBuilderTest.php b/tests/Unit/Transactions/Builder/EvmCallBuilderTest.php index d2261e2..27353a3 100644 --- a/tests/Unit/Transactions/Builder/EvmCallBuilderTest.php +++ b/tests/Unit/Transactions/Builder/EvmCallBuilderTest.php @@ -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()); @@ -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);