Documentation
¶
Overview ¶
Package abi provides an implementation of the Algorand ARC-4 ABI type system.
See https://arc.algorand.foundation/ARCs/arc-0004 for the corresponding specification.
Basic Operations ¶
This package can parse ABI type names using the `abi.TypeOf()` function.
`abi.TypeOf()` returns an `abi.Type` struct. The `abi.Type` struct's `Encode` and `Decode` methods can convert between Go values and encoded ABI byte strings.
Index ¶
- Constants
- func IsReferenceType(s string) bool
- func IsTransactionType(s string) bool
- func ParseMethodSignature(methodSig string) (name string, argTypes []string, returnType string, err error)
- func VerifyMethodSignature(methodSig string) error
- type Type
- func (t Type) ByteLen() (int, error)
- func (t Type) Decode(encoded []byte) (interface{}, error)
- func (t Type) Encode(value interface{}) ([]byte, error)
- func (t Type) Equal(t0 Type) bool
- func (t Type) IsDynamic() bool
- func (t Type) MarshalToJSON(value interface{}) ([]byte, error)
- func (t Type) String() string
- func (t Type) UnmarshalFromJSON(jsonEncoded []byte) (interface{}, error)
- type TypeKind
Constants ¶
const AccountReferenceType = "account"
AccountReferenceType is the ABI argument type string for account references
const AnyTransactionType = "txn"
AnyTransactionType is the ABI argument type string for a nonspecific transaction argument
const ApplicationCallTransactionType = "appl"
ApplicationCallTransactionType is the ABI argument type string for an application call transaction argument
const ApplicationReferenceType = "application"
ApplicationReferenceType is the ABI argument type string for application references
const AssetConfigTransactionType = "acfg"
AssetConfigTransactionType is the ABI argument type string for an asset configuration transaction argument
const AssetFreezeTransactionType = "afrz"
AssetFreezeTransactionType is the ABI argument type string for an asset freeze transaction argument
const AssetReferenceType = "asset"
AssetReferenceType is the ABI argument type string for asset references
const AssetTransferTransactionType = "axfer"
AssetTransferTransactionType is the ABI argument type string for an asset transfer transaction argument
const KeyRegistrationTransactionType = "keyreg"
KeyRegistrationTransactionType is the ABI argument type string for a key registration transaction argument
const PaymentTransactionType = "pay"
PaymentTransactionType is the ABI argument type string for a payment transaction argument
const VoidReturnType = "void"
VoidReturnType is the ABI return type string for a method that does not return any value
Variables ¶
This section is empty.
Functions ¶
func IsReferenceType ¶
IsReferenceType checks if a type string represents a reference type argument, such as "account", "asset", or "application".
func IsTransactionType ¶
IsTransactionType checks if a type string represents a transaction type argument, such as "txn", "pay", "keyreg", etc.
func ParseMethodSignature ¶
func ParseMethodSignature(methodSig string) (name string, argTypes []string, returnType string, err error)
ParseMethodSignature parses a method of format `method(argType1,argType2,...)retType` into `method` {`argType1`,`argType2`,...} and `retType`
NOTE: This function **DOES NOT** verify that the argument or return type strings represent valid ABI types. Consider using `VerifyMethodSignature` prior to calling this function if you wish to verify those types.
func VerifyMethodSignature ¶
VerifyMethodSignature checks if a method signature and its referenced types can be parsed properly
Types ¶
type Type ¶
type Type struct {
// contains filtered or unexported fields
}
Type is the struct that represents an ABI type.
Do not use the zero value of this struct. Use the `TypeOf` function to create an instance of an ABI type.
func MakeTupleType ¶
MakeTupleType makes tuple ABI type by taking an array of tuple element types as argument.
func TypeOf ¶
TypeOf parses an ABI type string. For example: `TypeOf("(uint64,byte[])")`
Note: this function only supports "basic" ABI types. Reference types and transaction types are not supported and will produce an error.
func (Type) Decode ¶
Decode is an ABI type method to decode bytes to Go values.
To decode an encoded ABI value to a Go interface value, this function stores the result in one of these interface values:
bool, for ABI `bool` types uint8/byte, for ABI `byte`, `uint8`, and `ufixed8x<M>` types, for all `M` uint16, for ABI `uint16` and `ufixed16x<M>` types, for all `M` uint32, for ABI `uint24`, `uint32`, `ufixed24x<M>`, and `ufixed32x<M>` types, for all `M` uint64, for ABI `uint48`, `uint56`, `uint64`, `ufixed48x<M>`, `ufixed56x<M>`, `ufixed64x<M>`, for all `M` *big.Int, for ABI `uint<N>` and `ufixed<N>x<M>`, for all 72 <= `N` <= 512, and all `M` string, for ABI `string` types []byte, for ABI `address` types []interface{}, for ABI static array, dynamic array, and tuple types
func (Type) Encode ¶
Encode is an ABI type method to encode Go values into bytes.
Depending on the ABI type instance, different values are acceptable for this method.
The ABI `bool` type accepts Go bool types.
The ABI `byte` type accepts Go byte/uint8 types.
The ABI `uint<N>` and `ufixed<N>x<M>` types accept all native Go integer types (uint/uint8/uint16/uint32/uint64/int/int8/int16/int32/int64) and *big.Int. However, an error will be returned if a negative value is given.
The ABI `string` type accepts Go string types.
The ABI `address`, static array, dynamic array, and tuple types accept slices and arrays of interfaces or specific types that are compatible with the contents of the ABI type's contained types. For example, the `address` type accepts Go types []interface{}, [32]interface{}, []byte, and [32]byte.
func (Type) MarshalToJSON ¶
MarshalToJSON convert golang value to JSON format from ABI type
func (Type) UnmarshalFromJSON ¶
UnmarshalFromJSON convert bytes to golang value following ABI type and encoding rules
type TypeKind ¶
type TypeKind uint32
TypeKind is an enum value which indicates the kind of an ABI type.
const ( // InvalidType represents an invalid and unused TypeKind. InvalidType TypeKind = iota // Uint is kind for ABI unsigned integer types, i.e. `uint<N>`. Uint // Byte is kind for the ABI `byte` type. Byte // Ufixed is the kind for ABI unsigned fixed point decimal types, i.e. `ufixed<N>x<M>`. Ufixed // Bool is the kind for the ABI `bool` type. Bool // ArrayStatic is the kind for ABI static array types, i.e. `<type>[<length>]`. ArrayStatic // Address is the kind for the ABI `address` type. Address // ArrayDynamic is the kind for ABI dynamic array types, i.e. `<type>[]`. ArrayDynamic // String is the kind for the ABI `string` type. String // Tuple is the kind for ABI tuple types, i.e. `(<type 0>,...,<type k>)`. Tuple )