digitaldonkey / ethereum-php

PHP interface to Ethereum JSON-RPC API. Fully typed Web3 for PHP 7.X
http://ethereum-php.org
MIT License
491 stars 176 forks source link

Exception on eth_getTransactionReceipt #37

Closed sebnyc closed 6 years ago

sebnyc commented 6 years ago

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 ...

sebnyc commented 6 years ago

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 ?

digitaldonkey commented 6 years ago

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.

https://github.com/digitaldonkey/ethereum-php/blob/f0ead696e7fe7f0e01ffcffeb6374ad3a8085f27/src/helpers/ethereum-client-workaround-helpers.php#L43-L54

sebnyc commented 6 years ago

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

digitaldonkey commented 6 years ago

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?

sebnyc commented 6 years ago

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.

digitaldonkey commented 6 years ago

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. https://github.com/digitaldonkey/ethereum-php/commit/ded4eb341d8962eac226fdb0ba93b6cc690a7bc1

Can you confirm @sebnyc ?

sebnyc commented 6 years ago

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