abi

package
v0.0.0-...-24d451d Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2020 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const ElementSize = 32

BVM 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
View Source
const FunctionIDSize = 4

Variables

This section is empty.

Functions

func GetPackingTypes

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

func Pack

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

func PackIntoStruct

func PackIntoStruct(argSpec []Argument, st interface{}) ([]byte, error)

func Signature

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

func Unpack

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

func UnpackEvent

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

* Given a eventSpec, get all the fields (topic fields or not)

func UnpackIntoStruct

func UnpackIntoStruct(argSpec []Argument, data []byte, st interface{}) error

func UnpackRevert

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 AbiSpec

type AbiSpec struct {
	Constructor FunctionSpec
	Fallback    FunctionSpec
	Functions   map[string]FunctionSpec
	Events      map[string]EventSpec
	EventsById  map[EventID]EventSpec
}
var RevertAbi *AbiSpec

RevertAbi exists to decode reverts. Any contract function call fail using revert(), assert() or require(). If a function exits this way, the this hardcoded ABI will be used.

func MergeAbiSpec

func MergeAbiSpec(abiSpec []*AbiSpec) *AbiSpec

MergeAbiSpec takes multiple AbiSpecs 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 ReadAbiSpec

func ReadAbiSpec(specBytes []byte) (*AbiSpec, error)

func ReadAbiSpecFile

func ReadAbiSpecFile(filename string) (*AbiSpec, error)

func (*AbiSpec) EventByID

func (abiSpec *AbiSpec) EventByID(topic []byte) (*EventSpec, error)

EventByID looks an event up by its topic hash in the ABI and returns nil if none found.

func (*AbiSpec) Pack

func (abiSpec *AbiSpec) 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 (*AbiSpec) Unpack

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

func (*AbiSpec) UnpackWithID

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

type AbiSpecJSON

type AbiSpecJSON struct {
	Name            string
	Type            string
	Inputs          []ArgumentJSON
	Outputs         []ArgumentJSON
	Constant        bool
	Payable         bool
	StateMutability string
	Anonymous       bool
}

type Argument

type Argument struct {
	Name        string
	BVM         BVMType
	IsArray     bool
	Indexed     bool
	Hashed      bool
	ArrayLength uint64
}

func BVMTypeFromReflect

func BVMTypeFromReflect(v reflect.Type) Argument

type ArgumentJSON

type ArgumentJSON struct {
	Name       string
	Type       string
	Components []ArgumentJSON
	Indexed    bool
}

type BVMAddress

type BVMAddress struct {
}

func (BVMAddress) Dynamic

func (e BVMAddress) Dynamic() bool

func (BVMAddress) GetSignature

func (e BVMAddress) GetSignature() string

func (BVMAddress) ImplicitCast

func (e BVMAddress) ImplicitCast(o BVMType) bool

func (BVMAddress) String

func (e BVMAddress) String() string

type BVMBool

type BVMBool struct {
}

func (BVMBool) Dynamic

func (e BVMBool) Dynamic() bool

func (BVMBool) GetSignature

func (e BVMBool) GetSignature() string

type BVMBytes

type BVMBytes struct {
	M uint64
}

func (BVMBytes) Dynamic

func (e BVMBytes) Dynamic() bool

func (BVMBytes) GetSignature

func (e BVMBytes) GetSignature() string

type BVMFixed

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

func (BVMFixed) Dynamic

func (e BVMFixed) Dynamic() bool

func (BVMFixed) GetSignature

func (e BVMFixed) GetSignature() string

type BVMInt

type BVMInt struct {
	M uint64
}

func (BVMInt) Dynamic

func (e BVMInt) Dynamic() bool

func (BVMInt) GetSignature

func (e BVMInt) GetSignature() string

type BVMString

type BVMString struct {
}

func (BVMString) Dynamic

func (e BVMString) Dynamic() bool

func (BVMString) GetSignature

func (e BVMString) GetSignature() string

type BVMType

type BVMType interface {
	GetSignature() string

	Dynamic() bool
	// contains filtered or unexported methods
}

type BVMUint

type BVMUint struct {
	M uint64
}

func (BVMUint) Dynamic

func (e BVMUint) Dynamic() bool

func (BVMUint) GetSignature

func (e BVMUint) GetSignature() string

type EventID

type EventID [EventIDSize]byte

func GetEventID

func GetEventID(signature string) (id EventID)

func (EventID) Bytes

func (fs EventID) Bytes() []byte

type EventSpec

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

type FunctionID

type FunctionID [FunctionIDSize]byte

func GetFunctionID

func GetFunctionID(signature string) (id FunctionID)

func (FunctionID) Bytes

func (fs FunctionID) Bytes() []byte

type FunctionSpec

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

func EncodeFunctionCall

func EncodeFunctionCall(abiData, funcName string, 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 SpecFromFunctionReflect

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

func SpecFromStructReflect

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) SetFunctionID

func (functionSpec *FunctionSpec) SetFunctionID(functionName string)

type Variable

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

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

Jump to

Keyboard shortcuts

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