blockchain

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 40 Imported by: 0

Documentation

Overview

Package blockchain provides infrastructure for interacting with the blockchain.

Index

Constants

View Source
const (
	APP_CHAIN_GATEWAY_PAUSED_KEY                     = "xmtp.appChainGateway.paused"
	DISTRIBUTION_MANAGER_PAUSED_KEY                  = "xmtp.distributionManager.paused"
	DISTRIBUTION_MANAGER_PROTOCOL_FEES_RECIPIENT_KEY = "xmtp.distributionManager.protocolFeesRecipient"

	GROUP_MESSAGE_BROADCASTER_MAX_PAYLOAD_SIZE_KEY = "xmtp.groupMessageBroadcaster.maxPayloadSize"
	GROUP_MESSAGE_BROADCASTER_MIN_PAYLOAD_SIZE_KEY = "xmtp.groupMessageBroadcaster.minPayloadSize"
	GROUP_MESSAGE_BROADCASTER_PAUSED_KEY           = "xmtp.groupMessageBroadcaster.paused"
	GROUP_MESSAGE_PAYLOAD_BOOTSTRAPPER_KEY         = "xmtp.groupMessageBroadcaster.payloadBootstrapper"

	IDENTITY_UPDATE_BROADCASTER_MAX_PAYLOAD_SIZE_KEY = "xmtp.identityUpdateBroadcaster.maxPayloadSize"
	IDENTITY_UPDATE_BROADCASTER_MIN_PAYLOAD_SIZE_KEY = "xmtp.identityUpdateBroadcaster.minPayloadSize"
	IDENTITY_UPDATE_BROADCASTER_PAUSED_KEY           = "xmtp.identityUpdateBroadcaster.paused"
	IDENTITY_UPDATE_PAYLOAD_BOOTSTRAPPER_KEY         = "xmtp.identityUpdateBroadcaster.payloadBootstrapper"

	NODE_REGISTRY_ADMIN_KEY               = "xmtp.nodeRegistry.admin"
	NODE_REGISTRY_MAX_CANONICAL_NODES_KEY = "xmtp.nodeRegistry.maxCanonicalNodes"

	PAYER_REGISTRY_MINIMUM_DEPOSIT_KEY      = "xmtp.payerRegistry.minimumDeposit"
	PAYER_REGISTRY_PAUSED_KEY               = "xmtp.payerRegistry.paused"
	PAYER_REGISTRY_WITHDRAW_LOCK_PERIOD_KEY = "xmtp.payerRegistry.withdrawLockPeriod"

	PAYER_REPORT_MANAGER_PROTOCOL_FEE_RATE_KEY = "xmtp.payerReportManager.protocolFeeRate"

	RATE_REGISTRY_CONGESTION_FEE_KEY         = "xmtp.rateRegistry.congestionFee"
	RATE_REGISTRY_MESSAGE_FEE_KEY            = "xmtp.rateRegistry.messageFee"
	RATE_REGISTRY_MIGRATOR_KEY               = "xmtp.rateRegistry.migrator"
	RATE_REGISTRY_STORAGE_FEE_KEY            = "xmtp.rateRegistry.storageFee"
	RATE_REGISTRY_TARGET_RATE_PER_MINUTE_KEY = "xmtp.rateRegistry.targetRatePerMinute"

	SETTLEMENT_CHAIN_GATEWAY_PAUSED_KEY = "xmtp.settlementChainGateway.paused"
)

Variables

View Source
var (
	ErrCodeNotFound = fmt.Errorf("error message does not contain a valid error code")
	ErrCodeNotInDic = fmt.Errorf("code not found in protocol errors dictionary")
	ErrCompileRegex = fmt.Errorf("error compiling regex")
)
View Source
var ErrNoLogsFound = errors.New("no logs found")

Functions

func IsUint96 added in v0.5.1

func IsUint96(v *big.Int) bool

func NewAppChainAdmin added in v0.5.1

func NewAppChainAdmin(
	logger *zap.Logger,
	client *ethclient.Client,
	signer TransactionSigner,
	contractsOptions config.ContractsOptions,
	parameterAdmin *ParameterAdmin,
) (*appChainAdmin, error)

func NewNodeRegistryAdmin

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

func NewNodeRegistryCaller

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

func NewRPCClient added in v0.5.0

func NewRPCClient(ctx context.Context, rpcURL string) (*ethclient.Client, error)

NewRPCClient creates a new RPC client that can be used for JSON-RPC calls. RPC providers usually implement middleware with optimizations for HTTP JSON-RPC requests.

func NewSettlementChainAdmin added in v0.5.1

func NewSettlementChainAdmin(
	logger *zap.Logger,
	client *ethclient.Client,
	signer TransactionSigner,
	contractsOptions config.ContractsOptions,
	parameterAdmin *ParameterAdmin,
) (*settlementChainAdmin, error)

func NewWebsocketClient added in v0.5.0

func NewWebsocketClient(
	ctx context.Context,
	wsURL string,
	opts ...WebsocketClientOption,
) (*ethclient.Client, error)

NewWebsocketClient creates a new websocket client that can be configured with dialer options. It's used mostly for subscriptions.

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)

WaitForTransaction waits for the given transaction hash to have been submitted to the chain and soft confirmed.

Types

type BlockchainError added in v0.5.1

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

func NewBlockchainError added in v0.5.1

func NewBlockchainError(e error) *BlockchainError

func (BlockchainError) Error added in v0.5.1

func (e BlockchainError) Error() string

func (BlockchainError) IsNoChange added in v0.5.1

func (e BlockchainError) IsNoChange() bool

type BlockchainPublisher

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

BlockchainPublisher 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.NonceManager,
) (*BlockchainPublisher, error)

func (*BlockchainPublisher) BootstrapGroupMessages added in v0.5.0

func (m *BlockchainPublisher) BootstrapGroupMessages(
	ctx context.Context,
	groupIDs [][16]byte,
	messages [][]byte,
	sequenceIDs []uint64,
) ([]*gm.GroupMessageBroadcasterMessageSent, error)

func (*BlockchainPublisher) BootstrapIdentityUpdates added in v0.5.0

func (m *BlockchainPublisher) BootstrapIdentityUpdates(
	ctx context.Context,
	inboxIDs [][32]byte,
	identityUpdates [][]byte,
	sequenceIDs []uint64,
) ([]*iu.IdentityUpdateBroadcasterIdentityUpdateCreated, error)

func (*BlockchainPublisher) Close added in v0.3.0

func (m *BlockchainPublisher) Close()

func (*BlockchainPublisher) PublishGroupMessage

func (m *BlockchainPublisher) PublishGroupMessage(
	ctx context.Context,
	groupID [16]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 IAppChainAdmin added in v0.5.1

type IAppChainAdmin interface {
	GetIdentityUpdateBootstrapper(ctx context.Context) (common.Address, error)
	SetIdentityUpdateBootstrapper(ctx context.Context, address common.Address) error
	GetGroupMessageBootstrapper(ctx context.Context) (common.Address, error)
	SetGroupMessageBootstrapper(ctx context.Context, address common.Address) error

	GetGroupMessagePauseStatus(ctx context.Context) (bool, error)
	SetGroupMessagePauseStatus(ctx context.Context, paused bool) error
	GetIdentityUpdatePauseStatus(ctx context.Context) (bool, error)
	SetIdentityUpdatePauseStatus(ctx context.Context, paused bool) error
	GetAppChainGatewayPauseStatus(ctx context.Context) (bool, error)
	SetAppChainGatewayPauseStatus(ctx context.Context, paused bool) error

	GetGroupMessageMaxPayloadSize(ctx context.Context) (uint64, error)
	SetGroupMessageMaxPayloadSize(ctx context.Context, size uint64) error
	GetGroupMessageMinPayloadSize(ctx context.Context) (uint64, error)
	SetGroupMessageMinPayloadSize(ctx context.Context, size uint64) error

	GetIdentityUpdateMaxPayloadSize(ctx context.Context) (uint64, error)
	SetIdentityUpdateMaxPayloadSize(ctx context.Context, size uint64) error
	GetIdentityUpdateMinPayloadSize(ctx context.Context) (uint64, error)
	SetIdentityUpdateMinPayloadSize(ctx context.Context, size uint64) error
}

type IBlockchainPublisher

type IBlockchainPublisher interface {
	Close()
	PublishIdentityUpdate(
		ctx context.Context,
		inboxID [32]byte,
		identityUpdate []byte,
	) (*iu.IdentityUpdateBroadcasterIdentityUpdateCreated, error)
	BootstrapIdentityUpdates(
		ctx context.Context,
		inboxIDs [][32]byte,
		identityUpdates [][]byte,
		sequenceIDs []uint64,
	) ([]*iu.IdentityUpdateBroadcasterIdentityUpdateCreated, error)
	PublishGroupMessage(
		ctx context.Context,
		groupID [16]byte,
		message []byte,
	) (*gm.GroupMessageBroadcasterMessageSent, error)
	BootstrapGroupMessages(
		ctx context.Context,
		groupIDs [][16]byte,
		messages [][]byte,
		sequenceIDs []uint64,
	) ([]*gm.GroupMessageBroadcasterMessageSent, error)
}

type INodeRegistryAdmin added in v0.3.0

type INodeRegistryAdmin interface {
	AddNode(
		ctx context.Context,
		ownerAddress common.Address,
		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)
}

type ISettlementChainAdmin added in v0.5.1

type ISettlementChainAdmin interface {
	GetSettlementChainGatewayPauseStatus(ctx context.Context) (bool, error)
	SetSettlementChainGatewayPauseStatus(ctx context.Context, paused bool) error
	GetPayerRegistryPauseStatus(ctx context.Context) (bool, error)
	SetPayerRegistryPauseStatus(ctx context.Context, paused bool) error
	GetDistributionManagerPauseStatus(ctx context.Context) (bool, error)
	SetDistributionManagerPauseStatus(ctx context.Context, paused bool) error

	GetDistributionManagerProtocolFeesRecipient(ctx context.Context) (common.Address, error)
	SetDistributionManagerProtocolFeesRecipient(ctx context.Context, addr common.Address) error
	GetNodeRegistryAdmin(ctx context.Context) (common.Address, error)
	SetNodeRegistryAdmin(ctx context.Context, addr common.Address) error

	GetPayerRegistryMinimumDeposit(ctx context.Context) (*big.Int, error)
	SetPayerRegistryMinimumDeposit(ctx context.Context, v *big.Int) error
	GetPayerRegistryWithdrawLockPeriod(ctx context.Context) (uint32, error)
	SetPayerRegistryWithdrawLockPeriod(ctx context.Context, v uint32) error

	GetPayerReportManagerProtocolFeeRate(ctx context.Context) (uint16, error)
	SetPayerReportManagerProtocolFeeRate(ctx context.Context, v uint16) error

	GetRateRegistryMigrator(ctx context.Context) (common.Address, error)
	SetRateRegistryMigrator(ctx context.Context, addr common.Address) error

	MintMockUSDC(ctx context.Context, addr common.Address, amount *big.Int) error
}

type LogStreamBuilder

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

LogStreamBuilder constructs 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 ParameterAdmin added in v0.5.1

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

func NewParameterAdmin added in v0.5.1

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

func (*ParameterAdmin) GetParameterAddress added in v0.5.1

func (n *ParameterAdmin) GetParameterAddress(
	ctx context.Context,
	paramName string,
) (common.Address, ProtocolError)

func (*ParameterAdmin) GetParameterBool added in v0.5.1

func (n *ParameterAdmin) GetParameterBool(
	ctx context.Context,
	paramName string,
) (bool, ProtocolError)

func (*ParameterAdmin) GetParameterUint8 added in v0.5.1

func (n *ParameterAdmin) GetParameterUint8(
	ctx context.Context,
	paramName string,
) (uint8, ProtocolError)

func (*ParameterAdmin) GetParameterUint16 added in v0.5.1

func (n *ParameterAdmin) GetParameterUint16(
	ctx context.Context,
	paramName string,
) (uint16, ProtocolError)

func (*ParameterAdmin) GetParameterUint32 added in v0.5.1

func (n *ParameterAdmin) GetParameterUint32(
	ctx context.Context,
	paramName string,
) (uint32, ProtocolError)

func (*ParameterAdmin) GetParameterUint64 added in v0.5.1

func (n *ParameterAdmin) GetParameterUint64(
	ctx context.Context,
	paramName string,
) (uint64, ProtocolError)

func (*ParameterAdmin) GetParameterUint96 added in v0.5.1

func (n *ParameterAdmin) GetParameterUint96(
	ctx context.Context,
	paramName string,
) (*big.Int, ProtocolError)

func (*ParameterAdmin) SetAddressParameter added in v0.5.1

func (n *ParameterAdmin) SetAddressParameter(
	ctx context.Context,
	paramName string,
	paramValue common.Address,
) ProtocolError

func (*ParameterAdmin) SetBoolParameter added in v0.5.1

func (n *ParameterAdmin) SetBoolParameter(
	ctx context.Context,
	paramName string,
	paramValue bool,
) ProtocolError

func (*ParameterAdmin) SetManyUint64Parameters added in v0.5.1

func (n *ParameterAdmin) SetManyUint64Parameters(
	ctx context.Context,
	items []Uint64Param,
) ProtocolError

func (*ParameterAdmin) SetUint8Parameter added in v0.5.1

func (n *ParameterAdmin) SetUint8Parameter(
	ctx context.Context,
	paramName string,
	paramValue uint8,
) ProtocolError

func (*ParameterAdmin) SetUint16Parameter added in v0.5.1

func (n *ParameterAdmin) SetUint16Parameter(
	ctx context.Context,
	paramName string,
	paramValue uint16,
) ProtocolError

func (*ParameterAdmin) SetUint32Parameter added in v0.5.1

func (n *ParameterAdmin) SetUint32Parameter(
	ctx context.Context,
	paramName string,
	paramValue uint32,
) ProtocolError

func (*ParameterAdmin) SetUint64Parameter added in v0.5.1

func (n *ParameterAdmin) SetUint64Parameter(
	ctx context.Context,
	paramName string,
	paramValue uint64,
) ProtocolError

func (*ParameterAdmin) SetUint96Parameter added in v0.5.1

func (n *ParameterAdmin) SetUint96Parameter(
	ctx context.Context,
	paramName string,
	v *big.Int,
) ProtocolError

type PayerReportsManager added in v0.5.0

type PayerReportsManager interface {
	SubmitPayerReport(ctx context.Context, report *payerreport.PayerReportWithStatus) error
	GetReport(
		ctx context.Context,
		originatorNodeID uint32,
		index uint64,
	) (*payerreport.PayerReport, error)
	GetDomainSeparator(ctx context.Context) (common.Hash, error)
	GetReportID(
		ctx context.Context,
		payerReport *payerreport.PayerReportWithStatus,
	) (payerreport.ReportID, 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 ProtocolError added in v0.5.1

type ProtocolError interface {
	error
	IsNoChange() bool
}

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{}),
) ProtocolError

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

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,
	paramAdmin *ParameterAdmin,
	client *ethclient.Client,
	contractsOptions config.ContractsOptions,
) (*RatesAdmin, error)

func (*RatesAdmin) AddRates added in v0.3.0

func (r *RatesAdmin) AddRates(ctx context.Context, rates fees.Rates) ProtocolError

* * * 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 ReportsManager added in v0.5.0

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

func NewReportsManager added in v0.5.0

func NewReportsManager(
	log *zap.Logger,
	client *ethclient.Client,
	signer TransactionSigner,
	options config.SettlementChainOptions,
) (*ReportsManager, error)

func (*ReportsManager) GetDomainSeparator added in v0.5.0

func (r *ReportsManager) GetDomainSeparator(ctx context.Context) (common.Hash, error)

func (*ReportsManager) GetReport added in v0.5.0

func (r *ReportsManager) GetReport(
	ctx context.Context,
	originatorNodeID uint32,
	index uint64,
) (*payerreport.PayerReport, error)

func (*ReportsManager) GetReportID added in v0.5.0

func (r *ReportsManager) GetReportID(
	ctx context.Context,
	payerReport *payerreport.PayerReportWithStatus,
) (payerreport.ReportID, error)

func (*ReportsManager) SubmitPayerReport added in v0.5.0

func (r *ReportsManager) SubmitPayerReport(
	ctx context.Context,
	report *payerreport.PayerReportWithStatus,
) error

type TransactionSigner

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

type Uint64Param added in v0.5.1

type Uint64Param struct {
	Name  string
	Value uint64
}

type WebsocketClientOption added in v0.5.0

type WebsocketClientOption func(*websocketClientConfig)

func WithKeepAliveConfig added in v0.5.0

func WithKeepAliveConfig(cfg net.KeepAliveConfig) WebsocketClientOption

Directories

Path Synopsis
Package noncemanager provides interfaces and implementations for managing transaction nonces in a blockchain environment.
Package noncemanager provides interfaces and implementations for managing transaction nonces in a blockchain environment.
redis
Package redis provides a Redis-backed implementation of the NonceManager interface.
Package redis provides a Redis-backed implementation of the NonceManager interface.
sql
Package sql provides a SQL database-backed implementation of the NonceManager interface.
Package sql provides a SQL database-backed implementation of the NonceManager interface.

Jump to

Keyboard shortcuts

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