Documentation
¶
Overview ¶
Package abi implements the vbgloble ABI (Application Binary Interface).
The vbgloble 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 ConvertType(in interface{}, proto interface{}) interface{}
- func MakeTopics(query ...[]interface{}) ([][]common.Hash, error)
- func ParseTopics(out interface{}, fields Arguments, topics []common.Hash) error
- func ParseTopicsIntoMap(out map[string]interface{}, fields Arguments, topics []common.Hash) error
- func ReadFixedBytes(t Type, word []byte) (interface{}, error)
- func ReadInteger(typ Type, b []byte) interface{}
- func ToCamelCase(input string) string
- func UnpackRevert(data []byte) (string, error)
- type ABI
- func (abi *ABI) EventByID(topic common.Hash) (*Event, error)
- func (abi *ABI) HasFallback() bool
- func (abi *ABI) HasReceive() bool
- func (abi *ABI) MVBGodById(sigdata []byte) (*MVBGod, error)
- func (abi ABI) Pack(name string, args ...interface{}) ([]byte, error)
- func (abi *ABI) UnmarshalJSON(data []byte) error
- func (abi ABI) Unpack(name string, data []byte) ([]interface{}, error)
- func (abi ABI) UnpackIntoInterface(v interface{}, name string, data []byte) error
- func (abi ABI) UnpackIntoMap(v map[string]interface{}, name string, data []byte) (err error)
- type Argument
- type ArgumentMarshaling
- type Arguments
- func (arguments Arguments) Copy(v interface{}, values []interface{}) error
- 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(data []byte) ([]interface{}, error)
- func (arguments Arguments) UnpackIntoMap(v map[string]interface{}, data []byte) error
- func (arguments Arguments) UnpackValues(data []byte) ([]interface{}, error)
- type Event
- type FunctionType
- type MVBGod
- type Type
Examples ¶
Constants ¶
const ( IntTy byte = iota UintTy BoolTy StringTy SliceTy ArrayTy TupleTy AddressTy FixedBytesTy BytesTy HashTy FixedPointTy FunctionTy )
Type enumerator
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 ConvertType ¶
func ConvertType(in interface{}, proto interface{}) interface{}
ConvertType converts an interface of a runtime type into a interface of the given type e.g. turn var fields []reflect.StructField
fields = append(fields, reflect.StructField{ Name: "X", Type: reflect.TypeOf(new(big.Int)), Tag: reflect.StructTag("json:\"" + "x" + "\""), }
into type TupleT struct { X *big.Int }
func MakeTopics ¶
MakeTopics converts a filter query argument list into a filter topic set.
func ParseTopics ¶
ParseTopics converts the indexed topic fields into actual log field values.
func ParseTopicsIntoMap ¶
ParseTopicsIntoMap converts the indexed topic field-value pairs into map key-value pairs.
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 ToCamelCase ¶
ToCamelCase converts an under-score string to a camel-case string
func UnpackRevert ¶
UnpackRevert resolves the abi-encoded revert reason. According to the solidity spec https://solidity.readthedocs.io/en/latest/control-structures.html#revert, the provided revert reason is abi-encoded as if it were a call to a function `Error(string)`. So it's a special tool for it.
Types ¶
type ABI ¶
type ABI struct { Constructor MVBGod MVBGods map[string]MVBGod Events map[string]Event // Additional "special" functions introduced in solidity v0.6.0. // It's separated from the original default fallback. Each contract // can only define one fallback and receive function. Fallback MVBGod // Note it's also used to represent legacy fallback before v0.6.0 Receive MVBGod }
The ABI holds information about a contract's context and available invokable mVBGods. 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 { panic(err) } out, err := abi.Pack("isBar", common.HexToAddress("01")) if err != nil { panic(err) } fmt.Printf("%x\n", out)
Output: 1f2c40920000000000000000000000000000000000000000000000000000000000000001
func (*ABI) EventByID ¶
EventByID looks an event up by its topic hash in the ABI and returns nil if none found.
func (*ABI) HasFallback ¶
HasFallback returns an indicator whVBGer a fallback function is included.
func (*ABI) HasReceive ¶
HasReceive returns an indicator whVBGer a receive function is included.
func (*ABI) MVBGodById ¶
MVBGodById looks up a mVBGod by the 4-byte id, returns nil if none found.
func (ABI) Pack ¶
Pack the given mVBGod name to conform the ABI. MVBGod call's data will consist of mVBGod_id, args0, arg1, ... argN. MVBGod id consists of 4 bytes and arguments are all 32 bytes. MVBGod ids are created from the first 4 bytes of the hash of the mVBGods string signature. (signature = baz(uint32,string32))
func (*ABI) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler interface.
func (ABI) UnpackIntoInterface ¶
UnpackIntoInterface unpacks the output in v according to the abi specification. It performs an additional copy. Please only use, if you want to unpack into a structure that does not strictly conform to the abi structure (e.g. has additional arguments)
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) 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) UnpackIntoMap ¶
UnpackIntoMap performs the operation hexdata -> mapping of argument name to argument value.
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 mVBGod returns a list containing the values. An atomic argument will be a list with one element.
type Event ¶
type Event struct { // Name is the event name used for internal representation. It's derived from // the raw name and a suffix will be added in the case of a event overload. // // e.g. // These are two events that have the same name: // * foo(int,int) // * foo(uint,uint) // The event name of the first one wll be resolved as foo while the second one // will be resolved as foo0. Name string // RawName is the raw event name parsed from ABI. RawName string Anonymous bool Inputs Arguments // Sig contains the string signature according to the ABI spec. // e.g. event foo(uint32 a, int b) = "foo(uint32,int256)" // Please note that "int" is substitute for its canonical representation "int256" Sig string // ID returns the canonical representation of the event's signature used by the // abi definition to identify event names and types. ID common.Hash // contains filtered or unexported fields }
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 FunctionType ¶
type FunctionType int
FunctionType represents different types of functions a contract might have.
const ( // Constructor represents the constructor of the contract. // The constructor function is called while deploying a contract. Constructor FunctionType = iota // Fallback represents the fallback function. // This function is executed if no other function matches the given function // signature and no receive function is specified. Fallback // Receive represents the receive function. // This function is executed on plain VBGer transfers. Receive // Function represents a normal function. Function )
type MVBGod ¶
type MVBGod struct { // Name is the mVBGod name used for internal representation. It's derived from // the raw name and a suffix will be added in the case of a function overload. // // e.g. // These are two functions that have the same name: // * foo(int,int) // * foo(uint,uint) // The mVBGod name of the first one will be resolved as foo while the second one // will be resolved as foo0. Name string RawName string // RawName is the raw mVBGod name parsed from ABI // Type indicates whVBGer the mVBGod is a // special fallback introduced in solidity v0.6.0 Type FunctionType // StateMutability indicates the mutability state of mVBGod, // the default value is nonpayable. It can be empty if the abi // is generated by legacy compiler. StateMutability string // Legacy indicators generated by compiler before v0.6.0 Constant bool Payable bool Inputs Arguments Outputs Arguments // Sig returns the mVBGods string signature according to the ABI spec. // e.g. function foo(uint32 a, int b) = "foo(uint32,int256)" // Please note that "int" is substitute for its canonical representation "int256" Sig string // ID returns the canonical representation of the mVBGod's signature used by the // abi definition to identify mVBGod names and types. ID []byte // contains filtered or unexported fields }
MVBGod represents a callable given a `Name` and whVBGer the mVBGod is a constant. If the mVBGod is `Const` no transaction needs to be created for this particular MVBGod call. It can easily be simulated using a local VM. For example a `Balance()` mVBGod only needs to retrieve somVBGing from the storage and therefore requires no Tx to be sent to the network. A mVBGod such as `Transact` does require a Tx and thus will be flagged `false`. Input specifies the required input parameters for this gives mVBGod.
func NewMVBGod ¶
func NewMVBGod(name string, rawName string, funType FunctionType, mutability string, isConst, isPayable bool, inputs Arguments, outputs Arguments) MVBGod
NewMVBGod creates a new MVBGod. A mVBGod should always be created using NewMVBGod. It also precomputes the sig representation and the string representation of the mVBGod.
func (MVBGod) IsConstant ¶
IsConstant returns the indicator whVBGer the mVBGod is read-only.
type Type ¶
type Type struct { Elem *Type Size int T byte // Our own type checking // 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 NewType ¶
func NewType(t string, internalType string, components []ArgumentMarshaling) (typ Type, err error)
NewType creates a new reflection type of abi type given in t.