-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs.go
70 lines (58 loc) · 1.85 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/common"
cli "github.com/jawher/mow.cli"
log "github.com/xlab/suplog"
"github.com/xlab/etherman/deployer"
)
func onLogs(cmd *cli.Cmd) {
contractAddress := cmd.StringArg("ADDRESS", "", "Contract address to interact with.")
txHash := cmd.StringArg("TX_HASH", "", "Transaction hash to find receipt.")
eventName := cmd.StringArg("EVENT_NAME", "", "Contract event to find in the logs.")
cmd.Spec = "ADDRESS TX_HASH EVENT_NAME"
cmd.Action = func() {
d, err := deployer.New(
deployer.OptionRPCTimeout(duration(*rpcTimeout, defaultRPCTimeout)),
deployer.OptionCallTimeout(duration(*callTimeout, defaultCallTimeout)),
deployer.OptionTxTimeout(duration(*txTimeout, defaultTxTimeout)),
// only options applicable to call
deployer.OptionEVMRPCEndpoint(*evmEndpoint),
deployer.OptionNoCache(*noCache),
deployer.OptionBuildCacheDir(*buildCacheDir),
deployer.OptionSolcAllowedPaths(*solAllowedPaths),
deployer.OptionEnableCoverage(*coverage),
)
if err != nil {
log.WithError(err).Fatalln("failed to init deployer")
}
logsOpts := deployer.ContractLogsOpts{
SolSource: *solSource,
ContractName: *contractName,
Contract: common.HexToAddress(*contractAddress),
}
if *coverage {
logsOpts.CoverageAgent = deployer.NewCoverageDataCollector(deployer.CoverageModeDefault)
}
log.Debugln("target contract", logsOpts.Contract.Hex())
log.Debugln("target tx", *txHash)
log.Debugln("target event name", *eventName)
events, err := d.Logs(
context.Background(),
logsOpts,
common.HexToHash(*txHash),
*eventName,
nil,
)
if err != nil {
log.Fatalln(err)
}
cmdOut, _ := json.MarshalIndent(events, "", "\t")
fmt.Println(string(cmdOut))
if *coverage {
logsOpts.CoverageAgent.ReportHTML(nil, *contractName)
}
}
}