@@ -2,6 +2,10 @@ package evm
2
2
3
3
import (
4
4
"context"
5
+ "github.com/ethereum/go-ethereum/common/hexutil"
6
+ "github.com/rarimo/rarimo-core/x/rarimocore/crypto/pkg"
7
+ rarimocore "github.com/rarimo/rarimo-core/x/rarimocore/types"
8
+ "google.golang.org/grpc"
5
9
"math/big"
6
10
"time"
7
11
@@ -59,6 +63,7 @@ func RunStateChangeListener(ctx context.Context, cfg config.Config) {
59
63
fromBlock : cfg .Ethereum ().StartFromBlock ,
60
64
blockWindow : cfg .Ethereum ().BlockWindow ,
61
65
maxBlocks : cfg .States ().MaxBlocksPerRequest ,
66
+ cosmos : cfg .Cosmos (),
62
67
}
63
68
64
69
running .WithBackOff (ctx , log , runnerName ,
@@ -81,6 +86,7 @@ type stateChangeListener struct {
81
86
broadcaster broadcaster.Broadcaster
82
87
msger stateUpdateMsger
83
88
blockHandler blockHandler
89
+ cosmos * grpc.ClientConn
84
90
85
91
filter func (string ) bool
86
92
fromBlock uint64
@@ -154,6 +160,16 @@ func (l *stateChangeListener) subscription(ctx context.Context) error {
154
160
continue
155
161
}
156
162
163
+ exist , err := l .checkGISTExist (ctx , msg1 )
164
+ if err != nil {
165
+ l .log .WithError (err ).WithField ("tx_hash" , e .Raw .TxHash .String ()).Error ("failed to check operation already exist" )
166
+ }
167
+
168
+ if exist {
169
+ l .log .WithField ("tx_hash" , e .Raw .TxHash .String ()).Debug ("operation already exist" )
170
+ continue
171
+ }
172
+
157
173
if err := l .broadcaster .BroadcastTx (ctx , msg1 ); err != nil {
158
174
l .log .WithError (err ).WithField ("tx_hash" , e .Raw .TxHash .String ()).Error (err , "failed to broadcast GIST updated msg" )
159
175
continue
@@ -175,6 +191,16 @@ func (l *stateChangeListener) subscription(ctx context.Context) error {
175
191
continue
176
192
}
177
193
194
+ exist , err = l .checkStateExist (ctx , msg )
195
+ if err != nil {
196
+ l .log .WithError (err ).WithField ("tx_hash" , e .Raw .TxHash .String ()).Error ("failed to check operation already exist" )
197
+ }
198
+
199
+ if exist {
200
+ l .log .WithField ("tx_hash" , e .Raw .TxHash .String ()).Debug ("operation already exist" )
201
+ continue
202
+ }
203
+
178
204
if err := l .broadcaster .BroadcastTx (ctx , msg ); err != nil {
179
205
l .log .WithError (err ).WithField ("tx_hash" , e .Raw .TxHash .String ()).Error (err , "failed to broadcast state updated msg" )
180
206
continue
@@ -184,6 +210,40 @@ func (l *stateChangeListener) subscription(ctx context.Context) error {
184
210
return nil
185
211
}
186
212
213
+ func (l * stateChangeListener ) checkGISTExist (ctx context.Context , msg * oracletypes.MsgCreateIdentityGISTTransferOp ) (bool , error ) {
214
+ resp , err := oracletypes .NewQueryClient (l .cosmos ).IdentityGISTTransfer (ctx , & oracletypes.QueryGetIdentityGISTTransferRequest {Msg : * msg })
215
+ if err != nil {
216
+ return false , errors .Wrap (err , "failed to get operation by message" )
217
+ }
218
+
219
+ content , err := pkg .GetIdentityGISTTransferContent (& resp .Transfer )
220
+ if err != nil {
221
+ return false , errors .Wrap (err , "failed to get operation content" )
222
+ }
223
+
224
+ index := hexutil .Encode (content .CalculateHash ())
225
+
226
+ _ , err = rarimocore .NewQueryClient (l .cosmos ).Operation (ctx , & rarimocore.QueryGetOperationRequest {Index : index })
227
+ return err == nil , nil
228
+ }
229
+
230
+ func (l * stateChangeListener ) checkStateExist (ctx context.Context , msg * oracletypes.MsgCreateIdentityStateTransferOp ) (bool , error ) {
231
+ resp , err := oracletypes .NewQueryClient (l .cosmos ).IdentityStateTransfer (ctx , & oracletypes.QueryGetIdentityStateTransferRequest {Msg : * msg })
232
+ if err != nil {
233
+ return false , errors .Wrap (err , "failed to get operation by message" )
234
+ }
235
+
236
+ content , err := pkg .GetIdentityStateTransferContent (& resp .Transfer )
237
+ if err != nil {
238
+ return false , errors .Wrap (err , "failed to get operation content" )
239
+ }
240
+
241
+ index := hexutil .Encode (content .CalculateHash ())
242
+
243
+ _ , err = rarimocore .NewQueryClient (l .cosmos ).Operation (ctx , & rarimocore.QueryGetOperationRequest {Index : index })
244
+ return err == nil , nil
245
+ }
246
+
187
247
func Map [T comparable ](arr []T ) map [T ]struct {} {
188
248
res := make (map [T ]struct {})
189
249
for _ , v := range arr {
0 commit comments