evm

package
v0.2.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package evm implements the chain client for EVM chains.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExplainRevert

func ExplainRevert(err error) error

ExplainRevert adds decoded revert data to an RPC error. Any error code is accepted: Besu before 26.x reports reverts with -32000 rather than 3.

func ExplainRevertData

func ExplainRevertData(data []byte) string

ExplainRevertData decodes a revert reason, falling back to its raw hex data.

Types

type Client

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

Client implements chains.Client for EVM chains.

func New

func New(chainID, rpcURL, wsURL, ics26RouterAddress string) (*Client, error)

New dials the chain and verifies each endpoint's chain ID.

func NewWithClient

func NewWithClient(chainID string, eth ETHClient, ics26RouterAddress string) (*Client, error)

func NewWithClients

func NewWithClients(chainID string, eth, ws ETHClient, ics26RouterAddress string) (*Client, error)

func (*Client) BesuClientRouter

func (c *Client) BesuClientRouter(ctx context.Context, clientID string) (common.Address, error)

BesuClientRouter returns the router clientID's light client is bound to. It fails for a client deployed before ibc-contracts dfba365f, which has none.

func (*Client) BesuClientState

func (c *Client) BesuClientState(
	ctx context.Context,
	clientID string,
) (besumsgs.IBesuLightClientMsgsClientState, error)

BesuClientState reads clientID's Besu light client state.

func (*Client) BesuConsensusStateHash

func (c *Client) BesuConsensusStateHash(ctx context.Context, clientID string, height uint64) (common.Hash, error)

BesuConsensusStateHash returns the hash of the consensus state clientID stores at height. The contract reverts when it stores none.

func (*Client) ChainID

func (c *Client) ChainID() string

func (*Client) FindAckTx

func (c *Client) FindAckTx(ctx context.Context, sourceClientID string, sequence uint64) (*v2.Tx, error)

func (*Client) FindRecvTx

func (c *Client) FindRecvTx(ctx context.Context, destClientID string, sequence uint64) (*v2.Tx, error)

FindRecvTx looks for the WriteAcknowledgement event because the router emits no RecvPacket event; acks are written synchronously in the receive tx.

func (*Client) FindSendPackets

func (c *Client) FindSendPackets(
	ctx context.Context,
	clientID string,
	sequences []uint64,
) ([]v2.PacketEvent, error)

FindSendPackets returns the SendPacket events for sequences on clientID. The block range is unbounded because clearing knows the sequences but not the heights they landed at, exactly as findPacketTx queries today.

func (*Client) FindTimeoutTx

func (c *Client) FindTimeoutTx(ctx context.Context, sourceClientID string, sequence uint64) (*v2.Tx, error)

func (*Client) GetAttestationSet

func (c *Client) GetAttestationSet(ctx context.Context, clientID string) ([]string, uint8, error)

GetAttestationSet returns clientID's on-chain attestor addresses and minimum required signature count.

func (*Client) GetBlockHeader

func (c *Client) GetBlockHeader(ctx context.Context, height uint64) (v2.BlockHeader, error)

func (*Client) GetCommitment

func (c *Client) GetCommitment(ctx context.Context, height uint64, hashedPath [32]byte) ([32]byte, error)

func (*Client) GetCounterparty

func (c *Client) GetCounterparty(ctx context.Context, clientID string) (string, error)

GetCounterparty returns the client ID this chain's router has registered as clientID's on-chain counterparty.

func (*Client) GetRouterProof

func (c *Client) GetRouterProof(ctx context.Context, height uint64, slots []common.Hash) (RouterProof, error)

GetRouterProof proves the router account and the requested storage slots at height via eth_getProof. The light client verifies the proofs, deriving each storage key from the packet itself.

func (*Client) IsPacketCommitted

func (c *Client) IsPacketCommitted(ctx context.Context, sourceClientID string, sequence uint64) (bool, error)

func (*Client) IsPacketReceived

func (c *Client) IsPacketReceived(ctx context.Context, destClientID string, sequence uint64) (bool, error)

func (*Client) LatestPacketSequence

func (c *Client) LatestPacketSequence(ctx context.Context, clientID string, height uint64) (uint64, error)

LatestPacketSequence returns the highest sequence ever assigned on clientID at height, read from the router's prevSequenceSends mapping because nextSequenceSend is internal and nothing exposes it. Sequences in use are 1..N, so zero means nothing has been sent on the client.

func (*Client) PacketCommitments

func (c *Client) PacketCommitments(
	ctx context.Context,
	clientID string,
	sequences []uint64,
	height uint64,
) ([]uint64, error)

PacketCommitments returns the subset of sequences whose packet commitment is still live on clientID at height. It is all or nothing: a truncated set reads as "everything else settled", which writes off packets whose funds are still in escrow, so any failure returns nil rather than a partial slice.

func (*Client) PacketRelayExecuted

func (c *Client) PacketRelayExecuted(
	ctx context.Context,
	txHash string,
	kind v2.RelayKind,
	sequence uint64,
	sourceClientID string,
	destClientID string,
) (bool, error)

func (*Client) PacketWriteAckStatus

func (c *Client) PacketWriteAckStatus(
	ctx context.Context,
	recvTxHash string,
	sequence uint64,
	sourceClientID string,
	destClientID string,
) (v2.WriteAckStatus, error)

func (*Client) RouterAddress

func (c *Client) RouterAddress() common.Address

RouterAddress returns the ICS26 router address.

func (*Client) SealedHeader

func (c *Client) SealedHeader(ctx context.Context, height uint64) (*besu.ParsedHeader, error)

SealedHeader returns the sealed Besu header at height, or the head at v2.LatestBlock.

func (*Client) SubscribeSendPackets

func (c *Client) SubscribeSendPackets(
	ctx context.Context,
	clientIDs []string,
	out chan<- v2.PacketEvent,
) (v2.Subscription, error)

SubscribeSendPackets streams SendPacket events for clientIDs to out. It is one shot: the subscription ends on the first transport, decode or header failure and does not reconnect.

func (*Client) TxHeight

func (c *Client) TxHeight(ctx context.Context, rawTxHash []byte) (uint64, error)

func (*Client) TxPacketEvents

func (c *Client) TxPacketEvents(ctx context.Context, rawTxHash []byte) ([]v2.PacketEvent, error)

func (*Client) WaitForChain

func (c *Client) WaitForChain(ctx context.Context) error

type ETHClient

type ETHClient interface {
	bind.ContractBackend

	BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
	NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
	EstimateGasAtBlock(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) (uint64, error)
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
	TransactionByHash(ctx context.Context, hash common.Hash) (*types.Transaction, bool, error)
	StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)

	// GetProof is eth_getProof for account at blockNumber, or the head when
	// nil: the account proof nodes and one storage proof per key, in the
	// order of keys.
	GetProof(
		ctx context.Context,
		account common.Address,
		keys []common.Hash,
		blockNumber *big.Int,
	) (accountProof [][]byte, storageProofs [][][]byte, err error)
}

ETHClient go-ethereum methods used by Client and by the tx submitter.

func Dial

func Dial(chainID, rpcURL string) (ETHClient, error)

Dial verifies the endpoint's chain ID, then records subsequent calls in metrics.

type RouterProof

type RouterProof struct {
	AccountProof  [][]byte
	StorageProofs [][][]byte
}

RouterProof is an eth_getProof result for the router at one height: the account proof nodes against the block's state root and the storage proof nodes of each requested slot, in request order.

Jump to

Keyboard shortcuts

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