Documentation
¶
Index ¶
Constants ¶
const ( // MonitoredTxStatusCreated means the tx was just added to the storage MonitoredTxStatusCreated = MonitoredTxStatus("created") // MonitoredTxStatusSent means that at least a eth tx was sent to the network MonitoredTxStatusSent = MonitoredTxStatus("sent") // MonitoredTxStatusFailed means the tx was already mined and failed with an // error that can't be recovered automatically, ex: the data in the tx is invalid // and the tx gets reverted MonitoredTxStatusFailed = MonitoredTxStatus("failed") // MonitoredTxStatusMined means the tx was already mined and the receipt // status is Successful MonitoredTxStatusMined = MonitoredTxStatus("mined") // MonitoredTxStatusSafe means the tx was already mined N blocks ago MonitoredTxStatusSafe = MonitoredTxStatus("safe") // MonitoredTxStatusFinalized means the tx was already mined M (M > N) blocks ago MonitoredTxStatusFinalized = MonitoredTxStatus("finalized") // MonitoredTxStatusEvicted means the tx exceeded the maximum number of retries and was evicted MonitoredTxStatusEvicted = MonitoredTxStatus("evicted") )
Variables ¶
var ( // ErrNotFound when the object is not found ErrNotFound = errors.New("not found") // ErrAlreadyExists when the object already exists ErrAlreadyExists = errors.New("already exists") )
Functions ¶
This section is empty.
Types ¶
type EthermanInterface ¶
type EthermanInterface interface {
// GetTx retrieves a transaction by its hash from the blockchain.
// Returns the transaction, a boolean indicating if it exists in the pending pool, and an error if any.
GetTx(ctx context.Context, txHash common.Hash) (*types.Transaction, bool, error)
// GetTxReceipt retrieves the receipt of a transaction using its hash.
// Returns the transaction receipt and an error if the receipt is not found or retrieval fails.
GetTxReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
// WaitTxToBeMined waits for a transaction to be mined or until the provided timeout expires.
// Returns true if the transaction was mined and an error if the transaction fails or times out.
WaitTxToBeMined(ctx context.Context, tx *types.Transaction, timeout time.Duration) (bool, error)
// SendTx broadcasts a signed transaction to the Ethereum network.
// Returns an error if the transaction cannot be sent.
SendTx(ctx context.Context, tx *types.Transaction) error
// CurrentNonce retrieves the current nonce of a specific account
// from the latest block (used for non-pending transactions).
// Returns the nonce and an error if the nonce cannot be retrieved.
CurrentNonce(ctx context.Context, account common.Address) (uint64, error)
// PendingNonce retrieves the pending nonce of a specific account (used for pending transactions).
// Returns the nonce and an error if the nonce cannot be retrieved.
PendingNonce(ctx context.Context, account common.Address) (uint64, error)
// SuggestedGasPrice retrieves the currently suggested gas price from the Ethereum network.
// Returns the suggested gas price in wei and an error if the gas price cannot be retrieved.
SuggestedGasPrice(ctx context.Context) (*big.Int, error)
// EstimateGas estimates the amount of gas required to execute a transaction between 'from' and 'to'.
// Takes the sender and recipient addresses, the value being sent, and the transaction data.
// Returns the estimated gas amount and an error if the estimation fails.
EstimateGas(ctx context.Context, from common.Address, to *common.Address, value *big.Int, data []byte) (uint64, error)
// EstimateGasBlobTx estimates the amount of gas required to execute a Blob transaction
// (with extra fields such as gasFeeCap and gasTipCap).
// Takes the sender and recipient addresses, the gas fee cap, gas tip cap, value, and transaction data.
// Returns the estimated gas and an error if the estimation fails.
EstimateGasBlobTx(
ctx context.Context,
from common.Address,
to *common.Address,
gasFeeCap *big.Int,
gasTipCap *big.Int,
value *big.Int,
data []byte,
) (uint64, error)
// CheckTxWasMined checks whether a transaction with the given hash was mined.
// Returns true if the transaction was mined, along with the receipt and an error if any.
CheckTxWasMined(ctx context.Context, txHash common.Hash) (bool, *types.Receipt, error)
// SignTx signs a transaction using the private key of the sender.
// Returns the signed transaction and an error if the signing fails.
SignTx(ctx context.Context, sender common.Address, tx *types.Transaction) (*types.Transaction, error)
// GetRevertMessage retrieves the revert reason for a failed transaction.
// Returns the revert message string and an error if the revert reason cannot be retrieved.
GetRevertMessage(ctx context.Context, tx *types.Transaction) (string, error)
// GetLatestBlockNumber retrieves the number of the latest block in the blockchain.
// Returns the block number and an error if it cannot be retrieved.
GetLatestBlockNumber(ctx context.Context) (uint64, error)
// GetHeaderByNumber retrieves the block header for a specific block number.
// If the block number is nil, it retrieves the latest block header.
// Returns the block header and an error if it cannot be retrieved.
GetHeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
// GetSuggestGasTipCap retrieves the currently suggested gas tip cap from the Ethereum network.
// Returns the gas tip cap and an error if it cannot be retrieved.
GetSuggestGasTipCap(ctx context.Context) (*big.Int, error)
// HeaderByNumber is an alias for GetHeaderByNumber. It retrieves the block header for a specific block number.
// Returns the block header and an error if it cannot be retrieved.
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
// PublicAddress returns the public addresses of the signers
PublicAddress() ([]common.Address, error)
}
EthermanInterface defines a set of methods for interacting with the Ethereum blockchain, including transaction management, gas estimation, signing, and retrieving blockchain information.
type MonitoredTx ¶
type MonitoredTx struct {
// ID is the tx identifier controlled by the caller
ID common.Hash `mapstructure:"id" meddler:"id,hash"`
// From is the sender of the tx, used to identify which private key should be used to sign the tx
From common.Address `mapstructure:"from" meddler:"from_address,address"`
// To is the receiver of the tx
To *common.Address `mapstructure:"to" meddler:"to_address,address"`
// Nonce is used to create the tx
Nonce uint64 `mapstructure:"nonce" meddler:"nonce"`
// Value is the transaction value
Value *big.Int `mapstructure:"value" meddler:"value,bigInt"`
// Data represents the transaction data
Data []byte `mapstructure:"data" meddler:"tx_data"`
// Gas is the amount of gas for the transaction
Gas uint64 `mapstructure:"gas" meddler:"gas"`
// GasOffset is the offset applied to the gas amount
GasOffset uint64 `mapstructure:"gasOffset" meddler:"gas_offset"`
// GasPrice is the price per gas unit for the transaction
GasPrice *big.Int `mapstructure:"gasPrice" meddler:"gas_price,bigInt"`
// BlobSidecar holds sidecar data for blob transactions
BlobSidecar *types.BlobTxSidecar `mapstructure:"blobSidecar" meddler:"blob_sidecar,json"`
// BlobGas is the gas amount for the blob transaction
BlobGas uint64 `mapstructure:"blobGas" meddler:"blob_gas"`
// BlobGasPrice is the gas price for blob transactions
BlobGasPrice *big.Int `mapstructure:"blobGasPrice" meddler:"blob_gas_price,bigInt"`
// GasTipCap is the tip cap for the gas fee
GasTipCap *big.Int `mapstructure:"gasTipCap" meddler:"gas_tip_cap,bigInt"`
// Status represents the status of this monitored transaction
Status MonitoredTxStatus `mapstructure:"status" meddler:"status"`
// BlockNumber represents the block where the transaction was identified to be mined
// This is used to control reorged monitored txs.
BlockNumber *big.Int `mapstructure:"blockNumber" meddler:"block_number,bigInt"`
// History represents all transaction hashes created using this struct and sent to the network
History map[common.Hash]bool `mapstructure:"history" meddler:"history,json"`
// CreatedAt is the timestamp for when the transaction was created
CreatedAt time.Time `mapstructure:"createdAt" meddler:"created_at,timeRFC3339"`
// UpdatedAt is the timestamp for when the transaction was last updated
UpdatedAt time.Time `mapstructure:"updatedAt" meddler:"updated_at,timeRFC3339"`
// EstimateGas indicates whether gas should be estimated or the last value should be reused
EstimateGas bool `mapstructure:"estimateGas" meddler:"estimate_gas"`
// RetryCount tracks the number of times this transaction has been retried
RetryCount uint64 `mapstructure:"retryCount" meddler:"retry_count"`
}
MonitoredTx represents a set of information used to build tx plus information to monitor if the transactions was sent successfully
func (*MonitoredTx) AddHistory ¶
func (mTx *MonitoredTx) AddHistory(tx *types.Transaction) (bool, error)
AddHistory adds a transaction to the monitoring history
func (*MonitoredTx) HistoryHashSlice ¶
func (mTx *MonitoredTx) HistoryHashSlice() []common.Hash
HistoryHashSlice returns the current history field as a string slice
func (*MonitoredTx) PopulateNullableStrings ¶
func (mTx *MonitoredTx) PopulateNullableStrings(toAddress, blockNumber, value, gasPrice, blobGasPrice, gasTipCap sql.NullString)
PopulateNullableStrings converts the nullable strings and populates them to MonitoredTx instance
func (*MonitoredTx) Tx ¶
func (mTx *MonitoredTx) Tx() *types.Transaction
Tx uses the current information to build a tx
type MonitoredTxResult ¶
type MonitoredTxResult struct {
ID common.Hash
To *common.Address
Nonce uint64
Value *big.Int
Data []byte
MinedAtBlockNumber *big.Int
Status MonitoredTxStatus
Txs map[common.Hash]TxResult
}
MonitoredTxResult represents the result of a execution of a monitored tx
type MonitoredTxStatus ¶
type MonitoredTxStatus string
MonitoredTxStatus represents the status of a monitored tx
func (MonitoredTxStatus) String ¶
func (s MonitoredTxStatus) String() string
String returns a string representation of the status
type StorageInterface ¶
type StorageInterface interface {
// Add inserts a new MonitoredTx into the storage.
// It takes a context and the MonitoredTx to be added.
// Returns an error if the transaction cannot be stored.
Add(ctx context.Context, mTx MonitoredTx) error
// Remove deletes a MonitoredTx from the storage using its ID (common.Hash).
// Returns an error if the transaction cannot be found or removed.
Remove(ctx context.Context, id common.Hash) error
// Get retrieves a MonitoredTx from the storage by its ID.
// Returns the MonitoredTx if found, or an error if it doesn't exist.
Get(ctx context.Context, id common.Hash) (MonitoredTx, error)
// GetByStatus retrieves all MonitoredTx entities with a matching status.
// Takes a list of MonitoredTxStatus to filter the transactions.
// Returns a slice of MonitoredTx and an error if any occurs during retrieval.
GetByStatus(ctx context.Context, statuses []MonitoredTxStatus) ([]MonitoredTx, error)
// GetByBlock retrieves MonitoredTx transactions that have a block number
// between the specified fromBlock and toBlock.
// If either block number is nil, it will be ignored in the query.
// Returns a slice of MonitoredTx and an error if any occurs.
GetByBlock(ctx context.Context, fromBlock, toBlock *uint64) ([]MonitoredTx, error)
// Update modifies an existing MonitoredTx in the storage.
// It takes a context and the MonitoredTx object with updated fields.
// Returns an error if the transaction cannot be updated.
Update(ctx context.Context, mTx MonitoredTx) error
// Empty removes all MonitoredTx entities from the storage.
// This is typically used for clearing all data or resetting the state.
// Returns an error if the operation fails.
Empty(ctx context.Context) error
}
StorageInterface defines the methods required to interact with the storage layer for managing MonitoredTx entities.