blockchain

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

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 NewClient

func NewClient(ctx context.Context, rpcUrl string) (*ethclient.Client, 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(
	logger *zap.Logger,
	client *ethclient.Client,
	signer TransactionSigner,
	contractOptions config.ContractsOptions,
) (*BlockchainPublisher, error)

func (*BlockchainPublisher) PublishGroupMessage

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

func (*BlockchainPublisher) PublishIdentityUpdate

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

type ChainClient

type ChainClient interface {
	ethereum.BlockNumberReader
	ethereum.LogFilterer
	ethereum.ChainIDReader
}

type IBlockchainPublisher

type IBlockchainPublisher interface {
	PublishIdentityUpdate(
		ctx context.Context,
		inboxId [32]byte,
		identityUpdate []byte,
	) (*abis.IdentityUpdatesIdentityUpdateCreated, error)
	PublishGroupMessage(
		ctx context.Context,
		groupdId [32]byte,
		message []byte,
	) (*abis.GroupMessagesMessageSent, 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 NodeRegistry

type NodeRegistry interface {
	AddNode(
		ctx context.Context,
		owner string,
		signingKeyPub *ecdsa.PublicKey,
		httpAddress string,
	) error
}

type NodeRegistryAdmin

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

* A NodeRegistryAdmin is a struct responsible for calling admin functions on the node registry *

func NewNodeRegistryAdmin

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

func (*NodeRegistryAdmin) AddNode

func (n *NodeRegistryAdmin) AddNode(
	ctx context.Context,
	owner string,
	signingKeyPub *ecdsa.PublicKey,
	httpAddress string,
) error

func (*NodeRegistryAdmin) UpdateHealth

func (n *NodeRegistryAdmin) UpdateHealth(
	ctx context.Context, nodeId int64, health bool,
) error

func (*NodeRegistryAdmin) UpdateHttpAddress

func (n *NodeRegistryAdmin) UpdateHttpAddress(
	ctx context.Context, nodeId int64, address string,
) error

type NodeRegistryCaller

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

* A NodeRegistryCaller is a struct responsible for calling public functions on the node registry *

func NewNodeRegistryCaller

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

func (*NodeRegistryCaller) GetAllNodes

func (n *NodeRegistryCaller) GetAllNodes(
	ctx context.Context,
) ([]abis.NodesNodeWithId, error)

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 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

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) Start

func (r *RpcLogStreamer) Start()

func (*RpcLogStreamer) Stop added in v0.1.1

func (r *RpcLogStreamer) Stop()

type TransactionSigner

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

Jump to

Keyboard shortcuts

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