update nostr plugin

This commit is contained in:
Kukks
2023-05-08 13:00:32 +02:00
parent b06e5ca95c
commit 0484c87863
2 changed files with 5 additions and 38 deletions

View File

@@ -11,7 +11,7 @@
<PropertyGroup> <PropertyGroup>
<Product>Nostr </Product> <Product>Nostr </Product>
<Description>Allows you to verify your nostr account with NIP5 and zap like the rest of the crazies</Description> <Description>Allows you to verify your nostr account with NIP5 and zap like the rest of the crazies</Description>
<Version>1.0.11</Version> <Version>1.0.12</Version>
</PropertyGroup> </PropertyGroup>
<!-- Plugin development properties --> <!-- Plugin development properties -->
<PropertyGroup> <PropertyGroup>
@@ -35,7 +35,7 @@
<ProjectReference Include="..\..\submodules\btcpayserver\BTCPayServer\BTCPayServer.csproj" /> <ProjectReference Include="..\..\submodules\btcpayserver\BTCPayServer\BTCPayServer.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="NNostr.Client" Version="0.0.24" /> <PackageReference Include="NNostr.Client" Version="0.0.25" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Resources" /> <Folder Include="Resources" />

View File

@@ -106,46 +106,13 @@ public class Zapper : IHostedService
{ {
try try
{ {
_logger.LogInformation($"Zapping {relay.Value.Length} to {relay.Key}"); _logger.LogInformation($"Zapping {relay.Value.Length} to {relay.Key}");
var cts = new CancellationTokenSource(); var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(30)); cts.CancelAfter(TimeSpan.FromSeconds(30));
var tcs = new TaskCompletionSource();
using var c = new NostrClient(new Uri(relay.Key)); using var c = new NostrClient(new Uri(relay.Key));
await c.ConnectAndWaitUntilConnected(cts.Token); _ = c.Connect(cts.Token);
await c.WaitUntilConnected(cts.Token);
var pendingOksOnIds = relay.Value.Select(a => a.Id).ToHashSet(); await c.SendEventsAndWaitUntilReceived(relay.Value, cts.Token);
var subscription = new NostrSubscriptionFilter()
{
Ids = pendingOksOnIds.ToArray()
};
c.EventsReceived+= (sender, args) =>
{
foreach (var nostrEvent in args.events)
{
if (nostrEvent.Id == "zap-confirmation")
{
pendingOksOnIds.Remove(nostrEvent.Id);
if (!pendingOksOnIds.Any())
{
tcs.SetResult();
}
}
}
};
await c.CreateSubscription("zap-confirmations",new []{subscription}, cts.Token);
c.OkReceived += (sender, okargs) =>
{
pendingOksOnIds.Remove(okargs.eventId);
if(!pendingOksOnIds.Any())
tcs.SetResult();
};
foreach (var nostrEvent in relay.Value)
{
await c.PublishEvent(nostrEvent, cts.Token);
}
await tcs.Task.WaitAsync(cts.Token);
await c.Disconnect(); await c.Disconnect();
} }
catch (Exception e) catch (Exception e)