mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-09 20:41:20 +00:00
0c91bfbf3e
* clean * save * pubsub * pubsub * pubsub * pubsub * pubsub * pubsub * save * tx pub-sub * tx pub-sub * clean * clean * save * save * save * save * save * Squashed 'interfaces/' content from commit c469f3ae0 git-subtree-dir: interfaces git-subtree-split: c469f3ae073b60c8821b61fed2910191080ef835 * save * save * save * save * Squashed 'interfaces/' changes from c469f3ae0..958dfc669 958dfc669 save git-subtree-dir: interfaces git-subtree-split: 958dfc669f8daeefe686a13aa852fb95f1537886 * save * save * up some deps * up some deps * clean * test * test * test * test * test * test * test * test * test * test * test * test
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
"github.com/ledgerwatch/turbo-geth/core/rawdb"
|
|
"github.com/ledgerwatch/turbo-geth/core/types"
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
|
"github.com/ledgerwatch/turbo-geth/rpc"
|
|
)
|
|
|
|
// GetHeaderByNumber implements tg_getHeaderByNumber. Returns a block's header given a block number ignoring the block's transaction and uncle list (may be faster).
|
|
func (api *TgImpl) GetHeaderByNumber(ctx context.Context, blockNumber rpc.BlockNumber) (*types.Header, error) {
|
|
// Pending block is only known by the miner
|
|
if blockNumber == rpc.PendingBlockNumber {
|
|
block := api.pendingBlock()
|
|
if block == nil {
|
|
return nil, nil
|
|
}
|
|
return block.Header(), nil
|
|
}
|
|
|
|
tx, err := api.db.BeginRo(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer tx.Rollback()
|
|
|
|
header := rawdb.ReadHeaderByNumber(ethdb.NewRoTxDb(tx), uint64(blockNumber.Int64()))
|
|
if header == nil {
|
|
return nil, fmt.Errorf("block header not found: %d", blockNumber.Int64())
|
|
}
|
|
|
|
return header, nil
|
|
}
|
|
|
|
// GetHeaderByHash implements tg_getHeaderByHash. Returns a block's header given a block's hash.
|
|
func (api *TgImpl) GetHeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) {
|
|
tx, err := api.db.BeginRo(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer tx.Rollback()
|
|
|
|
header, err := rawdb.ReadHeaderByHash(ethdb.NewRoTxDb(tx), hash)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if header == nil {
|
|
return nil, fmt.Errorf("block header not found: %s", hash.String())
|
|
}
|
|
|
|
return header, nil
|
|
}
|