-
Notifications
You must be signed in to change notification settings - Fork 32
/
get_logs.go
48 lines (40 loc) · 1.04 KB
/
get_logs.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
package eth
import (
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/lmittmann/w3/core"
)
// Logs requests the logs of the given ethereum.FilterQuery q.
func Logs(q ethereum.FilterQuery) core.CallFactoryReturns[[]types.Log] {
return &logsFactory{filterQuery: q}
}
type logsFactory struct {
// args
filterQuery ethereum.FilterQuery
// returns
returns *[]types.Log
}
func (f *logsFactory) Returns(logs *[]types.Log) core.Caller {
f.returns = logs
return f
}
// CreateRequest implements the core.RequestCreator interface.
func (f *logsFactory) CreateRequest() (rpc.BatchElem, error) {
arg, err := toFilterArg(f.filterQuery)
if err != nil {
return rpc.BatchElem{}, err
}
return rpc.BatchElem{
Method: "eth_getLogs",
Args: []any{arg},
Result: f.returns,
}, nil
}
// HandleResponse implements the core.ResponseHandler interface.
func (f *logsFactory) HandleResponse(elem rpc.BatchElem) error {
if err := elem.Error; err != nil {
return err
}
return nil
}