ethclient: BlockNumberByTransactionHash fixes #15210

This commit is contained in:
Jean-André Santoni 2018-01-10 20:09:00 +07:00
parent 7a59a9380e
commit eab15200c2

View file

@ -193,6 +193,21 @@ func (ec *Client) TransactionByHash(ctx context.Context, hash common.Hash) (tx *
return json.tx, json.BlockNumber == nil, nil return json.tx, json.BlockNumber == nil, nil
} }
// BlockNumberByTransactionHash returns block number for the transaction with the given hash.
func (ec *Client) BlockNumberByTransactionHash(ctx context.Context, hash common.Hash) (blockNumber *string, err error) {
var json *rpcTransaction
err = ec.c.CallContext(ctx, &json, "eth_getTransactionByHash", hash)
if err != nil {
return nil, err
} else if json == nil {
return nil, ethereum.NotFound
} else if _, r, _ := json.tx.RawSignatureValues(); r == nil {
return nil, fmt.Errorf("server returned transaction without signature")
}
setSenderFromServer(json.tx, json.From, json.BlockHash)
return json.BlockNumber, nil
}
// TransactionSender returns the sender address of the given transaction. The transaction // TransactionSender returns the sender address of the given transaction. The transaction
// must be known to the remote node and included in the blockchain at the given block and // must be known to the remote node and included in the blockchain at the given block and
// index. The sender is the one derived by the protocol at the time of inclusion. // index. The sender is the one derived by the protocol at the time of inclusion.