github.com/lmittmann/w3@v0.20.0/w3types/interfaces.go (about)

     1  /*
     2  Package w3types implements common types.
     3  */
     4  package w3types
     5  
     6  import "github.com/ethereum/go-ethereum/rpc"
     7  
     8  // Func is the interface that wraps the methods for ABI encoding and decoding.
     9  type Func interface {
    10  	// EncodeArgs ABI-encodes the given args and prepends the Func's 4-byte
    11  	// selector.
    12  	EncodeArgs(args ...any) (input []byte, err error)
    13  
    14  	// DecodeArgs ABI-decodes the given input to the given args.
    15  	DecodeArgs(input []byte, args ...any) (err error)
    16  
    17  	// DecodeReturns ABI-decodes the given output to the given returns.
    18  	DecodeReturns(output []byte, returns ...any) (err error)
    19  }
    20  
    21  // RPCCaller is the interface that groups the basic CreateRequest and
    22  // HandleResponse methods.
    23  type RPCCaller interface {
    24  	// Create a new rpc.BatchElem for doing the RPC call.
    25  	CreateRequest() (elem rpc.BatchElem, err error)
    26  
    27  	// Handle the response from the rpc.BatchElem to handle its result.
    28  	HandleResponse(elem rpc.BatchElem) (err error)
    29  }
    30  
    31  // RPCCallerFactory is the interface that wraps the basic Returns method.
    32  type RPCCallerFactory[T any] interface {
    33  	// Returns given argument points to the variable in which to store the
    34  	// calls result.
    35  	Returns(*T) RPCCaller
    36  }
    37  
    38  // RPCSubscriber is the interface that wraps the basic CreateRequest method.
    39  type RPCSubscriber interface {
    40  	// CreateRequest returns the namespace, channel, params for starting a new
    41  	// subscription and an error if the request cannot be created.
    42  	CreateRequest() (namespace string, ch any, params []any, err error)
    43  }