abi

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Unlicense Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
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)
)
View Source
var (
	ErrUnexpectedEOF = errors.New("abi: unexpected EOF")
)

Functions

func EncodeCallData

func EncodeCallData(sig Signature, dat func(*Builder) *Builder) []byte

func PrettyHex

func PrettyHex(xs []byte) string

Types

type Builder

type Builder struct {
	NewMem func() Memory
	// contains filtered or unexported fields
}

Builder is used to encode ethereum abi

func NewBuilder

func NewBuilder(fn func() Memory) *Builder

func (*Builder) Address

func (d *Builder) Address(a common.Address) *Builder

func (*Builder) BigInt

func (d *Builder) BigInt(ret *big.Int) *Builder

func (*Builder) BigUint

func (d *Builder) BigUint(a *uint256.Int) *Builder

DEPRECATED

func (*Builder) Bool

func (d *Builder) Bool(b bool) *Builder

func (*Builder) Bytes

func (d *Builder) Bytes(s []byte) *Builder

func (*Builder) DString

func (d *Builder) DString(s string) *Builder

func (*Builder) EnterArray

func (d *Builder) EnterArray(t TypeName, l int) *Builder

fixed size array TODO: write in a type + size compliance check later

func (*Builder) EnterDynamicArray

func (d *Builder) EnterDynamicArray() *Builder

length unspecified array

func (*Builder) EnterGroup

func (d *Builder) EnterGroup(l int, w bool) *Builder

l = 0 is variable length dynamic l = -1 is tuple (static) * # doesnt matter as long as negative l > 0 is length specified array (dynamic elements) l < 0 is length specified array (static elements)

func (*Builder) EnterTuple

func (d *Builder) EnterTuple() *Builder

func (*Builder) Exit

func (d *Builder) Exit() *Builder

exit dynamic element

func (*Builder) Finish

func (d *Builder) Finish(prefix ...[]byte) []byte

finish closes all children, and returns the result slice

func (*Builder) FixedBytes

func (d *Builder) FixedBytes(l int, s []byte) *Builder

0 < i <= 32

func (*Builder) Int

func (d *Builder) Int(i int) *Builder

func (*Builder) Mem

func (d *Builder) Mem() Memory

get the memory object, uses default memory impl by default

func (*Builder) PadRight

func (d *Builder) PadRight(xs []byte) *Builder

generic builder writer methods

func (*Builder) Uint

func (d *Builder) Uint(i uint) *Builder

func (*Builder) Uint16

func (d *Builder) Uint16(i uint16) *Builder

func (*Builder) Uint256

func (d *Builder) Uint256(a *uint256.Int) *Builder

func (*Builder) Uint8

func (d *Builder) Uint8(i uint8) *Builder

func (*Builder) Word

func (d *Builder) Word(xs []byte) *Builder

type Call

type Call string

func (Call) Decode

func (c Call) Decode() (Signature, []string)

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

func HexDecoder

func HexDecoder(s string) *Decoder

func NewDecoder

func NewDecoder(xs []byte) *Decoder

func (*Decoder) Address

func (d *Decoder) Address() (common.Address, error)

func (*Decoder) BigInt

func (d *Decoder) BigInt() (*big.Int, error)

func (*Decoder) Bool

func (d *Decoder) Bool() (bool, error)

func (*Decoder) Bytes added in v0.3.4

func (d *Decoder) Bytes() ([]byte, error)

func (*Decoder) DString

func (d *Decoder) DString() (string, error)

func (*Decoder) Dynamic

func (d *Decoder) Dynamic() (*Decoder, error)

func (*Decoder) DynamicLength

func (d *Decoder) DynamicLength() (*Decoder, int, error)

func (*Decoder) Int

func (d *Decoder) Int() (int, error)

func (*Decoder) Peek

func (d *Decoder) Peek(o []byte) (int, error)

func (*Decoder) PeekUint256

func (d *Decoder) PeekUint256() (*uint256.Int, error)

func (*Decoder) PeekWord

func (d *Decoder) PeekWord() (o [32]byte, err error)

reads 32 bytes

func (*Decoder) Read

func (d *Decoder) Read(o []byte) (int, error)

func (*Decoder) ReadN

func (d *Decoder) ReadN(n int) ([]byte, error)

reads n bytes

func (*Decoder) ReadNPadRight32

func (d *Decoder) ReadNPadRight32(n int) ([]byte, error)

func (*Decoder) ReadWord

func (d *Decoder) ReadWord() (o [32]byte, err error)

reads 32 bytes

func (*Decoder) Remaining

func (d *Decoder) Remaining() []byte

func (*Decoder) Seek

func (d *Decoder) Seek(offset int64, whence int) (int64, error)

func (*Decoder) Uint

func (d *Decoder) Uint() (uint, error)

func (*Decoder) Uint16

func (d *Decoder) Uint16() (uint16, error)

func (*Decoder) Uint256

func (d *Decoder) Uint256() (*uint256.Int, error)

func (*Decoder) Uint8

func (d *Decoder) Uint8() (uint8, error)

type Memory

type Memory interface {
	// returns the full data
	Data() []byte
	// increments the cursor by input, returns new cursor
	Pos(int) int
	// insert bytes to a location in memory, appending if needed
	Insert(loc int, data []byte)
	// replacing bytes at a location in memory, growing the slice if needed
	Put(loc int, data []byte)
}

Memory is the underlying store for decoder data

type Signature

type Signature string

represents the string that is hashed for things like function signature and event signatures

func SIG

func SIG(s string, t ...TypeName) Signature

func (Signature) Args

func (s Signature) Args() TypeName

func (Signature) Fn

func (s Signature) Fn() []byte

func (Signature) Hash

func (s Signature) Hash() common.Hash

func (Signature) Method

func (s Signature) Method() string

func (Signature) Selector

func (s Signature) Selector() [4]byte

func (Signature) SelectorB

func (s Signature) SelectorB() []byte

type TypeName

type TypeName string

represents a valid evm abi type.

const (
	NIL TypeName = ""

	BOOL     TypeName = "bool"
	FUNCTION TypeName = "function"
	ADDRESS  TypeName = "address"
	STRING   TypeName = "string"
)
const (
	UINT    TypeName = "uint256"
	UINT8   TypeName = "uint8"
	UINT16  TypeName = "uint16"
	UINT24  TypeName = "uint24"
	UINT32  TypeName = "uint32"
	UINT40  TypeName = "uint40"
	UINT48  TypeName = "uint48"
	UINT56  TypeName = "uint56"
	UINT64  TypeName = "uint64"
	UINT72  TypeName = "uint72"
	UINT80  TypeName = "uint80"
	UINT88  TypeName = "uint88"
	UINT96  TypeName = "uint96"
	UINT104 TypeName = "uint104"
	UINT112 TypeName = "uint112"
	UINT120 TypeName = "uint120"
	UINT128 TypeName = "uint128"
	UINT136 TypeName = "uint136"
	UINT144 TypeName = "uint144"
	UINT152 TypeName = "uint152"
	UINT160 TypeName = "uint160"
	UINT168 TypeName = "uint168"
	UINT176 TypeName = "uint176"
	UINT184 TypeName = "uint184"
	UINT192 TypeName = "uint192"
	UINT200 TypeName = "uint200"
	UINT208 TypeName = "uint208"
	UINT216 TypeName = "uint216"
	UINT224 TypeName = "uint224"
	UINT232 TypeName = "uint232"
	UINT240 TypeName = "uint240"
	UINT248 TypeName = "uint248"
	UINT256 TypeName = "uint256"
	INT     TypeName = "int256"
	INT8    TypeName = "int8"
	INT16   TypeName = "int16"
	INT24   TypeName = "int24"
	INT32   TypeName = "int32"
	INT40   TypeName = "int40"
	INT48   TypeName = "int48"
	INT56   TypeName = "int56"
	INT64   TypeName = "int64"
	INT72   TypeName = "int72"
	INT80   TypeName = "int80"
	INT88   TypeName = "int88"
	INT96   TypeName = "int96"
	INT104  TypeName = "int104"
	INT112  TypeName = "int112"
	INT120  TypeName = "int120"
	INT128  TypeName = "int128"
	INT136  TypeName = "int136"
	INT144  TypeName = "int144"
	INT152  TypeName = "int152"
	INT160  TypeName = "int160"
	INT168  TypeName = "int168"
	INT176  TypeName = "int176"
	INT184  TypeName = "int184"
	INT192  TypeName = "int192"
	INT200  TypeName = "int200"
	INT208  TypeName = "int208"
	INT216  TypeName = "int216"
	INT224  TypeName = "int224"
	INT232  TypeName = "int232"
	INT240  TypeName = "int240"
	INT248  TypeName = "int248"
	INT256  TypeName = "int256"
)
const (
	BYTES   TypeName = "bytes"
	BYTES1  TypeName = "bytes1"
	BYTES2  TypeName = "bytes2"
	BYTES3  TypeName = "bytes3"
	BYTES4  TypeName = "bytes4"
	BYTES5  TypeName = "bytes5"
	BYTES6  TypeName = "bytes6"
	BYTES7  TypeName = "bytes7"
	BYTES8  TypeName = "bytes8"
	BYTES9  TypeName = "bytes9"
	BYTES10 TypeName = "bytes10"
	BYTES11 TypeName = "bytes11"
	BYTES12 TypeName = "bytes12"
	BYTES13 TypeName = "bytes13"
	BYTES14 TypeName = "bytes14"
	BYTES15 TypeName = "bytes15"
	BYTES16 TypeName = "bytes16"
	BYTES17 TypeName = "bytes17"
	BYTES18 TypeName = "bytes18"
	BYTES19 TypeName = "bytes19"
	BYTES20 TypeName = "bytes20"
	BYTES21 TypeName = "bytes21"
	BYTES22 TypeName = "bytes22"
	BYTES23 TypeName = "bytes23"
	BYTES24 TypeName = "bytes24"
	BYTES25 TypeName = "bytes25"
	BYTES26 TypeName = "bytes26"
	BYTES27 TypeName = "bytes27"
	BYTES28 TypeName = "bytes28"
	BYTES29 TypeName = "bytes29"
	BYTES30 TypeName = "bytes30"
	BYTES31 TypeName = "bytes31"
	BYTES32 TypeName = "bytes32"
)

func ARRAY

func ARRAY(t TypeName, n int) TypeName

func FIXED

func FIXED(M, N int) TypeName

func SLICE

func SLICE(t TypeName) TypeName

func TUPLE

func TUPLE(elems ...TypeName) TypeName

func UFIXED

func UFIXED(M, N int) TypeName

func (TypeName) IsDynamic

func (t TypeName) IsDynamic() bool

func (TypeName) IsFixedSlice

func (t TypeName) IsFixedSlice() bool

func (TypeName) IsNumber

func (t TypeName) IsNumber() bool

func (TypeName) IsSimple

func (t TypeName) IsSimple() bool

func (TypeName) IsSlice

func (t TypeName) IsSlice() bool

func (TypeName) IsTuple

func (t TypeName) IsTuple() bool

func (TypeName) IsUnsigned

func (t TypeName) IsUnsigned() bool

func (TypeName) TupleArgs

func (t TypeName) TupleArgs() []TypeName

func (TypeName) UnSlice

func (t TypeName) UnSlice() (TypeName, int)

Jump to

Keyboard shortcuts

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