good morning!!!!

Skip to content
Snippets Groups Projects
Commit 15f24ff1 authored by Dmitry Shulyak's avatar Dmitry Shulyak Committed by Felix Lange
Browse files

ethclient: ensure tx json is not nil before accessing it (#19653)

TransactionInBlock crashed if json was nil and there was an error
because it tried to access fields `From` and `BlockHash` of the nil object.
parent 17381ecc
No related branches found
No related tags found
No related merge requests found
......@@ -241,12 +241,13 @@ func (ec *Client) TransactionCount(ctx context.Context, blockHash common.Hash) (
func (ec *Client) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error) {
var json *rpcTransaction
err := ec.c.CallContext(ctx, &json, "eth_getTransactionByBlockHashAndIndex", blockHash, hexutil.Uint64(index))
if err == nil {
if json == nil {
return nil, ethereum.NotFound
} else if _, r, _ := json.tx.RawSignatureValues(); r == nil {
return nil, fmt.Errorf("server returned transaction without signature")
}
if err != nil {
return nil, err
}
if json == nil {
return nil, ethereum.NotFound
} else if _, r, _ := json.tx.RawSignatureValues(); r == nil {
return nil, fmt.Errorf("server returned transaction without signature")
}
if json.From != nil && json.BlockHash != nil {
setSenderFromServer(json.tx, *json.From, *json.BlockHash)
......
......@@ -301,3 +301,21 @@ func TestBalanceAt(t *testing.T) {
})
}
}
func TestTransactionInBlockInterrupted(t *testing.T) {
backend, _ := newTestBackend(t)
client, _ := backend.Attach()
defer backend.Stop()
defer client.Close()
ec := NewClient(client)
ctx, cancel := context.WithCancel(context.Background())
cancel()
tx, err := ec.TransactionInBlock(ctx, common.Hash{1}, 1)
if tx != nil {
t.Fatal("transaction should be nil")
}
if err == nil {
t.Fatal("error should not be nil")
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment