|
3 | 3 | <h4>A gRPC interface for UTxO Blockchains</h4>
|
4 | 4 | </div>
|
5 | 5 | <div align="center">
|
6 |
| - <a href="https://www.nuget.org/packages/Utxorpc.Sdk/"> |
7 |
| - <img src="https://img.shields.io/nuget/v/Utxorpc.Sdk.svg" alt="NuGet"> |
8 |
| - </a> |
9 |
| - |
| 6 | + |
10 | 7 | 
|
11 | 8 | 
|
12 | 9 | 
|
13 | 10 | 
|
14 | 11 | 
|
15 | 12 |
|
| 13 | + <a href="https://www.nuget.org/packages/Utxorpc.Sdk/"> |
| 14 | + <img src="https://img.shields.io/nuget/v/Utxorpc.Sdk.svg" alt="NuGet"> |
| 15 | + </a> |
16 | 16 | </div>
|
17 | 17 |
|
18 | 18 |
|
@@ -43,23 +43,55 @@ The `SyncServiceClient` allows you to fetch blocks and follow chain tips with ea
|
43 | 43 | ```csharp
|
44 | 44 | using Utxorpc.Sdk;
|
45 | 45 | using Utxorpc.Sdk.Models;
|
| 46 | +using Utxorpc.Sdk.Models.Enums; |
46 | 47 |
|
47 |
| -var syncServiceClient = new SyncServiceClient("http://localhost:50051"); |
48 |
| - |
49 |
| -BlockRef blockRef = new BlockRef("1dace9bc646e9225251db04ff27397c199b04ec3f83c94cad28c438c3e7eeb50", 67823979); |
50 |
| -Block? block = await syncServiceClient.FetchBlockAsync(blockRef); |
51 |
| - |
52 |
| -if (block is not null) |
| 48 | +var headers = new Dictionary<string, string> |
53 | 49 | {
|
54 |
| - Console.WriteLine($"Block Hash: {block.Hash}"); |
55 |
| - Console.WriteLine($"Slot: {block.Slot}"); |
56 |
| - Console.WriteLine($"Native Bytes: {BitConverter.ToString(block.NativeBytes)}"); |
57 |
| -} |
58 |
| -else |
| 50 | + { "dmtr-api-key", "dmtr_utxorpc1vc0m93rynmltysttwm7ns9m3n5cklws6" }, |
| 51 | +}; |
| 52 | + |
| 53 | +var client = new SyncServiceClient( |
| 54 | + url: "https://preview.utxorpc-v0.demeter.run", |
| 55 | + headers |
| 56 | +); |
| 57 | + |
| 58 | +await foreach (NextResponse? response in client.FollowTipAsync( |
| 59 | + new BlockRef |
| 60 | + ( |
| 61 | + "b977e548f3364b114505f3311a10f89e5f5cf47e815765bce6750a5de48e5951", |
| 62 | + 58717900 |
| 63 | + ))) |
59 | 64 | {
|
60 |
| - Console.WriteLine("Block not found."); |
| 65 | + Console.WriteLine("___________________"); |
| 66 | + switch (response.Action) |
| 67 | + { |
| 68 | + case NextResponseAction.Apply: |
| 69 | + Block? applyBlock = response.AppliedBlock; |
| 70 | + if (applyBlock is not null) |
| 71 | + { |
| 72 | + Console.WriteLine($"Apply Block: {applyBlock.Hash} Slot: {applyBlock.Slot}"); |
| 73 | + Console.WriteLine($"Cbor: {Convert.ToHexString(applyBlock.NativeBytes ?? [])}"); |
| 74 | + } |
| 75 | + break; |
| 76 | + case NextResponseAction.Undo: |
| 77 | + Block? undoBlock = response.UndoneBlock; |
| 78 | + if (undoBlock is not null) |
| 79 | + { |
| 80 | + Console.WriteLine($"Undo Block: {undoBlock.Hash} Slot: {undoBlock.Slot}"); |
| 81 | + } |
| 82 | + break; |
| 83 | + case NextResponseAction.Reset: |
| 84 | + BlockRef? resetRef = response.ResetRef; |
| 85 | + if (resetRef is not null) |
| 86 | + { |
| 87 | + Console.WriteLine($"Reset to Block: {resetRef.Hash} Slot: {resetRef.Index}"); |
| 88 | + } |
| 89 | + break; |
| 90 | + } |
| 91 | + Console.WriteLine("___________________"); |
61 | 92 | }
|
62 | 93 |
|
| 94 | + |
63 | 95 | ```
|
64 | 96 |
|
65 | 97 | ### Roadmap
|
|
0 commit comments