Documentation
¶
Overview ¶
Package abi provides smart contract ABI encoding/decoding for ERC-20 tokens. It manages known smart contracts and supports ERC-20 call data encoding.
Index ¶
- Constants
- Variables
- type Option
- type SmartContractAbi
- type SmartContractAbiEntry
- type SmartContractAbiEntryInput
- type SmartContractAbiEntryOutput
- type SmartContractInfo
- type SmartContractsManager
- func (m *SmartContractsManager) Add(c *SmartContractInfo)
- func (m *SmartContractsManager) ColdStart() (err error)
- func (m *SmartContractsManager) Erc20CallGetBalance(address string) (callData string, err error)
- func (m *SmartContractsManager) Erc20DecodeAmount(callData []byte) (amount *big.Int)
- func (m *SmartContractsManager) Erc20DecodeIfTransfer(callData []byte) (address string, amount *big.Int, err error)
- func (m *SmartContractsManager) Erc20IsTransfer(callData []byte) bool
- func (m *SmartContractsManager) GetSmartContractAddressByName(contractName string) (contractAddress string, err error)
- func (m *SmartContractsManager) GetSmartContractAddressByToken(symbol string) (contractAddress string, err error)
- func (m *SmartContractsManager) GetSmartContractByAddress(contractAddress string) (contract *SmartContractInfo, err error)
- func (m *SmartContractsManager) GetSmartContractByToken(symbol string) (contract *SmartContractInfo, err error)
- func (m *SmartContractsManager) GetSmartContractList() (list map[string]string)
- func (m *SmartContractsManager) Init() error
- func (m *SmartContractsManager) Load() (err error)
- func (m *SmartContractsManager) Save() (err error)
- func (m *SmartContractsManager) Walk(view func(c *SmartContractInfo))
Constants ¶
const (
ParamTypeUint256 = "uint256"
)
Variables ¶
var ( // ErrSmartContractMethodParamsCountMismatch is returned when ABI params don't match. ErrSmartContractMethodParamsCountMismatch = errors.New("method params count mismatch") // ErrSmartContractUnknownMethod is returned when a method is not found in ABI. ErrSmartContractUnknownMethod = errors.New("unknown method") // ErrInvalidParamsData is returned when parameter data cannot be parsed. ErrInvalidParamsData = errors.New("invalid params Data") // ErrConfigStorageEmpty is returned when config storage is not configured. ErrConfigStorageEmpty = errors.New("config storage is empty") // ErrUnknownContract is returned when a contract is not in the registry. ErrUnknownContract = errors.New("unknown contract") // ErrNotTransferMethod is returned when call data is not a transfer method. ErrNotTransferMethod = errors.New("not transfer method") )
Error definitions for ABI operations.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*SmartContractsManager)
Option is a function that configures a SmartContractsManager.
func WithAddressCodec ¶
func WithAddressCodec(codec address.AddressCodec) Option
WithAddressCodec sets the address encoder/decoder for ABI encoding.
func WithStorage ¶
func WithStorage(storage storage.BinStorage) Option
WithStorage sets the storage backend for known contracts.
type SmartContractAbi ¶
type SmartContractAbi struct {
Entries []*SmartContractAbiEntry `json:"entries"`
// contains filtered or unexported fields
}
func (*SmartContractAbi) AddEntry ¶
func (a *SmartContractAbi) AddEntry(entry *SmartContractAbiEntry)
func (*SmartContractAbi) GetMethodById ¶
func (a *SmartContractAbi) GetMethodById(signature [4]byte) (entry *SmartContractAbiEntry, err error)
func (*SmartContractAbi) GetMethodByName ¶
func (a *SmartContractAbi) GetMethodByName(name string) (entry *SmartContractAbiEntry, err error)
type SmartContractAbiEntry ¶
type SmartContractAbiEntry struct {
Constant bool `json:"constant,omitempty"`
Signature [4]byte `json:"-"`
Name string `json:"name,omitempty"`
StateMutability string `json:"stateMutability,omitempty"`
Type string `json:"type"`
Inputs []*SmartContractAbiEntryInput `json:"inputs,omitempty"`
Outputs []*SmartContractAbiEntryOutput `json:"outputs,omitempty"`
}
func NewEntry ¶
func NewEntry() *SmartContractAbiEntry
func (*SmartContractAbiEntry) DecodeInputs ¶
func (e *SmartContractAbiEntry) DecodeInputs(data []byte) (paramsParsed []*paramInput, err error)
func (*SmartContractAbiEntry) GetSignature ¶
func (e *SmartContractAbiEntry) GetSignature() [4]byte
func (*SmartContractAbiEntry) String ¶
func (e *SmartContractAbiEntry) String() string
type SmartContractInfo ¶
type SmartContractsManager ¶
type SmartContractsManager struct {
// contains filtered or unexported fields
}
SmartContractsManager manages known smart contracts and provides ABI encoding. Maintains lookup maps by symbol, name, and address for efficient queries.
func NewManager ¶
func NewManager(options ...Option) *SmartContractsManager
NewManager creates a new smart contracts manager with the specified options.
func (*SmartContractsManager) Add ¶
func (m *SmartContractsManager) Add(c *SmartContractInfo)
Add adds a smart contract to the registry. Thread-safe.
func (*SmartContractsManager) ColdStart ¶
func (m *SmartContractsManager) ColdStart() (err error)
ColdStart initializes the contracts list with built-in defaults.
func (*SmartContractsManager) Erc20CallGetBalance ¶
func (m *SmartContractsManager) Erc20CallGetBalance(address string) (callData string, err error)
Erc20CallGetBalance encodes a balanceOf call for the given address.
func (*SmartContractsManager) Erc20DecodeAmount ¶
func (m *SmartContractsManager) Erc20DecodeAmount(callData []byte) (amount *big.Int)
Erc20DecodeAmount decodes a uint256 amount from call data.
func (*SmartContractsManager) Erc20DecodeIfTransfer ¶
func (m *SmartContractsManager) Erc20DecodeIfTransfer(callData []byte) (address string, amount *big.Int, err error)
Erc20DecodeIfTransfer decodes a transfer method's recipient and amount. Returns ErrNotTransferMethod if the call data is not a transfer.
func (*SmartContractsManager) Erc20IsTransfer ¶
func (m *SmartContractsManager) Erc20IsTransfer(callData []byte) bool
Erc20IsTransfer checks if the call data is an ERC-20 transfer method.
func (*SmartContractsManager) GetSmartContractAddressByName ¶
func (m *SmartContractsManager) GetSmartContractAddressByName(contractName string) (contractAddress string, err error)
GetSmartContractAddressByName finds a contract address by its name.
func (*SmartContractsManager) GetSmartContractAddressByToken ¶
func (m *SmartContractsManager) GetSmartContractAddressByToken(symbol string) (contractAddress string, err error)
GetSmartContractAddressByToken finds a contract address by its token symbol.
func (*SmartContractsManager) GetSmartContractByAddress ¶
func (m *SmartContractsManager) GetSmartContractByAddress(contractAddress string) (contract *SmartContractInfo, err error)
GetSmartContractByAddress finds a contract by its address.
func (*SmartContractsManager) GetSmartContractByToken ¶
func (m *SmartContractsManager) GetSmartContractByToken(symbol string) (contract *SmartContractInfo, err error)
GetSmartContractByToken finds a contract by its token symbol.
func (*SmartContractsManager) GetSmartContractList ¶
func (m *SmartContractsManager) GetSmartContractList() (list map[string]string)
GetSmartContractList returns a map of contract names to addresses.
func (*SmartContractsManager) Init ¶
func (m *SmartContractsManager) Init() error
Init initializes the manager by loading ERC-20 ABI and known contracts.
func (*SmartContractsManager) Load ¶
func (m *SmartContractsManager) Load() (err error)
Load reads the known contracts from storage.
func (*SmartContractsManager) Save ¶
func (m *SmartContractsManager) Save() (err error)
Save persists the known contracts to storage.
func (*SmartContractsManager) Walk ¶
func (m *SmartContractsManager) Walk(view func(c *SmartContractInfo))
Walk iterates over all known contracts with a read lock.