contract

package
v0.0.0-...-9e55092 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCallDecoder

func NewCallDecoder(method *goethABI.Method) func(data []byte, res any) error

NewCallDecoder creates a new decoder for the given method and result.

It can be used to create a CallOpts.Decoder.

func NewCallEncoder

func NewCallEncoder(method *goethABI.Method, args ...any) func() ([]byte, error)

NewCallEncoder creates a new encoder for the given method and arguments.

It can be used to create a CallOpts.Encoder.

func NewContractErrorDecoder

func NewContractErrorDecoder(contract *goethABI.Contract) func(err error) error

NewContractErrorDecoder creates a new decoder that can handle errors defined in the given contract.

It can be used to create a CallOpts.ErrorDecoder.

Types

type Call

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

Call is a contract call.

Using this type instead of performing the call directly allows to choose if the call should be executed immediately or passed as an argument to another function.

func NewCall

func NewCall(opts CallOpts) *Call

NewCall creates a new Call instance.

func (*Call) Address

func (c *Call) Address() types.Address

Address implements the Callable, Caller, TypedCaller, and Transactor interface.

func (*Call) Call

func (c *Call) Call(ctx context.Context, number types.BlockNumber, res any) error

Call executes the call and decodes the result into res.

func (*Call) CallData

func (c *Call) CallData() ([]byte, error)

CallData implements the Callable interface.

func (*Call) Client

func (c *Call) Client() rpc.RPC

Client implements the Caller, TypedCaller, and Transactor interface.

func (*Call) DecodeTo

func (c *Call) DecodeTo(data []byte, res any) error

DecodeTo implements the Decoder interface.

func (*Call) Gas

func (c *Call) Gas(ctx context.Context, number types.BlockNumber) (uint64, error)

Gas returns the estimated gas usage of the call.

type CallOpts

type CallOpts struct {
	// Client is the RPC client to use when performing the call or sending
	// the transaction.
	Client rpc.RPC

	// Address is the address of the contract to call or send a transaction to.
	Address types.Address

	// Encoder is an optional encoder that will be used to encode the
	// arguments of the contract call.
	Encoder func() ([]byte, error)

	// Decoder is an optional decoder that will be used to decode the result
	// returned by the contract call.
	Decoder func([]byte, any) error

	// ErrorDecoder is an optional decoder that will be used to decode the
	// error returned by the contract call.
	ErrorDecoder func(err error) error
}

CallOpts are the options for New*Call functions.

type Callable

type Callable interface {
	// Address returns the address of the contract to call.
	Address() types.Address

	// CallData returns the encoded call data.
	CallData() ([]byte, error)
}

Callable provides the data required to call a contract.

type Caller

type Caller interface {
	// Address returns the address of the contract to call.
	Address() types.Address

	// Client returns the RPC client to use when performing the call.
	Client() rpc.RPC

	// Call executes the call and decodes the result into res.
	Call(ctx context.Context, number types.BlockNumber, res any) error

	// Gas returns the estimated gas usage of the call.
	Gas(ctx context.Context, number types.BlockNumber) (uint64, error)
}

Caller can perform a call to a contract and decode the result.

type Decoder

type Decoder interface {
	DecodeTo([]byte, any) error
}

Decoder decodes the data returned by the contract call.

type SelfCaller

type SelfCaller interface {
	Callable
	Caller
	Decoder
}

SelfCaller is a Callable that can perform a call by itself.

type SelfTransactableCaller

type SelfTransactableCaller interface {
	Callable
	Caller
	Transactor
	Decoder
}

SelfTransactableCaller is a Callable that can perform a call or send a transaction by itself.

type TransactableCall

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

TransactableCall works like Call but can be also used to send a transaction.

func NewTransactableCall

func NewTransactableCall(opts CallOpts) *TransactableCall

NewTransactableCall creates a new TransactableCall instance.

func (*TransactableCall) SendTransaction

func (t *TransactableCall) SendTransaction(ctx context.Context) (*types.Hash, *types.Transaction, error)

SendTransaction sends a call as a transaction.

type Transactor

type Transactor interface {
	// Address returns the address of the contract to send a transaction to.
	Address() types.Address

	// Client returns the RPC client to use when sending the transaction.
	Client() rpc.RPC

	// SendTransaction sends a call as a transaction.
	SendTransaction(ctx context.Context) (*types.Hash, *types.Transaction, error)

	// Gas returns the estimated gas usage of the transaction.
	Gas(ctx context.Context, number types.BlockNumber) (uint64, error)
}

Transactor can send a transaction to a contract.

type TypedCall

type TypedCall[T any] struct {
	// contains filtered or unexported fields
}

TypedCall is a Call with a typed result.

func NewTypedCall

func NewTypedCall[T any](opts CallOpts) *TypedCall[T]

NewTypedCall creates a new TypedCall instance.

func (*TypedCall[T]) Call

func (t *TypedCall[T]) Call(ctx context.Context, number types.BlockNumber) (T, error)

Call executes the call and returns the decoded result.

func (*TypedCall[T]) Decode

func (t *TypedCall[T]) Decode(data []byte) (T, error)

Decode decodes the result of the call.

type TypedCaller

type TypedCaller[T any] interface {
	// Address returns the address of the contract to call.
	Address() types.Address

	// Client returns the RPC client to use when performing the call.
	Client() rpc.RPC

	// Call executes the call and decodes the result into res.
	Call(ctx context.Context, number types.BlockNumber) (T, error)

	// Gas returns the estimated gas usage of the call.
	Gas(ctx context.Context, number types.BlockNumber) (uint64, error)
}

TypedCaller can perform a call to a contract and decode the result.

type TypedDecoder

type TypedDecoder[T any] interface {
	Decode([]byte) (T, error)
}

TypedDecoder decodes the data returned by the contract call.

type TypedSelfCaller

type TypedSelfCaller[T any] interface {
	Callable
	TypedCaller[T]
	TypedDecoder[T]
	Decoder
}

TypedSelfCaller is a Callable that can perform a call by itself.

type TypedSelfTransactableCaller

type TypedSelfTransactableCaller[T any] interface {
	Callable
	TypedCaller[T]
	Transactor
	Decoder
}

TypedSelfTransactableCaller is a Callable that can perform a call or send a transaction by itself.

type TypedTransactableCall

type TypedTransactableCall[T any] struct {
	// contains filtered or unexported fields
}

TypedTransactableCall is a TransactableCall with a typed result.

func NewTypedTransactableCall

func NewTypedTransactableCall[T any](opts CallOpts) *TypedTransactableCall[T]

NewTypedTransactableCall creates a new TypedTransactableCall instance.

func (*TypedTransactableCall[T]) Call

func (t *TypedTransactableCall[T]) Call(ctx context.Context, number types.BlockNumber) (T, error)

Call executes the call and returns the decoded result.

func (*TypedTransactableCall[T]) Decode

func (t *TypedTransactableCall[T]) Decode(data []byte) (T, error)

Decode decodes the result of the call.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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