Documentation ¶
Index ¶
- Constants
- Variables
- func FindSingleEvent(abi *abi.ABI, receipt *types.Receipt, contractAddress common.Address, ...) error
- func IsSynced(ctx context.Context, backend Backend, maxDelay time.Duration) (bool, time.Time, error)
- func ParseEvent(a *abi.ABI, eventName string, c interface{}, e types.Log) error
- func WaitBlockAfterTransaction(ctx context.Context, backend Backend, pollingInterval time.Duration, ...) (*types.Header, error)
- func WaitSynced(ctx context.Context, logger log.Logger, backend Backend, ...) error
- type Backend
- type Monitor
- type Service
- type StoredTransaction
- type TxRequest
Constants ¶
const DefaultTipBoostPercent = 20
Variables ¶
var ( ErrEventNotFound = errors.New("event not found") ErrNoTopic = errors.New("no topic") )
var ( // ErrTransactionReverted denotes that the sent transaction has been // reverted. ErrTransactionReverted = errors.New("transaction reverted") ErrUnknownTransaction = errors.New("unknown transaction") ErrAlreadyImported = errors.New("already imported") )
var ErrMonitorClosed = errors.New("monitor closed")
var ErrTransactionCancelled = errors.New("transaction cancelled")
Functions ¶
func FindSingleEvent ¶
func FindSingleEvent(abi *abi.ABI, receipt *types.Receipt, contractAddress common.Address, event abi.Event, out interface{}) error
FindSingleEvent will find the first event of the given kind.
func IsSynced ¶
func IsSynced(ctx context.Context, backend Backend, maxDelay time.Duration) (bool, time.Time, error)
IsSynced will check if we are synced with the given blockchain backend. This is true if the current wall clock is after the block time of last block with the given maxDelay as the maximum duration we can be behind the block time.
func ParseEvent ¶
ParseEvent will parse the specified abi event from the given log
func WaitBlockAfterTransaction ¶ added in v1.2.0
Types ¶
type Backend ¶
type Backend interface { CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) SuggestGasPrice(ctx context.Context) (*big.Int, error) SuggestGasTipCap(ctx context.Context) (*big.Int, error) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error) SendTransaction(ctx context.Context, tx *types.Transaction) error TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error) BlockNumber(ctx context.Context) (uint64, error) BalanceAt(ctx context.Context, address common.Address, block *big.Int) (*big.Int, error) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error) ChainID(ctx context.Context) (*big.Int, error) Close() }
Backend is the minimum of blockchain backend functions we need.
type Monitor ¶
type Monitor interface { io.Closer // WatchTransaction watches the transaction until either there is 1 confirmation or a competing transaction with cancellationDepth confirmations. WatchTransaction(txHash common.Hash, nonce uint64) (<-chan types.Receipt, <-chan error, error) }
Monitor is a nonce-based watcher for transaction confirmations. Instead of watching transactions individually, the senders nonce is monitored and transactions are checked based on this. The idea is that if the nonce is still lower than that of a pending transaction, there is no point in actually checking the transaction for a receipt. At the same time if the nonce was already used and this was a few blocks ago we can reasonably assume that it will never confirm.
type Service ¶
type Service interface { io.Closer // Send creates a transaction based on the request (with gasprice increased by provided percentage) and sends it. Send(ctx context.Context, request *TxRequest, tipCapBoostPercent int) (txHash common.Hash, err error) // Call simulate a transaction based on the request. Call(ctx context.Context, request *TxRequest) (result []byte, err error) // WaitForReceipt waits until either the transaction with the given hash has been mined or the context is cancelled. // This is only valid for transaction sent by this service. WaitForReceipt(ctx context.Context, txHash common.Hash) (receipt *types.Receipt, err error) // WatchSentTransaction start watching the given transaction. // This wraps the monitors watch function by loading the correct nonce from the store. // This is only valid for transaction sent by this service. WatchSentTransaction(txHash common.Hash) (<-chan types.Receipt, <-chan error, error) // StoredTransaction retrieves the stored information for the transaction StoredTransaction(txHash common.Hash) (*StoredTransaction, error) // PendingTransactions retrieves the list of all pending transaction hashes PendingTransactions() ([]common.Hash, error) // ResendTransaction resends a previously sent transaction // This operation can be useful if for some reason the transaction vanished from the eth networks pending pool ResendTransaction(ctx context.Context, txHash common.Hash) error // CancelTransaction cancels a previously sent transaction by double-spending its nonce with zero-transfer one CancelTransaction(ctx context.Context, originalTxHash common.Hash) (common.Hash, error) // TransactionFee retrieves the transaction fee TransactionFee(ctx context.Context, txHash common.Hash) (*big.Int, error) // UnwrapABIError tries to unwrap the ABI error if the given error is not nil. // The original error is wrapped together with the ABI error if it exists. UnwrapABIError(ctx context.Context, req *TxRequest, err error, abiErrors map[string]abi.Error) error }
Service is the service to send transactions. It takes care of gas price, gas limit and nonce management.
type StoredTransaction ¶ added in v1.0.0
type StoredTransaction struct { To *common.Address // recipient of the transaction Data []byte // transaction data GasPrice *big.Int // used gas price GasLimit uint64 // used gas limit GasTipBoost int // adds a tip for the miner for prioritizing transaction GasTipCap *big.Int // adds a cap to the tip GasFeeCap *big.Int // adds a cap to maximum fee user is willing to pay Value *big.Int // amount of wei to send Nonce uint64 // used nonce Created int64 // creation timestamp Description string // description }
type TxRequest ¶
type TxRequest struct { To *common.Address // recipient of the transaction Data []byte // transaction data GasPrice *big.Int // gas price or nil if suggested gas price should be used GasLimit uint64 // gas limit or 0 if it should be estimated MinEstimatedGasLimit uint64 // minimum gas limit to use if the gas limit was estimated; it will not apply when this value is 0 or when GasLimit is not 0 GasFeeCap *big.Int // adds a cap to maximum fee user is willing to pay Value *big.Int // amount of wei to send Description string // optional description }
TxRequest describes a request for a transaction that can be executed.