Skip to content

Commit 44832f2

Browse files
committed
adding check state/gist exist
1 parent 9b1ee87 commit 44832f2

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/ethereum/go-ethereum v1.10.26
88
github.com/go-redis/redis/v8 v8.11.5
99
github.com/gogo/protobuf v1.3.3
10-
github.com/rarimo/rarimo-core v1.0.7-0.20231123231906-566dc0033e75
10+
github.com/rarimo/rarimo-core v1.1.0
1111
github.com/rarimo/saver-grpc-lib v1.0.0
1212
github.com/spf13/cast v1.5.1
1313
github.com/tendermint/tendermint v0.34.27
@@ -119,6 +119,7 @@ require (
119119
github.com/prometheus/common v0.39.0 // indirect
120120
github.com/prometheus/procfs v0.9.0 // indirect
121121
github.com/rarimo/broadcaster-svc v1.0.2 // indirect
122+
github.com/rarimo/go-merkle v0.0.0-20231004122345-36fa49031c66 // indirect
122123
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
123124
github.com/rjeczalik/notify v0.9.1 // indirect
124125
github.com/sasha-s/go-deadlock v0.3.1 // indirect

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,10 @@ github.com/rarimo/broadcaster-svc v1.0.2 h1:ExQcjjWCRP5+POLDlZHrTD1ffUsBH+Dgv5FA
12001200
github.com/rarimo/broadcaster-svc v1.0.2/go.mod h1:lYIHy+X4IqQt4eBdtMN/V352H3EV0/gO8G+32SFwUWI=
12011201
github.com/rarimo/cosmos-sdk v0.46.7 h1:jU2PiWzc+19SF02cXM0O0puKPeH1C6Q6t2lzJ9s1ejc=
12021202
github.com/rarimo/cosmos-sdk v0.46.7/go.mod h1:fqKqz39U5IlEFb4nbQ72951myztsDzFKKDtffYJ63nk=
1203-
github.com/rarimo/rarimo-core v1.0.7-0.20231123231906-566dc0033e75 h1:gCVlgChRHbV6aemA+WM6BDyexRvr/V8MtG7cInwF/k4=
1204-
github.com/rarimo/rarimo-core v1.0.7-0.20231123231906-566dc0033e75/go.mod h1:S8d3kZWPFuNsy7llrzUd8Rj92WSCrjSH2YEUD+2A+Ww=
1203+
github.com/rarimo/go-merkle v0.0.0-20231004122345-36fa49031c66 h1:1KAU4rfWWJwAJ/kencagL3k5BXN3HhP004QNkEUgvDE=
1204+
github.com/rarimo/go-merkle v0.0.0-20231004122345-36fa49031c66/go.mod h1:5Pt9Lk8w7fWhyRO/NMb5x8DRhF2lESRVPT5uOlezInQ=
1205+
github.com/rarimo/rarimo-core v1.1.0 h1:b3zN2HYBJY5AUFFm285i9vsyTTM9b7XwQGshrLYkD1I=
1206+
github.com/rarimo/rarimo-core v1.1.0/go.mod h1:auP3KgxaSwkOUrLWBifjnMbbSQTSBA9Y/gVgq1WU/B4=
12051207
github.com/rarimo/saver-grpc-lib v1.0.0 h1:MGUVjYg7unmodYczVsLqlqZNkT4CIgKqdo6aQtL1qdE=
12061208
github.com/rarimo/saver-grpc-lib v1.0.0/go.mod h1:DpugWK5B7Hi0bdC3MPe/9FD2zCxaRwsyykdwxtF1Zgg=
12071209
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=

internal/services/evm/stateChangeListener.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ package evm
22

33
import (
44
"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"
59
"math/big"
610
"time"
711

@@ -59,6 +63,7 @@ func RunStateChangeListener(ctx context.Context, cfg config.Config) {
5963
fromBlock: cfg.Ethereum().StartFromBlock,
6064
blockWindow: cfg.Ethereum().BlockWindow,
6165
maxBlocks: cfg.States().MaxBlocksPerRequest,
66+
cosmos: cfg.Cosmos(),
6267
}
6368

6469
running.WithBackOff(ctx, log, runnerName,
@@ -81,6 +86,7 @@ type stateChangeListener struct {
8186
broadcaster broadcaster.Broadcaster
8287
msger stateUpdateMsger
8388
blockHandler blockHandler
89+
cosmos *grpc.ClientConn
8490

8591
filter func(string) bool
8692
fromBlock uint64
@@ -154,6 +160,16 @@ func (l *stateChangeListener) subscription(ctx context.Context) error {
154160
continue
155161
}
156162

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+
157173
if err := l.broadcaster.BroadcastTx(ctx, msg1); err != nil {
158174
l.log.WithError(err).WithField("tx_hash", e.Raw.TxHash.String()).Error(err, "failed to broadcast GIST updated msg")
159175
continue
@@ -175,6 +191,16 @@ func (l *stateChangeListener) subscription(ctx context.Context) error {
175191
continue
176192
}
177193

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+
178204
if err := l.broadcaster.BroadcastTx(ctx, msg); err != nil {
179205
l.log.WithError(err).WithField("tx_hash", e.Raw.TxHash.String()).Error(err, "failed to broadcast state updated msg")
180206
continue
@@ -184,6 +210,40 @@ func (l *stateChangeListener) subscription(ctx context.Context) error {
184210
return nil
185211
}
186212

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+
187247
func Map[T comparable](arr []T) map[T]struct{} {
188248
res := make(map[T]struct{})
189249
for _, v := range arr {

0 commit comments

Comments
 (0)