mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
ethclient: Adding TransactionExtraInfoByHash method to the Client Struct
As a helper, I'm introducing the TransactionExtraInfoByHash that mimics the TransactionByHash method, but only returns the block hash and sender's address.
This commit is contained in:
parent
dcae0d348b
commit
b23399f4d9
1 changed files with 19 additions and 0 deletions
|
|
@ -205,6 +205,25 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TransactionExtraInfoByHash returns the transaction's extra info with the given hash.
|
||||||
|
func (ec *Client) TransactionExtraInfoByHash(ctx context.Context, hash common.Hash) (blockHash *common.Hash, from *common.Address, err error) {
|
||||||
|
var json *rpcTransaction
|
||||||
|
|
||||||
|
err = ec.c.CallContext(ctx, &json, "eth_getTransactionByHash", hash)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
} else if json == nil {
|
||||||
|
return nil, nil, ethereum.NotFound
|
||||||
|
} else if _, r, _ := json.tx.RawSignatureValues(); r == nil {
|
||||||
|
return nil, nil, fmt.Errorf("server returned transaction without signature")
|
||||||
|
}
|
||||||
|
if json.From != nil && json.BlockHash != nil {
|
||||||
|
setSenderFromServer(json.tx, *json.From, *json.BlockHash)
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.BlockHash, json.From, 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.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue