diff options
author | Steven Roose <stevenroose@gmail.com> | 2018-06-11 15:41:09 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-06-11 15:41:09 +0800 |
commit | 69c52bde3f5e48a3b74264bf4854e9768ede75b2 (patch) | |
tree | 7d5d6335fe63d3d8469214837d10f6e58ee51249 | |
parent | 2977538ac0c1157cc140c2df9b0c54e00441d935 (diff) | |
download | go-tangerine-69c52bde3f5e48a3b74264bf4854e9768ede75b2.tar.gz go-tangerine-69c52bde3f5e48a3b74264bf4854e9768ede75b2.tar.zst go-tangerine-69c52bde3f5e48a3b74264bf4854e9768ede75b2.zip |
ethclient: fix RPC parse error of Parity response (#16924)
The error produced when using a Parity RPC was the following:
ERROR: transaction did not get mined: failed to get tx for txid 0xbdeb094b3278019383c8da148ff1cb5b5dbd61bf8731bc2310ac1b8ed0235226: json: cannot unmarshal non-string into Go struct field txExtraInfo.blockHash of type common.Hash
-rw-r--r-- | ethclient/ethclient.go | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index b48224587..b40837c8c 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -141,7 +141,9 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface // Fill the sender cache of transactions in the block. txs := make([]*types.Transaction, len(body.Transactions)) for i, tx := range body.Transactions { - setSenderFromServer(tx.tx, tx.From, body.Hash) + if tx.From != nil { + setSenderFromServer(tx.tx, *tx.From, body.Hash) + } txs[i] = tx.tx } return types.NewBlockWithHeader(head).WithBody(txs, uncles), nil @@ -174,9 +176,9 @@ type rpcTransaction struct { } type txExtraInfo struct { - BlockNumber *string - BlockHash common.Hash - From common.Address + BlockNumber *string `json:"blockNumber,omitempty"` + BlockHash *common.Hash `json:"blockHash,omitempty"` + From *common.Address `json:"from,omitempty"` } func (tx *rpcTransaction) UnmarshalJSON(msg []byte) error { @@ -197,7 +199,9 @@ func (ec *Client) TransactionByHash(ctx context.Context, hash common.Hash) (tx * } else if _, r, _ := json.tx.RawSignatureValues(); r == nil { return nil, false, fmt.Errorf("server returned transaction without signature") } - setSenderFromServer(json.tx, json.From, json.BlockHash) + if json.From != nil && json.BlockHash != nil { + setSenderFromServer(json.tx, *json.From, *json.BlockHash) + } return json.tx, json.BlockNumber == nil, nil } @@ -244,7 +248,9 @@ func (ec *Client) TransactionInBlock(ctx context.Context, blockHash common.Hash, return nil, fmt.Errorf("server returned transaction without signature") } } - setSenderFromServer(json.tx, json.From, json.BlockHash) + if json.From != nil && json.BlockHash != nil { + setSenderFromServer(json.tx, *json.From, *json.BlockHash) + } return json.tx, err } |