Documentation
¶
Overview ¶
Package evm provides EVM chain interaction and transaction utilities.
Index ¶
- Variables
- func CalculateEvmFeeInLux(gasUsed uint64, gasPrice *big.Int) float64
- func ConvertToNanoLux(balance *big.Int) *big.Int
- func ExtractWarpMessageFromLogs(logs []*types.Log) (*warp.UnsignedMessage, error)
- func ExtractWarpMessageFromReceipt(receipt *types.Receipt) (*warp.UnsignedMessage, error)
- func GetClientWithoutScheme(rpcURL string) (ethclient.Client, string, error)
- func GetErrorFromTrace(trace map[string]interface{}, functionSignatureToError map[string]error) (error, error)
- func GetEventFromLogs[T any](logs []*types.Log, parser func(log types.Log) (T, error)) (T, error)
- func GetFunctionSelector(functionSignature string) string
- func GetTxTrace(rpcURL string, txID string) (map[string]interface{}, error)
- func GetWarpMessagesFromLogs(logs []*types.Log) []*warp.UnsignedMessage
- func HasScheme(rpcURL string) (bool, error)
- func HexToAddress(s string) common.Address
- func PrivateKeyToAddress(privateKey string) (crypto.Address, error)
- func TransactionError(tx *types.Transaction, err error, msg string, args ...interface{}) error
- func TxDump(description string, tx *types.Transaction) (string, error)
- type Client
- func (client Client) BlockByNumber(n *big.Int) (*types.Block, error)
- func (client Client) BlockNumber() (uint64, error)
- func (client Client) CalculateTxParams(address string) (*big.Int, *big.Int, uint64, error)
- func (client Client) ChainConfig() (*evmParams.ChainConfigWithUpgradesJSON, error)
- func (client Client) Close()
- func (client Client) ContractAlreadyDeployed(contractAddress string) (bool, error)
- func (client Client) CreateDummyBlocks(numBlocks int, privKeyStr string) error
- func (client Client) EstimateBaseFee() (*big.Int, error)
- func (client Client) EstimateGasLimit(msg ethereum.CallMsg) (uint64, error)
- func (client Client) FilterLogs(query ethereum.FilterQuery) ([]types.Log, error)
- func (client Client) FundAddress(sourceAddressPrivateKeyStr string, targetAddressStr string, amount *big.Int) (*types.Receipt, error)
- func (client Client) GetAddressBalance(addressStr string) (*big.Int, error)
- func (client Client) GetChainID() (*big.Int, error)
- func (client Client) GetContractBytecode(contractAddressStr string) ([]byte, error)
- func (client Client) GetPrivateKeyBalance(privateKey string) (*big.Int, error)
- func (client Client) GetTxOptsWithSigner(prefundedPrivateKeyStr string) (*bind.TransactOpts, error)
- func (client Client) IssueTx(txStr string) error
- func (client Client) NonceAt(addressStr string) (uint64, error)
- func (client Client) SendTransaction(tx *types.Transaction) error
- func (client Client) SetupProposerVM(privKey string) error
- func (client Client) SuggestGasTipCap() (*big.Int, error)
- func (client Client) TransactWithWarpMessage(from crypto.Address, privateKeyStr string, warpMessage *warp.Message, ...) (*types.Transaction, error)
- func (client Client) TransactionReceipt(hash common.Hash) (*types.Receipt, error)
- func (client Client) WaitForEVMBootstrapped(timeout time.Duration) error
- func (client Client) WaitForNewBlock(prevBlockNumber uint64, totalDuration time.Duration) error
- func (client Client) WaitForTransaction(tx *types.Transaction) (*types.Receipt, bool, error)
- type RawClient
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownErrorSelector = fmt.Errorf("unknown error selector")
Functions ¶
func ConvertToNanoLux ¶
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)
ExtractWarpMessageFromLogs gets first unsigned warp message contained in [logs].
func ExtractWarpMessageFromReceipt ¶
func ExtractWarpMessageFromReceipt( receipt *types.Receipt, ) (*warp.UnsignedMessage, error)
ExtractWarpMessageFromReceipt gets first unsigned warp message contained in [receipt].
func GetClientWithoutScheme ¶
GetClientWithoutScheme 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)
GetErrorFromTrace 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 ¶
GetEventFromLogs returns the first log in 'logs' that is successfully parsed by 'parser'.
func GetFunctionSelector ¶
GetFunctionSelector 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 ¶
GetTxTrace returns a trace for the given [txID] on [rpcURL]. Supports [repeatsOnFailure] failures.
func GetWarpMessagesFromLogs ¶
func GetWarpMessagesFromLogs( logs []*types.Log, ) []*warp.UnsignedMessage
GetWarpMessagesFromLogs gets all unsigned warp messages contained in [logs].
func HexToAddress ¶
HexToAddress converts hex string to common.Address (geth type)
func PrivateKeyToAddress ¶
PrivateKeyToAddress returns the public address associated with [privateKey].
func TransactionError ¶
func TransactionError(tx *types.Transaction, err error, msg string, args ...interface{}) error
TransactionError transforms 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 formatted [args]
Types ¶
type Client ¶
Client wraps over ethclient for calls used by SDK. 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 - receives addresses and private keys as strings
func GetClient ¶
GetClient connects an evm client to the given [rpcURL] supports [repeatsOnFailure] failures
func (Client) BlockByNumber ¶
BlockByNumber gets block [n] supports [repeatsOnFailure] failures
func (Client) BlockNumber ¶
BlockNumber gets current height supports [repeatsOnFailure] failures
func (Client) CalculateTxParams ¶
CalculateTxParams 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() (*evmParams.ChainConfigWithUpgradesJSON, error)
ChainConfig returns the chain conf supports [repeatsOnFailure] failures
func (Client) ContractAlreadyDeployed ¶
ContractAlreadyDeployed indicates wether a contract is deployed on [contractAddress] supports [repeatsOnFailure] failures
func (Client) CreateDummyBlocks ¶
CreateDummyBlocks issues dummy txs to create the given number of blocks
func (Client) EstimateBaseFee ¶
EstimateBaseFee returns the estimated base fee supports [repeatsOnFailure] failures
func (Client) EstimateGasLimit ¶
EstimateGasLimit returns the estimated gas limit supports [repeatsOnFailure] failures
func (Client) FilterLogs ¶
FilterLogs gets 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)
FundAddress transfers [amount] to [targetAddressStr] using [sourceAddressPrivateKeyStr] supports [repeatsOnFailure] failures on each step
func (Client) GetAddressBalance ¶
GetAddressBalance returns the balance for [address] supports [repeatsOnFailure] failures
func (Client) GetChainID ¶
GetChainID returns the chain ID supports [repeatsOnFailure] failures
func (Client) GetContractBytecode ¶
GetContractBytecode returns the contract bytecode at [contractAddress] supports [repeatsOnFailure] failures
func (Client) GetPrivateKeyBalance ¶
GetPrivateKeyBalance returns the balance for [privateKey] supports [repeatsOnFailure] failures
func (Client) GetTxOptsWithSigner ¶
func (client Client) GetTxOptsWithSigner( prefundedPrivateKeyStr string, ) (*bind.TransactOpts, error)
GetTxOptsWithSigner returns tx options that include signer for [prefundedPrivateKeyStr] supports [repeatsOnFailure] failures when gathering chain info
func (Client) IssueTx ¶
IssueTx encodes [txStr] to binary, sends and waits for it supports [repeatsOnFailure] failures on each step
func (Client) SendTransaction ¶
func (client Client) SendTransaction( tx *types.Transaction, ) error
SendTransaction sends [tx] supports [repeatsOnFailure] failures
func (Client) SetupProposerVM ¶
SetupProposerVM issues 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 ¶
SuggestGasTipCap returns the suggested gas tip supports [repeatsOnFailure] failures
func (Client) TransactWithWarpMessage ¶
func (client Client) TransactWithWarpMessage( from crypto.Address, privateKeyStr string, warpMessage *warp.Message, contract crypto.Address, callData []byte, value *big.Int, generateRawTxOnly bool, ) (*types.Transaction, error)
TransactWithWarpMessage 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 ¶
TransactionReceipt gets tx receipt for hash supports [repeatsOnFailure] failures
func (Client) WaitForEVMBootstrapped ¶
WaitForEVMBootstrapped waits for [timeout] until evm is bootstrapped considers evm is bootstrapped if it responds to an evm call (ChainID)
func (Client) WaitForNewBlock ¶
WaitForNewBlock waits until current height is bigger than the given previous height at [prevBlockNumber] supports [repeatsOnFailure] failures on each step
func (Client) WaitForTransaction ¶
WaitForTransaction 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
}
RawClient 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 ¶
GetRawClient connects a raw evm rpc client to the given [rpcURL]. Supports [repeatsOnFailure] failures.
func (RawClient) DebugTraceCall ¶
DebugTraceCall returns a trace for making a call on [client] with the given [data]. Supports [repeatsOnFailure] failures.