etherman

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultInterval is a time interval
	DefaultInterval = 2 * time.Millisecond
	// DefaultDeadline is a time interval
	DefaultDeadline = 2 * time.Minute
	// DefaultTxMinedDeadline is a time interval
	DefaultTxMinedDeadline = 5 * time.Second
)

Variables

View Source
var (
	// ErrNotFound is used when the object is not found
	ErrNotFound = errors.New("not found")
	// ErrPrivateKeyNotFound used when the provided sender does not have a private key registered to be used
	ErrPrivateKeyNotFound = errors.New("can't find sender private key to sign tx")
)
View Source
var (
	// ErrTimeoutReached is thrown when the timeout is reached and
	// because the condition is not matched
	ErrTimeoutReached = fmt.Errorf("timeout has been reached")
)

Functions

func Poll

func Poll(interval, deadline time.Duration, condition ConditionFunc) error

Poll retries the given condition with the given interval until it succeeds or the given deadline expires.

func RevertReason

func RevertReason(ctx context.Context, c ethClienter, tx *types.Transaction, blockNumber *big.Int) (string, error)

RevertReason returns the revert reason for a tx that has a receipt with failed status

func WaitSignal

func WaitSignal(cleanupFuncs ...func())

WaitSignal blocks until an Interrupt or Kill signal is received, then it executes the given cleanup functions and returns.

func WaitTxReceipt

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

WaitTxReceipt waits until a tx receipt is available or the given timeout expires.

func WaitTxToBeMined

func WaitTxToBeMined(
	parentCtx context.Context,
	client ethClienter,
	tx *types.Transaction,
	timeout time.Duration,
) error

WaitTxToBeMined waits until a tx has been mined or the given timeout expires.

Types

type Client

type Client struct {
	EthClient ethereumClient

	GasProviders externalGasProviders
	// contains filtered or unexported fields
}

Client is a simple implementation of EtherMan.

func NewClient

func NewClient(cfg Config) (*Client, error)

NewClient creates a new etherman.

func (*Client) AddOrReplaceAuth

func (etherMan *Client) AddOrReplaceAuth(auth bind.TransactOpts) error

AddOrReplaceAuth adds an authorization or replace an existent one to the same account

func (*Client) CheckTxWasMined

func (etherMan *Client) CheckTxWasMined(ctx context.Context, txHash common.Hash) (bool, *types.Receipt, error)

CheckTxWasMined check if a tx was already mined

func (*Client) CurrentNonce

func (etherMan *Client) CurrentNonce(ctx context.Context, account common.Address) (uint64, error)

CurrentNonce returns the current nonce for the provided account

func (*Client) EstimateGas

func (etherMan *Client) EstimateGas(
	ctx context.Context,
	from common.Address,
	to *common.Address,
	value *big.Int,
	data []byte,
) (uint64, error)

EstimateGas returns the estimated gas for the tx

func (*Client) EstimateGasBlobTx added in v0.1.0

func (etherMan *Client) EstimateGasBlobTx(
	ctx context.Context,
	from common.Address,
	to *common.Address,
	gasFeeCap *big.Int,
	gasTipCap *big.Int,
	value *big.Int,
	data []byte,
) (uint64, error)

EstimateGasBlobTx returns the estimated gas for the blob tx

func (*Client) GetHeaderByNumber added in v0.1.0

func (etherMan *Client) GetHeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)

GetHeaderByNumber returns a block header from the current canonical chain. If number is nil the latest header is returned

func (*Client) GetL1GasPrice

func (etherMan *Client) GetL1GasPrice(ctx context.Context) *big.Int

GetL1GasPrice gets the l1 gas price

func (*Client) GetLatestBlockNumber

func (etherMan *Client) GetLatestBlockNumber(ctx context.Context) (uint64, error)

GetLatestBlockNumber gets the latest block number from the ethereum

func (*Client) GetRevertMessage

func (etherMan *Client) GetRevertMessage(ctx context.Context, tx *types.Transaction) (string, error)

GetRevertMessage tries to get a revert message of a transaction

func (*Client) GetSuggestGasTipCap added in v0.1.0

func (etherMan *Client) GetSuggestGasTipCap(ctx context.Context) (*big.Int, error)

GetSuggestGasTipCap retrieves the currently suggested gas tip cap after EIP-1559 for timely transaction execution.

func (*Client) GetTx

func (etherMan *Client) GetTx(ctx context.Context, txHash common.Hash) (*types.Transaction, bool, error)

GetTx function get ethereum tx

func (*Client) GetTxReceipt

func (etherMan *Client) GetTxReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

GetTxReceipt function gets ethereum tx receipt

func (*Client) HeaderByNumber added in v0.1.5

func (etherMan *Client) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)

HeaderByNumber returns a block header from the current canonical chain. If number is nil, the latest known header is returned.

func (*Client) LoadAuthFromKeyStore

func (etherMan *Client) LoadAuthFromKeyStore(path, password string) (*bind.TransactOpts, error)

LoadAuthFromKeyStore loads an authorization from a key store file

func (*Client) PendingNonce

func (etherMan *Client) PendingNonce(ctx context.Context, account common.Address) (uint64, error)

PendingNonce returns the pending nonce for the provided account

func (*Client) SendTx

func (etherMan *Client) SendTx(ctx context.Context, tx *types.Transaction) error

SendTx sends a tx to L1

func (*Client) SignTx

func (etherMan *Client) SignTx(
	ctx context.Context,
	sender common.Address,
	tx *types.Transaction,
) (*types.Transaction, error)

SignTx tries to sign a transaction accordingly to the provided sender

func (*Client) SuggestedGasPrice

func (etherMan *Client) SuggestedGasPrice(ctx context.Context) (*big.Int, error)

SuggestedGasPrice returns the suggest nonce for the network at the moment

func (*Client) WaitTxToBeMined

func (etherMan *Client) WaitTxToBeMined(
	ctx context.Context,
	tx *types.Transaction,
	timeout time.Duration,
) (bool, error)

WaitTxToBeMined waits for an L1 tx to be mined. It will return error if the tx is reverted or timeout is exceeded

type ConditionFunc

type ConditionFunc func() (done bool, err error)

ConditionFunc is a generic function

type Config

type Config struct {
	// URL is the URL of the Ethereum node for L1
	URL string `mapstructure:"URL"`

	// allow that L1 gas price calculation use multiples sources
	MultiGasProvider bool `mapstructure:"MultiGasProvider"`
	// Configuration for use Etherscan as used as gas provider, basically it needs the API-KEY
	Etherscan etherscan.Config
	// L1ChainID is the chain ID of the L1
	L1ChainID uint64 `mapstructure:"L1ChainID"`
	// HTTPHeaders are the headers to be used in the HTTP requests
	HTTPHeaders map[string]string `mapstructure:"HTTPHeaders"`
}

Config represents the configuration of the etherman

type Wait

type Wait struct{}

Wait handles polliing until conditions are met.

func NewWait

func NewWait() *Wait

NewWait is the Wait constructor.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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