Documentation
¶
Index ¶
- Constants
- Variables
- func CompoundSingleValue(val Value, typeCounter, nameCounter *int) (Value, []CompoundType)
- func FindCompoundTypes(abi DecodedABI) ([]ItemValueIndex, []ItemValueIndex, []ItemValueIndex, []ItemValueIndex)
- func GenerateInterface(interfaceName, license, pragma string, abi DecodedABI, annotations Annotations, ...) error
- func GenerateName(nameCounter *int) string
- func GenerateType(typeCounter *int, internalType string) string
- func MethodSelector(function FunctionItem) []byte
- func ParseInternalType(internalType string) string
- func SolidityTypeRequiresLocation(solidityType string) bool
- type Annotations
- type CompoundType
- type DecodedABI
- type DecodedABIWithCompundTypes
- type ErrorItem
- type EventArgument
- type EventItem
- type FunctionItem
- type InterfaceSpecification
- type ItemValueIndex
- type NamedValue
- type TypeDeclaration
- type Value
Constants ¶
const InterfaceTemplate string = `` /* 1487-byte string literal not displayed */
This is the Go template used to generate Solidity interfaces to contracts with a given ABI. The template is meant to be applied to InterfaceSpecification structs.
Variables ¶
var VERSION string = "0.2.3"
The current version of solface.
Functions ¶
func CompoundSingleValue ¶
func CompoundSingleValue(val Value, typeCounter, nameCounter *int) (Value, []CompoundType)
Recursively creates the compound types required to represent the given value. If the top-level compound type has members which are also compound types themselves, they will be included in the second return value. The first return value is a transformation of the original value represented using the new compound types.
func FindCompoundTypes ¶
func FindCompoundTypes(abi DecodedABI) ([]ItemValueIndex, []ItemValueIndex, []ItemValueIndex, []ItemValueIndex)
Finds all the compound types that need to be defined in order to interface with a contract with the given decoded ABI.
Return values specify which items in the following arrays are compound types (by index): 1. Event inputs 2. Function inputs 3. Function outputs 4. Error inputs
func GenerateInterface ¶
func GenerateInterface(interfaceName, license, pragma string, abi DecodedABI, annotations Annotations, includeAnnotations bool, writer io.Writer) error
Generates a Solidity interface for the given ABI (with the given parameters). The specification is generated by applying the specification to a Go template.
func GenerateName ¶
Generates a fresh name for an anonymous attribute.
func GenerateType ¶
Generates a fresh name for an anonymous compound type.
func MethodSelector ¶
func MethodSelector(function FunctionItem) []byte
Calculates the 4-byte method selector for a given ABI function.
func ParseInternalType ¶
Parses the name of an internal type and either returns that name (for structs) or "Compound" (for any other type). For nested structs (e.g. structs defined in other contracts or interfaces), this only returns the final component of the name.
func SolidityTypeRequiresLocation ¶
This function returns true if the given Solidity type requires a location modifier ("memory", "storage", "calldata") when used as a function parameter or return value.
Types ¶
type Annotations ¶
Represents annotations for an ABI.
func Annotate ¶
func Annotate(decodedABI DecodedABI) (Annotations, error)
Generates annotations for a decoded ABI.
type CompoundType ¶
type CompoundType struct {
TypeName string
Members []NamedValue
}
Represents a compound type.
type DecodedABI ¶
type DecodedABI struct {
Events []EventItem
Functions []FunctionItem
Errors []ErrorItem
}
Represents a parsed ABI, usable in the rest of solface.
func Decode ¶
func Decode(rawJSON []byte) (DecodedABI, error)
type DecodedABIWithCompundTypes ¶
type DecodedABIWithCompundTypes struct {
OriginalABI DecodedABI
CompoundTypes []CompoundType
EnrichedABI DecodedABI
}
Represents a decoded ABI along with the compound types that need to be defined in a Solidity interface to a contract exposing that ABI.
func ResolveCompounds ¶
func ResolveCompounds(abi DecodedABI) DecodedABIWithCompundTypes
Transitively resolves all compound types comprising the parameters and return values of all items in the given decoded ABI.
type EventArgument ¶
Represents a parameter for an event in an ABI.
type EventItem ¶
type EventItem struct {
Type string
Name string `json:"name"`
Inputs []EventArgument
Anonymous bool
}
Represents a log event in an ABI.
type FunctionItem ¶
type FunctionItem struct {
Type string
Name string `json:"name,omitempty"`
Inputs []Value `json:"inputs,omitempty"`
Outputs []Value `json:"outputs,omitempty"`
StateMutability string `json:"stateMutability,omitempty"`
}
Represents a smart contract method in an ABI.
type InterfaceSpecification ¶
type InterfaceSpecification struct {
Name string
ABI DecodedABI
Annotations Annotations
IncludeAnnotations bool
CompoundTypes []CompoundType
SolfaceVersion string
License string
Pragma string
}
InterfaceSpecification specifies certain details about the Solidity interface that should be generated.
- Name: The name of the Solidity interface.
- ABI: The ABI that the interface is being generated for.
- Annotations: A list of annotations (interface ID, method selectors) for the interface.
- IncludeAnnotations: Whether or not to include the annotations in the generated interface.
- CompoundTypes: The compound types that need to be defined in the interface.
- SolfaceVersion: The version of solface that generated the interface.
- License: The SPDX license identifier to be generated at the top of the output - if empty, this will not be included.
- Pragma: The Solidity pragma to be generated at the top of the output - if empty, this will not be included.
type ItemValueIndex ¶
Represents an ordered pair of array indices, the first index representing a position in the ABI array, and the second index representing a position in the parameters array for that ABI item.
type NamedValue ¶
Represents a named parameter in an ABI item.
type TypeDeclaration ¶
type TypeDeclaration struct {
Type string
}
Represents a type declaration in an ABI.
type Value ¶
type Value struct {
Name string
Type string
InternalType string `json:"internalType,omitempty"`
Components []Value
}
Represents a value in an ABI.
func (Value) IsCompoundType ¶
Returns true if the given value is a compound type (i.e. composed of other types like a struct or array) and false otherwise.