blockchain

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const AddrLength = 20

AddrLength is byte length of eth account address.

Variables

View Source
var ErrAddrLength = errs.Class(fmt.Sprintf("Address must be %v bytes in length", AddrLength))

ErrAddrLength represents the error that the address is the wrong length.

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 Address

type Address = common.Address

Address is wallet address on eth chain.

func AddressFromBytes

func AddressFromBytes(byteAddr []byte) (Address, error)

AddressFromBytes creates a new address from hex bytes.

func AddressFromHex

func AddressFromHex(hex string) (Address, error)

AddressFromHex creates new address from hex string.

type Hash

type Hash = common.Hash

Hash represent cryptographic hash.

func HashFromBytes

func HashFromBytes(b []byte) Hash

HashFromBytes creates hash from byte slice.

type Header struct {
	ChainID   int64
	Hash      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 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 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 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