abi

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2020 License: Apache-2.0 Imports: 20 Imported by: 25

Documentation

Index

Constants

View Source
const ElementSize = 32

EVM Solidity calls and return values are packed into pieces of 32 bytes, including a bool (wasting 255 out of 256 bits)

View Source
const EventIDSize = 32

EventIDSize is the length of the event selector

View Source
const FunctionIDSize = 4

FunctionIDSize is the length of the function selector

Variables

This section is empty.

Functions

func GetPackingTypes added in v0.20.1

func GetPackingTypes(args []Argument) []interface{}

func Pack added in v0.20.1

func Pack(argSpec []Argument, args ...interface{}) ([]byte, error)

func PackEvent added in v0.28.0

func PackEvent(eventSpec *EventSpec, args ...interface{}) ([]binary.Word256, []byte, error)

func Signature added in v0.23.0

func Signature(name string, args []Argument) string

func Unpack added in v0.20.1

func Unpack(argSpec []Argument, data []byte, args ...interface{}) error

func UnpackEvent added in v0.22.0

func UnpackEvent(eventSpec *EventSpec, topics []binary.Word256, data []byte, args ...interface{}) error

func UnpackRevert added in v0.22.0

func UnpackRevert(data []byte) (message *string, err error)

UnpackRevert decodes the revert reason if a contract called revert. If no reason was given, message will be nil else it will point to the string

Types

type Argument added in v0.20.1

type Argument struct {
	Name        string
	EVM         EVMType
	IsArray     bool
	Indexed     bool
	Hashed      bool
	ArrayLength uint64
}

Argument is a decoded function parameter, return or event field

type EVMAddress added in v0.20.1

type EVMAddress struct {
}

func (EVMAddress) Dynamic added in v0.24.0

func (e EVMAddress) Dynamic() bool

func (EVMAddress) GetSignature added in v0.20.1

func (e EVMAddress) GetSignature() string

func (EVMAddress) ImplicitCast added in v0.28.0

func (e EVMAddress) ImplicitCast(o EVMType) bool

func (EVMAddress) String added in v0.28.0

func (e EVMAddress) String() string

type EVMBool added in v0.20.1

type EVMBool struct {
}

func (EVMBool) Dynamic added in v0.24.0

func (e EVMBool) Dynamic() bool

func (EVMBool) GetSignature added in v0.20.1

func (e EVMBool) GetSignature() string

func (EVMBool) ImplicitCast added in v0.28.0

func (e EVMBool) ImplicitCast(o EVMType) bool

func (EVMBool) String added in v0.28.0

func (e EVMBool) String() string

type EVMBytes added in v0.20.1

type EVMBytes struct {
	M uint64
}

func (EVMBytes) Dynamic added in v0.24.0

func (e EVMBytes) Dynamic() bool

func (EVMBytes) GetSignature added in v0.20.1

func (e EVMBytes) GetSignature() string

func (EVMBytes) ImplicitCast added in v0.28.0

func (e EVMBytes) ImplicitCast(o EVMType) bool

func (EVMBytes) String added in v0.28.0

func (e EVMBytes) String() string

type EVMFixed added in v0.20.1

type EVMFixed struct {
	N, M uint64
	// contains filtered or unexported fields
}

func (EVMFixed) Dynamic added in v0.24.0

func (e EVMFixed) Dynamic() bool

func (EVMFixed) GetSignature added in v0.20.1

func (e EVMFixed) GetSignature() string

func (EVMFixed) ImplicitCast added in v0.28.0

func (e EVMFixed) ImplicitCast(o EVMType) bool

type EVMInt added in v0.20.1

type EVMInt struct {
	M uint64
}

func (EVMInt) Dynamic added in v0.24.0

func (e EVMInt) Dynamic() bool

func (EVMInt) GetSignature added in v0.20.1

func (e EVMInt) GetSignature() string

func (EVMInt) ImplicitCast added in v0.28.0

func (e EVMInt) ImplicitCast(o EVMType) bool

func (EVMInt) String added in v0.28.0

func (e EVMInt) String() string

type EVMString added in v0.20.1

type EVMString struct {
}

func (EVMString) Dynamic added in v0.24.0

func (e EVMString) Dynamic() bool

func (EVMString) GetSignature added in v0.20.1

func (e EVMString) GetSignature() string

func (EVMString) ImplicitCast added in v0.28.0

func (e EVMString) ImplicitCast(o EVMType) bool

func (EVMString) String added in v0.28.0

func (e EVMString) String() string

type EVMType added in v0.20.1

type EVMType interface {
	GetSignature() string

	Dynamic() bool
	ImplicitCast(o EVMType) bool
	// contains filtered or unexported methods
}

type EVMUint added in v0.20.1

type EVMUint struct {
	M uint64
}

func (EVMUint) Dynamic added in v0.24.0

func (e EVMUint) Dynamic() bool

func (EVMUint) GetSignature added in v0.20.1

func (e EVMUint) GetSignature() string

func (EVMUint) ImplicitCast added in v0.28.0

func (e EVMUint) ImplicitCast(o EVMType) bool

func (EVMUint) String added in v0.28.0

func (e EVMUint) String() string

type EventID added in v0.23.0

type EventID [EventIDSize]byte

func GetEventID added in v0.23.0

func GetEventID(signature string) (id EventID)

func (EventID) Bytes added in v0.23.0

func (id EventID) Bytes() []byte

func (EventID) String added in v0.28.0

func (id EventID) String() string

type EventSpec added in v0.23.0

type EventSpec struct {
	ID        EventID
	Inputs    []Argument
	Name      string
	Anonymous bool
}

func (*EventSpec) Get added in v0.28.0

func (e *EventSpec) Get(key string) (interface{}, bool)

func (*EventSpec) String added in v0.28.0

func (e *EventSpec) String() string

func (*EventSpec) UnmarshalJSON added in v0.28.0

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

type FunctionID

type FunctionID [FunctionIDSize]byte

func GetFunctionID added in v0.20.1

func GetFunctionID(signature string) (id FunctionID)

func (FunctionID) Bytes added in v0.20.1

func (fs FunctionID) Bytes() []byte

type FunctionSpec added in v0.20.1

type FunctionSpec struct {
	Name       string
	FunctionID FunctionID
	Constant   bool
	Inputs     []Argument
	Outputs    []Argument
}

func EncodeFunctionCall added in v0.24.0

func EncodeFunctionCall(abiData, funcName string, logger *logging.Logger, args ...interface{}) ([]byte, *FunctionSpec, error)

EncodeFunctionCall ABI encodes a function call based on ABI in string abiData and the arguments specified as strings. The fname specifies which function should called, if it doesn't exist exist the fallback function will be called. If fname is the empty string, the constructor is called. The arguments must be specified in args. The count must match the function being called. Returns the ABI encoded function call, whether the function is constant according to the ABI (which means it does not modified contract state)

func EncodeFunctionCallFromFile added in v0.24.0

func EncodeFunctionCallFromFile(abiFileName, abiPath, funcName string, logger *logging.Logger, args ...interface{}) ([]byte, *FunctionSpec, error)

EncodeFunctionCallFromFile ABI encodes a function call based on ABI in file, and the arguments specified as strings. The abiFileName specifies the name of the ABI file, and abiPath the path where it can be found. The fname specifies which function should called, if it doesn't exist exist the fallback function will be called. If fname is the empty string, the constructor is called. The arguments must be specified in args. The count must match the function being called. Returns the ABI encoded function call, whether the function is constant according to the ABI (which means it does not modified contract state)

func NewFunctionSpec added in v0.29.0

func NewFunctionSpec(name string, inputs, outputs []Argument) *FunctionSpec

func SpecFromFunctionReflect added in v0.20.1

func SpecFromFunctionReflect(fname string, v reflect.Value, skipIn, skipOut int) *FunctionSpec

func SpecFromStructReflect added in v0.20.1

func SpecFromStructReflect(fname string, args reflect.Type, rets reflect.Type) *FunctionSpec

SpecFromStructReflect generates a FunctionSpec where the arguments and return values are described a struct. Both args and rets should be set to the return value of reflect.TypeOf() with the respective struct as an argument.

func (*FunctionSpec) SetConstant added in v0.29.0

func (f *FunctionSpec) SetConstant() *FunctionSpec

Sets this function as constant

func (*FunctionSpec) String added in v0.28.0

func (f *FunctionSpec) String() string

type Spec added in v0.28.0

type Spec struct {
	Constructor  *FunctionSpec
	Fallback     *FunctionSpec
	Functions    map[string]*FunctionSpec
	EventsByName map[string]*EventSpec
	EventsByID   map[EventID]*EventSpec
}

Spec is the ABI for contract decoded.

func LoadPath added in v0.24.0

func LoadPath(abiFileOrDirs ...string) (*Spec, error)

LoadPath loads one abi file or finds all files in a directory

func MergeSpec added in v0.28.0

func MergeSpec(abiSpec []*Spec) *Spec

MergeSpec takes multiple Specs and merges them into once structure. Note that the same function name or event name can occur in different abis, so there might be some information loss.

func NewSpec added in v0.29.0

func NewSpec() *Spec

func ReadSpec added in v0.28.0

func ReadSpec(specBytes []byte) (*Spec, error)

ReadSpec takes an ABI and decodes it for futher use

func ReadSpecFile added in v0.28.0

func ReadSpecFile(filename string) (*Spec, error)

ReadSpecFile reads an ABI file from a file

func (*Spec) GetEventAbi added in v0.28.0

func (spec *Spec) GetEventAbi(id EventID, addresses crypto.Address) (*EventSpec, error)

func (*Spec) Pack added in v0.28.0

func (spec *Spec) Pack(fname string, args ...interface{}) ([]byte, *FunctionSpec, error)

Pack ABI encodes a function call. The fname specifies which function should called, if it doesn't exist exist the fallback function will be called. If fname is the empty string, the constructor is called. The arguments must be specified in args. The count must match the function being called. Returns the ABI encoded function call, whether the function is constant according to the ABI (which means it does not modified contract state)

func (*Spec) Unpack added in v0.28.0

func (spec *Spec) Unpack(data []byte, fname string, args ...interface{}) error

Unpack decodes the return values from a function call

func (*Spec) UnpackWithID added in v0.28.0

func (spec *Spec) UnpackWithID(data []byte, args ...interface{}) error

type Variable added in v0.20.1

type Variable struct {
	Name  string
	Value string
}

Variable exist to unpack return values into, so have both the return value and its name

func DecodeFunctionReturn added in v0.24.1

func DecodeFunctionReturn(abiData, name string, data []byte) ([]*Variable, error)

func DecodeFunctionReturnFromFile added in v0.24.0

func DecodeFunctionReturnFromFile(abiLocation, binPath, funcName string, resultRaw []byte, logger *logging.Logger) ([]*Variable, error)

DecodeFunctionReturnFromFile ABI decodes the return value from a contract function call.

Jump to

Keyboard shortcuts

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