Documentation
¶
Overview ¶
Package types defines core interfaces and data structures for blockchain interaction. It provides abstractions for chain clients, transactions, blocks, and tokens.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockInfo ¶
type BlockInfo struct {
// BlockID is the block hash (e.g., 0x...).
BlockID string `json:"blockID"`
// Number is the block number (height).
Number int `json:"number"`
// ParentHash is the hash of the parent block.
ParentHash string `json:"parentHash"`
// Timestamp is the Unix timestamp when the block was mined.
Timestamp int64 `json:"timestamp"`
// Transactions contains all transactions in this block.
Transactions []*TransferInfo `json:"transactions"`
}
BlockInfo represents a blockchain block with its metadata and transactions.
type ChainClient ¶
type ChainClient interface {
ChainClientInfo
ChainClientMemPool
ChainClientBlocks
ChainClientTransactions
ChainClientBalances
ChainClientCoinTransfer
ChainClientTokenTransfer
}
ChainClient is the main interface for blockchain interaction. It aggregates all chain client capabilities into a single interface.
type ChainClientBalances ¶
type ChainClientBalances interface {
// BalanceOf returns the native coin balance of an address.
BalanceOf(address string) (balance *big.Int, err error)
// TokensBalanceOf returns the token balance of an address for a specific token.
TokensBalanceOf(address string, token string) (balance *big.Int, err error)
}
ChainClientBalances provides balance query operations for addresses.
type ChainClientBlocks ¶
type ChainClientBlocks interface {
// BlockNum returns the current (latest) block number.
BlockNum() (blockNum int64, err error)
// BlockByNum retrieves a block by its number. If fullInfo is true, includes transactions.
BlockByNum(blockNum int64, fullInfo bool) (block *BlockInfo, err error)
// BlockByHash retrieves a block by its hash. If fullInfo is true, includes transactions.
BlockByHash(blockHash string, fullInfo bool) (block *BlockInfo, err error)
}
ChainClientBlocks provides block query operations. Supports querying by block number or hash.
type ChainClientCoinTransfer ¶
type ChainClientCoinTransfer interface {
// TransferByPrivateKey sends native coins from one address to another.
TransferByPrivateKey(fromPrivateKey []byte, from, to string, amount *big.Int) (txHash string, err error)
// TransferGetEstimatedFee estimates the fee for a native coin transfer.
TransferGetEstimatedFee(from, to string, amount *big.Int) (fee *big.Int, err error)
// TransferAllByPrivateKey sends the entire balance (minus fees) to another address.
TransferAllByPrivateKey(fromPrivateKey []byte, from, to string) (txHash string, err error)
}
ChainClientCoinTransfer provides native coin transfer operations.
type ChainClientInfo ¶
type ChainClientInfo interface {
GetChainId() (chainId string)
GetChainName() (chainName string)
GetChainSymbol() (chainSymbol string)
GetAddressCodec() address.AddressCodec
Decimals() (decimals int)
TokensList() (tokensList []*TokenInfo)
MinConfirmations() (confirmations int)
TokenProtocols() []string
}
ChainClientInfo provides blockchain metadata and configuration. Implementations should return chain-specific information.
type ChainClientMemPool ¶
type ChainClientMemPool interface {
// MemPoolContent returns all pending transactions in the mempool.
MemPoolContent() (txs []*TransferInfo, err error)
}
ChainClientMemPool provides access to pending transactions in the memory pool.
type ChainClientTokenTransfer ¶
type ChainClientTokenTransfer interface {
// TransferTokenByPrivateKey sends tokens from one address to another.
TransferTokenByPrivateKey(fromPrivateKey []byte, from, to string, amount *big.Int, token string) (txHash string, err error)
// TransferAllTokenByPrivateKey sends the entire token balance to another address.
TransferAllTokenByPrivateKey(fromPrivateKey []byte, from, to string, token string) (txHash string, err error)
// TransferTokenGetEstimatedFee estimates the fee for a token transfer.
TransferTokenGetEstimatedFee(from, to string, amount *big.Int, token string) (fee *big.Int, err error)
}
ChainClientTokenTransfer provides ERC-20 token transfer operations.
type ChainClientTransactions ¶
type ChainClientTransactions interface {
// TransferInfoByHash retrieves a transaction by its hash.
TransferInfoByHash(txHash string) (tx *TransferInfo, err error)
// TransferInfoByNum retrieves a transaction by block number and transaction index.
TransferInfoByNum(blockNum int64, txIndex int) (tx *TransferInfo, err error)
}
ChainClientTransactions provides transaction query operations.
type Config ¶
type Config interface {
// Flag returns a boolean configuration flag by name.
Flag(flagName string) bool
// String returns a string configuration parameter, or defaultValue if not set.
String(flagName, defaultValue string) string
// Int returns an integer configuration parameter, or defaultValue if not set.
Int(flagName string, defaultValue int) int
}
Config defines the interface for accessing application configuration parameters. It supports boolean flags, string parameters, and integer parameters.
type DataDecoder ¶
DataDecoder is a function type for decoding chain-specific data.
type TokenInfo ¶
type TokenInfo struct {
// ContractAddress is the smart contract address of the token.
ContractAddress string `json:"contractAddress,omitempty"`
// Name is the full name of the token (e.g., "Tether USD").
Name string `json:"name"`
// Symbol is the short symbol of the token (e.g., "USDT").
Symbol string `json:"symbol"`
// Decimals is the number of decimal places for the token.
Decimals int `json:"decimals"`
// Protocol is the token standard (e.g., "ERC-20").
Protocol string `json:"protocol,omitempty"`
}
TokenInfo represents metadata for a cryptocurrency token (e.g., ERC-20).
type TransferInfo ¶
type TransferInfo struct {
// TxID is the transaction hash (e.g., 0x...).
TxID string `json:"txId"`
// Timestamp is the Unix timestamp of the transaction.
Timestamp int64 `json:"timestamp"`
// BlockNum is the block number containing this transaction (-1 if pending).
BlockNum int `json:"blockNum"`
// Success indicates whether the transaction was successful.
Success bool `json:"success"`
// Transfer indicates if this is a value transfer (not just a contract call).
Transfer bool `json:"transfer"`
// NativeCoin is true if this is a native coin transfer (ETH, not token).
NativeCoin bool `json:"nativeCoin,omitempty"`
// Symbol is the currency symbol (e.g., "ETH").
Symbol string `json:"symbol,omitempty"`
// SmartContract is true if the transaction involves a smart contract.
SmartContract bool `json:"smartContract,omitempty"`
// From is the sender address.
From string `json:"from"`
// To is the recipient address.
To string `json:"to"`
// Amount is the transfer amount in the smallest unit (wei for ETH).
Amount *big.Int `json:"amount"`
// Token is the token contract address (for token transfers).
Token string `json:"token,omitempty"`
// TokenSymbol is the token symbol (e.g., "USDT").
TokenSymbol string `json:"tokenSymbol,omitempty"`
// Fee is the transaction fee in the smallest unit.
Fee *big.Int `json:"fee"`
// InPool is true if the transaction is still in the mempool.
InPool bool `json:"inPool"`
// Confirmed is true if the transaction has enough confirmations.
Confirmed bool `json:"confirmed"`
// Confirmations is the number of block confirmations.
Confirmations int `json:"confirmations"`
// Decimals is the decimal precision for the currency/token.
Decimals int `json:"decimals"`
// ChainSpecificData holds chain-specific data in encoded form.
ChainSpecificData []byte `json:"chainSpecificData,omitempty"`
}
TransferInfo represents a blockchain transaction/transfer with all relevant details. It supports both native coin transfers and ERC-20 token transfers.
func (*TransferInfo) DecodeChainSpecificData ¶
func (t *TransferInfo) DecodeChainSpecificData(decoder DataDecoder) error
DecodeChainSpecificData decodes the chain-specific data using the provided decoder. This allows chain-specific data to be decoded without the types package needing to know about chain-specific structures.
type TxCache ¶
type TxCache interface {
// GetTransferInfo retrieves a cached transaction by its hash.
GetTransferInfo(txHash string) (tx *TransferInfo, err error)
// GetTransfersByAddress retrieves all cached transactions for an address.
GetTransfersByAddress(address string) (txs []*TransferInfo, err error)
}
TxCache provides cached transaction lookups. Used for fast retrieval of recently seen transactions.