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
- Variables
- func BytesConverter(source []byte, t string) interface{}
- func GenerateInputData(ct ContractType, input []byte) ([]byte, error)
- func GetFuncParamWrap(str string) []string
- func GetFuncParams(paramString string) []string
- func ParseWasmCallSolInput(input []byte) ([]byte, error)
- func ReadFixedBytes(t Type, word []byte) (interface{}, error)
- func ReadInteger(typ Type, b []byte) interface{}
- func SetInputLength(input []byte) (res []byte)
- func Sig(funcName string, types []string) string
- func SolInputStringTOInt(v string, bitSize int, hasNotPrefixU bool) (interface{}, error)
- func SolInputTypeConversion(t string, v string) (interface{}, error)
- func SpliceParam(param string) (paramType string, paramValue string, err error)
- func StringConverter(source string, t string) ([]byte, error)
- func StringConverterV2(source string, t string) ([]byte, error)
- func StringToArg(source string, t string) (interface{}, error)
- func ToCamelCase(input string) string
- func TrimSpace(str string) string
- func U256(n *big.Int) []byte
- func WasmArgToBytes(arg interface{}) []byte
- type ABI
- type Argument
- type ArgumentMarshaling
- type Arguments
- func (arguments Arguments) LengthNonIndexed() int
- func (arguments Arguments) NonIndexed() Arguments
- func (arguments Arguments) Pack(args ...interface{}) ([]byte, error)
- func (arguments Arguments) PackV2(args ...interface{}) ([]byte, error)
- func (arguments Arguments) PackValues(args []interface{}) ([]byte, error)
- func (arguments Arguments) ReturnBytesUnpack(data string) []interface{}
- func (arguments Arguments) Unpack(v interface{}, data []byte) error
- func (arguments Arguments) UnpackV2(v interface{}, data []byte) error
- func (arguments Arguments) UnpackValues(data []byte) ([]interface{}, error)
- func (arguments Arguments) UnpackValuesV2(data []byte) ([]interface{}, error)
- type ContractType
- type Event
- type Method
- type SolInput
- type Type
- type WasmInput
Examples ¶
Constants ¶
const ( IntTy byte = iota UintTy BoolTy StringTy SliceTy ArrayTy // TupleTy AddressTy FixedBytesTy BytesTy HashTy FixedPointTy FunctionTy // newly Added [2020-08-06] TupleTy )
Type enumerator
const ( ContractTypeWasm = "wasm" ContractTypeSolidity = "sol" )
Variables ¶
var ( // MaxUint256 is the maximum value that can be represented by a uint256 MaxUint256 = new(big.Int).Sub(new(big.Int).Lsh(common.Big1, 256), common.Big1) // MaxInt256 is the maximum value that can be represented by a int256 MaxInt256 = new(big.Int).Sub(new(big.Int).Lsh(common.Big1, 255), common.Big1) )
Functions ¶
func BytesConverter ¶
BytesConverter converts the bytes to the specific data type it is the same as the BytesConverter in ctool/core/bytes_util.go
func GenerateInputData ¶
func GenerateInputData(ct ContractType, input []byte) ([]byte, error)
func GetFuncParamWrap ¶
func GetFuncParams ¶
func ParseWasmCallSolInput ¶
func ReadFixedBytes ¶
ReadFixedBytes uses reflection to create a fixed array to be read from
func ReadInteger ¶
ReadInteger reads the integer based on its kind and returns the appropriate value
func SetInputLength ¶
func SolInputStringTOInt ¶
func SolInputTypeConversion ¶
func StringToArg ¶
related to the cpp.abi.json file
func ToCamelCase ¶
ToCamelCase converts an under-score string to a camel-case string
Types ¶
type ABI ¶
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) 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
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 ArgumentMarshaling ¶
type ArgumentMarshaling struct { Name string Type string InternalType string Components []ArgumentMarshaling Indexed bool }
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) ReturnBytesUnpack ¶
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.
func (Arguments) UnpackValuesV2 ¶
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 ContractType ¶
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.
type SolInput ¶
type SolInput struct { FuncName string `json:"func_name"` FuncParams []string `json:"func_params"` }
func (*SolInput) GenerateInputData ¶
Generate input data for solidity contract
func (*SolInput) NewContractTypeFromJson ¶
type Type ¶
type Type struct { Elem *Type Kind reflect.Kind Type reflect.Type Size int T byte // Our own type checking // newly Added [2020-08-06] // Tuple relative fields TupleRawName string // Raw struct name defined in source code, may be empty. TupleElems []*Type // Type information of all tuple fields TupleRawNames []string // Raw field name of all tuple fields TupleType reflect.Type // Underlying struct of the tuple // contains filtered or unexported fields }
Type is the reflection of the supported argument type
func NewTypeV2 ¶
func NewTypeV2(t string, internalType string, components []ArgumentMarshaling) (typ Type, err error)
NewType creates a new reflection type of abi type given in t.
func (Type) StringConvert ¶
newly added StringConvert converts the input string to the actual type defined in golang
type WasmInput ¶
type WasmInput struct { TxType int `json:"-"` FuncName string `json:"func_name"` FuncParams []string `json:"func_params"` }
func (*WasmInput) GenerateInputData ¶
Generate the input data of the wasm contract