Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DataLocation ¶
type DataLocation int8
DataLocation is the data location of the parameter, like storage, memory or calldata.
const ( UnspecifiedLocation DataLocation = iota Storage CallData Memory )
func (DataLocation) String ¶
func (d DataLocation) String() string
type InputKind ¶ added in v0.5.0
type InputKind int8
InputKind is the kind of the input string returned by the Kind function.
func Kind ¶ added in v0.5.0
Kind returns the kind of the input string.
This function helps determine which parser should be used to parse the input.
Note that some inputs are ambiguous. They could be interpreted either as a type or a function signature. For example, "foo" could be a type or a function name. Similarly, "function foo" could be interpreted as a function signature or a parameter "foo" with the type "function".
To avoid ambiguity, always add an empty parameter list to function signatures.
func (InputKind) IsParameter ¶ added in v0.5.0
IsParameter returns true if the input is a parameter.
It can be parsed using ParseParameter function.
func (InputKind) IsSignature ¶ added in v0.5.0
IsSignature returns true if the input is a signature for any type of function.
It can be parsed using ParseSignature function.
type Parameter ¶
type Parameter struct { // Name is an optional name of the argument or return value. Name string // Type is the parameter type, like uint256, bytes32, etc. It must // be empty for tuples. Type string // Tuple is a list tuple elements. It must be empty for non-tuple types. Tuple []Parameter // Arrays is the list of array dimensions, where each dimension is the // maximum length of the array. If the length is -1, the array is // unbounded. If the Arrays is empty, the argument is not an array. Arrays []int // Indexed indicates whether the argument is indexed. It must be false // for types other than event. Indexed bool // DataLocation indicates the data location of the argument. It should be // UnspecifiedLocation for types other than function and constructor. DataLocation DataLocation }
Parameter represents an argument or return value.
func ParseParameter ¶
ParseParameter parses the single parameter. The syntax is same as for parameters in the ParseSignature function.
func ParseStruct ¶
ParseStruct parses the struct definition.
It returns a structure as a tuple type where the tuple name is the struct name and the tuple elements are the struct fields.
type Signature ¶
type Signature struct { // Kind is the kind of the signature. Kind SignatureKind // Name is the name of the function, event or error. It should be empty for // fallback, receive and constructor kinds. Name string // Inputs is the list of input parameters. Inputs []Parameter // Outputs is the list of output parameters. Outputs []Parameter // Modifiers is the list of function modifiers. Modifiers []string }
Signature represents a signature of a function, constructor, fallback, receive, event or error.
func ParseSignature ¶
ParseSignature parses the function, constructor, fallback, receive, event or error signature. The syntax is similar to that of Solidity, but it is less strict. The argument names are always optional, and the return keyword can be omitted.
Tuples are represented as a list of types enclosed in parentheses, optionally prefixed with the "tuple" keyword.
Signature may be prepended with the keyword describing the signature kind. The following kinds are supported:
- function
- constructor
- fallback
- receive
- event
- error
The following examples are valid signatures:
- function foo(uint256 memory a, tuple(uint256 b1, uint256 b2) memory b) internal returns (uint256)
- function foo(uint256 a, (uint256 b1, uint256 b2) b) (uint256)
- foo(uint256,(uint256,uint256))(uint256)
- constructor(uint256 a, uint256 b)
- fallback(bytes memory a) returns (bytes memory)
- receive()
- event Foo(uint256 a, uint256 b)
- error Foo(uint256 a, uint256 b)
Signatures that are syntactically correct, but semantically invalid are rejected by the parser.
func ParseSignatureAs ¶
func ParseSignatureAs(kind SignatureKind, signature string) (Signature, error)
ParseSignatureAs works like ParseSignature, but it allows to specify the signature kind.
The kind can be UnknownKind, in which case the kind is inferred from the signature.
type SignatureKind ¶
type SignatureKind int8
SignatureKind is the kind of the signature, like function, constructor, fallback, etc.
const ( UnknownKind SignatureKind = iota FunctionKind ConstructorKind FallbackKind ReceiveKind EventKind ErrorKind )
func (SignatureKind) String ¶
func (s SignatureKind) String() string