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 ¶
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
Click to show internal directories.
Click to hide internal directories.