blockchain

package
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoHeader is error thrown when there is no header in db.
	ErrNoHeader = errs.New("HeadersDB: header not found")
)

Functions

This section is empty.

Types

type Header struct {
	ChainID   int64
	Hash      common.Hash
	Number    int64
	Timestamp time.Time
}

Header holds ethereum blockchain block header indexed data. No need to keep number as big.Int right now as block count on ethereum mainnet is far from overflowing int64 capacity.

type HeadersCache

type HeadersCache struct {
	// contains filtered or unexported fields
}

HeadersCache cache for blockchain block headers.

func NewHeadersCache

func NewHeadersCache(log *zap.Logger, db HeadersDB) *HeadersCache

NewHeadersCache creates new headers cache.

func (*HeadersCache) Get

func (headersCache *HeadersCache) Get(ctx context.Context, client *ethclient.Client, chainID int64, hash common.Hash) (Header, error)

Get retrieves block header from cache storage or fetches header from client and caches it. TODO: remove direct dependency on go-eth client from public API.

type HeadersDB

type HeadersDB interface {
	// Insert inserts new header to cache db.
	Insert(ctx context.Context, header Header) error
	// Delete deletes header from db by hash.
	Delete(ctx context.Context, ChainID int64, hash common.Hash) error
	// DeleteBefore deletes headers before the given time.
	DeleteBefore(ctx context.Context, before time.Time) (err error)
	// Get retrieves header by hash.
	Get(ctx context.Context, ChainID int64, hash common.Hash) (Header, error)
	// GetByNumber retrieves header by number.
	GetByNumber(ctx context.Context, ChainID int64, number int64) (Header, error)
	// List retrieves all headers stored in cache db.
	List(ctx context.Context) ([]Header, error)
}

HeadersDB is ethereum blockchain block header indexed cache.

architecture: Database

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL