web3

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WaitReadyRPC

func WaitReadyRPC(ctx context.Context, rpcURL string) error

WaitReadyRPC waits for the RPC endpoint to be ready by checking if it returns a valid block number. It will continuously try to get the block number until the context is canceled or a valid block number is received. The function returns an error if the context is canceled or if another error occurs.

Types

type Addresses

type Addresses struct {
	ProcessRegistry           common.Address
	StateTransitionZKVerifier common.Address
	ResultsZKVerifier         common.Address
}

Addresses contains the addresses of the contracts deployed in the network.

type BlockOverrides

type BlockOverrides struct {
	BaseFeePerGas *hexutil.Big `json:"baseFeePerGas,omitempty"`
	Timestamp     *hexutil.Big `json:"timestamp,omitempty"`
}

BlockOverrides lets you override block fields

type BlockStateCall

type BlockStateCall struct {
	BlockOverrides *BlockOverrides           `json:"blockOverrides,omitempty"`
	StateOverrides map[string]StateOverride  `json:"stateOverrides,omitempty"`
	Calls          []gethapitypes.SendTxArgs `json:"calls"`
}

BlockStateCall lets you override block fields, state, and queue up calls

type CallResult

type CallResult struct {
	Status     string          `json:"status"` // "0x1" or "0x0"
	ReturnData hexutil.Bytes   `json:"returnData"`
	GasUsed    hexutil.Uint64  `json:"gasUsed"`
	Logs       []gethtypes.Log `json:"logs"`
	Error      *rpc.RPCError   `json:"error,omitempty"`
}

CallResult is the result of a single call in a simulated block

type ContractABIs

type ContractABIs struct {
	ProcessRegistry           *abi.ABI
	StateTransitionZKVerifier *abi.ABI
	ResultsZKVerifier         *abi.ABI
	CensusValidator           *abi.ABI
}

ContractABIs contains the ABIs of the deployed contracts.

type Contracts

type Contracts struct {
	ChainID                  uint64
	ContractsAddresses       *Addresses
	ContractABIs             *ContractABIs
	Web3ConsensusAPIEndpoint string
	GasMultiplier            float64
	// contains filtered or unexported fields
}

Contracts contains the bindings to the deployed contracts.

func New

func New(web3rpcs []string, web3cApi string, gasMultiplier float64) (*Contracts, error)

New creates a new Contracts instance with the given web3 endpoints. It initializes the web3 pool and the client, and sets up the known processes

func (*Contracts) AccountAddress

func (c *Contracts) AccountAddress() common.Address

AccountAddress returns the address of the account used to sign transactions.

func (*Contracts) AccountNonce

func (c *Contracts) AccountNonce() (uint64, error)

AccountNonce returns the nonce of the account used to sign transactions.

func (*Contracts) AddWeb3Endpoint

func (c *Contracts) AddWeb3Endpoint(web3rpc string) error

AddWeb3Endpoint adds a new web3 endpoint to the pool.

func (*Contracts) BlobSidecarsOfBlock

func (c *Contracts) BlobSidecarsOfBlock(ctx context.Context, parentBeaconRoot *common.Hash) ([]*types.BlobSidecar, error)

BlobSidecarsOfBlock returns the blob sidecars stored in consensus layer, of a block identified by a parentBeaconRoot

func (*Contracts) BlobsByTxHash

func (c *Contracts) BlobsByTxHash(
	ctx context.Context,
	txHash common.Hash,
) ([]*types.BlobSidecar, error)

BlobsByTxHash returns all the blobs sidecars of a tx, given a `txHash`.

func (*Contracts) CensusValidatorABI

func (c *Contracts) CensusValidatorABI() *abi.ABI

CensusValidatorABI returns the ABI of the CensusValidator contract.

func (*Contracts) CheckTxStatus

func (c *Contracts) CheckTxStatus(txHash common.Hash) (bool, error)

CheckTxStatus checks the status of a transaction given its hash. Returns true if the transaction is confirmed and successful, false if it is still pending, or an error if the receipt query fails or the transaction was reverted on-chain.

func (*Contracts) Client

func (c *Contracts) Client() *rpc.Client

Client returns the web3 client used by the Contracts instance.

func (*Contracts) CreateProcess

func (c *Contracts) CreateProcess(process *types.Process) (types.ProcessID, *common.Hash, error)

CreateProcess creates a new process in the ProcessRegistry contract. It returns the process ID and the transaction hash.

func (*Contracts) CurrentBlock

func (c *Contracts) CurrentBlock() uint64

CurrentBlock returns the current block number for the chain.

func (*Contracts) DecodeError

func (c *Contracts) DecodeError(err error) (string, bool)

DecodeError tries to decode revert reasons or custom errors from err, and returns true if successful.

func (*Contracts) FetchOnchainCensusRoot

func (c *Contracts) FetchOnchainCensusRoot(address common.Address) (types.HexBytes, error)

FetchOnchainCensusRoot retrieves the census root from the specified census validator contract address.

func (*Contracts) LoadContracts

func (c *Contracts) LoadContracts(addresses *Addresses) error

LoadContracts loads the contracts

func (*Contracts) MonitorProcessChanges

func (c *Contracts) MonitorProcessChanges(
	ctx context.Context,
	interval time.Duration,
	retries int,
	filters ...types.Web3FilterFn,
) (<-chan *types.ProcessWithChanges, error)

MonitorProcessChanges monitors changes to processes by polling the ProcessRegistry contract every interval. It applies the provided filter functions to detect specific types of changes. It returns a channel that emits ProcessWithChanges objects representing the detected changes.

func (*Contracts) MonitorProcessCreation

func (c *Contracts) MonitorProcessCreation(ctx context.Context, interval time.Duration) (<-chan *types.Process, error)

MonitorProcessCreation monitors the creation of new processes by polling the ProcessRegistry contract every interval.

func (*Contracts) NewEIP4844Transaction

func (c *Contracts) NewEIP4844Transaction(
	ctx context.Context,
	to common.Address,
	data []byte,
	blobsSidecar *types.BlobTxSidecar,
) (*gethtypes.Transaction, error)

NewEIP4844Transaction method creates and signs a new EIP-4844 (type-3) transaction by calculating the nonce from the RPC and returning the result of NewEIP4844TransactionWithNonce.

func (*Contracts) NewEIP4844TransactionWithNonce

func (c *Contracts) NewEIP4844TransactionWithNonce(
	ctx context.Context,
	to common.Address,
	data []byte,
	nonce uint64,
	blobsSidecar *types.BlobTxSidecar,
) (*gethtypes.Transaction, error)

NewEIP4844TransactionWithNonce method creates and signs a new EIP-4844. It calculates gas limits and fee caps, and returns the signed transaction. The provided nonce is used (caller must ensure it's correct).

Requirements:

  • `to` MUST be non-nil per EIP-4844.
  • `method` MUST be a valid method in the ABI.
  • `c.signer` MUST be non-nil (private key set).

func (*Contracts) NextProcessID

func (c *Contracts) NextProcessID(address common.Address) (types.ProcessID, error)

NextProcessID returns the next process ID that will be created in the ProcessRegistry contract for the given address.

func (*Contracts) Process

func (c *Contracts) Process(processID types.ProcessID) (*types.Process, error)

Process returns the process with the given ID from the ProcessRegistry contract.

func (*Contracts) ProcessCensusRootFilter

func (c *Contracts) ProcessCensusRootFilter(ctx context.Context, start, end uint64, ch chan<- *types.ProcessWithChanges) error

ProcessCensusRootFilter monitors changes in process census root.

func (*Contracts) ProcessChangesFilters

func (c *Contracts) ProcessChangesFilters() []types.Web3FilterFn

ProcessChangesFilters returns the list of filters to monitor process changes.

func (*Contracts) ProcessMaxVotersFilter

func (c *Contracts) ProcessMaxVotersFilter(ctx context.Context, start, end uint64, ch chan<- *types.ProcessWithChanges) error

ProcessMaxVotersFilter monitors changes in process max voters.

func (*Contracts) ProcessRegistryABI

func (c *Contracts) ProcessRegistryABI() *abi.ABI

ProcessRegistryABI returns the ABI of the ProcessRegistry contract.

func (*Contracts) ProcessRegistryAddress

func (c *Contracts) ProcessRegistryAddress() (string, error)

func (*Contracts) ProcessStateRootFilter

func (c *Contracts) ProcessStateRootFilter(ctx context.Context, start, end uint64, ch chan<- *types.ProcessWithChanges) error

ProcessStateRootFilter monitors changes in process state root.

func (*Contracts) ProcessStatusFilter

func (c *Contracts) ProcessStatusFilter(ctx context.Context, start, end uint64, ch chan<- *types.ProcessWithChanges) error

ProcessStatusFilter monitors changes in process status.

func (*Contracts) RegisterKnownProcess

func (c *Contracts) RegisterKnownProcess(processID types.ProcessID)

RegisterKnownProcess adds a process ID to the knownProcesses map. This is used during initialization to register processes that were created before the monitor started, ensuring their events are not filtered out.

func (*Contracts) ResultsVerifierABI

func (c *Contracts) ResultsVerifierABI() *abi.ABI

ResultsVerifierABI returns the ABI of the ResultsVerifier contract.

func (*Contracts) ResultsVerifierAddress

func (c *Contracts) ResultsVerifierAddress() (string, error)

func (*Contracts) SetAccountPrivateKey

func (c *Contracts) SetAccountPrivateKey(hexPrivKey string) error

SetAccountPrivateKey sets the private key to be used for signing transactions.

func (*Contracts) SetProcessCensus

func (c *Contracts) SetProcessCensus(processID types.ProcessID, census types.Census) (*common.Hash, error)

SetProcessCensus sets the census of the process with the given ID in the ProcessRegistry contract. It returns the transaction hash of the census update, or an error if the update fails.

func (*Contracts) SetProcessMaxVoters

func (c *Contracts) SetProcessMaxVoters(processID types.ProcessID, maxVoters *types.BigInt) (*common.Hash, error)

SetProcessMaxVoters sets the maximum number of voters for the process with the given ID in the ProcessRegistry contract. It returns the transaction hash of the update, or an error if the update fails.

func (*Contracts) SetProcessResults

func (c *Contracts) SetProcessResults(
	processID types.ProcessID,
	proof, inputs []byte,
	timeout time.Duration, callback ...func(error),
) error

SetProcessResults sets the results of the process with the given ID in the ProcessRegistry contract and waits for the transaction to be mined. Once mined or the timeout is reached, it calls the optional callback with the result of the operation. It returns an error if the submission fails.

func (*Contracts) SetProcessStatus

func (c *Contracts) SetProcessStatus(processID types.ProcessID, status types.ProcessStatus) (*common.Hash, error)

SetProcessStatus sets the status of the process with the given ID in the ProcessRegistry contract. It returns the transaction hash of the status update, or an error if the update fails.

func (*Contracts) SetProcessTransition

func (c *Contracts) SetProcessTransition(
	processID types.ProcessID,
	proof, inputs []byte,
	blobsSidecar *types.BlobTxSidecar,
	timeout time.Duration,
	callback ...func(error),
) error

SetProcessTransition submits a state transition for the process with the given ID and waits for the transaction to be mined. Once mined or the timeout is reached, it calls the optional callback with the result of the operation. It returns an error if the submission fails.

func (*Contracts) SetTxManager

func (c *Contracts) SetTxManager(tm *txmanager.TxManager)

SetTxManager sets the transaction manager to be used by the Contracts instance.

func (*Contracts) SignMessage

func (c *Contracts) SignMessage(msg []byte) ([]byte, error)

SignMessage signs a message with the account private key.

func (*Contracts) Signer

func (c *Contracts) Signer() *ethSigner.Signer

Signer returns the signer used by the Contracts instance.

func (*Contracts) SimulateContractCall

func (c *Contracts) SimulateContractCall(
	ctx context.Context,
	contractAddr common.Address,
	data []byte,
	blobsSidecar *types.BlobTxSidecar,
) error

SimulateContractCall simulates a contract call using the eth_simulateV1 RPC method. If blobsSidecar is provided, it will simulate an EIP4844 transaction with blob data. If blobsSidecar is nil, it will simulate a regular contract call. NOTE: this is a temporary method to simulate contract calls it works on geth but not expected to work on other clients or external rpc providers.

func (*Contracts) SimulateProcessResults

func (c *Contracts) SimulateProcessResults(
	ctx context.Context,
	processID types.ProcessID,
	proof, inputs []byte,
) error

SimulateProcessResults simulates a setProcessResults contract call using the eth_simulateV1 RPC method.

NOTE: this is a temporary method to simulate contract calls it works on geth but not expected to work on other clients or external rpc providers.

func (*Contracts) SimulateProcessTransition

func (c *Contracts) SimulateProcessTransition(
	ctx context.Context,
	processID types.ProcessID,
	proof, inputs []byte,
	blobsSidecar *types.BlobTxSidecar,
) error

SimulateProcessTransition simulates a submitStateTransition contract call using the eth_simulateV1 RPC method. If blobsSidecar is provided, it will simulate an EIP4844 transaction with blob data. If blobsSidecar is nil, it will simulate a regular contract call.

NOTE: this is a temporary method to simulate contract calls it works on geth but not expected to work on other clients or external rpc providers.

func (*Contracts) StateRoot

func (c *Contracts) StateRoot(processID types.ProcessID) (*types.BigInt, error)

StateRoot returns the state root of the process with the given ID. It returns an error if the process does not exist or if there is an issue with the contract call.

func (*Contracts) StateTransitionVerifierABI

func (c *Contracts) StateTransitionVerifierABI() *abi.ABI

StateTransitionVerifierABI returns the ABI of the ZKVerifier contract.

func (*Contracts) StateTransitionVerifierAddress

func (c *Contracts) StateTransitionVerifierAddress() (string, error)

func (*Contracts) SupportBlobTxs

func (c *Contracts) SupportBlobTxs() bool

SupportBlobTxs returns whether the current contracts support blob transactions.

func (*Contracts) TransactionAndBlockHeader

func (c *Contracts) TransactionAndBlockHeader(ctx context.Context, txHash common.Hash,
) (*gethtypes.Transaction, *gethtypes.Header, error)

TransactionAndBlockHeader returns the full tx identified by txHash and the header of the block it was mined in.

func (*Contracts) WaitTxByHash

func (c *Contracts) WaitTxByHash(txHash common.Hash, timeOut time.Duration, cb ...func(error)) error

WaitTxByHash waits for a transaction to be mined given its hash. If the transaction is not mined within the timeout, it returns an error.

func (*Contracts) WaitTxByID

func (c *Contracts) WaitTxByID(id []byte, timeOut time.Duration, cb ...func(error)) error

WaitTxByID waits for a transaction to be mined given its hash. If the transaction is not mined within the timeout, it returns an error.

func (*Contracts) Web3Pool

func (c *Contracts) Web3Pool() *rpc.Web3Pool

Web3Pool returns the web3 pool used by the Contracts instance.

type SimulatedBlock

type SimulatedBlock struct {
	Hash   common.Hash  `json:"hash"`
	Number string       `json:"number"`
	Calls  []CallResult `json:"calls"`
}

SimulatedBlock is the result of a simulated block

type SimulationRequest

type SimulationRequest struct {
	BlockStateCalls        []BlockStateCall `json:"blockStateCalls"`
	Validation             bool             `json:"validation,omitempty"`
	TraceTransfers         bool             `json:"traceTransfers,omitempty"`
	ReturnFullTransactions bool             `json:"returnFullTransactions,omitempty"`
}

SimulationRequest is the top‐level payload for eth_simulateV1

type StateOverride

type StateOverride struct {
	Balance *hexutil.Big   `json:"balance,omitempty"`
	Nonce   hexutil.Uint64 `json:"nonce,omitempty"`
	Code    *hexutil.Bytes `json:"code,omitempty"`
}

StateOverride lets you override state fields

Directories

Path Synopsis
rpc

Jump to

Keyboard shortcuts

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