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

View File

@@ -114,8 +114,7 @@ public class Zapper : IHostedService
var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(30));
using var c = new NostrClient(new Uri(relay.Key));
_ = c.Connect(cts.Token);
await c.WaitUntilConnected(cts.Token);
await c.Connect(cts.Token);
await c.SendEventsAndWaitUntilReceived(relay.Value, cts.Token);
await c.Disconnect();
}

View File

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

View File

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