Documentation
¶
Overview ¶
Package abi provides functionality for parsing and manipulating Solidity contract ABIs (Application Binary Interfaces). It includes features for normalizing type names, parsing mapping types, handling struct types, detecting mapping and struct types, and converting ABIs to JSON formats.
Package abi provides tools for building and parsing Ethereum ABI (Application Binary Interface) data.
Package abi provides tools for building and parsing Ethereum ABI (Application Binary Interface) data.
Index ¶
- type Builder
- func (b *Builder) Build() (err error)
- func (b *Builder) GetAstBuilder() *ast.ASTBuilder
- func (b *Builder) GetEntryContract() *Contract
- func (b *Builder) GetEventAsAbi(unit *ir.Event) ([]*Method, error)
- func (b *Builder) GetFunctionAsABI(unit *ir.Function) ([]*Method, error)
- func (b *Builder) GetParser() *ir.Builder
- func (b *Builder) GetRoot() *Root
- func (b *Builder) GetSources() *solgo.Sources
- func (b *Builder) GetTypeResolver() *TypeResolver
- func (b *Builder) Parse() (errs []error)
- func (p *Builder) ToABI(contract *Contract) (*abi.ABI, error)
- func (b *Builder) ToJSON(d any) ([]byte, error)
- func (b *Builder) ToJSONPretty() ([]byte, error)
- func (b *Builder) ToProto() *abi_pb.Root
- func (b *Builder) ToProtoPretty() ([]byte, error)
- type Contract
- type Method
- type MethodIO
- type Root
- func (r *Root) GetContractByName(name string) *Contract
- func (r *Root) GetContracts() map[string]*Contract
- func (r *Root) GetContractsAsSlice() []*Contract
- func (r *Root) GetContractsCount() int32
- func (r *Root) GetEntryContract() *Contract
- func (r *Root) GetEntryId() int64
- func (r *Root) GetEntryName() string
- func (r *Root) GetIR() *ir.RootSourceUnit
- func (r *Root) HasContracts() bool
- func (r *Root) ToProto() *abi_pb.Root
- type Type
- type TypeResolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder facilitates the construction of Ethereum ABIs.
func NewBuilderFromSources ¶
NewBuilderFromSources initializes a new ABI builder using the provided sources. It sets up the necessary IR builder based on the given sources.
func (*Builder) GetAstBuilder ¶
func (b *Builder) GetAstBuilder() *ast.ASTBuilder
GetAstBuilder returns the AST builder.
func (*Builder) GetEntryContract ¶
GetEntryContract retrieves the entry contract of the ABI.
func (*Builder) GetEventAsAbi ¶ added in v0.3.2
func (*Builder) GetFunctionAsABI ¶ added in v0.3.2
func (*Builder) GetSources ¶
GetSources returns the source files being processed.
func (*Builder) GetTypeResolver ¶
func (b *Builder) GetTypeResolver() *TypeResolver
GetTypeResolver returns the type resolver for the ABI.
func (*Builder) ToJSON ¶
ToJSON returns the JSON representation of the ABI. If the provided data is not nil, it marshals the data; otherwise, it marshals the root.
func (*Builder) ToJSONPretty ¶
ToJSONPretty returns a prettified JSON representation of the ABI.
func (*Builder) ToProtoPretty ¶
ToProtoPretty returns a prettified JSON representation of the protocol buffer version of the ABI.
type Contract ¶
type Contract []*Method
Contract represents a collection of Ethereum contract methods.
func (*Contract) GetMethodByName ¶ added in v0.3.1
func (*Contract) GetMethodByType ¶ added in v0.3.1
type Method ¶
type Method struct { Components []MethodIO `json:"components,omitempty"` // Components of the parameter, used if it's a struct or tuple type. Inputs []MethodIO `json:"inputs"` // Input parameters of the function. Outputs []MethodIO `json:"outputs"` // Output parameters of the function. Name string `json:"name"` // Name of the function. Type string `json:"type"` // Type of the method (always "function" for functions). StateMutability string `json:"stateMutability"` // State mutability of the function (e.g., pure, view, nonpayable, payable). }
Method represents a contract function.
type MethodIO ¶
type MethodIO struct { Indexed bool `json:"indexed,omitempty"` // Indicates if the parameter is indexed. Only used by events. InternalType string `json:"internalType,omitempty"` // Represents the internal Solidity type of the parameter. Name string `json:"name"` // Name of the parameter. Type string `json:"type"` // Type of the parameter. Components []MethodIO `json:"components,omitempty"` // Components of the parameter, used if it's a struct or tuple type. StateMutability string `json:"stateMutability,omitempty"` // State mutability of the function (e.g., pure, view, nonpayable, payable). Inputs []MethodIO `json:"inputs,omitempty"` // Input parameters of the function. Outputs []MethodIO `json:"outputs,omitempty"` // Output parameters of the function. }
MethodIO represents an input or output parameter of a contract method or event.
type Root ¶
type Root struct { EntryContractId int64 `json:"entry_contract_id"` // ID of the entry contract. EntryContractName string `json:"entry_contract_name"` // Name of the entry contract. ContractsCount int32 `json:"contracts_count"` // Count of contracts in the ABI. Contracts map[string]*Contract `json:"contracts"` // Map of contract names to their respective Contract structures. // contains filtered or unexported fields }
Root represents the root of a Solidity contract's ABI structure.
func (*Root) GetContractByName ¶
GetContractByName retrieves a contract by its name from the ABI. Returns nil if the contract is not found.
func (*Root) GetContracts ¶
GetContracts returns the map of contracts.
func (*Root) GetContractsAsSlice ¶
GetContractsAsSlice returns the slice contracts.
func (*Root) GetContractsCount ¶
GetContractsCount returns the total number of contracts in the ABI.
func (*Root) GetEntryContract ¶
GetEntryContract retrieves the entry contract from the ABI.
func (*Root) GetEntryId ¶
GetEntryId returns the entry contract ID.
func (*Root) GetEntryName ¶
GetEntryName returns the entry contract name.
func (*Root) GetIR ¶
func (r *Root) GetIR() *ir.RootSourceUnit
GetIR returns the underlying IR node of the RootSourceUnit.
func (*Root) HasContracts ¶
HasContracts checks if the ABI has any contracts. Returns true if there are one or more contracts, otherwise false.
type Type ¶
type Type struct { Name string Type string InternalType string Outputs []Type Components []MethodIO }
Type represents a type within the Ethereum ABI.
type TypeResolver ¶
type TypeResolver struct {
// contains filtered or unexported fields
}
TypeResolver provides methods to resolve and discover types within the ABI.
func (*TypeResolver) ResolveMappingType ¶
func (t *TypeResolver) ResolveMappingType(typeName *ast.TypeDescription) ([]MethodIO, []MethodIO)
ResolveMappingType resolves the input and output types for a given mapping type. It returns slices of MethodIO for inputs and outputs respectively.
func (*TypeResolver) ResolveStructType ¶
func (t *TypeResolver) ResolveStructType(typeName *ast.TypeDescription) MethodIO
ResolveStructType resolves the type of a given struct and returns its MethodIO representation.
func (*TypeResolver) ResolveType ¶
func (t *TypeResolver) ResolveType(typeName *ast.TypeDescription) string
ResolveType determines the type of a given typeName based on its identifier. It returns a string representation of the type.