This commit is contained in:
Kukks
2023-05-15 18:18:17 +02:00
parent 0bb47d4a97
commit e5e0ec0b70
4 changed files with 20 additions and 10 deletions

View File

@@ -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.27" /> <PackageReference Include="NNostr.Client" Version="0.0.28" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Resources" /> <Folder Include="Resources" />

View File

@@ -114,8 +114,7 @@ public class Zapper : IHostedService
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)); using var c = new NostrClient(new Uri(relay.Key));
_ = c.Connect(cts.Token); await c.Connect(cts.Token);
await c.WaitUntilConnected(cts.Token);
await c.SendEventsAndWaitUntilReceived(relay.Value, cts.Token); await c.SendEventsAndWaitUntilReceived(relay.Value, cts.Token);
await c.Disconnect(); await c.Disconnect();
} }

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.WebSockets;
using System.Text.Json; using System.Text.Json;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -31,9 +32,14 @@ public class Nostr
var ct = CancellationTokenSource var ct = CancellationTokenSource
.CreateLinkedTokenSource(cancellationToken, new CancellationTokenSource(TimeSpan.FromMinutes(1)).Token) .CreateLinkedTokenSource(cancellationToken, new CancellationTokenSource(TimeSpan.FromMinutes(1)).Token)
.Token; .Token;
var client = new NostrClient(relayUri, socket => socket.Options.Proxy = httpClientHandler?.Proxy); var client = new NostrClient(relayUri, socket =>
_ = client.Connect(ct); {
await client.WaitUntilConnected(ct); if (socket is ClientWebSocket clientWebSocket && httpClientHandler != null)
{
clientWebSocket.Options.Proxy = httpClientHandler.Proxy;
}
});
await client.Connect(ct);
await client.SendEventsAndWaitUntilReceived(evts, ct); await client.SendEventsAndWaitUntilReceived(evts, ct);
client.Dispose(); client.Dispose();
@@ -69,14 +75,19 @@ public class Nostr
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var nostrClient = new NostrClient(relayUri, socket => socket.Options.Proxy = relayUri.IsLocalNetwork()? null: httpClientHandler?.Proxy); var nostrClient = new NostrClient(relayUri, socket =>
{
if (socket is ClientWebSocket clientWebSocket && httpClientHandler != null)
{
clientWebSocket.Options.Proxy = httpClientHandler.Proxy;
}
});
var result = new List<NostrEvent>(); var result = new List<NostrEvent>();
var network = currentNetwork.Name.ToLower(); var network = currentNetwork.Name.ToLower();
var cts = CancellationTokenSource.CreateLinkedTokenSource(new CancellationTokenSource(TimeSpan.FromMinutes(1)).Token, var cts = CancellationTokenSource.CreateLinkedTokenSource(new CancellationTokenSource(TimeSpan.FromMinutes(1)).Token,
cancellationToken); cancellationToken);
_ = nostrClient.Connect(cts.Token); await nostrClient.Connect(cts.Token);
await nostrClient.WaitUntilConnected(cts.Token);
result = await nostrClient.SubscribeForEvents( result = await nostrClient.SubscribeForEvents(
new[] new[]

View File

@@ -47,7 +47,7 @@ public class NostrWabisabiApiServer: IHostedService
_ = _client.ListenForMessages(); _ = _client.ListenForMessages();
var filter = new NostrSubscriptionFilter() var filter = new NostrSubscriptionFilter()
{ {
PublicKey = new[] {_coordinatorKey.ToHex()}, ReferencedPublicKeys = new[] {_coordinatorKey.ToHex()},
Kinds = new[] { CommunicationKind}, Kinds = new[] { CommunicationKind},
Since = DateTimeOffset.UtcNow.Subtract(TimeSpan.FromHours(1)) Since = DateTimeOffset.UtcNow.Subtract(TimeSpan.FromHours(1))
}; };