Skip to content

Commit

Permalink
Update Zenon Ledger Wallet to 0.1.3 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
KingGorrin committed Apr 29, 2024
1 parent 2d7efdf commit 76460d5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
22 changes: 14 additions & 8 deletions src/ZenonCli/Commands/General.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CommandLine;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Concurrent;
using System.Reflection;
using System.Text;
Expand Down Expand Up @@ -148,20 +149,25 @@ protected override async Task ProcessAsync()
var queue = new BlockingCollection<Hash>();

WriteInfo("Subscribing for account-block events ...");
await Zdk!.Subscribe.ToAllAccountBlocks((json) =>
var subscriptionId = "";
Zdk!.Client.Subscribe("ledger.subscription", (string subscription, JToken[] result) =>
{
for (var i = 0; i < json.Length; i += 1)
if (subscription == subscriptionId)
{
var tx = json[i];
if (tx.Value<string>("toAddress") != address.ToString())
for (var i = 0; i < result.Length; i += 1)
{
continue;
var tx = result[i];
if (tx.Value<string>("toAddress") != address.ToString())
{
continue;
}
var hash = ParseHash(tx.Value<string>("hash"));
WriteInfo($"receiving transaction with hash {hash}");
queue.Add(hash);
}
var hash = ParseHash(tx.Value<string>("hash"));
WriteInfo($"receiving transaction with hash {hash}");
queue.Add(hash);
}
});
subscriptionId = await Zdk!.Subscribe.ToAllAccountBlocks();
WriteInfo("Subscribed successfully!");

while (true)
Expand Down
25 changes: 16 additions & 9 deletions src/ZenonCli/Commands/Htlc.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommandLine;
using Newtonsoft.Json.Linq;
using System.Numerics;
using Zenon;
using Zenon.Abi;
Expand Down Expand Up @@ -410,20 +411,26 @@ private async Task<bool> MonitorAsync(Zdk zdk, Address address, HtlcInfo[] htlcs
var queue = new List<Hash>();

WriteInfo("Subscribing for htlc-contract events ...");
await zdk.Subscribe.ToAllAccountBlocks((json) =>
var subscriptionId = "";
Zdk!.Client.Subscribe("ledger.subscription", (string subscription, JToken[] result) =>
{
// Extract hashes for all new tx that interact with the htlc contract
for (var i = 0; i < json.Length; i += 1)
if (subscription == subscriptionId)
{
var tx = json[i];
if (tx.Value<string>("toAddress") != Address.HtlcAddress.ToString())
continue;
// Extract hashes for all new tx that interact with the htlc contract
for (var i = 0; i < result.Length; i += 1)
{
var tx = result[i];
if (tx.Value<string>("toAddress") != Address.HtlcAddress.ToString())
continue;
var hash = Hash.Parse(tx.Value<string>("hash"));
WriteInfo($"Receiving transaction with hash {hash}");
queue.Add(hash);
var hash = Hash.Parse(tx.Value<string>("hash"));
WriteInfo($"Receiving transaction with hash {hash}");
queue.Add(hash);
}
}
});
subscriptionId = await Zdk!.Subscribe.ToAllAccountBlocks();
WriteInfo("Subscribed successfully!");

while (true)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ZenonCli/ZenonCli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<PackageReference Include="Cryptography.ECDSA.Secp256k1" Version="1.1.3" />
<PackageReference Include="HidApi.Net" Version="1.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Zenon.Wallet.Ledger" Version="0.1.2" />
<PackageReference Include="Zenon.Wallet.Ledger" Version="0.1.3" />
</ItemGroup>

</Project>

0 comments on commit 76460d5

Please sign in to comment.