abi

package
v0.0.0-...-fda7d28 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IntTy byte = iota
	UintTy
	BoolTy
	StringTy
	SliceTy
	AddressTy
	FixedBytesTy
	BytesTy
	HashTy
	FixedPointTy
	FunctionTy
)

Type enumerator

Variables

View Source
var (
	Big1   = big.NewInt(1)
	Big2   = big.NewInt(2)
	Big3   = big.NewInt(3)
	Big0   = big.NewInt(0)
	Big32  = big.NewInt(32)
	Big256 = big.NewInt(256)
	Big257 = big.NewInt(257)

	// MaxUint256 is the maximum value that can be represented by a uint256.
	MaxUint256 = new(big.Int).Sub(new(big.Int).Lsh(Big1, 256), Big1)
	// MaxInt256 is the maximum value that can be represented by a int256.
	MaxInt256 = new(big.Int).Sub(new(big.Int).Lsh(Big1, 255), Big1)
)

Functions

func Encode

func Encode(v interface{}, t Type) ([]byte, error)

Encode encodes a value

func ReadFixedBytes

func ReadFixedBytes(t Type, word []byte) (interface{}, error)

ReadFixedBytes uses reflection to create a fixed array to be read from.

func ReadInteger

func ReadInteger(typ Type, b []byte) interface{}

ReadInteger reads the integer based on its kind and returns the appropriate value.

Types

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.

type Arguments

type Arguments []Argument

func (Arguments) NonIndexed

func (arguments Arguments) NonIndexed() Arguments

NonIndexed returns the arguments with indexed arguments filtered out.

func (Arguments) String

func (arguments Arguments) String() string

func (Arguments) Unpack

func (arguments Arguments) Unpack(data []byte) ([]interface{}, 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 {
	// RawName is the raw event name parsed from ABI.
	RawName string
	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
}

func NewEvent

func NewEvent(event string) (*Event, error)

NewEvent creates a new event from a string signature signature format: "FirmwareUpdated(string name, string version, string uri, string avatar,address indexed from)"

func (*Event) String

func (e *Event) String() string

func (*Event) Unpack

func (e *Event) Unpack(data []byte) ([]interface{}, error)

type Method

type Method struct {
	Name   string
	Sig    string
	Inputs []Type
}

currently tinygo does not support compile array, tuple, function, fixed bytes

func NewMethod

func NewMethod(sig string) (*Method, error)

NewMethod creates a new method from a string signature signature format: "method_name(type,type,...)"

func (*Method) ID

func (m *Method) ID() []byte

ID returns the id of the method

func (*Method) Pack

func (m *Method) Pack(args ...interface{}) ([]byte, error)

Pack packs the given arguments into a byte slice according to the method signature

func (*Method) String

func (m *Method) String() string

type Type

type Type struct {
	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)

func (Type) Encode

func (t Type) Encode(v interface{}) ([]byte, error)

Encode encodes an object using this type

func (Type) String

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

String implements Stringer.

Jump to

Keyboard shortcuts

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