extethclient

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: LGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package extethclient provides libraries for interacting with an ethereum node using a specific private key.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EthClient

type EthClient interface {
	Address() ethcommon.Address
	SetAddress(addr ethcommon.Address)
	PrivateKey() *ecdsa.PrivateKey
	HasPrivateKey() bool
	Endpoint() string

	Balance(ctx context.Context) (*coins.WeiAmount, error)
	ERC20Balance(ctx context.Context, token ethcommon.Address) (*coins.ERC20TokenAmount, error)

	ERC20Info(ctx context.Context, tokenAddr ethcommon.Address) (*coins.ERC20TokenInfo, error)

	SetGasPrice(uint64)
	SetGasLimit(uint64)
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
	CallOpts(ctx context.Context) *bind.CallOpts
	TxOpts(ctx context.Context) (*bind.TransactOpts, error)
	ChainID() *big.Int
	Lock()   // Lock the wallet so only one transaction runs at at time
	Unlock() // Unlock the wallet after a transaction is complete

	// Transfer transfers ETH to the given address, nonce Lock()/Unlock()
	// handling is done internally. The gasLimit field when the destination
	// address is not a contract.
	Transfer(
		ctx context.Context,
		to ethcommon.Address,
		amount *coins.WeiAmount,
		gasLimit *uint64,
	) (*ethtypes.Receipt, error)

	// Sweep transfers all funds to the given address, nonce Lock()/Unlock()
	// handling is done internally. Dust may be left is sending to a contract
	// address, otherwise the balance afterward will be zero.
	Sweep(ctx context.Context, to ethcommon.Address) (*ethtypes.Receipt, error)

	// CancelTxWithNonce attempts to cancel a transaction with the given nonce
	// by sending a zero-value tx to ourselves. Since the nonce is fixed, no
	// locking is done. You can even intentionally run this method to fail some
	// other method that has the lock and is waiting for a receipt.
	CancelTxWithNonce(ctx context.Context, nonce uint64, gasPrice *big.Int) (*ethtypes.Receipt, error)

	WaitForReceipt(ctx context.Context, txHash ethcommon.Hash) (*ethtypes.Receipt, error)
	WaitForTimestamp(ctx context.Context, ts time.Time) error
	LatestBlockTimestamp(ctx context.Context) (time.Time, error)

	Close()
	Raw() *ethclient.Client
}

EthClient provides management of a private key and other convenience functions layered on top of the go-ethereum client. You can still access the raw go-ethereum client via the Raw() method.

func CreateTestClient

func CreateTestClient(t *testing.T, ethKey *ecdsa.PrivateKey) EthClient

CreateTestClient creates and extended eth client using the passed ethereum wallet key. Cleanup on test completion is handled automatically.

func NewEthClient

func NewEthClient(
	ctx context.Context,
	env common.Environment,
	endpoint string,
	privKey *ecdsa.PrivateKey,
) (EthClient, error)

NewEthClient creates and returns our extended ethereum client/wallet. The passed context is only used for creation. The privKey can be nil if you are using an external signer.

Jump to

Keyboard shortcuts

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