digitaldonkey/ethereum-php

Exception on eth_getTransactionReceipt

sebnyc opened this issue · 7 comments

When a transaction receipt has a log array that includes a data value of "0x", it triggers an exception

Try with :
$tr = $eth->eth_getTransactionReceipt(new EthD32("0xee04d9e2258909ca642acde0612597732f4ba244952e23eb83ecac3fe8dd5091"));

You should get this exception :
InvalidArgumentException : Value of dynamic ABI type is not a valid hex string.

at /var/www/vendor/digitaldonkey/ethereum-php/src/DataType/EthBytes.php:36
32| */
33| public function validate($val, array $params)
34| {
35| if (!ctype_xdigit($this->removeHexPrefix($val))) {
36| throw new \InvalidArgumentException(
37| 'Value of dynamic ABI type is not a valid hex string.'
38| );
39| }
40| return $this->ensureHexPrefix($val);

Exception trace:

1 Ethereum\DataType\EthBytes::validate("0x", [])
/var/www/vendor/digitaldonkey/ethereum-php/src/DataType/EthDataType.php:239

2 Ethereum\DataType\EthDataType::setValue("0x", [])
/var/www/vendor/digitaldonkey/ethereum-php/src/DataType/EthD.php:145

3 Ethereum\DataType\EthD::__construct("0x")
/var/www/vendor/digitaldonkey/ethereum-php/src/Ethereum.php:522

4 Ethereum\Ethereum::arrayToComplexType("\Ethereum\DataType\FilterChange")
/var/www/vendor/digitaldonkey/ethereum-php/src/Ethereum.php:513

5 Ethereum\Ethereum::arrayToComplexType("\Ethereum\DataType\Receipt")
/var/www/vendor/digitaldonkey/ethereum-php/src/Ethereum.php:284
...

It looks like EthBytes class considers "0x" as an invalid value because ctype_xdigit("") returns false.
@digitaldonkey do you think we can modify this validate() function and safely allow "0x" values with a simple check on $val length ?

I ran into this more often. Which Ethereum client are you using?
Some clients return "0x" others just null ...

Would be great to have a workaround which tackles this issue in general.

/**
* Workaround for Ethereum\DataType\Transaction.
*
* Fixing the "to" address field might be "0x0" instead of null.
*/
function eth_workaround_ethereum_datatype_transaction(array $values)
{
if (isset($values['to']) && $values['to'] === '0x0') {
$values['to'] = null;
}
return $values;
}

@digitaldonkey I'm using Parity 2.0.1 beta.
What would be the correct value instead of "0x" ?

I actually don't know. I don't know any specification on empty return values.
Considering the log entry is null not 0 the whole data should be null instead of EthD to be consistent.
What you think?

Well, I'm not sure about that but I would propose to convert data to null in a
function eth_workaround_ethereum_datatype_filterchange(array $values) when it has this 0xvalue.

For reference:
"WRONG: 0x (should always have at least one digit - zero is "0x0")"
https://ethereum.gitbooks.io/frontier-guide/content/rpc.html#output-hex-values

As far as I remember we fixed this. Added a Test in dev.
ded4eb3

Can you confirm @sebnyc ?

@digitaldonkey Yes, it's part of the pull request you have merged yesterday. Now "0x" is replaced by null.