mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-17 23:54:26 +01:00
update nostr plugin
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
<PropertyGroup>
|
||||
<Product>Nostr </Product>
|
||||
<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>
|
||||
<!-- Plugin development properties -->
|
||||
<PropertyGroup>
|
||||
@@ -35,7 +35,7 @@
|
||||
<ProjectReference Include="..\..\submodules\btcpayserver\BTCPayServer\BTCPayServer.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NNostr.Client" Version="0.0.24" />
|
||||
<PackageReference Include="NNostr.Client" Version="0.0.25" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources" />
|
||||
|
||||
@@ -106,46 +106,13 @@ public class Zapper : IHostedService
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
_logger.LogInformation($"Zapping {relay.Value.Length} to {relay.Key}");
|
||||
var cts = new CancellationTokenSource();
|
||||
cts.CancelAfter(TimeSpan.FromSeconds(30));
|
||||
var tcs = new TaskCompletionSource();
|
||||
using var c = new NostrClient(new Uri(relay.Key));
|
||||
await c.ConnectAndWaitUntilConnected(cts.Token);
|
||||
|
||||
var pendingOksOnIds = relay.Value.Select(a => a.Id).ToHashSet();
|
||||
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);
|
||||
_ = c.Connect(cts.Token);
|
||||
await c.WaitUntilConnected(cts.Token);
|
||||
await c.SendEventsAndWaitUntilReceived(relay.Value, cts.Token);
|
||||
await c.Disconnect();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
Reference in New Issue
Block a user