abi

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 16 Imported by: 15

Documentation

Index

Constants

View Source
const WordLength = 32

WordLength is the number of bytes in an EVM word.

Variables

View Source
var (
	// MaxUint contains the maximum unsigned integer for each bit size.
	MaxUint = map[int]*big.Int{}

	// MaxInt contains the maximum signed integer for each bit size.
	MaxInt = map[int]*big.Int{}

	// MinInt contains the minimum signed integer for each bit size.
	MinInt = map[int]*big.Int{}
)
View Source
var Default = NewABI()

Default is the default ABI instance that is used by the package-level functions.

It is recommended to create a new ABI instance using NewABI rather than modifying the default instance, as this can potentially interfere with other packages that use the default ABI instance.

View Source
var Panic = NewError("Panic", NewTupleType(TupleTypeElem{Name: "error", Type: NewUintType(256)}))

Panic is the Error instance for panic responses.

View Source
var Revert = NewError("Error", NewTupleType(TupleTypeElem{Name: "error", Type: NewStringType()}))

Revert is the Error instance for revert responses.

Functions

func DecodePanic

func DecodePanic(data []byte) *big.Int

DecodePanic decodes the panic data returned by contract calls. If the data is not a valid panic message, it returns nil.

func DecodeRevert

func DecodeRevert(data []byte) string

DecodeRevert decodes the revert data returned by contract calls. If the data is not a valid revert message, it returns an empty string.

func DecodeValue

func DecodeValue(t Type, abi []byte, val any) error

DecodeValue decodes the given ABI-encoded data into the given value. Value must be a pointer to a struct or a map.

func DecodeValues

func DecodeValues(t Type, abi []byte, vals ...any) error

DecodeValues decodes the given ABI-encoded data into the given values. The t type must be a tuple type.

func EncodeValue

func EncodeValue(t Type, val any) ([]byte, error)

EncodeValue encodes a value to ABI encoding.

func EncodeValues

func EncodeValues(t Type, vals ...any) ([]byte, error)

EncodeValues encodes a list of values to ABI encoding. The t type must be a tuple type.

func IsPanic

func IsPanic(data []byte) bool

IsPanic returns true if the data has the panic prefix.

func IsRevert

func IsRevert(data []byte) bool

IsRevert returns true if the data has the revert prefix.

func MustDecodeValue added in v0.5.0

func MustDecodeValue(t Type, abi []byte, val any)

MustDecodeValue is like DecodeValue but panics on error.

func MustDecodeValues added in v0.5.0

func MustDecodeValues(t Type, abi []byte, vals ...any)

MustDecodeValues is like DecodeValues but panics on error.

func MustEncodeValue

func MustEncodeValue(t Type, val any) []byte

MustEncodeValue is like EncodeValue but panics on error.

func MustEncodeValues

func MustEncodeValues(t Type, vals ...any) []byte

MustEncodeValues is like EncodeValues but panics on error.

func ToPanicError added in v0.4.2

func ToPanicError(data []byte) error

ToPanicError converts the panic data returned by contract calls into a PanicError. If the data does not contain a valid panic message, it returns nil.

func ToRevertError added in v0.4.2

func ToRevertError(data []byte) error

ToRevertError converts the revert data returned by contract calls into a RevertError. If the data does not contain a valid revert message, it returns nil.

Types

type ABI

type ABI struct {
	// Types is a map of known ABI types.
	// The key is the name of the type, and the value is the type.
	Types map[string]Type

	// Mapper is used to map values to and from ABI types.
	Mapper Mapper
}

ABI structure implements the Ethereum ABI (Application Binary Interface).

It provides methods for working with ABI, such as parsing, encoding and decoding data.

The package provides default ABI instance that is used by the package-level functions. It is possible to create custom ABI instances and use them instead of the default one.

func NewABI

func NewABI() *ABI

NewABI creates a new ABI instance.

For most use cases, the default ABI instance should be used instead of creating a new one.

func (*ABI) DecodeValue

func (a *ABI) DecodeValue(t Type, abi []byte, val any) error

DecodeValue decodes the given ABI-encoded data into the given value. Value must be a pointer to a struct or a map.

func (*ABI) DecodeValues

func (a *ABI) DecodeValues(t Type, abi []byte, vals ...any) error

DecodeValues decodes the given ABI-encoded data into the given values. The t type must be a tuple type.

func (*ABI) EncodeValue

func (a *ABI) EncodeValue(t Type, val any) ([]byte, error)

EncodeValue encodes a value to ABI encoding.

func (*ABI) EncodeValues

func (a *ABI) EncodeValues(t Type, vals ...any) ([]byte, error)

EncodeValues encodes a list of values to ABI encoding. The t type must be a tuple type.

func (*ABI) LoadJSON added in v0.5.0

func (a *ABI) LoadJSON(path string) (*Contract, error)

LoadJSON loads the ABI from the given JSON file and returns a Contract instance.

func (*ABI) MustDecodeValue added in v0.5.0

func (a *ABI) MustDecodeValue(t Type, abi []byte, val any)

MustDecodeValue is like DecodeValue but panics on error.

func (*ABI) MustDecodeValues added in v0.5.0

func (a *ABI) MustDecodeValues(t Type, abi []byte, vals ...any)

MustDecodeValues is like DecodeValues but panics on error.

func (*ABI) MustEncodeValue added in v0.5.0

func (a *ABI) MustEncodeValue(t Type, val any) []byte

MustEncodeValue is like EncodeValue but panics on error.

func (*ABI) MustEncodeValues added in v0.5.0

func (a *ABI) MustEncodeValues(t Type, vals ...any) []byte

MustEncodeValues is like EncodeValues but panics on error.

func (*ABI) MustLoadJSON added in v0.5.0

func (a *ABI) MustLoadJSON(path string) *Contract

MustLoadJSON is like LoadJSON but panics on error.

func (*ABI) MustParseConstructor added in v0.5.0

func (a *ABI) MustParseConstructor(signature string) *Constructor

MustParseConstructor is like ParseConstructor but panics on error.

func (*ABI) MustParseError added in v0.5.0

func (a *ABI) MustParseError(signature string) *Error

MustParseError is like ParseError but panics on error.

func (*ABI) MustParseEvent added in v0.5.0

func (a *ABI) MustParseEvent(signature string) *Event

MustParseEvent is like ParseEvent but panics on error.

func (*ABI) MustParseJSON added in v0.5.0

func (a *ABI) MustParseJSON(data []byte) *Contract

MustParseJSON is like ParseJSON but panics on error.

func (*ABI) MustParseMethod added in v0.5.0

func (a *ABI) MustParseMethod(signature string) *Method

MustParseMethod is like ParseMethod but panics on error.

func (*ABI) MustParseSignatures added in v0.5.0

func (a *ABI) MustParseSignatures(signatures ...string) *Contract

MustParseSignatures is like ParseSignatures but panics on error.

func (*ABI) MustParseStruct added in v0.5.0

func (a *ABI) MustParseStruct(definition string) Type

MustParseStruct is like ParseStruct but panics on error.

func (*ABI) MustParseType added in v0.5.0

func (a *ABI) MustParseType(signature string) Type

MustParseType is like ParseType but panics on error.

func (*ABI) NewConstructor

func (a *ABI) NewConstructor(inputs *TupleType) *Constructor

NewConstructor creates a new Constructor instance.

func (*ABI) NewError

func (a *ABI) NewError(name string, inputs *TupleType) *Error

NewError creates a new Error instance.

This method is rarely used, see ParseError for a more convenient way to create a new Error.

func (*ABI) NewEvent

func (a *ABI) NewEvent(name string, inputs *EventTupleType, anonymous bool) *Event

NewEvent creates a new Event instance.

func (*ABI) NewMethod

func (a *ABI) NewMethod(name string, inputs, outputs *TupleType, mutability StateMutability) *Method

NewMethod creates a new Method instance.

func (*ABI) ParseConstructor

func (a *ABI) ParseConstructor(signature string) (*Constructor, error)

ParseConstructor parses a constructor signature and returns a new Constructor.

See ParseConstructor for more information.

func (*ABI) ParseError

func (a *ABI) ParseError(signature string) (*Error, error)

ParseError parses an error signature and returns a new Error.

See ParseError for more information.

func (*ABI) ParseEvent

func (a *ABI) ParseEvent(signature string) (*Event, error)

ParseEvent parses an event signature and returns a new Event.

See ParseEvent for more information.

func (*ABI) ParseJSON

func (a *ABI) ParseJSON(data []byte) (*Contract, error)

ParseJSON parses the given ABI JSON and returns a Contract instance.

func (*ABI) ParseMethod

func (a *ABI) ParseMethod(signature string) (*Method, error)

ParseMethod parses a method signature and returns a new Method.

See ParseMethod for more information.

func (*ABI) ParseSignatures

func (a *ABI) ParseSignatures(signatures ...string) (*Contract, error)

ParseSignatures parses list of signatures and returns a Contract instance. Signatures must be prefixed with the kind, e.g. "constructor" or "event". For functions, the "function" prefix can be omitted.

In case of duplicate function, event or error names, a counter will be appended to the name starting from 2.

func (*ABI) ParseStruct added in v0.1.1

func (a *ABI) ParseStruct(definition string) (Type, error)

ParseStruct parses a struct definition and returns a new Type.

See ParseStruct for more information.

func (*ABI) ParseType

func (a *ABI) ParseType(signature string) (Type, error)

ParseType parses a type signature and returns a new Type.

See ParseType for more information.

type AddressType

type AddressType struct{}

AddressType represents an address type.

func NewAddressType

func NewAddressType() *AddressType

NewAddressType creates a new "address" type.

func (*AddressType) CanonicalType

func (a *AddressType) CanonicalType() string

CanonicalType implements the Type interface.

func (*AddressType) IsDynamic added in v0.5.0

func (a *AddressType) IsDynamic() bool

IsDynamic implements the Type interface.

func (*AddressType) String

func (a *AddressType) String() string

String implements the Type interface.

func (*AddressType) Value

func (a *AddressType) Value() Value

Value implements the Type interface.

type AddressValue

type AddressValue types.Address

AddressValue is a value of address type.

During encoding, the AddressValue can be mapped to the types.Address type, string as a hex-encoded address. For other types, the rules for []byte slice described in the documentation of anymapper package are used.

func (*AddressValue) Address

func (a *AddressValue) Address() types.Address

Address returns the address value.

func (*AddressValue) DecodeABI

func (a *AddressValue) DecodeABI(words Words) (int, error)

DecodeABI implements the Value interface.

func (*AddressValue) EncodeABI

func (a *AddressValue) EncodeABI() (Words, error)

EncodeABI implements the Value interface.

func (*AddressValue) IsDynamic

func (a *AddressValue) IsDynamic() bool

IsDynamic implements the Value interface.

func (*AddressValue) MapFrom

func (a *AddressValue) MapFrom(m Mapper, src any) error

MapFrom implements the anymapper.MapFrom interface.

func (*AddressValue) MapTo

func (a *AddressValue) MapTo(_ Mapper, dst any) error

MapTo implements the anymapper.MapTo interface.

func (*AddressValue) SetAddress

func (a *AddressValue) SetAddress(v types.Address)

SetAddress sets the value of the AddressValue.

type AliasType

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

AliasType wraps another type and gives it a different type name. The canonical type name is the same as the wrapped type.

func NewAliasType

func NewAliasType(alias string, typ Type) *AliasType

NewAliasType creates a new alias type.

func (*AliasType) CanonicalType

func (a *AliasType) CanonicalType() string

CanonicalType implements the Type interface.

func (*AliasType) IsDynamic added in v0.5.0

func (a *AliasType) IsDynamic() bool

IsDynamic implements the Type interface.

func (*AliasType) String

func (a *AliasType) String() string

String implements the Type interface.

func (*AliasType) Type added in v0.5.0

func (a *AliasType) Type() Type

Type returns the aliased type.

func (*AliasType) Value

func (a *AliasType) Value() Value

Value implements the Type interface.

type ArrayType

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

ArrayType represents an unbounded array type.

func NewArrayType

func NewArrayType(typ Type) *ArrayType

NewArrayType creates a dynamic array type with the given element type.

func (*ArrayType) CanonicalType

func (a *ArrayType) CanonicalType() string

CanonicalType implements the Type interface.

func (*ArrayType) ElementType

func (a *ArrayType) ElementType() Type

ElementType returns the type of the array elements.

func (*ArrayType) IsDynamic added in v0.5.0

func (a *ArrayType) IsDynamic() bool

IsDynamic implements the Type interface.

func (*ArrayType) String

func (a *ArrayType) String() string

String implements the Type interface.

func (*ArrayType) Value

func (a *ArrayType) Value() Value

Value implements the Type interface.

type ArrayValue

type ArrayValue struct {
	Elems []Value
	Type  Type
}

ArrayValue is a value of array type.

During encoding, the ArrayValue can be mapped from a slice or an array.

During decoding the ArrayValue is mapped to a slice or an array of the same size.

func (*ArrayValue) DecodeABI

func (a *ArrayValue) DecodeABI(data Words) (int, error)

DecodeABI implements the Value interface.

func (*ArrayValue) EncodeABI

func (a *ArrayValue) EncodeABI() (Words, error)

EncodeABI implements the Value interface.

func (*ArrayValue) IsDynamic

func (a *ArrayValue) IsDynamic() bool

IsDynamic implements the Value interface.

func (*ArrayValue) MapFrom

func (a *ArrayValue) MapFrom(m Mapper, src any) error

MapFrom implements the anymapper.MapFrom interface.

func (*ArrayValue) MapTo

func (a *ArrayValue) MapTo(m Mapper, dst any) error

MapTo implements the anymapper.MapTo interface.

type BoolType

type BoolType struct{}

BoolType represents a boolean type.

func NewBoolType

func NewBoolType() *BoolType

NewBoolType creates a new "bool" type.

func (*BoolType) CanonicalType

func (b *BoolType) CanonicalType() string

CanonicalType implements the Type interface.

func (*BoolType) IsDynamic added in v0.5.0

func (b *BoolType) IsDynamic() bool

IsDynamic implements the Type interface.

func (*BoolType) String

func (b *BoolType) String() string

String implements the Type interface.

func (*BoolType) Value

func (b *BoolType) Value() Value

Value implements the Type interface.

type BoolValue

type BoolValue bool

BoolValue is a value of bool type.

During encoding and decoding, the BoolValue is mapped using the bool rules described in the documentation of anymapper package.

func (*BoolValue) DecodeABI

func (b *BoolValue) DecodeABI(words Words) (int, error)

DecodeABI implements the Value interface.

func (*BoolValue) EncodeABI

func (b *BoolValue) EncodeABI() (Words, error)

EncodeABI implements the Value interface.

func (*BoolValue) IsDynamic

func (b *BoolValue) IsDynamic() bool

IsDynamic implements the Value interface.

func (*BoolValue) MapFrom

func (b *BoolValue) MapFrom(_ Mapper, src any) error

MapFrom implements the anymapper.MapFrom interface.

func (*BoolValue) MapTo

func (b *BoolValue) MapTo(_ Mapper, dst any) error

MapTo implements the anymapper.MapTo interface.

func (*BoolValue) SetBool

func (b *BoolValue) SetBool(v bool)

SetBool sets the value of the BoolValue.

type BytesType

type BytesType struct{}

BytesType represents a bytes type.

func NewBytesType

func NewBytesType() *BytesType

NewBytesType creates a new "bytes" type.

func (*BytesType) CanonicalType

func (b *BytesType) CanonicalType() string

CanonicalType implements the Type interface.

func (*BytesType) IsDynamic added in v0.5.0

func (b *BytesType) IsDynamic() bool

IsDynamic implements the Type interface.

func (*BytesType) String

func (b *BytesType) String() string

String implements the Type interface.

func (*BytesType) Value

func (b *BytesType) Value() Value

Value implements the Type interface.

type BytesValue

type BytesValue []byte

BytesValue is a value of bytes type.

During encoding ad decoding, the BytesValue can be mapped using the slice rules described in the documentation of anymapper package.

func (*BytesValue) Bytes

func (b *BytesValue) Bytes() []byte

Bytes returns the value of the BytesValue.

func (*BytesValue) DecodeABI

func (b *BytesValue) DecodeABI(data Words) (int, error)

DecodeABI implements the Value interface.

func (*BytesValue) EncodeABI

func (b *BytesValue) EncodeABI() (Words, error)

EncodeABI implements the Value interface.

func (*BytesValue) IsDynamic

func (b *BytesValue) IsDynamic() bool

IsDynamic implements the Value interface.

func (*BytesValue) MapFrom

func (b *BytesValue) MapFrom(m Mapper, src any) error

MapFrom implements the anymapper.MapFrom interface.

func (*BytesValue) MapTo

func (b *BytesValue) MapTo(m Mapper, dst any) error

MapTo implements the anymapper.MapTo interface.

func (*BytesValue) SetBytes

func (b *BytesValue) SetBytes(data []byte)

SetBytes sets the value of the BytesValue.

type Constructor

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

Constructor represents a constructor in an Contract. The constructor can be used to encode arguments for a constructor call.

func MustParseConstructor

func MustParseConstructor(signature string) *Constructor

MustParseConstructor is like ParseConstructor but panics on error.

func NewConstructor

func NewConstructor(inputs *TupleType) *Constructor

NewConstructor creates a new Constructor instance.

This method is rarely used, see ParseConstructor for a more convenient way to create a new Constructor.

func ParseConstructor

func ParseConstructor(signature string) (*Constructor, error)

ParseConstructor parses a constructor signature and returns a new Constructor.

A constructor signature is similar to a method signature, but it does not have a name and returns no values. It can be optionally prefixed with the "constructor" keyword.

The following examples are valid signatures:

((uint256,bytes32)[])
((uint256 a, bytes32 b)[] c)
constructor(tuple(uint256 a, bytes32 b)[] memory c)

This function is equivalent to calling Parser.ParseConstructor with the default configuration.

func (*Constructor) EncodeArg

func (m *Constructor) EncodeArg(code []byte, arg any) ([]byte, error)

EncodeArg encodes an argument for a contract deployment. The map or structure must have fields with the same names as the constructor arguments.

func (*Constructor) EncodeArgs

func (m *Constructor) EncodeArgs(code []byte, args ...any) ([]byte, error)

EncodeArgs encodes arguments for a contract deployment. The map or structure must have fields with the same names as the constructor arguments.

func (*Constructor) Inputs

func (m *Constructor) Inputs() *TupleType

Inputs returns the input arguments of the constructor as a tuple type.

func (*Constructor) MustEncodeArg added in v0.5.0

func (m *Constructor) MustEncodeArg(code []byte, arg any) []byte

MustEncodeArg is like EncodeArg but panics on error.

func (*Constructor) MustEncodeArgs added in v0.5.0

func (m *Constructor) MustEncodeArgs(code []byte, args ...any) []byte

MustEncodeArgs is like EncodeArgs but panics on error.

func (*Constructor) String

func (m *Constructor) String() string

String returns the human-readable signature of the constructor.

type Contract

type Contract struct {
	Constructor        *Constructor
	Methods            map[string]*Method
	MethodsBySignature map[string]*Method
	Events             map[string]*Event
	Errors             map[string]*Error
	Types              map[string]Type // Types defined in the ABI (structs, enums and user-defined Value Types)
}

Contract provides a high-level API for interacting with a contract. It can be created from a JSON ABI definition using the ParseJSON function or from a list of signatures using the ParseSignatures function.

func LoadJSON

func LoadJSON(path string) (*Contract, error)

LoadJSON loads the ABI from the given JSON file and returns a Contract instance.

func MustLoadJSON added in v0.5.0

func MustLoadJSON(path string) *Contract

MustLoadJSON is like LoadJSON but panics on error.

func MustParseJSON

func MustParseJSON(data []byte) *Contract

MustParseJSON is like ParseJSON but panics on error.

func MustParseSignatures

func MustParseSignatures(signatures ...string) *Contract

MustParseSignatures is like ParseSignatures but panics on error.

func ParseJSON

func ParseJSON(data []byte) (*Contract, error)

ParseJSON parses the given ABI JSON and returns a Contract instance.

func ParseSignatures

func ParseSignatures(signatures ...string) (*Contract, error)

ParseSignatures parses list of signatures and returns a Contract instance. Signatures must be prefixed with the kind, e.g. "function" or "event".

It accepts signatures in the same format as ParseConstructor, ParseMethod, ParseEvent, and ParseError functions.

func (*Contract) HandleError added in v0.5.0

func (c *Contract) HandleError(err error) error

HandleError converts an error returned by a contract call to a RevertError, PanicError, or CustomError if applicable. If not, it returns the original error.

func (*Contract) IsError added in v0.4.2

func (c *Contract) IsError(data []byte) bool

IsError returns true if the given error data, returned by a contract call, corresponds to a revert, panic, or custom error.

func (*Contract) RegisterTypes added in v0.5.0

func (c *Contract) RegisterTypes(a *ABI)

RegisterTypes registers types defined in the contract to the given ABI instance. This enables the use of types defined in the contract in all Parse* methods.

If the type name already exists, it will be overwritten.

func (*Contract) ToError added in v0.4.2

func (c *Contract) ToError(data []byte) error

ToError returns an error if the given error data, returned by a contract call, corresponds to a revert, panic, or a custom error. It returns nil if the data cannot be recognized as an error.

type CustomError added in v0.4.2

type CustomError struct {
	Type *Error // The error type.
	Data []byte // The error data returned by the contract call.
}

CustomError represents a custom error returned by a contract call.

func (CustomError) Error added in v0.4.2

func (e CustomError) Error() string

Error implements the error interface.

type Error

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

Error represents an error in an ABI. The error can be used to decode errors returned by a contract call.

func MustParseError

func MustParseError(signature string) *Error

MustParseError is like ParseError but panics on error.

func NewError

func NewError(name string, inputs *TupleType) *Error

NewError creates a new Error instance.

func ParseError

func ParseError(signature string) (*Error, error)

ParseError parses an error signature and returns a new Error.

An error signature is similar to a method signature, but returns no values. It can be optionally prefixed with the "error" keyword.

The following examples are valid signatures:

foo((uint256,bytes32)[])
foo((uint256 a, bytes32 b)[] c)
error foo(tuple(uint256 a, bytes32 b)[] c)

This function is equivalent to calling Parser.ParseError with the default configuration.

func (*Error) DecodeValue

func (e *Error) DecodeValue(data []byte, val any) error

DecodeValue decodes the error into a map or structure. If a structure is given, it must have fields with the same names as error arguments.

func (*Error) DecodeValues

func (e *Error) DecodeValues(data []byte, vals ...any) error

DecodeValues decodes the error into a map or structure. If a structure is given, it must have fields with the same names as error arguments.

func (*Error) FourBytes

func (e *Error) FourBytes() FourBytes

FourBytes is the first four bytes of the Keccak256 hash of the error signature.

func (*Error) HandleError added in v0.5.0

func (e *Error) HandleError(err error) error

HandleError converts an error returned by a contract call to a custom error if possible. If provider error is nil, it returns nil.

func (*Error) Inputs

func (e *Error) Inputs() *TupleType

Inputs returns the input arguments of the error as a tuple type.

func (*Error) Is

func (e *Error) Is(data []byte) bool

Is returns true if the ABI encoded data is an error of this type.

func (*Error) MustDecodeValue added in v0.5.0

func (e *Error) MustDecodeValue(data []byte, val any)

MustDecodeValue is like DecodeValue but panics on error.

func (*Error) MustDecodeValues added in v0.5.0

func (e *Error) MustDecodeValues(data []byte, vals ...any)

MustDecodeValues is like DecodeValues but panics on error.

func (*Error) Name

func (e *Error) Name() string

Name returns the name of the error.

func (*Error) Signature

func (e *Error) Signature() string

Signature returns the error signature, that is, the error name and the canonical type of error arguments.

func (*Error) String

func (e *Error) String() string

String returns the human-readable signature of the error.

func (*Error) ToError added in v0.4.2

func (e *Error) ToError(data []byte) error

ToError converts the error data returned by contract calls into a CustomError. If the data does not contain a valid error message, it returns nil.

type Event

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

Event represents an event in an ABI. The event can be used to decode events emitted by a contract.

func MustParseEvent

func MustParseEvent(signature string) *Event

MustParseEvent is like ParseEvent but panics on error.

func NewEvent

func NewEvent(name string, inputs *EventTupleType, anonymous bool) *Event

NewEvent creates a new Event instance.

This method is rarely used, see ParseEvent for a more convenient way to create a new Event.

func ParseEvent

func ParseEvent(signature string) (*Event, error)

ParseEvent parses an event signature and returns a new Event.

An event signature is similar to a method signature, but returns no values. It can be optionally prefixed with the "event" keyword.

The following examples are valid signatures:

foo(int indexed,(uint256,bytes32)[])
foo(int indexed a, (uint256 b, bytes32 c)[] d)
event foo(int indexed a tuple(uint256 b, bytes32 c)[] d)

This function is equivalent to calling Parser.ParseEvent with the default configuration.

func (*Event) DecodeValue

func (e *Event) DecodeValue(topics []types.Hash, data []byte, val any) error

DecodeValue decodes the event into a map or structure. If a structure is given, it must have fields with the same names as the event arguments.

func (*Event) DecodeValues

func (e *Event) DecodeValues(topics []types.Hash, data []byte, vals ...any) error

DecodeValues decodes the event into a map or structure. If a structure is given, it must have fields with the same names as the event arguments.

func (*Event) Inputs

func (e *Event) Inputs() *EventTupleType

Inputs returns the input arguments of the event as a tuple type.

func (*Event) MustDecodeValue added in v0.5.0

func (e *Event) MustDecodeValue(topics []types.Hash, data []byte, val any)

MustDecodeValue is like DecodeValue but panics on error.

func (*Event) MustDecodeValues added in v0.5.0

func (e *Event) MustDecodeValues(topics []types.Hash, data []byte, vals ...any)

MustDecodeValues is like DecodeValues but panics on error.

func (*Event) Name

func (e *Event) Name() string

Name returns the name of the event.

func (*Event) Signature

func (e *Event) Signature() string

Signature returns the event signature, that is, the event name and the canonical type of the input arguments.

func (*Event) String

func (e *Event) String() string

String returns the human-readable signature of the event.

func (*Event) Topic0

func (e *Event) Topic0() types.Hash

Topic0 returns the first topic of the event, that is, the Keccak256 hash of the event signature.

type EventTupleElem

type EventTupleElem struct {
	// Name of the tuple element. It is used when mapping values from and to
	// maps and structures. If the name is empty, when creating a new value,
	// the name will be set to topicN or dataN, where N is the index of the
	// topic or data element. Topics are counted from 1 because the first topic
	// is the event signature.
	Name string

	// Indexed indicates whether the element is indexed.
	Indexed bool

	// Type is the type of the element.
	Type Type
}

EventTupleElem is an element of an event tuple.

type EventTupleType

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

EventTupleType represents a tuple type for event inputs. It works just like TupleType, but elements can be marked as indexed. When creating a new value, the indexed elements will be created first, followed by the non-indexed elements.

func NewEventTupleType

func NewEventTupleType(elems ...EventTupleElem) *EventTupleType

NewEventTupleType creates a new tuple type with the given elements.

func (*EventTupleType) CanonicalType

func (t *EventTupleType) CanonicalType() string

CanonicalType implements the Type interface.

func (*EventTupleType) DataSize

func (t *EventTupleType) DataSize() int

DataSize returns the number of non-indexed elements in the tuple.

func (*EventTupleType) DataTuple added in v0.2.0

func (t *EventTupleType) DataTuple() *TupleType

DataTuple returns the tuple of non-indexed arguments.

func (*EventTupleType) Elements

func (t *EventTupleType) Elements() []EventTupleElem

Elements returns the tuple elements.

func (*EventTupleType) IndexedSize

func (t *EventTupleType) IndexedSize() int

IndexedSize returns the number of indexed elements in the tuple.

func (*EventTupleType) IsDynamic added in v0.5.0

func (t *EventTupleType) IsDynamic() bool

IsDynamic implements the Type interface.

func (*EventTupleType) Size

func (t *EventTupleType) Size() int

Size returns the number of elements in the tuple.

func (*EventTupleType) String

func (t *EventTupleType) String() string

String implements the Type interface.

func (*EventTupleType) TopicsTuple added in v0.2.0

func (t *EventTupleType) TopicsTuple() *TupleType

TopicsTuple returns the tuple of indexed arguments.

If the type is indexed and dynamic, the type will be converted to bytes32.

func (*EventTupleType) Value

func (t *EventTupleType) Value() Value

Value implements the Type interface.

type FixedArrayType

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

FixedArrayType represents a fixed-size array type.

func NewFixedArrayType

func NewFixedArrayType(typ Type, size int) *FixedArrayType

NewFixedArrayType creates a new fixed array type with the given element type and size.

func (*FixedArrayType) CanonicalType

func (f *FixedArrayType) CanonicalType() string

CanonicalType implements the Type interface.

func (*FixedArrayType) ElementType

func (f *FixedArrayType) ElementType() Type

ElementType returns the type of the array elements.

func (*FixedArrayType) IsDynamic added in v0.5.0

func (f *FixedArrayType) IsDynamic() bool

IsDynamic implements the Type interface.

func (*FixedArrayType) Size

func (f *FixedArrayType) Size() int

Size returns the size of the array.

func (*FixedArrayType) String

func (f *FixedArrayType) String() string

String implements the Type interface.

func (*FixedArrayType) Value

func (f *FixedArrayType) Value() Value

Value implements the Type interface.

type FixedArrayValue

type FixedArrayValue []Value

FixedArrayValue is a value of fixed array type. The size of a slice is assumed to be equal to the size of the type.

During encoding, the FixedArrayValue can be mapped from a slice or an array.

During decoding the FixedArrayValue is mapped to a slice or an array of the same size.

func (FixedArrayValue) DecodeABI

func (a FixedArrayValue) DecodeABI(data Words) (int, error)

DecodeABI implements the Value interface.

func (FixedArrayValue) EncodeABI

func (a FixedArrayValue) EncodeABI() (Words, error)

EncodeABI implements the Value interface.

func (FixedArrayValue) IsDynamic

func (a FixedArrayValue) IsDynamic() bool

IsDynamic implements the Value interface.

func (FixedArrayValue) MapFrom

func (a FixedArrayValue) MapFrom(m Mapper, src any) error

MapFrom implements the anymapper.MapFrom interface.

func (FixedArrayValue) MapTo

func (a FixedArrayValue) MapTo(m Mapper, dst any) error

MapTo implements the anymapper.MapTo interface.

type FixedBytesType

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

FixedBytesType represents a fixed-size bytes type.

func NewFixedBytesType

func NewFixedBytesType(size int) *FixedBytesType

NewFixedBytesType creates a new fixed-size bytes type with the given size. The size must be between 1 and 32.

func (*FixedBytesType) CanonicalType

func (f *FixedBytesType) CanonicalType() string

CanonicalType implements the Type interface.

func (*FixedBytesType) IsDynamic added in v0.5.0

func (f *FixedBytesType) IsDynamic() bool

IsDynamic implements the Type interface.

func (*FixedBytesType) Size

func (f *FixedBytesType) Size() int

Size returns the size of the bytes type.

func (*FixedBytesType) String

func (f *FixedBytesType) String() string

String implements the Type interface.

func (*FixedBytesType) Value

func (f *FixedBytesType) Value() Value

Value implements the Type interface.

type FixedBytesValue

type FixedBytesValue []byte

FixedBytesValue is a value of fixed bytes type. The size of a slice is assumed to be equal to the size of the bytesN type.

During encoding and decoding, the FixedBytesValue is mapped using the slice rules described in the documentation of anymapper package. Both values must have the same size.

func (*FixedBytesValue) Bytes

func (b *FixedBytesValue) Bytes() []byte

Bytes returns the value of the FixedBytesValue.

func (FixedBytesValue) DecodeABI

func (b FixedBytesValue) DecodeABI(data Words) (int, error)

DecodeABI implements the Value interface.

func (FixedBytesValue) EncodeABI

func (b FixedBytesValue) EncodeABI() (Words, error)

EncodeABI implements the Value interface.

func (FixedBytesValue) IsDynamic

func (b FixedBytesValue) IsDynamic() bool

IsDynamic implements the Value interface.

func (FixedBytesValue) MapFrom

func (b FixedBytesValue) MapFrom(m Mapper, src any) error

MapFrom implements the anymapper.MapFrom interface.

func (FixedBytesValue) MapTo

func (b FixedBytesValue) MapTo(_ Mapper, dst any) error

MapTo implements the anymapper.MapTo interface.

func (*FixedBytesValue) SetBytes

func (b *FixedBytesValue) SetBytes(data []byte) error

SetBytes sets the value of the FixedBytesValue.

type FourBytes

type FourBytes [4]byte

FourBytes is a 4-byte method selector.

func (FourBytes) Bytes

func (f FourBytes) Bytes() []byte

Bytes returns the four bytes as a byte slice.

func (FourBytes) Hex

func (f FourBytes) Hex() string

Hex returns the four bytes as a hex string.

func (FourBytes) Match

func (f FourBytes) Match(data []byte) bool

Match returns true if the given ABI data matches the four byte selector.

func (FourBytes) String

func (f FourBytes) String() string

String returns the four bytes as a hex string.

type IntType

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

IntType represents a signed integer type.

func NewIntType

func NewIntType(size int) *IntType

NewIntType creates a new "int" type with the given size. The size must be between 8 and 256 and a multiple of 8.

func (*IntType) CanonicalType

func (i *IntType) CanonicalType() string

CanonicalType implements the Type interface.

func (*IntType) IsDynamic added in v0.5.0

func (i *IntType) IsDynamic() bool

IsDynamic implements the Type interface.

func (*IntType) Size

func (i *IntType) Size() int

Size returns the size of the int type.

func (*IntType) String

func (i *IntType) String() string

Type implements the Type interface.

func (*IntType) Value

func (i *IntType) Value() Value

Value implements the Type interface.

type IntValue

type IntValue struct {
	big.Int
	Size int
}

IntValue is a value of intN types.

During encoding, the IntValue is mapped to the *big.Int type using the rules described in the documentation of anymapper package.

During decoding, the IntValue is mapped from the *big.Int type using the rules described in the documentation of anymapper package.

func (*IntValue) DecodeABI

func (i *IntValue) DecodeABI(words Words) (int, error)

DecodeABI implements the Value interface.

func (*IntValue) EncodeABI

func (i *IntValue) EncodeABI() (Words, error)

EncodeABI implements the Value interface.

func (*IntValue) IsDynamic

func (i *IntValue) IsDynamic() bool

IsDynamic implements the Value interface.

func (*IntValue) MapFrom

func (i *IntValue) MapFrom(_ Mapper, src any) error

MapFrom implements the anymapper.MapFrom interface.

func (*IntValue) MapTo

func (i *IntValue) MapTo(_ Mapper, dst any) error

MapTo implements the anymapper.MapTo interface.

type MapFrom

type MapFrom interface {
	// MapFrom maps the value from the ABI Value.
	//
	// src is never a pointer.
	MapFrom(m Mapper, src any) error
}

MapFrom maps the value from the ABI Value.

type MapTo

type MapTo interface {
	// MapTo maps the value to the ABI Value.
	//
	// dst is always an initialized pointer.
	MapTo(m Mapper, dst any) error
}

MapTo maps the value to the ABI Value.

type Mapper

type Mapper interface {
	Map(src any, dst any) error
}

Mapper used to map values to and from ABI types.

type Method

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

Method represents a method in an ABI. The method can be used to encode arguments for a method call and decode return values from a method call.

func MustParseMethod

func MustParseMethod(signature string) *Method

MustParseMethod is like ParseMethod but panics on error.

func NewMethod

func NewMethod(name string, inputs, outputs *TupleType, mutability StateMutability) *Method

NewMethod creates a new Method instance.

This method is rarely used, see ParseMethod for a more convenient way to create a new Method.

func ParseMethod

func ParseMethod(signature string) (*Method, error)

ParseMethod parses a method signature and returns a new Method.

The method accepts Solidity method signatures, but allows to omit the "function" keyword, argument names and the "returns" keyword. Method modifiers and argument data location specifiers are allowed. Tuple types are indicated by parentheses, with the optional keyword "tuple" before the parentheses.

If argument names are omitted, the default "argN" is used, where N is the argument index. Similarly, if return value names are omitted, "argN" is also used.

The following examples are valid signatures:

foo((uint256,bytes32)[])(uint256)
foo((uint256 a, bytes32 b)[] c)(uint256 d)
function foo(tuple(uint256 a, bytes32 b)[] memory c) pure returns (uint256 d)

This function is equivalent to calling Parser.ParseMethod with the default configuration.

func (*Method) DecodeArg

func (m *Method) DecodeArg(data []byte, arg any) error

DecodeArg decodes an ABI-encoded data into a provided map or struct.

Provided struct or map must have fields that match the names of the method's arguments.

Provided data must be prefixed with the method selector.

func (*Method) DecodeArgs

func (m *Method) DecodeArgs(data []byte, args ...any) error

DecodeArgs decodes an ABI-encoded data into a provided list of arguments.

Provided data must be prefixed with the method selector.

func (*Method) DecodeValue

func (m *Method) DecodeValue(data []byte, val any) error

DecodeValue decodes an ABI-encoded data into a provided map or struct.

Provided struct or map must have fields that match the names of the method's return values.

func (*Method) DecodeValues

func (m *Method) DecodeValues(data []byte, vals ...any) error

DecodeValues decodes an ABI-encoded data into a provided list of return variables.

func (*Method) EncodeArg

func (m *Method) EncodeArg(arg any) ([]byte, error)

EncodeArg encodes arguments for a method call using a provided map or structure.

Provided struct or map must have fields that match the names of the method's arguments.

The return value is a ABI-encoded data prefixed with the method selector.

func (*Method) EncodeArgs

func (m *Method) EncodeArgs(args ...any) ([]byte, error)

EncodeArgs encodes arguments for a method call using a provided list of arguments.

The return value is a ABI-encoded data prefixed with the method selector.

func (*Method) FourBytes

func (m *Method) FourBytes() FourBytes

FourBytes is the first four bytes of the Keccak256 hash of the method signature. It is also known as a "function selector."

func (*Method) Inputs

func (m *Method) Inputs() *TupleType

Inputs returns the input arguments of the method as a tuple type.

func (*Method) MustDecodeArg added in v0.5.0

func (m *Method) MustDecodeArg(data []byte, arg any)

MustDecodeArg is like DecodeArg but panics on error.

func (*Method) MustDecodeArgs added in v0.5.0

func (m *Method) MustDecodeArgs(data []byte, args ...any)

MustDecodeArgs is like DecodeArgs but panics on error.

func (*Method) MustDecodeValue added in v0.5.0

func (m *Method) MustDecodeValue(data []byte, val any)

MustDecodeValue is like DecodeValue but panics on error.

func (*Method) MustDecodeValues added in v0.5.0

func (m *Method) MustDecodeValues(data []byte, vals ...any)

MustDecodeValues is like DecodeValues but panics on error.

func (*Method) MustEncodeArg added in v0.5.0

func (m *Method) MustEncodeArg(arg any) []byte

MustEncodeArg is like EncodeArg but panics on error.

func (*Method) MustEncodeArgs added in v0.5.0

func (m *Method) MustEncodeArgs(args ...any) []byte

MustEncodeArgs is like EncodeArgs but panics on error.

func (*Method) Name

func (m *Method) Name() string

Name returns the name of the method.

func (*Method) Outputs

func (m *Method) Outputs() *TupleType

Outputs returns the output values of the method as a tuple type.

func (*Method) Signature

func (m *Method) Signature() string

Signature returns the method signature, that is, the method name and the canonical types of the input arguments.

func (*Method) StateMutability added in v0.5.0

func (m *Method) StateMutability() StateMutability

StateMutability returns the state mutability of the method.

func (*Method) String

func (m *Method) String() string

String returns the human-readable signature of the method.

type PanicError added in v0.4.2

type PanicError struct {
	Code *big.Int
}

PanicError represents an error returned by contract calls when the call panics.

func (PanicError) Error added in v0.4.2

func (e PanicError) Error() string

Error implements the error interface.

type RevertError added in v0.4.2

type RevertError struct {
	Reason string
}

RevertError represents an error returned by contract calls when the call reverts.

func (RevertError) Error added in v0.4.2

func (e RevertError) Error() string

Error implements the error interface.

type StateMutability added in v0.5.0

type StateMutability int
const (
	StateMutabilityUnknown StateMutability = iota
	StateMutabilityPure
	StateMutabilityView
	StateMutabilityNonPayable
	StateMutabilityPayable
)

func StateMutabilityFromString added in v0.5.0

func StateMutabilityFromString(s string) StateMutability

func (StateMutability) String added in v0.5.0

func (m StateMutability) String() string

type StringType

type StringType struct{}

StringType represents a string type.

func NewStringType

func NewStringType() *StringType

NewStringType creates a new "string" type.

func (*StringType) CanonicalType

func (s *StringType) CanonicalType() string

CanonicalType implements the Type interface.

func (*StringType) IsDynamic added in v0.5.0

func (s *StringType) IsDynamic() bool

IsDynamic implements the Type interface.

func (*StringType) String

func (s *StringType) String() string

Type implements the Type interface.

func (*StringType) Value

func (s *StringType) Value() Value

Value implements the Type interface.

type StringValue

type StringValue string

StringValue is a value of bytes type.

During encoding ad decoding, the StringValue is mapped using the string rules described in the documentation of anymapper package.

func (*StringValue) DecodeABI

func (s *StringValue) DecodeABI(data Words) (int, error)

DecodeABI implements the Value interface.

func (*StringValue) EncodeABI

func (s *StringValue) EncodeABI() (Words, error)

EncodeABI implements the Value interface.

func (*StringValue) IsDynamic

func (s *StringValue) IsDynamic() bool

IsDynamic implements the Value interface.

func (*StringValue) MapFrom

func (s *StringValue) MapFrom(m Mapper, src any) error

MapFrom implements the anymapper.MapFrom interface.

func (*StringValue) MapTo

func (s *StringValue) MapTo(m Mapper, dst any) error

MapTo implements the anymapper.MapTo interface.

func (*StringValue) SetString

func (s *StringValue) SetString(str string)

SetString sets the value of the StringValue.

func (*StringValue) String

func (s *StringValue) String() string

String returns the value of the StringValue.

type TupleType

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

TupleType represents a tuple type.

func NewTupleType

func NewTupleType(elems ...TupleTypeElem) *TupleType

NewTupleType creates a new tuple type with the given elements.

func (*TupleType) CanonicalType

func (t *TupleType) CanonicalType() string

CanonicalType implements the Type interface.

func (*TupleType) Elements

func (t *TupleType) Elements() []TupleTypeElem

Elements returns the tuple elements.

func (*TupleType) IsDynamic added in v0.5.0

func (t *TupleType) IsDynamic() bool

IsDynamic implements the Type interface.

func (*TupleType) Size

func (t *TupleType) Size() int

Size returns the number of elements in the tuple.

func (*TupleType) String

func (t *TupleType) String() string

String implements the Type interface.

func (*TupleType) Value

func (t *TupleType) Value() Value

Value implements the Type interface.

type TupleTypeElem

type TupleTypeElem struct {
	// Name of the tuple element. It is used when mapping values from and to
	// maps and structures. If the name is empty, when creating a new value
	// the name will be set to argN, where N is the index of the element.
	Name string

	// Type is the type of the element.
	Type Type
}

TupleTypeElem is an element of a tuple.

type TupleValue

type TupleValue []TupleValueElem

TupleValue is a value of tuple type.

During encoding, the TupleValue can be mapped from a struct or a map where keys or struct fields are used as tuple element names.

During decoding, the TupleValue can be mapped to a struct or a map where tuple element names are used as keys or struct fields.

func (*TupleValue) DecodeABI

func (t *TupleValue) DecodeABI(words Words) (int, error)

DecodeABI implements the Value interface.

func (*TupleValue) EncodeABI

func (t *TupleValue) EncodeABI() (Words, error)

EncodeABI implements the Value interface.

func (*TupleValue) IsDynamic

func (t *TupleValue) IsDynamic() bool

IsDynamic implements the Value interface.

func (*TupleValue) MapFrom

func (t *TupleValue) MapFrom(m Mapper, src any) error

MapFrom implements the anymapper.MapFrom interface.

func (*TupleValue) MapTo

func (t *TupleValue) MapTo(m Mapper, dst any) error

MapTo implements the anymapper.MapTo interface.

type TupleValueElem

type TupleValueElem struct {
	// Name of the tuple element. It is used when mapping values from and to
	// maps and structures.
	Name string

	// Value is the value of the tuple element. It is used to encode and decode
	// the ABI data.
	Value Value
}

TupleValueElem is an element of tuple value.

type Type

type Type interface {
	// IsDynamic indicates whether the type is dynamic.
	IsDynamic() bool

	// CanonicalType is the type as it would appear in the ABI.
	//
	// Only the types defined in the ABI specification are allowed:
	// https://docs.soliditylang.org/en/latest/abi-spec.html
	//
	// In case of a tuple, the canonical type is the canonical type of the
	// tuple's elements, separated by commas and enclosed in parentheses.
	// Arrays are represented by the canonical name of the element type
	// followed by square brackets with the array size.
	CanonicalType() string

	// String returns the user-friendly name of the type.
	String() string

	// Value creates a new zero value for the type.
	Value() Value
}

Type is a representation of a type like uint256 or address. The type can be used to create a new value of that type, but it cannot store a value.

func MustParseStruct added in v0.1.1

func MustParseStruct(definition string) Type

MustParseStruct is like ParseStruct but panics on error.

func MustParseType

func MustParseType(signature string) Type

MustParseType is like ParseType but panics on error.

func ParseStruct added in v0.1.1

func ParseStruct(definition string) (Type, error)

ParseStruct parses a struct definition and returns a new Type.

It is similar to ParseType, but accepts a struct definition instead of a type signature.

For example, the following two calls are equivalent:

ParseType("(uint256 a, bytes32 b)")
ParseStruct("struct { uint256 a; bytes32 b; }")

func ParseType

func ParseType(signature string) (Type, error)

ParseType parses a type signature and returns a new Type.

A type can be either an elementary type like uint256 or a tuple type. Tuple types are denoted by parentheses, with the optional keyword "tuple" before the parentheses. Parameter names are optional.

The generated types can be used to create new values, which can then be used to encode or decode ABI data.

Custom types may be added to the ABI.Types, this will allow the parser to handle them.

The following examples are valid type signatures:

uint256
(uint256 a,bytes32 b)
tuple(uint256 a, bytes32 b)[]

This function is equivalent to calling Parser.ParseType with the default configuration.

type UintType

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

UintType represents an unsigned integer type.

func NewUintType

func NewUintType(size int) *UintType

NewUintType creates a new "uint" type with the given size. The size must be between 8 and 256 and a multiple of 8.

func (*UintType) CanonicalType

func (u *UintType) CanonicalType() string

CanonicalType implements the Type interface.

func (*UintType) IsDynamic added in v0.5.0

func (u *UintType) IsDynamic() bool

IsDynamic implements the Type interface.

func (*UintType) Size

func (u *UintType) Size() int

Size returns the size of the uint type.

func (*UintType) String

func (u *UintType) String() string

String implements the Type interface.

func (*UintType) Value

func (u *UintType) Value() Value

Value implements the Type interface.

type UintValue

type UintValue struct {
	big.Int
	Size int
}

UintValue is a value of uintN types.

During encoding, the UintValue is mapped to the *big.Int type using the rules described in the documentation of anymapper package.

During decoding, the UintValue is mapped from the *big.Int type using the rules described in the documentation of anymapper package.

func (*UintValue) DecodeABI

func (u *UintValue) DecodeABI(words Words) (int, error)

DecodeABI implements the Value interface.

func (*UintValue) EncodeABI

func (u *UintValue) EncodeABI() (Words, error)

EncodeABI implements the Value interface.

func (*UintValue) IsDynamic

func (u *UintValue) IsDynamic() bool

IsDynamic implements the Value interface.

func (*UintValue) MapFrom

func (u *UintValue) MapFrom(_ Mapper, src any) error

MapFrom implements the anymapper.MapFrom interface.

func (*UintValue) MapTo

func (u *UintValue) MapTo(_ Mapper, dst any) error

MapTo implements the anymapper.MapTo interface.

type Value

type Value interface {
	// IsDynamic indicates whether the type is dynamic.
	IsDynamic() bool

	// EncodeABI returns the ABI encoding of the value.
	EncodeABI() (Words, error)

	// DecodeABI sets the value from the ABI encoded data.
	DecodeABI(Words) (int, error)
}

Value represents a value that can be encoded to and from ABI.

Values are used as an intermediate representation during encoding and decoding ABI data. Usually, they are not used outside the abi package.

When data is encoded using Encoder, the values provided to Encoder are mapped to Value instances using the anymapper package, and then they are used to encode the ABI data. When the data is decoded using Decoder, the Value instances are used to decode the ABI data, and then the values are mapped to the target types.

type Word

type Word [WordLength]byte

Word represents a 32-bytes EVM word.

func BytesToWords

func BytesToWords(b []byte) []Word

func (Word) Bytes

func (w Word) Bytes() []byte

Bytes returns the word as a byte slice.

func (Word) IsZero

func (w Word) IsZero() bool

IsZero returns true if all bytes in then word are zeros.

func (Word) LeadingZeros

func (w Word) LeadingZeros() int

LeadingZeros returns the number of leading zero bits.

func (*Word) SetBytesPadLeft

func (w *Word) SetBytesPadLeft(b []byte) error

SetBytesPadLeft sets the word to the given bytes, padded on the left.

func (*Word) SetBytesPadRight

func (w *Word) SetBytesPadRight(b []byte) error

SetBytesPadRight sets the word to the given bytes, padded on the right.

func (Word) TrailingZeros

func (w Word) TrailingZeros() int

TrailingZeros returns the number of trailing zero bits.

type Words

type Words []Word

Words is a slice of words.

func (*Words) AppendBytes

func (w *Words) AppendBytes(b []byte)

AppendBytes appends the given bytes to the words.

func (Words) Bytes

func (w Words) Bytes() []byte

Bytes returns the words as a byte slice.

func (*Words) SetBytes

func (w *Words) SetBytes(b []byte)

SetBytes sets the words to the given bytes.

Jump to

Keyboard shortcuts

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