Skip to content

Commit 76460d5

Browse files
authored
Update Zenon Ledger Wallet to 0.1.3 (#10)
1 parent 2d7efdf commit 76460d5

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

src/ZenonCli/Commands/General.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using CommandLine;
22
using Newtonsoft.Json;
3+
using Newtonsoft.Json.Linq;
34
using System.Collections.Concurrent;
45
using System.Reflection;
56
using System.Text;
@@ -148,20 +149,25 @@ protected override async Task ProcessAsync()
148149
var queue = new BlockingCollection<Hash>();
149150

150151
WriteInfo("Subscribing for account-block events ...");
151-
await Zdk!.Subscribe.ToAllAccountBlocks((json) =>
152+
var subscriptionId = "";
153+
Zdk!.Client.Subscribe("ledger.subscription", (string subscription, JToken[] result) =>
152154
{
153-
for (var i = 0; i < json.Length; i += 1)
155+
if (subscription == subscriptionId)
154156
{
155-
var tx = json[i];
156-
if (tx.Value<string>("toAddress") != address.ToString())
157+
for (var i = 0; i < result.Length; i += 1)
157158
{
158-
continue;
159+
var tx = result[i];
160+
if (tx.Value<string>("toAddress") != address.ToString())
161+
{
162+
continue;
163+
}
164+
var hash = ParseHash(tx.Value<string>("hash"));
165+
WriteInfo($"receiving transaction with hash {hash}");
166+
queue.Add(hash);
159167
}
160-
var hash = ParseHash(tx.Value<string>("hash"));
161-
WriteInfo($"receiving transaction with hash {hash}");
162-
queue.Add(hash);
163168
}
164169
});
170+
subscriptionId = await Zdk!.Subscribe.ToAllAccountBlocks();
165171
WriteInfo("Subscribed successfully!");
166172

167173
while (true)

src/ZenonCli/Commands/Htlc.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using CommandLine;
2+
using Newtonsoft.Json.Linq;
23
using System.Numerics;
34
using Zenon;
45
using Zenon.Abi;
@@ -410,20 +411,26 @@ private async Task<bool> MonitorAsync(Zdk zdk, Address address, HtlcInfo[] htlcs
410411
var queue = new List<Hash>();
411412

412413
WriteInfo("Subscribing for htlc-contract events ...");
413-
await zdk.Subscribe.ToAllAccountBlocks((json) =>
414+
var subscriptionId = "";
415+
Zdk!.Client.Subscribe("ledger.subscription", (string subscription, JToken[] result) =>
414416
{
415-
// Extract hashes for all new tx that interact with the htlc contract
416-
for (var i = 0; i < json.Length; i += 1)
417+
if (subscription == subscriptionId)
417418
{
418-
var tx = json[i];
419-
if (tx.Value<string>("toAddress") != Address.HtlcAddress.ToString())
420-
continue;
419+
// Extract hashes for all new tx that interact with the htlc contract
420+
for (var i = 0; i < result.Length; i += 1)
421+
{
422+
var tx = result[i];
423+
if (tx.Value<string>("toAddress") != Address.HtlcAddress.ToString())
424+
continue;
421425

422-
var hash = Hash.Parse(tx.Value<string>("hash"));
423-
WriteInfo($"Receiving transaction with hash {hash}");
424-
queue.Add(hash);
426+
var hash = Hash.Parse(tx.Value<string>("hash"));
427+
WriteInfo($"Receiving transaction with hash {hash}");
428+
queue.Add(hash);
429+
}
425430
}
426431
});
432+
subscriptionId = await Zdk!.Subscribe.ToAllAccountBlocks();
433+
WriteInfo("Subscribed successfully!");
427434

428435
while (true)
429436
{

src/ZenonCli/ZenonCli.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<PackageReference Include="Cryptography.ECDSA.Secp256k1" Version="1.1.3" />
3131
<PackageReference Include="HidApi.Net" Version="1.0.2" />
3232
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
33-
<PackageReference Include="Zenon.Wallet.Ledger" Version="0.1.2" />
33+
<PackageReference Include="Zenon.Wallet.Ledger" Version="0.1.3" />
3434
</ItemGroup>
3535

3636
</Project>

0 commit comments

Comments
 (0)