base

package
v0.0.0-...-2da98db Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvVarLatestBlock is the environment variable that forces the observer to scan from the latest block
	EnvVarLatestBlock = "latest"

	// DefaultBlockCacheSize is the default number of blocks that the observer will keep in cache for performance (without RPC calls)
	// Cached blocks can be used to get block information and verify transactions
	DefaultBlockCacheSize = 1000

	// DefaultHeaderCacheSize is the default number of headers that the observer will keep in cache for performance (without RPC calls)
	// Cached headers can be used to get header information
	DefaultHeaderCacheSize = 1000
)
View Source
const (
	ComplianceLogFile = "compliance.log"
)

Variables

This section is empty.

Functions

func EnvVarLatestBlockByChain

func EnvVarLatestBlockByChain(chain chains.Chain) string

EnvVarLatestBlock returns the environment variable for the latest block by chain.

Types

type Logger

type Logger struct {
	Std        zerolog.Logger
	Compliance zerolog.Logger
}

Logger contains the base loggers

func DefaultLogger

func DefaultLogger() Logger

DefaultLoggers creates default base loggers for tests

func InitLogger

func InitLogger(cfg config.Config) (Logger, error)

InitLogger initializes the base loggers

type Observer

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

Observer is the base structure for chain observers, grouping the common logic for each chain observer client. The common logic includes: chain, chainParams, contexts, zetacore client, tss, lastBlock, db, metrics, loggers etc.

func NewObserver

func NewObserver(
	chain chains.Chain,
	chainParams observertypes.ChainParams,
	zetacoreClient interfaces.ZetacoreClient,
	tss interfaces.TSSSigner,
	blockCacheSize int,
	headerCacheSize int,
	ts *metrics.TelemetryServer,
	logger Logger,
) (*Observer, error)

NewObserver creates a new base observer.

func (*Observer) BlockCache

func (ob *Observer) BlockCache() *lru.Cache

BlockCache returns the block cache for the observer.

func (*Observer) Chain

func (ob *Observer) Chain() chains.Chain

Chain returns the chain for the observer.

func (*Observer) ChainParams

func (ob *Observer) ChainParams() observertypes.ChainParams

ChainParams returns the chain params for the observer.

func (*Observer) CloseDB

func (ob *Observer) CloseDB() error

CloseDB close the database.

func (*Observer) DB

func (ob *Observer) DB() *gorm.DB

DB returns the database for the observer.

func (*Observer) HeaderCache

func (ob *Observer) HeaderCache() *lru.Cache

HeaderCache returns the header cache for the observer.

func (*Observer) LastBlock

func (ob *Observer) LastBlock() uint64

LastBlock get external last block height.

func (*Observer) LastBlockScanned

func (ob *Observer) LastBlockScanned() uint64

LastBlockScanned get last block scanned (not necessarily caught up with the chain; could be slow/paused).

func (*Observer) LoadLastBlockScanned

func (ob *Observer) LoadLastBlockScanned(logger zerolog.Logger) error

LoadLastBlockScanned loads last scanned block from environment variable or from database. The last scanned block is the height from which the observer should continue scanning.

func (*Observer) Logger

func (ob *Observer) Logger() *ObserverLogger

Logger returns the logger for the observer.

func (*Observer) Mu

func (ob *Observer) Mu() *sync.Mutex

Mu returns the mutex for the observer.

func (*Observer) OpenDB

func (ob *Observer) OpenDB(dbPath string, dbName string) error

OpenDB open sql database in the given path.

func (*Observer) ReadLastBlockScannedFromDB

func (ob *Observer) ReadLastBlockScannedFromDB() (uint64, error)

ReadLastBlockScannedFromDB reads the last scanned block from the database.

func (*Observer) SaveLastBlockScanned

func (ob *Observer) SaveLastBlockScanned(blockNumber uint64) error

SaveLastBlockScanned saves the last scanned block to memory and database.

func (*Observer) Stop

func (ob *Observer) Stop()

Stop notifies all goroutines to stop and closes the database.

func (*Observer) StopChannel

func (ob *Observer) StopChannel() chan struct{}

StopChannel returns the stop channel for the observer.

func (*Observer) TSS

func (ob *Observer) TSS() interfaces.TSSSigner

Tss returns the tss signer for the observer.

func (*Observer) TelemetryServer

func (ob *Observer) TelemetryServer() *metrics.TelemetryServer

TelemetryServer returns the telemetry server for the observer.

func (*Observer) WithBlockCache

func (ob *Observer) WithBlockCache(cache *lru.Cache) *Observer

WithBlockCache attaches a new block cache to the observer.

func (*Observer) WithChain

func (ob *Observer) WithChain(chain chains.Chain) *Observer

WithChain attaches a new chain to the observer.

func (*Observer) WithChainParams

func (ob *Observer) WithChainParams(params observertypes.ChainParams) *Observer

WithChainParams attaches a new chain params to the observer.

func (*Observer) WithHeaderCache

func (ob *Observer) WithHeaderCache(cache *lru.Cache) *Observer

WithHeaderCache attaches a new header cache to the observer.

func (*Observer) WithLastBlock

func (ob *Observer) WithLastBlock(lastBlock uint64) *Observer

WithLastBlock set external last block height.

func (*Observer) WithLastBlockScanned

func (ob *Observer) WithLastBlockScanned(blockNumber uint64) *Observer

WithLastBlockScanned set last block scanned (not necessarily caught up with the chain; could be slow/paused).

func (*Observer) WithLogger

func (ob *Observer) WithLogger(logger Logger) *Observer

WithLogger attaches a new logger to the observer.

func (*Observer) WithTSS

func (ob *Observer) WithTSS(tss interfaces.TSSSigner) *Observer

WithTSS attaches a new tss signer to the observer.

func (*Observer) WithTelemetryServer

func (ob *Observer) WithTelemetryServer(ts *metrics.TelemetryServer) *Observer

WithTelemetryServer attaches a new telemetry server to the observer.

func (*Observer) WithZetacoreClient

func (ob *Observer) WithZetacoreClient(client interfaces.ZetacoreClient) *Observer

WithZetacoreClient attaches a new zetacore client to the observer.

func (*Observer) WriteLastBlockScannedToDB

func (ob *Observer) WriteLastBlockScannedToDB(lastScannedBlock uint64) error

WriteLastBlockScannedToDB saves the last scanned block to the database.

func (*Observer) ZetacoreClient

func (ob *Observer) ZetacoreClient() interfaces.ZetacoreClient

ZetacoreClient returns the zetacore client for the observer.

type ObserverLogger

type ObserverLogger struct {
	// the parent logger for the chain observer
	Chain zerolog.Logger

	// the logger for inbound transactions
	Inbound zerolog.Logger

	// the logger for outbound transactions
	Outbound zerolog.Logger

	// the logger for the chain's gas price
	GasPrice zerolog.Logger

	// the logger for block headers
	Headers zerolog.Logger

	// the logger for the compliance check
	Compliance zerolog.Logger
}

ObserverLogger contains the loggers for chain observers

type Signer

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

Signer is the base structure for grouping the common logic between chain signers. The common logic includes: chain, chainParams, contexts, tss, metrics, loggers etc.

func NewSigner

func NewSigner(chain chains.Chain, tss interfaces.TSSSigner, ts *metrics.TelemetryServer, logger Logger) *Signer

NewSigner creates a new base signer

func (*Signer) Chain

func (s *Signer) Chain() chains.Chain

Chain returns the chain for the signer

func (*Signer) Lock

func (s *Signer) Lock()

Lock locks the signer

func (*Signer) Logger

func (s *Signer) Logger() *Logger

Logger returns the logger for the signer

func (*Signer) TSS

func (s *Signer) TSS() interfaces.TSSSigner

Tss returns the tss signer for the signer

func (*Signer) TelemetryServer

func (s *Signer) TelemetryServer() *metrics.TelemetryServer

TelemetryServer returns the telemetry server for the signer

func (*Signer) Unlock

func (s *Signer) Unlock()

Unlock unlocks the signer

func (*Signer) WithChain

func (s *Signer) WithChain(chain chains.Chain) *Signer

WithChain attaches a new chain to the signer

func (*Signer) WithTSS

func (s *Signer) WithTSS(tss interfaces.TSSSigner) *Signer

WithTSS attaches a new tss signer to the signer

func (*Signer) WithTelemetryServer

func (s *Signer) WithTelemetryServer(ts *metrics.TelemetryServer) *Signer

WithTelemetryServer attaches a new telemetry server to the signer

Jump to

Keyboard shortcuts

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