transaction

package
v0.0.0-...-966b6e9 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEventNotFound = errors.New("event not found")
	ErrNoTopic       = errors.New("no topic")
)
View Source
var (
	// ErrTransactionReverted denotes that the transaction has been reverted.
	ErrTransactionReverted  = errors.New("transaction reverted")
	ErrUnknownTransaction   = errors.New("unknown transaction")
	ErrAlreadyImported      = errors.New("already imported")
	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

func ParseEvent(a *abi.ABI, eventName string, c interface{}, e types.Log) error

ParseEvent will parse the specified abi event from the given log

func WaitSynced

func WaitSynced(ctx context.Context, backend Backend, maxDelay time.Duration) error

WaitSynced will wait until we are synced with the given blockchain backend, with the given maxDelay duration as the maximum time we can be behind the last block.

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 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) (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)
	// 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)
	// FilterLogs filters the events from contract
	FilterLogs(ctx context.Context, query ethereum.FilterQuery) (*[]types.Log, error)
}

Service is the service to send transactions. It takes care of gas price, gas limit and nonce management.

func NewTxService

func NewTxService(logger *logrus.Logger, backend WrappedBackend, signer signer.Signer) (Service, error)

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
	GasTipBoost          int             // adds a tip for the miner for prioritizing transaction
	GasTipCap            *big.Int        // adds a cap to the tip
	Created              int64           // creation timestamp
	// contains filtered or unexported fields
}

TxRequest describes a request for a transaction that can be executed.

type TxService

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

func (*TxService) Call

func (t *TxService) Call(ctx context.Context, request *TxRequest) (result []byte, err error)

func (*TxService) CancelTransaction

func (t *TxService) CancelTransaction(ctx context.Context, originalTxHash common.Hash) (common.Hash, error)

func (*TxService) Close

func (t *TxService) Close() error

func (*TxService) FilterLogs

func (t *TxService) FilterLogs(ctx context.Context, query ethereum.FilterQuery) (*[]types.Log, error)

func (*TxService) Send

func (t *TxService) Send(ctx context.Context, request *TxRequest) (txHash common.Hash, err error)

func (*TxService) SuggestedFeeAndTip

func (t *TxService) SuggestedFeeAndTip(ctx context.Context) (*big.Int, *big.Int, error)

func (*TxService) TransactionFee

func (t *TxService) TransactionFee(ctx context.Context, txHash common.Hash) (*big.Int, error)

func (*TxService) WaitForReceipt

func (t *TxService) WaitForReceipt(ctx context.Context, txHash common.Hash) (receipt *types.Receipt, err error)

type WrappedBackend

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

func NewBackend

func NewBackend(backend Backend) *WrappedBackend

func (*WrappedBackend) BalanceAt

func (b *WrappedBackend) BalanceAt(ctx context.Context, address common.Address, block *big.Int) (*big.Int, error)

func (*WrappedBackend) BlockNumber

func (b *WrappedBackend) BlockNumber(ctx context.Context) (uint64, error)

func (*WrappedBackend) CallContract

func (b *WrappedBackend) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)

func (*WrappedBackend) ChainID

func (b *WrappedBackend) ChainID(ctx context.Context) (*big.Int, error)

func (*WrappedBackend) Close

func (b *WrappedBackend) Close()

func (*WrappedBackend) CodeAt

func (b *WrappedBackend) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)

func (*WrappedBackend) EstimateGas

func (b *WrappedBackend) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)

func (*WrappedBackend) FilterLogs

func (b *WrappedBackend) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)

func (*WrappedBackend) HeaderByNumber

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

func (*WrappedBackend) NonceAt

func (b *WrappedBackend) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)

func (*WrappedBackend) PendingNonceAt

func (b *WrappedBackend) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

func (*WrappedBackend) SendTransaction

func (b *WrappedBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error

func (*WrappedBackend) SuggestGasPrice

func (b *WrappedBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error)

func (*WrappedBackend) SuggestGasTipCap

func (b *WrappedBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error)

func (*WrappedBackend) TransactionByHash

func (b *WrappedBackend) TransactionByHash(ctx context.Context, hash common.Hash) (*types.Transaction, bool, error)

func (*WrappedBackend) TransactionReceipt

func (b *WrappedBackend) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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