mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 04:57:17 +00:00
3bec75cdc4
* initial * update rpc deamon readme * use read-only transactions
44 lines
1.1 KiB
Go
44 lines
1.1 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/rpc"
|
|
)
|
|
|
|
// GetHeaderByNumber returns a block's header by number
|
|
func (api *TgImpl) GetHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) {
|
|
tx, err := api.db.Begin(ctx, nil, false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer tx.Rollback()
|
|
|
|
header := rawdb.ReadHeaderByNumber(tx, uint64(number.Int64()))
|
|
if header == nil {
|
|
return nil, fmt.Errorf("block header not found: %d", number.Int64())
|
|
}
|
|
|
|
return header, nil
|
|
}
|
|
|
|
// GetHeaderByHash returns a block's header by hash
|
|
func (api *TgImpl) GetHeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) {
|
|
tx, err := api.db.Begin(ctx, nil, false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer tx.Rollback()
|
|
|
|
header := rawdb.ReadHeaderByHash(tx, hash)
|
|
if header == nil {
|
|
return nil, fmt.Errorf("block header not found: %s", hash.String())
|
|
}
|
|
|
|
return header, nil
|
|
}
|