/
interfaces.go
54 lines (42 loc) · 1.6 KB
/
interfaces.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Package w3types implements common types.
*/
package w3types
import "github.com/ethereum/go-ethereum/rpc"
// Func is the interface that wraps the methods for ABI encoding and decoding.
type Func interface {
// EncodeArgs ABI-encodes the given args and prepends the Func's 4-byte
// selector.
EncodeArgs(args ...any) (input []byte, err error)
// DecodeArgs ABI-decodes the given input to the given args.
DecodeArgs(input []byte, args ...any) (err error)
// DecodeReturns ABI-decodes the given output to the given returns.
DecodeReturns(output []byte, returns ...any) (err error)
}
// RPCCaller is the interface that groups the basic CreateRequest and
// HandleResponse methods.
type RPCCaller interface {
// Create a new rpc.BatchElem for doing the RPC call.
CreateRequest() (elem rpc.BatchElem, err error)
// Handle the response from the rpc.BatchElem to handle its result.
HandleResponse(elem rpc.BatchElem) (err error)
}
// RPCCallerFactory is the interface that wraps the basic Returns method.
type RPCCallerFactory[T any] interface {
// Returns given argument points to the variable in which to store the
// calls result.
Returns(*T) RPCCaller
}
// Caller is the interface that groups the basic CreateRequest and
// HandleResponse methods.
//
// Deprecated: Use the [RPCCaller] interface instead.
type Caller = RPCCaller
// CallerFactory is the interface that wraps the basic Returns method.
//
// Deprecated: Use the [RPCCallerFactory] interface instead.
type CallerFactory[T any] interface {
// Returns given argument points to the variable in which to store the
// calls result.
Returns(*T) Caller
}