mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-17 07:34:24 +01:00
update nostr zapper
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Product>Nostr</Product>
|
<Product>Nostr</Product>
|
||||||
<Description>NIP5 addresses, Zap support, Nostr Wallet Connect Lightning support</Description>
|
<Description>NIP5 addresses, Zap support, Nostr Wallet Connect Lightning support</Description>
|
||||||
<Version>1.1.8</Version>
|
<Version>1.1.9</Version>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<!-- Plugin development properties -->
|
<!-- Plugin development properties -->
|
||||||
@@ -36,7 +36,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.48" />
|
<PackageReference Include="NNostr.Client" Version="0.0.49" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Resources" />
|
<Folder Include="Resources" />
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ public class Zapper : IHostedService
|
|||||||
private readonly InvoiceRepository _invoiceRepository;
|
private readonly InvoiceRepository _invoiceRepository;
|
||||||
private IEventAggregatorSubscription _subscription;
|
private IEventAggregatorSubscription _subscription;
|
||||||
private readonly ConcurrentBag<PendingZapEvent> _pendingZapEvents = new();
|
private readonly ConcurrentBag<PendingZapEvent> _pendingZapEvents = new();
|
||||||
|
private readonly NNostr.Client.NostrClientPool _nostrClientPool;
|
||||||
|
|
||||||
public async Task<ZapperSettings> GetSettings()
|
public async Task<ZapperSettings> GetSettings()
|
||||||
{
|
{
|
||||||
@@ -85,6 +86,7 @@ public class Zapper : IHostedService
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
_settingsRepository = settingsRepository;
|
_settingsRepository = settingsRepository;
|
||||||
_invoiceRepository = invoiceRepository;
|
_invoiceRepository = invoiceRepository;
|
||||||
|
_nostrClientPool = new NNostr.Client.NostrClientPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StartAsync(CancellationToken cancellationToken)
|
public Task StartAsync(CancellationToken cancellationToken)
|
||||||
@@ -123,13 +125,14 @@ public class Zapper : IHostedService
|
|||||||
_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));
|
||||||
using var c = new NostrClient(new Uri(relay.Key));
|
var pool= await
|
||||||
await c.Connect(cts.Token);
|
_nostrClientPool.GetClientAndConnect(new []{new Uri(relay.Key)}, cts.Token);
|
||||||
await c.SendEventsAndWaitUntilReceived(relay.Value, cts.Token);
|
using var c = pool.Item2;
|
||||||
await c.Disconnect();
|
await pool.Item1.SendEventsAndWaitUntilReceived(relay.Value, cts.Token);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
_logger.LogError(e, $"Error zapping {relay.Value.Length} events to {relay.Key}");
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -185,31 +188,31 @@ public class Zapper : IHostedService
|
|||||||
var relays = zapRequestEvent.Tags.Where(tag => tag.TagIdentifier == "relays").SelectMany(tag => tag.Data).ToArray();
|
var relays = zapRequestEvent.Tags.Where(tag => tag.TagIdentifier == "relays").SelectMany(tag => tag.Data).ToArray();
|
||||||
|
|
||||||
var tags = zapRequestEvent.Tags.Where(a => a.TagIdentifier.Length == 1).ToList();
|
var tags = zapRequestEvent.Tags.Where(a => a.TagIdentifier.Length == 1).ToList();
|
||||||
tags.Add(new()
|
|
||||||
|
|
||||||
|
tags.AddRange(new[]
|
||||||
|
{
|
||||||
|
new NostrEventTag
|
||||||
{
|
{
|
||||||
TagIdentifier = "bolt11",
|
TagIdentifier = "bolt11",
|
||||||
Data = new() {pmd.BOLT11}
|
Data = new() {pmd.BOLT11}
|
||||||
});
|
},
|
||||||
|
|
||||||
tags.Add(new()
|
new NostrEventTag()
|
||||||
{
|
{
|
||||||
TagIdentifier = "description",
|
TagIdentifier = "description",
|
||||||
Data = new() {zapRequest}
|
Data = new() {zapRequest}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var userNostrSettings = await _nip5Controller.GetForStore(arg.Invoice.StoreId);
|
var userNostrSettings = await _nip5Controller.GetForStore(arg.Invoice.StoreId);
|
||||||
var key = userNostrSettings?.PrivateKey is not null
|
var key = !string.IsNullOrEmpty(userNostrSettings?.PrivateKey)
|
||||||
? NostrExtensions.ParseKey(userNostrSettings?.PrivateKey)
|
? NostrExtensions.ParseKey(userNostrSettings?.PrivateKey)
|
||||||
: settings.ZappingKey;
|
: settings.ZappingKey;
|
||||||
|
|
||||||
var pubkey = userNostrSettings?.PubKey is not null
|
|
||||||
? userNostrSettings?.PubKey
|
|
||||||
: settings.ZappingPublicKeyHex;
|
|
||||||
var zapReceipt = new NostrEvent()
|
var zapReceipt = new NostrEvent()
|
||||||
{
|
{
|
||||||
Kind = 9735,
|
Kind = 9735,
|
||||||
CreatedAt = DateTimeOffset.UtcNow,
|
|
||||||
PublicKey = pubkey,
|
|
||||||
Content = zapRequestEvent.Content,
|
Content = zapRequestEvent.Content,
|
||||||
Tags = tags
|
Tags = tags
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user