Documentation ¶
Overview ¶
Package abi implements the Ethereum ABI (Application Binary Interface).
The Ethereum ABI is strongly typed, known at compile time and static. This ABI will handle basic type casting; unsigned to signed and visa versa. It does not handle slice casting such as unsigned slice to signed slice. Bit size type casting is also handled. ints with a bit size of 32 will be properly cast to int256, etc.
Index ¶
- Constants
- func ByteArrayToString(v interface{}) (string, error)
- func FuncSelector(funcName string, argsType []string) string
- func TypeConversion(gvalue string, gtype string) string
- func U256(n *big.Int) []byte
- type ABI
- func (abi ABI) Decode(funcName string, result []byte) (interface{}, error)
- func (abi ABI) Encode(funcName string, args ...interface{}) ([]byte, error)
- func (abi ABI) GetEvent(eventSig string) (*Event, error)
- func (abi ABI) GetMethod(methodSig string) (*Method, error)
- func (abi ABI) GetPayload(funcName string, args ...string) string
- func (abi *ABI) MethodById(sigdata []byte) (*Method, error)
- func (abi ABI) Pack(name string, args ...interface{}) ([]byte, error)
- func (abi *ABI) UnmarshalJSON(data []byte) error
- func (abi ABI) Unpack(v interface{}, name string, output []byte) (err error)
- func (abi *ABI) UnpackInput(v interface{}, methodName string, data []byte) (err error)
- func (abi *ABI) UnpackInputWithoutMethod(v interface{}, data []byte) (err error)
- func (abi ABI) UnpackLog(v interface{}, name string, data string, topics []string) (err error)
- func (abi *ABI) UnpackResult(v interface{}, name, data string) (err error)
- type Argument
- type Arguments
- func (arguments Arguments) Indexed() Arguments
- func (arguments Arguments) LengthNonIndexed() int
- func (arguments Arguments) NonIndexed() Arguments
- func (arguments Arguments) Pack(args ...interface{}) ([]byte, error)
- func (arguments Arguments) PackValues(args []interface{}) ([]byte, error)
- func (arguments Arguments) Unpack(v interface{}, data []byte) error
- func (arguments Arguments) UnpackValues(data []byte) ([]interface{}, error)
- type Event
- type Method
- type Type
Examples ¶
Constants ¶
const ( IntTy byte = iota UintTy BoolTy StringTy SliceTy ArrayTy AddressTy FixedBytesTy BytesTy HashTy FixedPointTy FunctionTy )
Type enumerator
const UNIT = 64
Variables ¶
This section is empty.
Functions ¶
func ByteArrayToString ¶
ByteArrayToString transfer a byte array to string
func FuncSelector ¶
FuncSelector convert func and args to ABI set(uint256) -> 60fe47b1
func TypeConversion ¶
TypeConversion conversion go type to binary
Types ¶
type ABI ¶
type ABI struct { Constructor Method Methods map[string]Method Events map[string]Event // contains filtered or unexported fields }
The ABI holds information about a contract's context and available invokable methods. It will allow you to type check function calls and packs data accordingly.
func JSON ¶
JSON returns a parsed ABI interface and error if it failed.
Example ¶
const definition = `[{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"isBar","outputs":[{"name":"","type":"bool"}],"type":"function"}]` abi, err := JSON(strings.NewReader(definition)) if err != nil { log.Fatalln(err) } out, err := abi.Pack("isBar", common.HexToAddress("01")) if err != nil { log.Fatalln(err) } fmt.Printf("%x\n", out)
Output: 1f2c40920000000000000000000000000000000000000000000000000000000000000001
func (ABI) Decode ¶
funcName is the function name of contract result is the return value of invocation solidity contract
func (ABI) Encode ¶
funcName is the function name of contract args is the arguments of function, should be string or []interface{}
func (ABI) GetPayload ¶
GetPayload is used to convert func and args to binary
func (*ABI) MethodById ¶
MethodById looks up a method by the 4-byte id returns nil if none found
func (ABI) Pack ¶
Pack the given method name to conform the ABI. Method call's data will consist of method_id, args0, arg1, ... argN. Method id consists of 4 bytes and arguments are all 32 bytes. Method ids are created from the first 4 bytes of the hash of the methods string signature. (signature = baz(uint32,string32))
func (*ABI) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler interface
func (*ABI) UnpackInput ¶
UnpackInput unpack method input
func (*ABI) UnpackInputWithoutMethod ¶
UnpackInputWithoutMethod unpack input
func (ABI) UnpackLog ¶
Unpack log output in v according to the abi specification param data means the Data field of TxLog, params topics means the Topics field of TxLog
warn: try to decode a dynamic type indexed event param(like: bytes in solidity) will cause panic
func (*ABI) UnpackResult ¶
UnpackResult use abi to decode data from solidity return
type Argument ¶
Argument holds the name of the argument and the corresponding type. Types are used when packing and testing arguments.
func (*Argument) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler interface
type Arguments ¶
type Arguments []Argument
func (Arguments) LengthNonIndexed ¶
LengthNonIndexed returns the number of arguments when not counting 'indexed' ones. Only events can ever have 'indexed' arguments, it should always be false on arguments for method input/output
func (Arguments) NonIndexed ¶
NonIndexed returns the arguments with indexed arguments filtered out
func (Arguments) PackValues ¶
PackValues performs the operation Go format -> Hexdata It is the semantic opposite of UnpackValues
func (Arguments) UnpackValues ¶
UnpackValues can be used to unpack ABI-encoded hexdata according to the ABI-specification, without supplying a struct to unpack into. Instead, this method returns a list containing the values. An atomic argument will be a list with one element.
type Event ¶
Event is an event potentially triggered by the EVM's LOG mechanism. The Event holds type information (inputs) about the yielded output. Anonymous events don't get the signature canonical representation as the first LOG topic.
type Method ¶
Method represents a callable given a `Name` and whether the method is a constant. If the method is `Const` no transaction needs to be created for this particular Method call. It can easily be simulated using a local VM. For example a `Balance()` method only needs to retrieve something from the storage and therefor requires no Tx to be send to the network. A method such as `Transact` does require a Tx and thus will be flagged `true`. Input specifies the required input parameters for this gives method.