ethutil

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2020 License: MIT Imports: 13 Imported by: 35

Documentation

Overview

Package ethutil provides utilities used for dealing with Ethereum concerns in the context of implementing cross-chain interfaces defined in pkg/chain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddressFromHex

func AddressFromHex(hex string) (common.Address, error)

AddressFromHex converts the passed string to a common.Address and returns it, unless it is not a valid address, in which case it returns an error. Compare to common.HexToAddress, which assumes the address is valid and does not provide for an error return.

func CallAtBlock

func CallAtBlock(
	fromAddress common.Address,
	blockNumber *big.Int,
	value *big.Int,
	contractABI *abi.ABI,
	caller bind.ContractCaller,
	errorResolver *ErrorResolver,
	contractAddress common.Address,
	method string,
	result interface{},
	parameters ...interface{},
) error

CallAtBlock allows the invocation of a particular contract method at a particular block. It papers over the fact that abigen bindings don't directly support calling at a particular block, and is mostly meant for use from generated contract code.

func ConnectClients

func ConnectClients(url string, urlRPC string) (*ethclient.Client, *rpc.Client, *rpc.Client, error)

ConnectClients takes HTTP and RPC URLs and returns initialized versions of standard, WebSocket, and RPC clients for the Ethereum node at that address.

func DecryptKeyFile

func DecryptKeyFile(keyFile, password string) (*keystore.Key, error)

DecryptKeyFile reads in a key file and uses the password to decrypt it.

func EstimateGas

func EstimateGas(
	from common.Address,
	to common.Address,
	method string,
	contractABI *abi.ABI,
	transactor bind.ContractTransactor,
	parameters ...interface{},
) (uint64, error)

EstimateGas tries to estimate the gas needed to execute a specific transaction based on the current pending state of the backend blockchain. There is no guarantee that this is the true gas limit requirement as other transactions may be added or removed by miners, but it should provide a basis for setting a reasonable default.

func WrapCallLogging

func WrapCallLogging(logger log.EventLogger, backend bind.ContractBackend) bind.ContractBackend

WrapCallLogging wraps certain call-related methods on the given `backend` with debug logging sent to the given `logger`. Actual functionality is delegated to the passed backend.

Types

type ErrorResolver

type ErrorResolver struct {
	// contains filtered or unexported fields
}

ErrorResolver bundles up the bits needed to turn errors like "failed to estimate gas needed" that are triggered by contract reverts but don't include revert causes into proper revert error messages from a contract by calling the contract method without trying to commit it.

It has one method, ResolveError, that does the heavy lifting.

func NewErrorResolver

func NewErrorResolver(
	contractCaller ethereum.ContractCaller,
	abi *abi.ABI,
	address *common.Address,
) *ErrorResolver

NewErrorResolver returns an ErroResolver for the given Ethereum client, contract ABI, and contract address combination.

func (*ErrorResolver) ResolveError

func (er *ErrorResolver) ResolveError(
	originalErr error,
	from common.Address,
	value *big.Int,
	methodName string,
	parameters ...interface{},
) error

ResolveError resolves the given transaction error to a standard error that, if available, contains the error message the transaction produced when reverting.

ResolveError achieves this by re-calling the transaction (not submitting it for block inclusion, just calling it for its results). `value` is the value in gwei to send along with the simulated call.

type TransactionOptions

type TransactionOptions struct {
	// GasLimit specifies a gas limit to set on a transaction call; should be
	// ignored if set to 0.
	GasLimit uint64
	// GasPrice specifies a gas price to set on a transaction call; should be
	// ignored if set to nil.
	GasPrice *big.Int
}

TransactionOptions represents custom transaction options which can be used while invoking contracts methods.

func (TransactionOptions) Apply

func (to TransactionOptions) Apply(transactorOptions *bind.TransactOpts)

Apply takes a bind.TransactOpts pointer and applies the options described in TransactionOptions to it. Note that a GasLimit of 0 or a GasPrice of nil are not applied to the passed options; these values indicate that the options should remain unchanged.

Jump to

Keyboard shortcuts

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