mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
This commit is contained in:
parent
47520a1316
commit
bd1d41d3bc
1 changed files with 29 additions and 6 deletions
|
|
@ -86,11 +86,22 @@ func (ec *Client) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo
|
|||
return ec.getBlock(ctx, "eth_getBlockByHash", hash, true)
|
||||
}
|
||||
|
||||
// BlockByNumber returns a block from the current canonical chain. If number is nil, the
|
||||
// latest known block is returned.
|
||||
// BlockByNumber returns a block from the current canonical chain.
|
||||
// If `number` is nil, the latest known block is returned.
|
||||
//
|
||||
// Note that loading full blocks requires two requests. Use HeaderByNumber
|
||||
// if you don't need all transactions or uncle headers.
|
||||
// Use `HeaderByNumber` if you don't need full transaction data or uncle headers.
|
||||
//
|
||||
// Supported special block number tags:
|
||||
// - `earliest` : The genesis (earliest) block
|
||||
// - `latest` : The most recently included block
|
||||
// - `committed` : The latest committed block
|
||||
// - `pending` : The pending block
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
// ```go
|
||||
// BlockByNumber(context.Background(), big.NewInt(int64(rpc.LatestBlockNumber)))
|
||||
// ```
|
||||
func (ec *Client) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) {
|
||||
return ec.getBlock(ctx, "eth_getBlockByNumber", toBlockNumArg(number), true)
|
||||
}
|
||||
|
|
@ -204,8 +215,20 @@ func (ec *Client) HeaderByHash(ctx context.Context, hash common.Hash) (*types.He
|
|||
return head, err
|
||||
}
|
||||
|
||||
// HeaderByNumber returns a block header from the current canonical chain. If number is
|
||||
// nil, the latest known header is returned.
|
||||
// HeaderByNumber returns a block header from the current canonical chain.
|
||||
// If `number` is nil, the latest known block header is returned.
|
||||
//
|
||||
// Supported special block number tags:
|
||||
// - `earliest` : The genesis (earliest) block
|
||||
// - `latest` : The most recently included block
|
||||
// - `committed` : The latest committed block
|
||||
// - `pending` : The pending block
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
// ```go
|
||||
// HeaderByNumber(context.Background(), big.NewInt(int64(rpc.LatestBlockNumber)))
|
||||
// ```
|
||||
func (ec *Client) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) {
|
||||
var head *types.Header
|
||||
err := ec.c.CallContext(ctx, &head, "eth_getBlockByNumber", toBlockNumArg(number), false)
|
||||
|
|
|
|||
Loading…
Reference in a new issue