Skip to content

Commit 944ffb2

Browse files
committed
ethclient: Fix RPC parse error of Parity response
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
1 parent ea06da0 commit 944ffb2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

ethclient/ethclient.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
141141
// Fill the sender cache of transactions in the block.
142142
txs := make([]*types.Transaction, len(body.Transactions))
143143
for i, tx := range body.Transactions {
144-
setSenderFromServer(tx.tx, tx.From, body.Hash)
144+
if tx.From != nil {
145+
setSenderFromServer(tx.tx, *tx.From, body.Hash)
146+
}
145147
txs[i] = tx.tx
146148
}
147149
return types.NewBlockWithHeader(head).WithBody(txs, uncles), nil
@@ -174,9 +176,9 @@ type rpcTransaction struct {
174176
}
175177

176178
type txExtraInfo struct {
177-
BlockNumber *string
178-
BlockHash common.Hash
179-
From common.Address
179+
BlockNumber *string `json:"blockNumber,omitempty"`
180+
BlockHash *common.Hash `json:"blockHash,omitempty"`
181+
From *common.Address `json:"from,omitempty"`
180182
}
181183

182184
func (tx *rpcTransaction) UnmarshalJSON(msg []byte) error {
@@ -197,7 +199,9 @@ func (ec *Client) TransactionByHash(ctx context.Context, hash common.Hash) (tx *
197199
} else if _, r, _ := json.tx.RawSignatureValues(); r == nil {
198200
return nil, false, fmt.Errorf("server returned transaction without signature")
199201
}
200-
setSenderFromServer(json.tx, json.From, json.BlockHash)
202+
if json.From != nil && json.BlockHash != nil {
203+
setSenderFromServer(json.tx, *json.From, *json.BlockHash)
204+
}
201205
return json.tx, json.BlockNumber == nil, nil
202206
}
203207

@@ -244,7 +248,9 @@ func (ec *Client) TransactionInBlock(ctx context.Context, blockHash common.Hash,
244248
return nil, fmt.Errorf("server returned transaction without signature")
245249
}
246250
}
247-
setSenderFromServer(json.tx, json.From, json.BlockHash)
251+
if json.From != nil && json.BlockHash != nil {
252+
setSenderFromServer(json.tx, *json.From, *json.BlockHash)
253+
}
248254
return json.tx, err
249255
}
250256

0 commit comments

Comments
 (0)