From 4483806f82efb07099b57bfc54364a263c9f8d18 Mon Sep 17 00:00:00 2001 From: Kukks Date: Fri, 18 Aug 2023 11:42:29 +0200 Subject: [PATCH] upd --- .../Coordinator/WabisabiCoordinatorService.cs | 15 +++------------ .../Coordinator/WabisabiCoordinatorSettings.cs | 11 ++++++++--- .../WabisabiStoreController.cs | 2 +- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorService.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorService.cs index 64601d8..61def52 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorService.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorService.cs @@ -217,24 +217,15 @@ public class WabisabiCoordinatorService : PeriodicRunner { var network = _clientProvider.GetExplorerClient("BTC").Network.NBitcoinNetwork; var s = await GetSettings(); + if (s.Enabled && !string.IsNullOrEmpty(s.NostrIdentity) && s.NostrRelay is not null && s.UriToAdvertise is not null) { - ECPrivKey key; - try - { - key = NostrExtensions.ParseKey(s.NostrIdentity); - } - catch (Exception e) - { - s.NostrIdentity = null; - await UpdateSettings(s); - throw; - } + var k = s.GetKey(); await Nostr.Publish(s.NostrRelay, new[] { - await Nostr.CreateCoordinatorDiscoveryEvent(network, key, s.UriToAdvertise, + await Nostr.CreateCoordinatorDiscoveryEvent(network, k, s.UriToAdvertise, s.CoordinatorDescription) },s.UriToAdvertise.IsOnion()? _socks5HttpClientHandler: null, cancel); } diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorSettings.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorSettings.cs index d8c4634..c7f0916 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorSettings.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/Coordinator/WabisabiCoordinatorSettings.cs @@ -14,9 +14,14 @@ public class WabisabiCoordinatorSettings public Uri NostrRelay { get; set; } = new Uri("wss://kukks.org/nostr"); public List DiscoveredCoordinators { get; set; } = new(); - - [JsonIgnore] public ECPrivKey? Key => string.IsNullOrEmpty(NostrIdentity)? null: NostrExtensions.ParseKey(NostrIdentity); - [JsonIgnore] public ECXOnlyPubKey PubKey => Key?.CreatePubKey().ToXOnlyPubKey(); + + + public ECPrivKey GetKey() + { + return string.IsNullOrEmpty(NostrIdentity) ? null : NostrExtensions.ParseKey(NostrIdentity); + } + + public ECXOnlyPubKey GetPubKey() => GetKey()?.CreatePubKey().ToXOnlyPubKey(); public Uri UriToAdvertise { get; set; } public string TermsConditions { get; set; } = @" These terms and conditions govern your use of the Coinjoin Coordinator service. By using the service, you agree to be bound by these terms and conditions. If you do not agree to these terms and conditions, you should not use the service. diff --git a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiStoreController.cs b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiStoreController.cs index 3f62388..af64f91 100644 --- a/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiStoreController.cs +++ b/Plugins/BTCPayServer.Plugins.Wabisabi/WabisabiStoreController.cs @@ -183,7 +183,7 @@ namespace BTCPayServer.Plugins.Wabisabi var result = await Nostr.Discover( _socks5HttpClientHandler, relayUri, network, - coordSettings.Key?.CreateXOnlyPubKey().ToHex(), CancellationToken.None); + coordSettings.GetPubKey()?.ToHex(), CancellationToken.None); if(result.Any()) TempData["DiscoveredCoordinators"] = JsonConvert.SerializeObject(result); else