evm

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Overview

Copyright (C) 2025, Lux Industries Inc. All rights reserved. See the file LICENSE for licensing terms.

Copyright (C) 2025, Lux Industries Inc. All rights reserved. See the file LICENSE for licensing terms.

Copyright (C) 2025, Lux Industries Inc. All rights reserved. See the file LICENSE for licensing terms.

Copyright (C) 2025, Lux Industries Inc. All rights reserved. See the file LICENSE for licensing terms.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownErrorSelector = fmt.Errorf("unknown error selector")

Functions

func CalculateEvmFeeInLux

func CalculateEvmFeeInLux(gasUsed uint64, gasPrice *big.Int) float64

func ConvertToNanoLux

func ConvertToNanoLux(balance *big.Int) *big.Int

ConvertToNanoLux converts a balance in Lux to NanoLux. It adds 0.5 to the balance before dividing by 1e9 to round it to the nearest whole number.

func ExtractWarpMessageFromLogs

func ExtractWarpMessageFromLogs(
	logs []*types.Log,
) (*warp.UnsignedMessage, error)

get first unsigned warp message contained in [logs]

func ExtractWarpMessageFromReceipt

func ExtractWarpMessageFromReceipt(
	receipt *types.Receipt,
) (*warp.UnsignedMessage, error)

get first unsigned warp message contained in [receipt]

func GetClientWithoutScheme

func GetClientWithoutScheme(rpcURL string) (ethclient.Client, string, error)

tries to connect an ethclient to a rpc url without scheme, by trying out different possible schemes: ws, wss, https, http

func GetErrorFromTrace

func GetErrorFromTrace(
	trace map[string]interface{},
	functionSignatureToError map[string]error,
) (error, error)

returns golang error associated with [trace] by using [functionSignatureToError] to map function signatures to evm function selectors in [trace], and then to golang errors first returned error is the mapped error, second error is for errors obtained executing this function

func GetEventFromLogs

func GetEventFromLogs[T any](logs []*types.Log, parser func(log types.Log) (T, error)) (T, error)

Returns the first log in 'logs' that is successfully parsed by 'parser'

func GetFunctionSelector

func GetFunctionSelector(functionSignature string) string

returns evm function selector code for the given function signature evm maps function and error signatures into codes that are then used in traces

func GetTxTrace

func GetTxTrace(rpcURL string, txID string) (map[string]interface{}, error)

returns a trace for the given [txID] on [rpcURL] supports [repeatsOnFailure] failures

func GetWarpMessagesFromLogs

func GetWarpMessagesFromLogs(
	logs []*types.Log,
) []*warp.UnsignedMessage

get all unsigned warp messages contained in [logs]

func HasScheme

func HasScheme(rpcURL string) (bool, error)

indicates if the given rpc url has schema or not

func PrivateKeyToAddress

func PrivateKeyToAddress(privateKey string) (common.Address, error)

returns the public address associated with [privateKey]

func TransactionError

func TransactionError(tx *types.Transaction, err error, msg string, args ...interface{}) error

transform a tx operation error into an error that contains: - the [err] itself - the [tx] hash (or information on the tx not being submitted) - another descriptive [msg], together with formated [args]

func TxDump

func TxDump(description string, tx *types.Transaction) (string, error)

dumps a [tx] hexa description, for it to be separately issued using external tools

Types

type Client

type Client struct {
	EthClient ethclient.Client
	URL       string
}

wraps over ethclient for calls used by SDK. featues: - finds out url scheme in case it is missing, to connect to ws/wss/http/https - repeats to try to recover from failures, generating its own context for each call - logs rpc url in case of failure - receives addresses and private keys as strings

func GetClient

func GetClient(rpcURL string) (Client, error)

connects an evm client to the given [rpcURL] supports [repeatsOnFailure] failures

func (Client) BlockByNumber

func (client Client) BlockByNumber(n *big.Int) (*types.Block, error)

gets block [n] supports [repeatsOnFailure] failures

func (Client) BlockNumber

func (client Client) BlockNumber() (uint64, error)

gets current height supports [repeatsOnFailure] failures

func (Client) CalculateTxParams

func (client Client) CalculateTxParams(
	address string,
) (*big.Int, *big.Int, uint64, error)

Returns gasFeeCap, gasTipCap, and nonce to be used when constructing a transaction supports [repeatsOnFailure] failures on each step

func (Client) ChainConfig

func (client Client) ChainConfig() (*params.ChainConfigWithUpgradesJSON, error)

returns the chain conf supports [repeatsOnFailure] failures

func (Client) Close

func (client Client) Close()

closes underlying ethclient connection

func (Client) ContractAlreadyDeployed

func (client Client) ContractAlreadyDeployed(
	contractAddress string,
) (bool, error)

indicates wether a contract is deployed on [contractAddress] supports [repeatsOnFailure] failures

func (Client) CreateDummyBlocks

func (client Client) CreateDummyBlocks(
	numBlocks int,
	privKeyStr string,
) error

issue dummy txs to create the given number of blocks

func (Client) EstimateBaseFee

func (client Client) EstimateBaseFee() (*big.Int, error)

returns the estimated base fee supports [repeatsOnFailure] failures

func (Client) EstimateGasLimit

func (client Client) EstimateGasLimit(
	msg interfaces.CallMsg,
) (uint64, error)

returns the estimated gas limit supports [repeatsOnFailure] failures

func (Client) FilterLogs

func (client Client) FilterLogs(query interfaces.FilterQuery) ([]types.Log, error)

get logs as given by [query] supports [repeatsOnFailure] failures

func (Client) FundAddress

func (client Client) FundAddress(
	sourceAddressPrivateKeyStr string,
	targetAddressStr string,
	amount *big.Int,
) (*types.Receipt, error)

transfers [amount] to [targetAddressStr] using [sourceAddressPrivateKeyStr] supports [repeatsOnFailure] failures on each step

func (Client) GetAddressBalance

func (client Client) GetAddressBalance(
	addressStr string,
) (*big.Int, error)

returns the balance for [address] supports [repeatsOnFailure] failures

func (Client) GetChainID

func (client Client) GetChainID() (*big.Int, error)

returns the chain ID supports [repeatsOnFailure] failures

func (Client) GetContractBytecode

func (client Client) GetContractBytecode(
	contractAddressStr string,
) ([]byte, error)

returns the contract bytecode at [contractAddress] supports [repeatsOnFailure] failures

func (Client) GetPrivateKeyBalance

func (client Client) GetPrivateKeyBalance(
	privateKey string,
) (*big.Int, error)

returns the balance for [privateKey] supports [repeatsOnFailure] failures

func (Client) GetTxOptsWithSigner

func (client Client) GetTxOptsWithSigner(
	prefundedPrivateKeyStr string,
) (*bind.TransactOpts, error)

returns tx options that include signer for [prefundedPrivateKeyStr] supports [repeatsOnFailure] failures when gathering chain info

func (Client) IssueTx

func (client Client) IssueTx(
	txStr string,
) error

encode [txStr] to binary, sends and waits for it supports [repeatsOnFailure] failures on each step

func (Client) NonceAt

func (client Client) NonceAt(
	addressStr string,
) (uint64, error)

returns the nonce at [address] supports [repeatsOnFailure] failures

func (Client) SendTransaction

func (client Client) SendTransaction(
	tx *types.Transaction,
) error

sends [tx] supports [repeatsOnFailure] failures

func (Client) SetupProposerVM

func (client Client) SetupProposerVM(
	privKey string,
) error

issue transactions on [client] so as to activate Proposer VM Fork this should generate a PostForkBlock because its parent block (genesis) has a timestamp (0) that is greater than or equal to the fork activation time of 0. Therefore, subsequent blocks should be built with BuildBlockWithContext. the current timestamp should be after the ProposerVM activation time (aka ApricotPhase4). supports [repeatsOnFailure] failures on each step

func (Client) SuggestGasTipCap

func (client Client) SuggestGasTipCap() (*big.Int, error)

returns the suggested gas tip supports [repeatsOnFailure] failures

func (Client) TransactWithWarpMessage

func (client Client) TransactWithWarpMessage(
	from common.Address,
	privateKeyStr string,
	warpMessage *luxWarp.Message,
	contract common.Address,
	callData []byte,
	value *big.Int,
	generateRawTxOnly bool,
) (*types.Transaction, error)

generates a transaction signed with [privateKeyStr], calling a [contract] method using [callData] including [warpMessage] in the tx accesslist if [generateRawTxOnly] is set, it generates a similar, unsigned tx, with given [from] address

func (Client) TransactionReceipt

func (client Client) TransactionReceipt(hash common.Hash) (*types.Receipt, error)

get tx receipt for hash supports [repeatsOnFailure] failures

func (Client) WaitForEVMBootstrapped

func (client Client) WaitForEVMBootstrapped(timeout time.Duration) error

waits for [timeout] until evm is bootstrapped considers evm is bootstrapped if it responds to an evm call (ChainID)

func (Client) WaitForNewBlock

func (client Client) WaitForNewBlock(
	prevBlockNumber uint64,
	totalDuration time.Duration,
) error

waits until current height is bigger than the given previous height at [prevBlockNumber] supports [repeatsOnFailure] failures on each step

func (Client) WaitForTransaction

func (client Client) WaitForTransaction(
	tx *types.Transaction,
) (*types.Receipt, bool, error)

waits for [tx]'s receipt to have successful state supports [repeatsOnFailure] failures

type RawClient

type RawClient struct {
	RPCClient *rpc.Client
	URL       string
	// also used at mocks
	CallContext func(context.Context, interface{}, string, ...interface{}) error
}

wraps over rpc.Client for calls used by SDK. used to make evm calls not available in ethclient: - debug trace call - debug trace transaction features: - finds out url scheme in case it is missing, to connect to ws/wss/http/https - repeats to try to recover from failures, generating its own context for each call - logs rpc url in case of failure

func GetRawClient

func GetRawClient(rpcURL string) (RawClient, error)

connects a raw evm rpc client to the given [rpcURL] supports [repeatsOnFailure] failures

func (RawClient) Close

func (client RawClient) Close()

closes underlying rpc connection

func (RawClient) DebugTraceCall

func (client RawClient) DebugTraceCall(
	data map[string]string,
) (map[string]interface{}, error)

returns a trace for making a call on [client] with the given [data] supports [repeatsOnFailure] failures

func (RawClient) DebugTraceTransaction

func (client RawClient) DebugTraceTransaction(
	txID string,
) (map[string]interface{}, error)

returns a trace for the given [txID] on [client] supports [repeatsOnFailure] failures

Jump to

Keyboard shortcuts

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