TokenMint icon indicating copy to clipboard operation
TokenMint copied to clipboard

Potential problem with batch JSON-RPC request

Open gagarin55 opened this issue 7 years ago • 1 comments

You may have an issue with this code

rpc.getTransactionData(address).then((result) => {
            const balance = new BigNumber(result[0].result).toString();
            const gasPrice = result[1].result;
            const nonce = result[2].result;

https://github.com/ethereumproject/TokenMint/blob/master/src/store/transactionActions.js#L11

According to JSON-RPC specification (http://www.jsonrpc.org/specification):

The Response objects being returned from a batch call MAY be returned in any order within the Array

So, there is no order in result.

In emerald-js library I suggest following implementation for batch requests - https://github.com/ethereumproject/emerald-js/blob/master/src/rpc/jsonrpc.js#L73

You can check example in tests - https://github.com/ethereumproject/emerald-js/blob/master/src/rpc/jsonrpc.test.js#L5

The idea is that we map handler for each response by request id.

Much appreciate any comments and suggestions!

gagarin55 avatar Sep 12 '17 20:09 gagarin55

@gagarin55 I think that is a reasonable solution. The current batch API is used because it matches Epool's mewapi. Gastracker API does not support batch requests right now, I think. It would be good to standardize batch requests.

elaineo avatar Sep 14 '17 10:09 elaineo