ether-camp / ethereum-harmony

DEPRECATED! Ethereum Independent Peer
GNU General Public License v3.0
253 stars 89 forks source link

toJsonHex with an empty byte array produces "0x" which does not work in the remix IDE #104

Closed tbocek closed 6 years ago

tbocek commented 6 years ago

The problem with "to":"0x" and "value":"0x" is that the remix IDE cannot convert those numbers and addresses and throws the following exception: "Error: new BigNumber() not a base 16 number". For the gettransactionreceipt, the JSON looks as follows:

{"jsonrpc":"2.0","id":63,"result":{"hash":"0x4f2a5...","nonce":"0x00", "blockHash":"0x57698...","blockNumber":"0x2","transactionIndex":"0x0", "from":"0x5c5a...","to":"0x","gas":"0x012118","gasPrice":"0x0ba43b7400", "value":"0x","input":"0x608060405260..."}}

This fix checks if the byte array or the resulting string is empty and if it is the case it returns 0x0 for the value or null for the address. This fixes the issue with the remix IDE

According to https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethgettransactionreceipt, value must be a BigNumber, and "0x" seems not to be a valid BigNumber

tbocek commented 6 years ago

@zilm13 Makes sense to check the other DTOs as well. I have updated my pull request accordingly

zilm13 commented 6 years ago

@tbocek i think we should return 0 for null same way you do for empty array

tbocek commented 6 years ago

@zilm13 I think this does not work. Web3J expects for an address 20 bytes, and when I returned 0x0 for every empty byte array, Web3J threw an IndexOutOfBoundsException. If the address is not valid, then Web3J is fine with that. However, I tested with "0x0" and not "0".

tbocek commented 6 years ago

Ah, got it. I think it does not matter, but probably its better to return 0.

zilm13 commented 6 years ago

@tbocek I've just realized - we are not adding 0x normally in helper, but it's hex data

tbocek commented 6 years ago

@zilm13 What do you mean, every toJsonHex* adds a 0x in TypeConverter?

zilm13 commented 6 years ago

Ahhh i'm blind sorry. Everything is ok, will merge shortly.