blockchain

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 30 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 (
	RATE_REGISTRY_MESSAGE_FEE_KEY            = "xmtp.rateRegistry.messageFee"
	RATE_REGISTRY_STORAGE_FEE_KEY            = "xmtp.rateRegistry.storageFee"
	RATE_REGISTRY_CONGESTION_FEE_KEY         = "xmtp.rateRegistry.congestionFee"
	RATE_REGISTRY_TARGET_RATE_PER_MINUTE_KEY = "xmtp.rateRegistry.targetRatePerMinute"
)
View Source
const (
	NODE_REGISTRY_MAX_CANONICAL_NODES_KEY = "xmtp.nodeRegistry.maxCanonicalNodes"
)

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: - estimates the gas required for the transaction - checks if the sender has enough balance to cover the gas cost - executes a transaction - waits for it to be mined - processes the event logs

func NewClient

func NewClient(ctx context.Context, wsUrl 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 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,
	) (uint32, error)
	AddToNetwork(ctx context.Context, nodeId uint32) error
	RemoveFromNetwork(ctx context.Context, nodeId uint32) error
	SetHttpAddress(ctx context.Context, nodeId uint32, httpAddress string) error
	SetMaxCanonical(ctx context.Context, limit uint8) error
}

type INodeRegistryCaller added in v0.3.0

type INodeRegistryCaller interface {
	GetAllNodes(ctx context.Context) ([]noderegistry.INodeRegistryNodeWithId, error)
	GetNode(ctx context.Context, nodeId uint32) (noderegistry.INodeRegistryNode, error)
	OwnerOf(ctx context.Context, nodeId uint32) (common.Address, error)
	GetMaxCanonicalNodes(
		ctx context.Context,
	) (uint8, 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 fees.Rates,
) 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.

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