Skip to content
This repository was archived by the owner on Jul 13, 2022. It is now read-only.

Commit a92ea6f

Browse files
authored
Fixing known events (#480)
1 parent 07c1cd0 commit a92ea6f

File tree

5 files changed

+92
-4
lines changed

5 files changed

+92
-4
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ lint:
3131
fi;
3232
./bin/golangci-lint run ./... --timeout 5m0s
3333

34+
lint-fix:
35+
if [ ! -f ./bin/golangci-lint ]; then \
36+
$(MAKE) get-lint; \
37+
fi;
38+
./bin/golangci-lint run ./... --timeout 5m0s --fix
39+
3440
build:
3541
@echo " > \033[32mBuilding binary...\033[0m "
3642
cd cmd/chainbridge && env GOARCH=amd64 go build -o ../../build/chainbridge
@@ -88,4 +94,4 @@ docker-e2e:
8894
docker-compose -f ./docker-compose-e2e.yml up -V
8995

9096
clean:
91-
rm -rf build/ solidity/
97+
rm -rf build/ solidity/

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/ChainSafe/chainbridge-substrate-events v0.0.0-20200715141113-87198532025e
77
github.com/ChainSafe/log15 v1.0.0
88
github.com/btcsuite/btcd v0.20.1-beta // indirect
9-
github.com/centrifuge/go-substrate-rpc-client v2.0.0-alpha.3+incompatible
9+
github.com/centrifuge/go-substrate-rpc-client v2.0.0-alpha.4+incompatible
1010
github.com/ethereum/go-ethereum v1.9.13
1111
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
1212
github.com/stretchr/testify v1.4.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtE
4444
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
4545
github.com/centrifuge/go-substrate-rpc-client v2.0.0-alpha.3+incompatible h1:d8hQYVrpemZ6ZN38kL1XdQtezXTwrgiVXgQg+M3Lay0=
4646
github.com/centrifuge/go-substrate-rpc-client v2.0.0-alpha.3+incompatible/go.mod h1:GBMLH8MQs5g4FcrytcMm9uRgBnTL1LIkNTue6lUPhZU=
47+
github.com/centrifuge/go-substrate-rpc-client v2.0.0-alpha.4+incompatible h1:qlmlrelmXOzo090rJgvGpO4Cg4OYx5RwyMBw5yK3gGw=
48+
github.com/centrifuge/go-substrate-rpc-client v2.0.0-alpha.4+incompatible/go.mod h1:GBMLH8MQs5g4FcrytcMm9uRgBnTL1LIkNTue6lUPhZU=
4749
github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk=
4850
github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
4951
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=

shared/substrate/events.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ type EventNewMultisig struct {
8282

8383
// TimePoint contains height and index
8484
type TimePoint struct {
85-
Height types.BlockNumber
85+
Height types.U32
8686
Index types.U32
8787
}
8888

@@ -126,7 +126,7 @@ type Events struct {
126126
Example_Remark []EventExampleRemark //nolint:stylecheck,golint
127127
Nfts_DepositAsset []EventNFTDeposited //nolint:stylecheck,golint
128128
Council_Proposed []types.EventCollectiveProposed //nolint:stylecheck,golint
129-
Council_Voted []types.EventCollectiveProposed //nolint:stylecheck,golint
129+
Council_Voted []types.EventCollectiveVoted //nolint:stylecheck,golint
130130
Council_Approved []types.EventCollectiveApproved //nolint:stylecheck,golint
131131
Council_Disapproved []types.EventCollectiveDisapproved //nolint:stylecheck,golint
132132
Council_Executed []types.EventCollectiveExecuted //nolint:stylecheck,golint
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2020 ChainSafe Systems
2+
// SPDX-License-Identifier: LGPL-3.0-only
3+
4+
package subtest
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/ChainSafe/ChainBridge/e2e/substrate"
11+
utils "github.com/ChainSafe/ChainBridge/shared/substrate"
12+
gsrpc "github.com/centrifuge/go-substrate-rpc-client"
13+
"github.com/centrifuge/go-substrate-rpc-client/types"
14+
)
15+
16+
func TestChain_Events(t *testing.T) {
17+
targetURL := substrate.TestSubEndpoint // Replace with desired endpoint
18+
api, err := gsrpc.NewSubstrateAPI(targetURL)
19+
if err != nil {
20+
panic(err)
21+
}
22+
23+
meta, err := api.RPC.State.GetMetadataLatest()
24+
if err != nil {
25+
panic(err)
26+
}
27+
28+
key, err := types.CreateStorageKey(meta, "System", "Events", nil, nil)
29+
if err != nil {
30+
panic(err)
31+
}
32+
33+
//fmt.Printf("%x\n", key)
34+
35+
//latest, err := api.RPC.Chain.GetBlockLatest()
36+
//if err != nil {
37+
// panic(err)
38+
//}
39+
latestNumber := uint32(1) // Set to uint32(latest.Block.Header.Number)
40+
41+
batchSize := uint32(1) // Set to higher value accordingly, like 1000
42+
current := uint64(0) // Start block
43+
numBatches := latestNumber - uint32(current)/batchSize
44+
45+
// Not smart enough to adjust batch size to last batch
46+
// Manually trigger the last one with minimum batch size
47+
for i := uint32(0); i < numBatches; i++ {
48+
lower, err := api.RPC.Chain.GetBlockHash(current)
49+
if err != nil {
50+
panic(err)
51+
}
52+
53+
upperBlock := current + uint64(batchSize)
54+
upper, err := api.RPC.Chain.GetBlockHash(upperBlock)
55+
if err != nil {
56+
panic(err)
57+
}
58+
59+
raws, err := api.RPC.State.QueryStorage([]types.StorageKey{key}, lower, upper)
60+
if err != nil {
61+
panic(err)
62+
}
63+
64+
for j := 0; j < len(raws); j++ {
65+
events := utils.Events{}
66+
for k := 0; k < len(raws[j].Changes); k++ {
67+
raw := raws[j].Changes[k]
68+
fmt.Printf("Processing events for block %s with data: %x\n", raws[j].Block.Hex(), raw.StorageData)
69+
err = types.EventRecordsRaw(raw.StorageData).DecodeEventRecords(meta, &events)
70+
if err != nil {
71+
panic(err)
72+
}
73+
}
74+
}
75+
76+
fmt.Println("Events batch successfully processed: ", i, "until block", upperBlock)
77+
current += uint64(batchSize)
78+
}
79+
80+
}

0 commit comments

Comments
 (0)