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.
This commit is contained in:
		
				
					committed by
					
						
						Felix Lange
					
				
			
			
				
	
			
			
			
						parent
						
							17381ecc66
						
					
				
				
					commit
					15f24ff189
				
			@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user