abi

package
v2.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2023 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IntTy byte = iota
	UintTy
	BoolTy
	StringTy
	SliceTy
	ArrayTy
	AddressTy
	GidTy
	TokenIdTy
	FixedBytesTy
	BytesTy
)

Type enumerator

Variables

This section is empty.

Functions

func U256

func U256(n *big.Int) []byte

U256 converts a big Int into a 256bit VM number.

Types

type ABIContract

type ABIContract struct {
	Constructor Method
	Methods     map[string]Method
	Callbacks   map[string]Method
	OffChains   map[string]Method
	Events      map[string]Event
	Variables   map[string]Variable
}

The ABIContract 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 JSONToABIContract

func JSONToABIContract(reader io.Reader) (ABIContract, error)

JSONToABIContract returns a parsed ABI interface and error if it failed.

func (ABIContract) DirectUnpackEvent

func (abi ABIContract) DirectUnpackEvent(topics []types.Hash, data []byte) (string, []interface{}, error)

DirectUnpackEvent output in param list according to the abi specification

func (ABIContract) DirectUnpackMethodInput

func (abi ABIContract) DirectUnpackMethodInput(name string, input []byte) ([]interface{}, error)

DirectUnpackMethodInput output in param list according to the abi specification

func (ABIContract) DirectUnpackOffchainOutput

func (abi ABIContract) DirectUnpackOffchainOutput(name string, output []byte) ([]interface{}, error)

DirectUnpackOffchainOutput output in param list according to the abi specification

func (ABIContract) EventID

func (abi ABIContract) EventID(name string) (*types.Hash, error)

EventID return error if not found

func (*ABIContract) MethodById

func (abi *ABIContract) MethodById(sigdata []byte) (*Method, error)

MethodById looks up a method by the 4-byte id returns nil if none found

func (ABIContract) PackCallback

func (abi ABIContract) PackCallback(name string, args ...interface{}) ([]byte, error)

func (ABIContract) PackEvent

func (abi ABIContract) PackEvent(name string, args ...interface{}) (topics []types.Hash, data []byte, err error)

func (ABIContract) PackMethod

func (abi ABIContract) PackMethod(name string, args ...interface{}) ([]byte, error)

func (ABIContract) PackOffChain

func (abi ABIContract) PackOffChain(name string, args ...interface{}) ([]byte, error)

func (ABIContract) PackVariable

func (abi ABIContract) PackVariable(name string, args ...interface{}) ([]byte, error)

func (*ABIContract) UnmarshalJSON

func (abi *ABIContract) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface

func (ABIContract) UnpackEvent

func (abi ABIContract) UnpackEvent(v interface{}, name string, input []byte) (err error)

UnpackEvent output in v according to the abi specification

func (ABIContract) UnpackMethod

func (abi ABIContract) UnpackMethod(v interface{}, name string, input []byte) (err error)

UnpackMethod output in v according to the abi specification

func (ABIContract) UnpackVariable

func (abi ABIContract) UnpackVariable(v interface{}, name string, input []byte) (err error)

type Argument

type Argument struct {
	Name    string
	Type    Type
	Indexed bool // indexed is only used by events
}

Argument holds the name of the argument and the corresponding type. Types are used when packing and testing arguments.

func (*Argument) UnmarshalJSON

func (argument *Argument) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface

type Arguments

type Arguments []Argument

func (Arguments) DirectUnpack

func (arguments Arguments) DirectUnpack(data []byte) ([]interface{}, error)

Unpack performs the operation hexdata -> Go format

func (Arguments) Pack

func (arguments Arguments) Pack(args ...interface{}) ([]byte, error)

Pack performs the operation Go format -> Hexdata

func (Arguments) PackValues

func (arguments Arguments) PackValues(args []interface{}) ([]byte, error)

PackValues performs the operation Go format -> Hexdata It is the semantic opposite of UnpackValues

func (Arguments) Unpack

func (arguments Arguments) Unpack(v interface{}, data []byte) error

Unpack performs the operation hexdata -> Go format

func (Arguments) UnpackValues

func (arguments Arguments) UnpackValues(data []byte) ([]interface{}, error)

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

type Event struct {
	Name             string
	Inputs           Arguments
	IndexedInputs    Arguments
	NonIndexedInputs Arguments
}

Event is an event potentially triggered by the VM'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.

func (Event) DirectUnPack

func (e Event) DirectUnPack(topics []types.Hash, data []byte) ([]interface{}, error)

func (Event) Id

func (e Event) Id() types.Hash

Id returns the canonical representation of the event's signature used by the abi definition to identify event names and types.

func (Event) Pack

func (e Event) Pack(args ...interface{}) ([]types.Hash, []byte, error)

func (Event) String

func (e Event) String() string

func (*Event) UnmarshalJSON

func (e *Event) UnmarshalJSON(data []byte) error

type Method

type Method struct {
	Name string

	Inputs  Arguments
	Outputs Arguments
	// contains filtered or unexported fields
}

Method represents a callable given a `Names` 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.

func (Method) Id

func (method Method) Id() []byte

func (Method) Sig

func (method Method) Sig() string

Sig returns the methods string signature according to the ABI spec.

Example

function foo(uint32 a, int b)    =    "foo(uint32,int256)"

Please note that "int" is substitute for its canonical representation "int256"

func (Method) String

func (method Method) String() string

type Type

type Type struct {
	Elem *Type

	Kind reflect.Kind
	Type reflect.Type
	Size int
	T    byte // Our own type checking
	// contains filtered or unexported fields
}

Type is the reflection of the supported argument type

func NewType

func NewType(t string) (typ Type, err error)

NewType creates a new reflection type of abi type given in t.

func (Type) String

func (t Type) String() (out string)

String implements Stringer

type Variable

type Variable struct {
	Name   string
	Inputs Arguments
}

Variable is used only in built-in contracts

func (Variable) String

func (v Variable) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL