-
Notifications
You must be signed in to change notification settings - Fork 119
/
replay.go
188 lines (148 loc) · 5.01 KB
/
replay.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package main
import (
"github.com/Sifchain/sifnode/cmd/ebrelayer/txs"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
"log"
"strconv"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"go.uber.org/zap"
"github.com/Sifchain/sifnode/cmd/ebrelayer/relayer"
)
// RunReplayEthereumCmd executes replayEthereumCmd
func RunReplayEthereumCmd(cmd *cobra.Command, args []string) error {
cliContext, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
tendermintNode := args[0]
web3Provider := args[1]
if !common.IsHexAddress(args[2]) {
return errors.Errorf("invalid [bridge-registry-contract-address]: %s", args[1])
}
contractAddress := common.HexToAddress(args[2])
if len(strings.Trim(args[3], "")) == 0 {
return errors.Errorf("invalid [validator-moniker]: %s", args[2])
}
validatorMoniker := args[3]
//mnemonic := args[4]
fromBlock, err := strconv.ParseInt(args[5], 10, 64)
if err != nil {
return errors.Errorf("invalid [from-block]: %s", args[5])
}
toBlock, err := strconv.ParseInt(args[6], 10, 64)
if err != nil {
return errors.Errorf("invalid [to-block]: %s", args[6])
}
cosmosFromBlock, err := strconv.ParseInt(args[7], 10, 64)
if err != nil {
return errors.Errorf("invalid [from-block]: %s", args[7])
}
cosmosToBlock, err := strconv.ParseInt(args[8], 10, 64)
if err != nil {
return errors.Errorf("invalid [to-block]: %s", args[8])
}
logger, err := zap.NewProduction()
if err != nil {
log.Fatalln("failed to init zap logging")
}
sugaredLogger := logger.Sugar()
symbolTranslator, err := buildSymbolTranslator(cmd.Flags())
if err != nil {
return err
}
ethSub := relayer.NewEthereumSub(cliContext, tendermintNode, validatorMoniker, web3Provider,
contractAddress, nil, nil, sugaredLogger)
txFactory := tx.NewFactoryCLI(cliContext, cmd.Flags())
ethSub.Replay(txFactory, fromBlock, toBlock, cosmosFromBlock, cosmosToBlock, symbolTranslator)
return nil
}
// RunReplayCosmosCmd executes initRelayerCmd
func RunReplayCosmosCmd(cmd *cobra.Command, args []string) error {
// Validate and parse arguments
if len(strings.Trim(args[0], "")) == 0 {
return errors.Errorf("invalid [tendermint-node]: %s", args[0])
}
tendermintNode := args[0]
if !relayer.IsWebsocketURL(args[1]) {
return errors.Errorf("invalid [web3-provider]: %s", args[1])
}
web3Provider := args[1]
if !common.IsHexAddress(args[2]) {
return errors.Errorf("invalid [bridge-registry-contract-address]: %s", args[2])
}
contractAddress := common.HexToAddress(args[2])
fromBlock, err := strconv.ParseInt(args[3], 10, 64)
if err != nil {
return errors.Errorf("invalid [from-block]: %s", args[3])
}
toBlock, err := strconv.ParseInt(args[4], 10, 64)
if err != nil {
return errors.Errorf("invalid [to-block]: %s", args[4])
}
ethFromBlock, err := strconv.ParseInt(args[5], 10, 64)
if err != nil {
return errors.Errorf("invalid [eth-from-block]: %s", args[3])
}
ethToBlock, err := strconv.ParseInt(args[6], 10, 64)
if err != nil {
return errors.Errorf("invalid [eth-to-block]: %s", args[4])
}
logger, err := zap.NewProduction()
if err != nil {
log.Fatalln("failed to init zap logging")
}
sugaredLogger := logger.Sugar()
symbolTranslator, err := buildSymbolTranslator(cmd.Flags())
if err != nil {
return err
}
key, err := txs.LoadPrivateKey()
if err != nil {
log.Fatalf("failed to load ETHEREUM_PRIVATE_KEY")
}
// Initialize new Cosmos event listener
cosmosSub := relayer.NewCosmosSub(tendermintNode, web3Provider, contractAddress, key, nil, sugaredLogger)
cosmosSub.Replay(symbolTranslator, fromBlock, toBlock, ethFromBlock, ethToBlock)
return nil
}
// RunListMissedCosmosEventCmd executes initRelayerCmd
func RunListMissedCosmosEventCmd(cmd *cobra.Command, args []string) error {
// Validate and parse arguments
if len(strings.Trim(args[0], "")) == 0 {
return errors.Errorf("invalid [tendermint-node]: %s", args[0])
}
tendermintNode := args[0]
if !relayer.IsWebsocketURL(args[1]) {
return errors.Errorf("invalid [web3-provider]: %s", args[1])
}
web3Provider := args[1]
if !common.IsHexAddress(args[2]) {
return errors.Errorf("invalid [bridge-registry-contract-address]: %s", args[2])
}
contractAddress := common.HexToAddress(args[2])
if !common.IsHexAddress(args[3]) {
return errors.Errorf("invalid [relayer-ethereum-address]: %s", args[3])
}
relayerEthereumAddress := common.HexToAddress(args[3])
days, err := strconv.ParseInt(args[4], 10, 64)
if err != nil {
return errors.Errorf("invalid [days]: %s", args[3])
}
logger, err := zap.NewProduction()
if err != nil {
log.Fatalln("failed to init zap logging")
}
sugaredLogger := logger.Sugar()
symbolTranslator, err := buildSymbolTranslator(cmd.Flags())
if err != nil {
return err
}
// Initialize new Cosmos event listener
listMissedCosmosEvent := relayer.NewListMissedCosmosEvent(tendermintNode, web3Provider, contractAddress, relayerEthereumAddress, days, sugaredLogger)
listMissedCosmosEvent.ListMissedCosmosEvent(symbolTranslator)
return nil
}