util

package
v0.1.120 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Silent = 0
	Panic  = 100
	Fatal  = 200
	Error  = 300
	Warn   = 400
	Info   = 500
	Debug  = 600
	Trace  = 700
)

Verbosity levels. https://pkg.go.dev/github.com/rs/zerolog#readme-leveled-logging

View Source
const (
	Multicall3SCAddr          = "0xcA11bde05977b3631167028862bE2a173976CA11"
	Multicall3DeployerAddress = "0x05f32b3cc3888453ff71b01135b34ff8e41263f2"
	Multicall3SignedDeployTX  = "" /* 7854-byte string literal not displayed */
)

Variables

This section is empty.

Functions

func BlockUntilSuccessful

func BlockUntilSuccessful(ctx context.Context, c *ethclient.Client, retryable func() error) error

func CompareFloatsWithTolerance added in v0.1.103

func CompareFloatsWithTolerance(a, b, tolerance float64) bool

func Ecrecover

func Ecrecover(header *types.Header) (signer []byte, err error)

Ecrecover recovers the signer address from a block header's seal (the last SignatureLength bytes of Extra) using the clique seal hash.

The header may come straight off the p2p wire, so treat it as untrusted. clique's encodeSigHeader panics rather than errors on any post-Merge trailing field it does not expect -- WithdrawalsHash, ExcessBlobGas, BlobGasUsed, ParentBeaconRoot, and as of go-ethereum v1.17.4 SlotNumber. Every one is rlp:"optional", so a peer sets them at will, and a caller running on a peer goroutine takes the whole process down with it.

The panic is converted to an error rather than pre-checked field by field on purpose: that set grows with the geth releases that add one, and a hand-kept field list would silently stop covering it at the next dependency bump.

func EcrecoverTx added in v0.1.73

func EcrecoverTx(tx *types.Transaction) ([]byte, error)

func GetAddress added in v0.1.88

func GetAddress(ctx context.Context, privateKey *ecdsa.PrivateKey) common.Address

func GetAddressAndPrivateKeyHex added in v0.1.88

func GetAddressAndPrivateKeyHex(ctx context.Context, privateKey *ecdsa.PrivateKey) (string, string)

Returns the address and private key of the given private key

func GetBlockRange

func GetBlockRange(ctx context.Context, from, to uint64, c *ethrpc.Client, onlyTxHashes bool) ([]*json.RawMessage, error)

func GetBlockRangeInPages

func GetBlockRangeInPages(ctx context.Context, from, to, pageSize uint64, c *ethrpc.Client, onlyTxHashes bool) ([]*json.RawMessage, error)

func GetChainID added in v0.1.103

func GetChainID(ctx context.Context, ec *ethrpc.Client) (*big.Int, error)

func GetForkID added in v0.1.63

func GetForkID(rpc *ethrpc.Client) (uint64, error)

func GetHexString added in v0.1.65

func GetHexString(data any) string

func GetPrivateKeyHex added in v0.1.88

func GetPrivateKeyHex(privateKey *ecdsa.PrivateKey) string

func GetReceipts

func GetReceipts(ctx context.Context, rawBlocks []*json.RawMessage, c *ethrpc.Client, batchSize uint64) ([]*json.RawMessage, error)

func GetRollupAddress added in v0.1.63

func GetRollupAddress(rpc *ethrpc.Client) (string, error)

func GetRollupManagerAddress added in v0.1.63

func GetRollupManagerAddress(rpc *ethrpc.Client) (string, error)

func GetSenderFromTx added in v0.1.103

func GetSenderFromTx(ctx context.Context, tx rpctypes.PolyTransaction) (common.Address, error)

GetSenderFromTx recovers the sender address from a transaction without using types.Transaction

func GetTxPoolStatus

func GetTxPoolStatus(rpc *ethrpc.Client) (uint64, uint64, error)

func GetZkEVMBatches

func GetZkEVMBatches(rpc *ethrpc.Client) (uint64, uint64, uint64, error)

func HeaderByBlockNumber added in v0.1.103

func HeaderByBlockNumber(ctx context.Context, ec *ethrpc.Client, blockNum *ethrpc.BlockNumber) (*types.Header, error)

HeaderByBlockNumber retrieves a block header using rpc.BlockNumber. If blockNum is nil, it defaults to latest block. Examples:

  • HeaderByBlockNumber(ctx, client, nil) // latest
  • HeaderByBlockNumber(ctx, client, &rpc.LatestBlockNumber)
  • HeaderByBlockNumber(ctx, client, &rpc.FinalizedBlockNumber)
  • num := rpc.BlockNumber(12345); HeaderByBlockNumber(ctx, client, &num)

func HexToBigInt

func HexToBigInt(hexString string) (*big.Int, error)

HexToBigInt converts a hexadecimal string to a big integer.

func IsMulticall3Supported added in v0.1.90

func IsMulticall3Supported(ctx context.Context, c *ethclient.Client, tryDeployIfNotExist bool, tops *bind.TransactOpts, customAddr *common.Address) (*common.Address, bool)

func Multicall3DeterministicDeploy added in v0.1.98

func Multicall3DeterministicDeploy(c *ethclient.Client, sender *bind.TransactOpts) (common.Address, *types.Transaction, *multicall3.Multicall3, error)

func Multicall3Exists added in v0.1.90

func Multicall3Exists(ctx context.Context, c *ethclient.Client, customAddr *common.Address) (common.Address, bool, error)

func Multicall3FundAccountsWithERC20Token added in v0.1.92

func Multicall3FundAccountsWithERC20Token(ctx context.Context, c *ethclient.Client, tops *bind.TransactOpts, accounts []common.Address, tokenAddress common.Address, amount *big.Int, customAddr *common.Address) (approveTx, transfersTx *types.Transaction, err error)

func Multicall3FundAccountsWithNativeToken added in v0.1.90

func Multicall3FundAccountsWithNativeToken(c *ethclient.Client, tops *bind.TransactOpts, accounts []common.Address, amount *big.Int, customAddr *common.Address) (*types.Transaction, error)

func Multicall3IndeterministicDeploy added in v0.1.98

func Multicall3IndeterministicDeploy(c *ethclient.Client, sender *bind.TransactOpts) (common.Address, *types.Transaction, *multicall3.Multicall3, error)

func Multicall3MaxAccountsToFundPerTx added in v0.1.90

func Multicall3MaxAccountsToFundPerTx(ctx context.Context, c *ethclient.Client) (uint64, error)

func Multicall3New added in v0.1.90

func Multicall3New(c *ethclient.Client, customAddr *common.Address) (common.Address, *multicall3.Multicall3, error)

func ParseVerbosity added in v0.1.90

func ParseVerbosity(v string) (int, error)

ParseVerbosity parses a verbosity string (e.g., "info", "debug") or integer and returns the corresponding verbosity level.

func ReadPrivateKeysFromFile added in v0.1.88

func ReadPrivateKeysFromFile(sendingAddressesFile string) ([]*ecdsa.PrivateKey, error)

func SendTx

func SendTx(ctx context.Context, c *ethclient.Client, privateKey *ecdsa.PrivateKey, to *common.Address, amount *big.Int, data []byte, gasLimit uint64) error

SendTx is a simple wrapper to send a transaction from one Ethereum address to another.

func SetLogLevel

func SetLogLevel(verbosity int)

SetLogLevel sets the log level based on the flags. https://logging.apache.org/log4j/2.x/manual/customloglevels.html

func SetLogMode

func SetLogMode(mode LogMode) error

SetLogMode updates the log format.

func ValidateURL added in v0.1.101

func ValidateURL(input string) error

ValidateURL checks if a string URL can be parsed and if it has a valid scheme.

func WaitPreconf added in v0.1.104

func WaitPreconf(ctx context.Context, client *ethclient.Client, txHash common.Hash, timeout time.Duration) (bool, error)

WaitPreconf waits for a preconf status check with a specified timeout. Uses exponential backoff with jitter, similar to WaitReceiptWithTimeout.

func WaitReceipt added in v0.1.92

func WaitReceipt(ctx context.Context, client *ethclient.Client, txHash common.Hash) (*types.Receipt, error)

WaitReceipt waits for a transaction receipt with default parameters.

func WaitReceiptWithRetries added in v0.1.92

func WaitReceiptWithRetries(ctx context.Context, client *ethclient.Client, txHash common.Hash, maxRetries uint, initialDelayMs uint) (*types.Receipt, error)

WaitReceiptWithRetries waits for a transaction receipt with retries and exponential backoff.

func WaitReceiptWithTimeout added in v0.1.92

func WaitReceiptWithTimeout(ctx context.Context, client *ethclient.Client, txHash common.Hash, timeout time.Duration) (*types.Receipt, error)

WaitReceiptWithTimeout waits for a transaction receipt with a specified timeout.

func WrapDeployedCode added in v0.1.65

func WrapDeployedCode(deployedBytecode string, storageBytecode string) string

Types

type BlockUntilSuccessfulFn

type BlockUntilSuccessfulFn func(ctx context.Context, c *ethclient.Client, f func() error) error

BlockUntilSuccessfulFn is designed to wait until a specified number of Ethereum blocks have been mined, periodically checking for the completion of a given function within each block interval.

type LogMode

type LogMode string

LogMode represents the logger mode.

const (
	Console LogMode = "console"
	JSON    LogMode = "json"
)

Jump to

Keyboard shortcuts

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