blockchain

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxConcurrentRequests = 64
	BestGuessConcurrency  = 32
)

MaxConcurrentRequests the blockchain mempool can usually only hold 64 transactions from the same fromAddress

View Source
const (
	BACKFILL_BLOCKS = uint64(1000)
	// Don't index very new blocks to account for reorgs
	// Setting to 0 since we are talking about L2s with low reorg risk
	LAG_FROM_HIGHEST_BLOCK = uint64(0)
	ERROR_SLEEP_TIME       = 100 * time.Millisecond
	NO_LOGS_SLEEP_TIME     = 1 * time.Second
)

Variables

This section is empty.

Functions

func ExecuteTransaction added in v0.3.0

func ExecuteTransaction(
	ctx context.Context,
	signer TransactionSigner,
	logger *zap.Logger,
	client *ethclient.Client,
	txFunc func(*bind.TransactOpts) (*types.Transaction, error),
	eventParser func(*types.Log) (interface{}, error),
	logHandler func(interface{}),
) error

ExecuteTransaction is a helper function that: - executes a transaction - waits for it to be mined - processes the event logs

func NewClient

func NewClient(ctx context.Context, rpcUrl string) (*ethclient.Client, error)

func NewNodeRegistryAdmin

func NewNodeRegistryAdmin(
	logger *zap.Logger,
	client *ethclient.Client,
	signer TransactionSigner,
	contractsOptions config.ContractsOptions,
) (*nodeRegistryAdmin, error)

func WaitForTransaction

func WaitForTransaction(
	ctx context.Context,
	logger *zap.Logger,
	client *ethclient.Client,
	timeout time.Duration,
	pollSleep time.Duration,
	hash common.Hash,
) (*types.Receipt, error)

Waits for the given transaction hash to have been submitted to the chain and soft confirmed

Types

type BlockchainPublisher

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

Can publish to the blockchain, signing messages using the provided signer

func NewBlockchainPublisher

func NewBlockchainPublisher(
	ctx context.Context,
	logger *zap.Logger,
	client *ethclient.Client,
	signer TransactionSigner,
	contractOptions config.ContractsOptions,
	nonceManager NonceManager,
) (*BlockchainPublisher, error)

func (*BlockchainPublisher) Close added in v0.3.0

func (m *BlockchainPublisher) Close()

func (*BlockchainPublisher) PublishGroupMessage

func (m *BlockchainPublisher) PublishGroupMessage(
	ctx context.Context,
	groupID [32]byte,
	message []byte,
) (*gm.GroupMessageBroadcasterMessageSent, error)

func (*BlockchainPublisher) PublishIdentityUpdate

func (m *BlockchainPublisher) PublishIdentityUpdate(
	ctx context.Context,
	inboxId [32]byte,
	identityUpdate []byte,
) (*iu.IdentityUpdateBroadcasterIdentityUpdateCreated, error)

type ContractConfig added in v0.2.2

type ContractConfig struct {
	FromBlock       uint64
	ContractAddress common.Address
	Topics          []common.Hash
	EventChannel    chan<- types.Log
	// contains filtered or unexported fields
}

Struct defining all the information required to filter events from logs

type IBlockchainPublisher

type IBlockchainPublisher interface {
	PublishIdentityUpdate(
		ctx context.Context,
		inboxId [32]byte,
		identityUpdate []byte,
	) (*iu.IdentityUpdateBroadcasterIdentityUpdateCreated, error)
	PublishGroupMessage(
		ctx context.Context,
		groupdId [32]byte,
		message []byte,
	) (*gm.GroupMessageBroadcasterMessageSent, error)
}

type INodeRegistryAdmin added in v0.3.0

type INodeRegistryAdmin interface {
	AddNode(
		ctx context.Context,
		owner string,
		signingKeyPub *ecdsa.PublicKey,
		httpAddress string,
		minMonthlyFeeMicroDollars int64,
	) error
	AddToNetwork(ctx context.Context, nodeId int64) error
	RemoveFromNetwork(ctx context.Context, nodeId int64) error
	SetHttpAddress(ctx context.Context, nodeId int64, httpAddress string) error
	SetMinMonthlyFee(ctx context.Context, nodeId int64, minMonthlyFeeMicroDollars int64) error
	SetMaxActiveNodes(ctx context.Context, maxActiveNodes uint8) error
	SetNodeOperatorCommissionPercent(ctx context.Context, commissionPercent int64) error
}

type INodeRegistryCaller added in v0.3.0

type INodeRegistryCaller interface {
	GetAllNodes(ctx context.Context) ([]noderegistry.INodeRegistryNodeWithId, error)
	GetNode(ctx context.Context, nodeId int64) (noderegistry.INodeRegistryNode, error)
	OwnerOf(ctx context.Context, nodeId int64) (common.Address, error)
}

func NewNodeRegistryCaller

func NewNodeRegistryCaller(
	logger *zap.Logger,
	client *ethclient.Client,
	contractsOptions config.ContractsOptions,
) (INodeRegistryCaller, error)

type LogStreamBuilder

type LogStreamBuilder interface {
	ListenForContractEvent(
		fromBlock uint64,
		contractAddress common.Address,
		topic common.Hash,
	) <-chan types.Log
	Build() (LogStreamer, error)
}

Construct a raw blockchain listener that can be used to listen for events across many contract event types

type LogStreamer

type LogStreamer interface {
	Start(ctx context.Context) error
}

type NonceContext added in v0.3.0

type NonceContext struct {
	Nonce   big.Int
	Cancel  func()
	Consume func() error
}

type NonceManager added in v0.3.0

type NonceManager interface {
	GetNonce(ctx context.Context) (*NonceContext, error)
	FastForwardNonce(ctx context.Context, nonce big.Int) error
	Replenish(ctx context.Context, nonce big.Int) error
}

type OpenConnectionsLimiter added in v0.3.0

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

OpenConnectionsLimiter controls the number of concurrent requests

func NewOpenConnectionsLimiter added in v0.3.0

func NewOpenConnectionsLimiter(maxConcurrent int) *OpenConnectionsLimiter

NewOpenConnectionsLimiter initializes a OpenConnectionsLimiter with a limit

type PrivateKeySigner

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

* PrivateKeySigner is a naive and not secure implementation of the TransactionSigner interface.

It is meant to be used in tests only *

func NewPrivateKeySigner

func NewPrivateKeySigner(privateKeyString string, chainID int) (*PrivateKeySigner, error)

func (*PrivateKeySigner) FromAddress

func (s *PrivateKeySigner) FromAddress() common.Address

func (*PrivateKeySigner) SignerFunc

func (s *PrivateKeySigner) SignerFunc() bind.SignerFn

type RatesAdmin added in v0.3.0

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

* A RatesAdmin is a struct responsible for calling admin functions on the RatesRegistry contract *

func NewRatesAdmin added in v0.3.0

func NewRatesAdmin(
	logger *zap.Logger,
	client *ethclient.Client,
	signer TransactionSigner,
	contractsOptions config.ContractsOptions,
) (*RatesAdmin, error)

func (*RatesAdmin) AddRates added in v0.3.0

func (r *RatesAdmin) AddRates(
	ctx context.Context,
	rates rateregistry.RateRegistryRates,
) error

* * * AddRates adds a new rate to the rates manager. * The new rate must have a later start time than the last rate in the contract.

func (*RatesAdmin) Contract added in v0.3.0

func (r *RatesAdmin) Contract() *rateregistry.RateRegistry

type RpcLogStreamBuilder

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

The builder that allows you to configure contract events to listen for

func NewRpcLogStreamBuilder

func NewRpcLogStreamBuilder(
	ctx context.Context,
	client *ethclient.Client,
	logger *zap.Logger,
) *RpcLogStreamBuilder

func (*RpcLogStreamBuilder) Build

func (c *RpcLogStreamBuilder) Build() (*RpcLogStreamer, error)

func (*RpcLogStreamBuilder) ListenForContractEvent

func (c *RpcLogStreamBuilder) ListenForContractEvent(
	fromBlock uint64,
	contractAddress common.Address,
	topics []common.Hash,
	maxDisconnectTime time.Duration,
) (<-chan types.Log, chan<- uint64)

type RpcLogStreamer

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

* A RpcLogStreamer is a naive implementation of the ChainStreamer interface. It queries a remote blockchain node for log events to backfill history, and then streams new events, to get a complete history of events on a chain. *

func NewRpcLogStreamer

func NewRpcLogStreamer(
	ctx context.Context,
	client ChainClient,
	logger *zap.Logger,
	watchers []ContractConfig,
) *RpcLogStreamer

func (*RpcLogStreamer) Client added in v0.2.0

func (r *RpcLogStreamer) Client() ChainClient

func (*RpcLogStreamer) GetNextPage added in v0.2.2

func (r *RpcLogStreamer) GetNextPage(
	config ContractConfig,
	fromBlock uint64,
) (logs []types.Log, nextBlock *uint64, err error)

func (*RpcLogStreamer) Start

func (r *RpcLogStreamer) Start()

func (*RpcLogStreamer) Stop added in v0.1.1

func (r *RpcLogStreamer) Stop()

type SQLBackedNonceManager added in v0.3.0

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

func NewSQLBackedNonceManager added in v0.3.0

func NewSQLBackedNonceManager(db *sql.DB, logger *zap.Logger) *SQLBackedNonceManager

func (*SQLBackedNonceManager) FastForwardNonce added in v0.3.0

func (s *SQLBackedNonceManager) FastForwardNonce(ctx context.Context, nonce big.Int) error

func (*SQLBackedNonceManager) GetNonce added in v0.3.0

func (*SQLBackedNonceManager) Replenish added in v0.3.0

func (s *SQLBackedNonceManager) Replenish(ctx context.Context, nonce big.Int) error

type TransactionSigner

type TransactionSigner interface {
	FromAddress() common.Address
	SignerFunc() bind.SignerFn
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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