|
1 | 1 | package main
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - // Complex "go-sdk/complex" |
5 |
| - // "go-sdk/metadata" |
6 |
| - // Balances "go-sdk/metadata/pallets/balances" |
| 4 | + "github.com/vedhavyas/go-subkey/v2" |
| 5 | + "github.com/vedhavyas/go-subkey/v2/sr25519" |
7 | 6 | "go-sdk/complex"
|
8 |
| - "go-sdk/primitives" |
9 |
| - "sync" |
10 |
| - "time" |
11 |
| - // "github.com/vedhavyas/go-subkey/v2" |
12 |
| - // "github.com/vedhavyas/go-subkey/v2/sr25519" |
| 7 | + Balances "go-sdk/metadata/pallets/balances" |
13 | 8 | )
|
14 | 9 |
|
15 |
| -func Job(targetBlockNumber uint32, wg *sync.WaitGroup) { |
16 |
| - sdk := NewSDK2("https://mainnet-rpc.avail.so/rpc") |
17 |
| - targetBlockHash := sdk.Client.Rpc.Chain.GetBlockHash(primitives.NewSome(targetBlockNumber)) |
18 |
| - println("Block Number:", targetBlockNumber, "Block Hash: ", targetBlockHash.ToHexWith0x()) |
19 |
| - |
20 |
| - targetBlockHash2 := targetBlockHash |
21 |
| - /* |
22 |
| - Turing |
23 |
| - if targetBlockNumber == 297282 { |
24 |
| - targetBlockHash2 = sdk.Client.Rpc.Chain.GetBlockHash(primitives.NewSome(targetBlockNumber - 1)) |
25 |
| - } |
26 |
| - */ |
27 |
| - if err := sdk.Client.InitMetadata(primitives.NewSome(targetBlockHash2)); err != nil { |
28 |
| - panic(err) |
29 |
| - } |
30 |
| - |
31 |
| - // Decoding Extrinsics and Events |
32 |
| - complex.NewBlock(sdk.Client, targetBlockHash) |
33 |
| - wg.Done() |
34 |
| -} |
35 |
| - |
36 | 10 | func main() {
|
37 |
| - sdk := NewSDK2("https://mainnet-rpc.avail.so/rpc") |
38 |
| - println("Genesis: ", sdk.Client.Rpc.Chain.GetBlockHash(primitives.NewSome(uint32(0))).ToHexWith0x()) |
39 |
| - |
40 |
| - targetBlockNumber := uint32(246585) |
41 |
| - var wg sync.WaitGroup |
42 |
| - for { |
43 |
| - for i := 1; i <= 100; i++ { |
44 |
| - wg.Add(1) |
45 |
| - go Job(targetBlockNumber, &wg) |
46 |
| - targetBlockNumber += 1 |
47 |
| - } |
48 |
| - |
49 |
| - wg.Wait() |
50 |
| - time.Sleep(time.Millisecond * 50) |
51 |
| - } |
52 |
| - |
53 |
| - /* |
54 |
| - // Go through blocks and see which one is not decodable |
55 |
| -
|
56 |
| - add, err := metadata.NewAccountIdFromAddress("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY") |
57 |
| - if err != nil { |
58 |
| - panic(err) |
59 |
| - } |
60 |
| - println(add.ToHuman()) |
| 11 | + sdk := NewSDK(LocalEndpoint) |
| 12 | + uri := "bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice" |
| 13 | + scheme := new(sr25519.Scheme) |
| 14 | + account, _ := subkey.DeriveKeyPair(scheme, uri) |
61 | 15 |
|
62 |
| - uri := "bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice" |
63 |
| - scheme := new(sr25519.Scheme) |
64 |
| - account, _ := subkey.DeriveKeyPair(scheme, uri) |
| 16 | + var tx = sdk.Tx.DataAvailability.SubmitData([]byte("aabbcc")) |
| 17 | + var options = complex.NewTransactionOptions().WithAppId(uint32(1)) |
65 | 18 |
|
66 |
| - var tx = sdk.Tx.DataAvailability.SubmitData([]byte("aabbcc")) |
67 |
| - var options = Complex.NewTransactionOptions().WithAppId(uint32(1)) |
| 19 | + var details = tx.ExecuteAndWatch(account, false, options) |
| 20 | + println("Block Hash: ", details.BlockHash.ToHexWith0x()) |
| 21 | + println("Block Number: ", details.BlockNumber) |
| 22 | + println("TX Events ", len(details.Events.Unwrap())) |
68 | 23 |
|
69 |
| - var details = tx.ExecuteAndWatch(account, false, options) |
70 |
| - println("Block Hash: ", details.BlockHash.ToHexWith0x()) |
71 |
| - println("Block Number: ", details.BlockNumber) |
72 |
| - println("TX Events ", len(details.Events.Unwrap())) |
| 24 | + var events = details.Events.UnwrapOrDefault() |
73 | 25 |
|
74 |
| - var eves = details.Events.Unwrap() |
| 26 | + var event = complex.FindFirst(events, Balances.EventWithdraw{}).UnwrapOrDefault() |
| 27 | + println("Who:", event.Who.ToHuman()) |
| 28 | + println("Amount: ", event.Amount.ToHuman()) |
75 | 29 |
|
76 |
| - var res = Complex.FindFirst(eves, Balances.EventWithdraw{}) |
77 |
| - println("Who:", res.Unwrap().Who.ToHuman()) |
78 |
| - println("Amount: ", res.Unwrap().Amount.ToHuman()) |
79 |
| - */ |
80 | 30 | }
|
0 commit comments