/
interfaces.go
45 lines (35 loc) · 1.27 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
/*
Package w3protypes implements common types.
*/
package w3protypes
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)
}
// RequestCreator is the interface that wraps the basic CreateRequest method.
type RequestCreator interface {
CreateRequest() (elem rpc.BatchElem, err error)
}
// ResponseHandler is the interface that wraps the basic HandleResponse method.
type ResponseHandler interface {
HandleResponse(elem rpc.BatchElem) (err error)
}
// Caller is the interface that groups the basic CreateRequest and
// HandleResponse methods.
type Caller interface {
RequestCreator
ResponseHandler
}
// CallerFactory is the interface that wraps the basic Returns method.
type CallerFactory[T any] interface {
// Returns given argument points to the variable in which to store the
// calls result.
Returns(*T) Caller
}