From 9b90e10b66fbc29dac096757729abb5c8269f748 Mon Sep 17 00:00:00 2001 From: Kukks Date: Thu, 10 Oct 2024 11:32:00 +0200 Subject: [PATCH] wip --- BTCPayServerPlugins.sln | 32 +-- BTCPayServerPlugins.sln.DotSettings.user | 15 ++ ...PayServer.Plugins.BitcoinWhitepaper.csproj | 2 +- .../BitcoinWhitepaperPlugin.cs | 2 +- .../BTCPayServer.Plugins.Blink.csproj | 2 +- .../BTCPayServer.Plugins.Blink/BlinkPlugin.cs | 2 +- .../BTCPayServer.Plugins.Breez.csproj | 4 +- .../BreezController.cs | 36 ++- .../BreezLightningClient.cs | 4 +- .../BTCPayServer.Plugins.Breez/BreezPlugin.cs | 2 +- .../BreezService.cs | 17 +- .../Views/Breez/SwapIn.cshtml | 9 +- .../Views/Breez/SwapInRefund.cshtml | 6 +- .../Views/Breez/SwapOut.cshtml | 7 +- .../Views/Breez/Sweep.cshtml | 5 +- .../Views/Breez/_Layout.cshtml | 10 - .../Views/Breez/_Nav.cshtml | 41 ---- .../Views/Shared/Breez/BreezNav.cshtml | 68 +++-- .../Views/Shared/Breez/BreezNodeInfo.cshtml | 2 +- .../BTCPayServer.Plugins.Bringin.csproj | 4 +- .../BringinPlugin.cs | 5 +- .../BringinService.cs | 51 ++-- .../Components/BringinWidget.razor | 43 ++-- .../BTCPayServer.Plugins.DataErasure.csproj | 2 +- .../DataErasureController.cs | 14 +- .../DataErasurePlugin.cs | 2 +- .../DataErasureService.cs | 136 ++++++---- .../DataErasureSettings.cs | 2 + .../Views/DataErasure/Update.cshtml | 15 ++ ...PayServer.Plugins.DynamicRateLimits.csproj | 2 +- .../DynamicRateLimitsPlugin.cs | 2 +- .../Views/DynamicRatesLimiter/Update.cshtml | 5 - .../Shared/DynamicRateLimitsPlugin/Nav.cshtml | 10 +- ...BTCPayServer.Plugins.DynamicReports.csproj | 2 +- .../DynamicReportsPlugin.cs | 2 +- .../PostgresReportProvider.cs | 8 +- .../Views/DynamicReports/Update.cshtml | 2 - .../Shared/DynamicReportsPlugin/Nav.cshtml | 9 +- .../BTCPayServer.Plugins.FileSeller.csproj | 2 +- .../FileSellerPlugin.cs | 5 +- .../FileSellerTemplateEditorItemDetail.cshtml | 6 +- .../BTCPayServer.Plugins.FixedFloat.csproj | 2 +- .../FixedFloatPlugin.cs | 25 +- .../FixedFloatSettings.cs | 40 ++- .../UpdateFixedFloatSettings.cshtml | 6 +- .../CheckoutContentExtension.cshtml | 19 -- .../Shared/FixedFloat/CheckoutEnd.cshtml | 12 - .../CheckoutPaymentExtension.cshtml | 25 +- .../CheckoutPaymentMethodExtension.cshtml | 2 +- .../FixedFloat/CheckoutTabExtension.cshtml | 13 - .../BTCPayServer.Plugins.LDK.csproj | 43 ---- Plugins/BTCPayServer.Plugins.LDK/Program.cs | 232 ------------------ .../BTCPayServer.Plugins.LiquidPlus.csproj | 2 +- .../Controllers/StoreLiquidController.cs | 93 ++++--- .../LiquidPlusPlugin.cs | 22 +- .../BTCPayServer.Plugins.MicroNode.csproj | 2 +- .../MicroNodeContextFactory.cs | 20 +- .../MicroNodeController.cs | 23 +- .../MicroNodePlugin.cs | 2 +- .../MicroNodeService.cs | 42 ++-- .../BTCPayServer.Plugins.NIP05.csproj | 2 +- .../BTCPayServer.Plugins.NIP05/Nip05Plugin.cs | 2 +- .../Views/Nip5/Edit.cshtml | 2 +- Plugins/BTCPayServer.Plugins.NIP05/Zapper.cs | 20 +- .../BTCPayServer.Plugins.Prism.csproj | 2 +- .../Components/PrismEdit.razor | 13 +- .../LNURLPrismDestinationValidator.cs | 7 +- .../OnChainPrismClaimCreate.cs | 7 +- .../OnChainPrismDestinationValidator.cs | 5 +- .../OpenSatsDestinationValidator.cs | 16 +- .../OpenSatsPrismClaimCreate.cs | 20 +- .../BTCPayServer.Plugins.Prism/PrismPlugin.cs | 2 +- .../PrismSettings.cs | 2 +- .../BTCPayServer.Plugins.Prism/SatBreaker.cs | 102 ++++---- .../BTCPayServer.Plugins.SideShift.csproj | 2 +- .../PrismClaimCreate.cs | 84 ------- .../PrismDestinationValidate.cs | 17 -- .../PrismEditFiltercs.cs | 15 -- .../PrismSideshiftDestination.cs | 16 -- .../SideShiftController.cs | 47 ++-- .../SideShiftPlugin.cs | 38 +-- .../SideShift/CheckoutContentExtension.cshtml | 26 -- .../Views/Shared/SideShift/CheckoutEnd.cshtml | 14 -- .../SideShift/CheckoutPaymentExtension.cshtml | 40 ++- .../CheckoutPaymentMethodExtension.cshtml | 2 +- .../SideShift/CheckoutTabExtension.cshtml | 12 - .../Shared/SideShift/PrismEnhance.cshtml | 212 ---------------- .../SideShift/PullPaymentViewInsert.cshtml | 10 +- .../SideShift/UpdateSideShiftSettings.cshtml | 7 +- .../BTCPayServer.Plugins.Subscriptions.csproj | 2 +- .../SubscriptionController.cs | 11 +- .../SubscriptionPlugin.cs | 9 +- .../AppMigrate.cs | 4 +- .../BTCPayServer.Plugins.TicketTailor.csproj | 2 +- .../TicketTailorController.cs | 17 +- .../TicketTailorPlugin.cs | 2 +- .../TicketTailorService.cs | 7 +- .../BTCPayServer.Plugins.Wabisabi.csproj | 2 +- .../BTCPayWallet.cs | 21 +- .../Coordinator/WabisabiScriptResolver.cs | 6 +- .../Views/Shared/Wabisabi/CoinView.cshtml | 5 +- .../Wabisabi/CoinjoinHistoryTable.cshtml | 10 +- .../UpdateWabisabiSettings.cshtml | 6 - .../UpdateWabisabiStoreSettings.cshtml | 5 +- .../WabisabiPlugin.cs | 16 +- .../WabisabiService.cs | 3 +- .../WalletProvider.cs | 13 +- submodules/btcpayserver | 2 +- 108 files changed, 757 insertions(+), 1350 deletions(-) delete mode 100644 Plugins/BTCPayServer.Plugins.Breez/Views/Breez/_Layout.cshtml delete mode 100644 Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutContentExtension.cshtml delete mode 100644 Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutEnd.cshtml delete mode 100644 Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutTabExtension.cshtml delete mode 100644 Plugins/BTCPayServer.Plugins.LDK/BTCPayServer.Plugins.LDK.csproj delete mode 100644 Plugins/BTCPayServer.Plugins.LDK/Program.cs delete mode 100644 Plugins/BTCPayServer.Plugins.SideShift/PrismClaimCreate.cs delete mode 100644 Plugins/BTCPayServer.Plugins.SideShift/PrismDestinationValidate.cs delete mode 100644 Plugins/BTCPayServer.Plugins.SideShift/PrismEditFiltercs.cs delete mode 100644 Plugins/BTCPayServer.Plugins.SideShift/PrismSideshiftDestination.cs delete mode 100644 Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/CheckoutContentExtension.cshtml delete mode 100644 Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/CheckoutEnd.cshtml delete mode 100644 Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/CheckoutTabExtension.cshtml delete mode 100644 Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/PrismEnhance.cshtml diff --git a/BTCPayServerPlugins.sln b/BTCPayServerPlugins.sln index f43c282..67a81c8 100644 --- a/BTCPayServerPlugins.sln +++ b/BTCPayServerPlugins.sln @@ -83,8 +83,8 @@ Global {B19C9F52-DC47-466D-8B5C-2D202B7B003F}.Altcoins-Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU {B19C9F52-DC47-466D-8B5C-2D202B7B003F}.Altcoins-Release|Any CPU.ActiveCfg = Altcoins-Release|Any CPU {B19C9F52-DC47-466D-8B5C-2D202B7B003F}.Altcoins-Release|Any CPU.Build.0 = Altcoins-Release|Any CPU - {B19C9F52-DC47-466D-8B5C-2D202B7B003F}.Debug|Any CPU.ActiveCfg = Altcoins-Debug|Any CPU - {B19C9F52-DC47-466D-8B5C-2D202B7B003F}.Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU + {B19C9F52-DC47-466D-8B5C-2D202B7B003F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B19C9F52-DC47-466D-8B5C-2D202B7B003F}.Debug|Any CPU.Build.0 = Debug|Any CPU {AD9635BB-C70E-4676-BB04-900D51B01666}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {AD9635BB-C70E-4676-BB04-900D51B01666}.Debug|Any CPU.Build.0 = Debug|Any CPU {AD9635BB-C70E-4676-BB04-900D51B01666}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -99,48 +99,48 @@ Global {8F158B88-0FEE-44FF-8552-7C0F17D5C508}.Altcoins-Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU {8F158B88-0FEE-44FF-8552-7C0F17D5C508}.Altcoins-Release|Any CPU.ActiveCfg = Altcoins-Release|Any CPU {8F158B88-0FEE-44FF-8552-7C0F17D5C508}.Altcoins-Release|Any CPU.Build.0 = Altcoins-Release|Any CPU - {8F158B88-0FEE-44FF-8552-7C0F17D5C508}.Debug|Any CPU.ActiveCfg = Altcoins-Debug|Any CPU - {8F158B88-0FEE-44FF-8552-7C0F17D5C508}.Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU + {8F158B88-0FEE-44FF-8552-7C0F17D5C508}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8F158B88-0FEE-44FF-8552-7C0F17D5C508}.Debug|Any CPU.Build.0 = Debug|Any CPU {DF85EFA4-0EF5-4A99-853F-E6F9C88E3F8C}.Release|Any CPU.ActiveCfg = Release|Any CPU {DF85EFA4-0EF5-4A99-853F-E6F9C88E3F8C}.Release|Any CPU.Build.0 = Release|Any CPU {DF85EFA4-0EF5-4A99-853F-E6F9C88E3F8C}.Altcoins-Debug|Any CPU.ActiveCfg = Altcoins-Debug|Any CPU {DF85EFA4-0EF5-4A99-853F-E6F9C88E3F8C}.Altcoins-Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU {DF85EFA4-0EF5-4A99-853F-E6F9C88E3F8C}.Altcoins-Release|Any CPU.ActiveCfg = Altcoins-Release|Any CPU {DF85EFA4-0EF5-4A99-853F-E6F9C88E3F8C}.Altcoins-Release|Any CPU.Build.0 = Altcoins-Release|Any CPU - {DF85EFA4-0EF5-4A99-853F-E6F9C88E3F8C}.Debug|Any CPU.ActiveCfg = Altcoins-Debug|Any CPU - {DF85EFA4-0EF5-4A99-853F-E6F9C88E3F8C}.Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU + {DF85EFA4-0EF5-4A99-853F-E6F9C88E3F8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DF85EFA4-0EF5-4A99-853F-E6F9C88E3F8C}.Debug|Any CPU.Build.0 = Debug|Any CPU {2C5C4DF9-BA1F-4671-9F24-B22D7C9C3D21}.Release|Any CPU.ActiveCfg = Release|Any CPU {2C5C4DF9-BA1F-4671-9F24-B22D7C9C3D21}.Release|Any CPU.Build.0 = Release|Any CPU {2C5C4DF9-BA1F-4671-9F24-B22D7C9C3D21}.Altcoins-Debug|Any CPU.ActiveCfg = Altcoins-Debug|Any CPU {2C5C4DF9-BA1F-4671-9F24-B22D7C9C3D21}.Altcoins-Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU {2C5C4DF9-BA1F-4671-9F24-B22D7C9C3D21}.Altcoins-Release|Any CPU.ActiveCfg = Altcoins-Release|Any CPU {2C5C4DF9-BA1F-4671-9F24-B22D7C9C3D21}.Altcoins-Release|Any CPU.Build.0 = Altcoins-Release|Any CPU - {2C5C4DF9-BA1F-4671-9F24-B22D7C9C3D21}.Debug|Any CPU.ActiveCfg = Altcoins-Debug|Any CPU - {2C5C4DF9-BA1F-4671-9F24-B22D7C9C3D21}.Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU + {2C5C4DF9-BA1F-4671-9F24-B22D7C9C3D21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2C5C4DF9-BA1F-4671-9F24-B22D7C9C3D21}.Debug|Any CPU.Build.0 = Debug|Any CPU {D7E7309D-C4F4-496A-B2C8-BC5D3991B9C0}.Release|Any CPU.ActiveCfg = Release|Any CPU {D7E7309D-C4F4-496A-B2C8-BC5D3991B9C0}.Release|Any CPU.Build.0 = Release|Any CPU {D7E7309D-C4F4-496A-B2C8-BC5D3991B9C0}.Altcoins-Debug|Any CPU.ActiveCfg = Altcoins-Debug|Any CPU {D7E7309D-C4F4-496A-B2C8-BC5D3991B9C0}.Altcoins-Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU {D7E7309D-C4F4-496A-B2C8-BC5D3991B9C0}.Altcoins-Release|Any CPU.ActiveCfg = Altcoins-Release|Any CPU {D7E7309D-C4F4-496A-B2C8-BC5D3991B9C0}.Altcoins-Release|Any CPU.Build.0 = Altcoins-Release|Any CPU - {D7E7309D-C4F4-496A-B2C8-BC5D3991B9C0}.Debug|Any CPU.ActiveCfg = Altcoins-Debug|Any CPU - {D7E7309D-C4F4-496A-B2C8-BC5D3991B9C0}.Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU + {D7E7309D-C4F4-496A-B2C8-BC5D3991B9C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D7E7309D-C4F4-496A-B2C8-BC5D3991B9C0}.Debug|Any CPU.Build.0 = Debug|Any CPU {3F2E0BA0-9EA7-490F-894D-F9703F35B174}.Release|Any CPU.ActiveCfg = Release|Any CPU {3F2E0BA0-9EA7-490F-894D-F9703F35B174}.Release|Any CPU.Build.0 = Release|Any CPU {3F2E0BA0-9EA7-490F-894D-F9703F35B174}.Altcoins-Debug|Any CPU.ActiveCfg = Altcoins-Debug|Any CPU {3F2E0BA0-9EA7-490F-894D-F9703F35B174}.Altcoins-Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU {3F2E0BA0-9EA7-490F-894D-F9703F35B174}.Altcoins-Release|Any CPU.ActiveCfg = Altcoins-Release|Any CPU {3F2E0BA0-9EA7-490F-894D-F9703F35B174}.Altcoins-Release|Any CPU.Build.0 = Altcoins-Release|Any CPU - {3F2E0BA0-9EA7-490F-894D-F9703F35B174}.Debug|Any CPU.ActiveCfg = Altcoins-Debug|Any CPU - {3F2E0BA0-9EA7-490F-894D-F9703F35B174}.Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU + {3F2E0BA0-9EA7-490F-894D-F9703F35B174}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3F2E0BA0-9EA7-490F-894D-F9703F35B174}.Debug|Any CPU.Build.0 = Debug|Any CPU {6295533A-F941-40CA-B889-FE6C0432ED53}.Release|Any CPU.ActiveCfg = Release|Any CPU {6295533A-F941-40CA-B889-FE6C0432ED53}.Release|Any CPU.Build.0 = Release|Any CPU {6295533A-F941-40CA-B889-FE6C0432ED53}.Altcoins-Debug|Any CPU.ActiveCfg = Altcoins-Debug|Any CPU {6295533A-F941-40CA-B889-FE6C0432ED53}.Altcoins-Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU {6295533A-F941-40CA-B889-FE6C0432ED53}.Altcoins-Release|Any CPU.ActiveCfg = Altcoins-Release|Any CPU {6295533A-F941-40CA-B889-FE6C0432ED53}.Altcoins-Release|Any CPU.Build.0 = Altcoins-Release|Any CPU - {6295533A-F941-40CA-B889-FE6C0432ED53}.Debug|Any CPU.ActiveCfg = Altcoins-Debug|Any CPU - {6295533A-F941-40CA-B889-FE6C0432ED53}.Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU + {6295533A-F941-40CA-B889-FE6C0432ED53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6295533A-F941-40CA-B889-FE6C0432ED53}.Debug|Any CPU.Build.0 = Debug|Any CPU {58863D86-3C78-4BEC-ACB6-2F82CC141210}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {58863D86-3C78-4BEC-ACB6-2F82CC141210}.Debug|Any CPU.Build.0 = Debug|Any CPU {58863D86-3C78-4BEC-ACB6-2F82CC141210}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -155,8 +155,8 @@ Global {B4E2ED08-4AD3-4648-8BDB-3107200460B9}.Altcoins-Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU {B4E2ED08-4AD3-4648-8BDB-3107200460B9}.Altcoins-Release|Any CPU.ActiveCfg = Altcoins-Release|Any CPU {B4E2ED08-4AD3-4648-8BDB-3107200460B9}.Altcoins-Release|Any CPU.Build.0 = Altcoins-Release|Any CPU - {B4E2ED08-4AD3-4648-8BDB-3107200460B9}.Debug|Any CPU.ActiveCfg = Altcoins-Debug|Any CPU - {B4E2ED08-4AD3-4648-8BDB-3107200460B9}.Debug|Any CPU.Build.0 = Altcoins-Debug|Any CPU + {B4E2ED08-4AD3-4648-8BDB-3107200460B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B4E2ED08-4AD3-4648-8BDB-3107200460B9}.Debug|Any CPU.Build.0 = Debug|Any CPU {5E1BAA06-7828-47BC-89D6-19C2A78EA427}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5E1BAA06-7828-47BC-89D6-19C2A78EA427}.Debug|Any CPU.Build.0 = Debug|Any CPU {5E1BAA06-7828-47BC-89D6-19C2A78EA427}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/BTCPayServerPlugins.sln.DotSettings.user b/BTCPayServerPlugins.sln.DotSettings.user index c5e1c77..6f6e799 100644 --- a/BTCPayServerPlugins.sln.DotSettings.user +++ b/BTCPayServerPlugins.sln.DotSettings.user @@ -1,7 +1,21 @@  ForceIncluded ForceIncluded + ForceIncluded + ForceIncluded ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded ExplicitlyExcluded ExplicitlyExcluded ForceIncluded @@ -50,6 +64,7 @@ + True \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.BitcoinWhitepaper/BTCPayServer.Plugins.BitcoinWhitepaper.csproj b/Plugins/BTCPayServer.Plugins.BitcoinWhitepaper/BTCPayServer.Plugins.BitcoinWhitepaper.csproj index 5744dc0..a0d35d2 100644 --- a/Plugins/BTCPayServer.Plugins.BitcoinWhitepaper/BTCPayServer.Plugins.BitcoinWhitepaper.csproj +++ b/Plugins/BTCPayServer.Plugins.BitcoinWhitepaper/BTCPayServer.Plugins.BitcoinWhitepaper.csproj @@ -10,7 +10,7 @@ Bitcoin Whitepaper This makes the Bitcoin whitepaper available on your BTCPay Server. - 1.0.4 + 1.0.5 true diff --git a/Plugins/BTCPayServer.Plugins.BitcoinWhitepaper/BitcoinWhitepaperPlugin.cs b/Plugins/BTCPayServer.Plugins.BitcoinWhitepaper/BitcoinWhitepaperPlugin.cs index d5b45a6..5528d45 100644 --- a/Plugins/BTCPayServer.Plugins.BitcoinWhitepaper/BitcoinWhitepaperPlugin.cs +++ b/Plugins/BTCPayServer.Plugins.BitcoinWhitepaper/BitcoinWhitepaperPlugin.cs @@ -7,7 +7,7 @@ namespace BTCPayServer.Plugins.BitcoinWhitepaper { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = { - new() { Identifier = nameof(BTCPayServer), Condition = ">=1.12.0" } + new() { Identifier = nameof(BTCPayServer), Condition = ">=2.0.0" } }; } } diff --git a/Plugins/BTCPayServer.Plugins.Blink/BTCPayServer.Plugins.Blink.csproj b/Plugins/BTCPayServer.Plugins.Blink/BTCPayServer.Plugins.Blink.csproj index 1ed0f44..dc923b1 100644 --- a/Plugins/BTCPayServer.Plugins.Blink/BTCPayServer.Plugins.Blink.csproj +++ b/Plugins/BTCPayServer.Plugins.Blink/BTCPayServer.Plugins.Blink.csproj @@ -9,7 +9,7 @@ Blink Blink Lightning support - 1.0.8 + 1.0.9 true BTCPayServer.Plugins.Blink diff --git a/Plugins/BTCPayServer.Plugins.Blink/BlinkPlugin.cs b/Plugins/BTCPayServer.Plugins.Blink/BlinkPlugin.cs index d5756b8..24ca597 100644 --- a/Plugins/BTCPayServer.Plugins.Blink/BlinkPlugin.cs +++ b/Plugins/BTCPayServer.Plugins.Blink/BlinkPlugin.cs @@ -12,7 +12,7 @@ namespace BTCPayServer.Plugins.Blink { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = { - new() {Identifier = nameof(BTCPayServer), Condition = ">=1.12.0"} + new() { Identifier = nameof(BTCPayServer), Condition = ">=2.0.0" } }; diff --git a/Plugins/BTCPayServer.Plugins.Breez/BTCPayServer.Plugins.Breez.csproj b/Plugins/BTCPayServer.Plugins.Breez/BTCPayServer.Plugins.Breez.csproj index e105617..cd39693 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/BTCPayServer.Plugins.Breez.csproj +++ b/Plugins/BTCPayServer.Plugins.Breez/BTCPayServer.Plugins.Breez.csproj @@ -9,7 +9,7 @@ Breez / Greenlight Lightweight lightning baby! - 1.0.8 + 1.0.9 true @@ -34,7 +34,7 @@ - + diff --git a/Plugins/BTCPayServer.Plugins.Breez/BreezController.cs b/Plugins/BTCPayServer.Plugins.Breez/BreezController.cs index 90e338e..84ef2c9 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/BreezController.cs +++ b/Plugins/BTCPayServer.Plugins.Breez/BreezController.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using System.IO.Compression; -using System.Linq; using System.Threading.Tasks; using Breez.Sdk; using BTCPayServer.Abstractions.Constants; @@ -12,13 +11,13 @@ using BTCPayServer.Lightning; using BTCPayServer.Models; using BTCPayServer.Payments; using BTCPayServer.Payments.Lightning; +using BTCPayServer.Services.Invoices; using BTCPayServer.Services.Stores; using BTCPayServer.Services.Wallets; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using NBitcoin; using NBitcoin.DataEncoders; -using NBXplorer.DerivationStrategy; namespace BTCPayServer.Plugins.Breez; @@ -26,15 +25,19 @@ namespace BTCPayServer.Plugins.Breez; [Route("plugins/{storeId}/Breez")] public class BreezController : Controller { + private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary; private readonly BTCPayNetworkProvider _btcPayNetworkProvider; private readonly BreezService _breezService; private readonly BTCPayWalletProvider _btcWalletProvider; private readonly StoreRepository _storeRepository; - public BreezController(BTCPayNetworkProvider btcPayNetworkProvider, + public BreezController( + PaymentMethodHandlerDictionary paymentMethodHandlerDictionary, + BTCPayNetworkProvider btcPayNetworkProvider, BreezService breezService, BTCPayWalletProvider btcWalletProvider, StoreRepository storeRepository) { + _paymentMethodHandlerDictionary = paymentMethodHandlerDictionary; _btcPayNetworkProvider = btcPayNetworkProvider; _breezService = breezService; _btcWalletProvider = btcWalletProvider; @@ -113,7 +116,7 @@ public class BreezController : Controller if (address.Equals("store", StringComparison.InvariantCultureIgnoreCase)) { var store = ControllerContext.HttpContext.GetStoreData() - .GetDerivationSchemeSettings(_btcPayNetworkProvider, "BTC"); + .GetDerivationSchemeSettings(_paymentMethodHandlerDictionary, "BTC"); var res = await _btcWalletProvider.GetWallet(storeId) .ReserveAddressAsync(storeId, store.AccountDerivation, "Breez"); address = res.Address.ToString(); @@ -264,7 +267,7 @@ public class BreezController : Controller if (address.Equals("store", StringComparison.InvariantCultureIgnoreCase)) { var store = ControllerContext.HttpContext.GetStoreData() - .GetDerivationSchemeSettings(_btcPayNetworkProvider, "BTC"); + .GetDerivationSchemeSettings(_paymentMethodHandlerDictionary, "BTC"); var res = await _btcWalletProvider.GetWallet(storeId) .ReserveAddressAsync(storeId, store.AccountDerivation, "Breez"); address = res.Address.ToString(); @@ -342,10 +345,8 @@ public class BreezController : Controller public async Task Configure(string storeId, string command, BreezSettings settings) { var store = HttpContext.GetStoreData(); - var existing = store.GetSupportedPaymentMethods(_btcPayNetworkProvider).OfType() - .FirstOrDefault(method => - method.PaymentId.PaymentType == LightningPaymentType.Instance && - method.PaymentId.CryptoCode == "BTC"); + var pmi = PaymentTypes.LN.GetPaymentMethodId("BTC"); + var existing = store.GetPaymentMethodConfig(pmi, _paymentMethodHandlerDictionary); if (command == "clear") { @@ -355,7 +356,7 @@ public class BreezController : Controller var isStoreSetToThisMicro = existing?.GetExternalLightningUrl() == client?.ToString(); if (client is not null && isStoreSetToThisMicro) { - store.SetSupportedPaymentMethod(existing.PaymentId, null); + store.SetPaymentMethodConfig(_paymentMethodHandlerDictionary[pmi], null); await _storeRepository.UpdateStore(store); } return RedirectToAction(nameof(Configure), new {storeId}); @@ -422,18 +423,13 @@ public class BreezController : Controller if(existing is null) { - existing = new LightningSupportedPaymentMethod() - { - CryptoCode = "BTC" - }; + + existing = new LightningPaymentMethodConfig(); var client = _breezService.GetClient(storeId); existing.SetLightningUrl(client); - store.SetSupportedPaymentMethod(existing); - var lnurl = new LNURLPaySupportedPaymentMethod() - { - CryptoCode = "BTC", - }; - store.SetSupportedPaymentMethod(lnurl); + store.SetPaymentMethodConfig(_paymentMethodHandlerDictionary[pmi], existing); + var lnurlPMI = PaymentTypes.LNURL.GetPaymentMethodId("BTC"); + store.SetPaymentMethodConfig(_paymentMethodHandlerDictionary[lnurlPMI], new LNURLPaymentMethodConfig()); await _storeRepository.UpdateStore(store); } diff --git a/Plugins/BTCPayServer.Plugins.Breez/BreezLightningClient.cs b/Plugins/BTCPayServer.Plugins.Breez/BreezLightningClient.cs index f7657f4..8607495 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/BreezLightningClient.cs +++ b/Plugins/BTCPayServer.Plugins.Breez/BreezLightningClient.cs @@ -252,7 +252,7 @@ public class BreezLightningClient : ILightningClient, IDisposable, EventListener OffchainBalance = new OffchainBalance() { Local = LightMoney.MilliSatoshis(ni.channelsBalanceMsat), - Remote = LightMoney.MilliSatoshis(ni.inboundLiquidityMsats), + Remote = LightMoney.MilliSatoshis(ni.totalInboundLiquidityMsats), } }; } @@ -275,7 +275,7 @@ public class BreezLightningClient : ILightningClient, IDisposable, EventListener } else { - result = Sdk.SendPayment(new SendPaymentRequest(bolt11, (ulong?) payParams.Amount?.MilliSatoshi)); + result = Sdk.SendPayment(new SendPaymentRequest(bolt11,false, (ulong?) payParams.Amount?.MilliSatoshi)); } var details = result.payment.details as PaymentDetails.Ln; diff --git a/Plugins/BTCPayServer.Plugins.Breez/BreezPlugin.cs b/Plugins/BTCPayServer.Plugins.Breez/BreezPlugin.cs index b657216..ecd582c 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/BreezPlugin.cs +++ b/Plugins/BTCPayServer.Plugins.Breez/BreezPlugin.cs @@ -12,7 +12,7 @@ namespace BTCPayServer.Plugins.Breez { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = { - new() { Identifier = nameof(BTCPayServer), Condition = ">=1.13.2" } + new() { Identifier = nameof(BTCPayServer), Condition = ">=2.0.0" } }; public override void Execute(IServiceCollection applicationBuilder) diff --git a/Plugins/BTCPayServer.Plugins.Breez/BreezService.cs b/Plugins/BTCPayServer.Plugins.Breez/BreezService.cs index cf643a0..40fee5e 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/BreezService.cs +++ b/Plugins/BTCPayServer.Plugins.Breez/BreezService.cs @@ -11,7 +11,9 @@ using BTCPayServer.Events; using BTCPayServer.HostedServices; using BTCPayServer.Payments; using BTCPayServer.Payments.Lightning; +using BTCPayServer.Services.Invoices; using BTCPayServer.Services.Stores; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using NBitcoin; @@ -22,7 +24,8 @@ public class BreezService:EventHostedServiceBase { private readonly StoreRepository _storeRepository; private readonly IOptions _dataDirectories; - private readonly BTCPayNetworkProvider _btcPayNetworkProvider; + private readonly IServiceProvider _serviceProvider; + private PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary => _serviceProvider.GetRequiredService(); private readonly ILogger _logger; private Dictionary _settings; private Dictionary _clients = new(); @@ -31,12 +34,12 @@ public class BreezService:EventHostedServiceBase EventAggregator eventAggregator, StoreRepository storeRepository, IOptions dataDirectories, - BTCPayNetworkProvider btcPayNetworkProvider, + IServiceProvider serviceProvider, ILogger logger) : base(eventAggregator, logger) { _storeRepository = storeRepository; _dataDirectories = dataDirectories; - _btcPayNetworkProvider = btcPayNetworkProvider; + _serviceProvider = serviceProvider; _logger = logger; } @@ -133,13 +136,13 @@ public class BreezService:EventHostedServiceBase { _settings.Remove(storeId, out var oldSettings ); var data = await _storeRepository.FindStore(storeId); - var existing = data?.GetSupportedPaymentMethods(_btcPayNetworkProvider) - .OfType().FirstOrDefault(method => - method.CryptoCode == "BTC" && method.PaymentId.PaymentType == LightningPaymentType.Instance); + var pmi = PaymentTypes.LN.GetPaymentMethodId("BTC"); + var existing = + data?.GetPaymentMethodConfig(pmi, _paymentMethodHandlerDictionary); var isBreez = existing?.GetExternalLightningUrl() == $"type=breez;key={oldSettings.PaymentKey}"; if (isBreez) { - data.SetSupportedPaymentMethod(new PaymentMethodId("BTC", LightningPaymentType.Instance), null ); + data.SetPaymentMethodConfig(_paymentMethodHandlerDictionary[pmi], null ); await _storeRepository.UpdateStore(data); } Directory.Delete(GetWorkDir(storeId), true); diff --git a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapIn.cshtml b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapIn.cshtml index 5e55528..4bf18ac 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapIn.cshtml +++ b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapIn.cshtml @@ -1,7 +1,5 @@ @using Breez.Sdk @using BTCPayServer -@using BTCPayServer.Abstractions.Extensions -@using BTCPayServer.Abstractions.Contracts @using BTCPayServer.Client @using BTCPayServer.Components.QRCode @using BTCPayServer.Components.TruncateCenter @@ -10,13 +8,15 @@ @using BTCPayServer.Plugins.Breez @using BTCPayServer.Security @using BTCPayServer.Services +@using BTCPayServer.Services.Invoices @using Microsoft.AspNetCore.Mvc.TagHelpers @using NBitcoin @inject BreezService BreezService -@inject BTCPayNetworkProvider BtcPayNetworkProvider @inject TransactionLinkProviders TransactionLinkProviders +@inject PaymentMethodHandlerDictionary PaymentMethodHandlerDictionary @{ ViewData.SetActivePage("Breez", "Swap In", "SwapIn"); + var pmi = PaymentTypes.CHAIN.GetPaymentMethodId("BTC"); string storeId = Model switch { string s => s, @@ -38,10 +38,9 @@ } var refundables = sdk.ListRefundables(); - var deriv = Context.GetStoreData().GetDerivationSchemeSettings(BtcPayNetworkProvider, "BTC"); + var deriv = Context.GetStoreData().GetDerivationSchemeSettings(PaymentMethodHandlerDictionary, "BTC"); var ni = sdk.NodeInfo(); var f = sdk.RecommendedFees(); - var pmi = new PaymentMethodId("BTC", PaymentTypes.BTCLike); } diff --git a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapInRefund.cshtml b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapInRefund.cshtml index 24a12b4..773c2a3 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapInRefund.cshtml +++ b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapInRefund.cshtml @@ -1,18 +1,18 @@ @using BTCPayServer -@using BTCPayServer.Abstractions.Extensions @using BTCPayServer.Plugins.Breez @using BTCPayServer.Security +@using BTCPayServer.Services.Invoices @using Microsoft.AspNetCore.Mvc.TagHelpers @using Microsoft.AspNetCore.Routing @model string @inject BreezService BreezService -@inject BTCPayNetworkProvider BtcPayNetworkProvider +@inject PaymentMethodHandlerDictionary PaymentMethodHandlerDictionary @{ var storeId = Context.GetImplicitStoreId(); var address = Context.GetRouteValue("address").ToString(); ViewData.SetActivePage("Breez", "Create Swapin Refund", "SwapIn"); - var deriv = Context.GetStoreData().GetDerivationSchemeSettings(BtcPayNetworkProvider, "BTC"); + var deriv = Context.GetStoreData().GetDerivationSchemeSettings(PaymentMethodHandlerDictionary, "BTC"); var sdk = BreezService.GetClient(storeId)?.Sdk; var f = sdk.RecommendedFees(); } diff --git a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapOut.cshtml b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapOut.cshtml index 25e8381..800fe0a 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapOut.cshtml +++ b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/SwapOut.cshtml @@ -1,11 +1,12 @@ @using Breez.Sdk @using BTCPayServer -@using BTCPayServer.Abstractions.Extensions @using BTCPayServer.Models.StoreViewModels @using BTCPayServer.Plugins.Breez @using BTCPayServer.Security +@using BTCPayServer.Services.Invoices +@using Microsoft.AspNetCore.Mvc.TagHelpers @inject BreezService BreezService -@inject BTCPayNetworkProvider BtcPayNetworkProvider +@inject PaymentMethodHandlerDictionary PaymentMethodHandlerDictionary @{ @@ -29,7 +30,7 @@ if (sdk is null) return; var inProgressSwaps = sdk.InProgressReverseSwaps(); - var deriv = Context.GetStoreData().GetDerivationSchemeSettings(BtcPayNetworkProvider, "BTC"); + var deriv = Context.GetStoreData().GetDerivationSchemeSettings(PaymentMethodHandlerDictionary, "BTC"); var f = sdk.RecommendedFees(); var swapOutRec = sdk.FetchReverseSwapFees(new ReverseSwapFeesRequest()); } diff --git a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/Sweep.cshtml b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/Sweep.cshtml index 78d75f7..f84788a 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/Sweep.cshtml +++ b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/Sweep.cshtml @@ -2,9 +2,10 @@ @using BTCPayServer.Models.StoreViewModels @using BTCPayServer.Plugins.Breez @using BTCPayServer.Security +@using BTCPayServer.Services.Invoices @using Microsoft.AspNetCore.Mvc.TagHelpers @inject BreezService BreezService -@inject BTCPayNetworkProvider BtcPayNetworkProvider +@inject PaymentMethodHandlerDictionary PaymentMethodHandlerDictionary @{ Layout = "_Layout"; ViewData.SetActivePage("Breez", "Sweep", "Sweep"); @@ -24,7 +25,7 @@ var sdk = BreezService.GetClient(storeId)?.Sdk; if (sdk is null) return; - var deriv = Context.GetStoreData().GetDerivationSchemeSettings(BtcPayNetworkProvider, "BTC"); + var deriv = Context.GetStoreData().GetDerivationSchemeSettings(PaymentMethodHandlerDictionary, "BTC"); var f = sdk.RecommendedFees(); } diff --git a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/_Layout.cshtml b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/_Layout.cshtml deleted file mode 100644 index 0517521..0000000 --- a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/_Layout.cshtml +++ /dev/null @@ -1,10 +0,0 @@ -@{ - Layout = "../Shared/_NavLayout.cshtml"; - ViewData["NavPartialName"] = "_Nav"; -} - -@RenderBody() \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/_Nav.cshtml b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/_Nav.cshtml index b78ff32..e69de29 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/_Nav.cshtml +++ b/Plugins/BTCPayServer.Plugins.Breez/Views/Breez/_Nav.cshtml @@ -1,41 +0,0 @@ -@using BTCPayServer.Abstractions.Extensions -@using BTCPayServer.Client -@using BTCPayServer.Models.StoreViewModels -@using BTCPayServer.Plugins.Breez -@using BTCPayServer.Security -@using Microsoft.AspNetCore.Mvc.TagHelpers - -@inject BreezService BreezService -@{ - var storeId = Model switch - { - string s => s, - StoreDashboardViewModel dashboardModel => dashboardModel.StoreId, - _ => Context.GetImplicitStoreId() - }; - var client = BreezService.GetClient(storeId); - var sdk = client?.Sdk; -} - -
- \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Breez/Views/Shared/Breez/BreezNav.cshtml b/Plugins/BTCPayServer.Plugins.Breez/Views/Shared/Breez/BreezNav.cshtml index 0fcab48..cd8f756 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/Views/Shared/Breez/BreezNav.cshtml +++ b/Plugins/BTCPayServer.Plugins.Breez/Views/Shared/Breez/BreezNav.cshtml @@ -1,27 +1,67 @@ +@using Breez.Sdk @using BTCPayServer.Abstractions.Contracts @using BTCPayServer.Abstractions.Extensions @using BTCPayServer.Client +@using BTCPayServer.Models.StoreViewModels +@using BTCPayServer.Plugins.Breez +@using BTCPayServer.Security @using Microsoft.AspNetCore.Mvc.TagHelpers @inject IScopeProvider ScopeProvider +@inject BreezService BreezService @{ - var storeId = ScopeProvider.GetCurrentStoreId(); + var storeId = Model switch + { + string s => s, + StoreDashboardViewModel dashboardModel => dashboardModel.StoreId, + _ => Context.GetImplicitStoreId() + }; + var active = @ViewData.IsActivePage("Breez"); + var client = string.IsNullOrEmpty(active) ? null : BreezService.GetClient(storeId); + var sdk = client?.Sdk; } @if (!string.IsNullOrEmpty(storeId)) { -} + + @if (sdk is not null) + { + + + + + + @if (client.Events.Any()) + { + + } + } +} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Breez/Views/Shared/Breez/BreezNodeInfo.cshtml b/Plugins/BTCPayServer.Plugins.Breez/Views/Shared/Breez/BreezNodeInfo.cshtml index 31c4708..267f2f5 100644 --- a/Plugins/BTCPayServer.Plugins.Breez/Views/Shared/Breez/BreezNodeInfo.cshtml +++ b/Plugins/BTCPayServer.Plugins.Breez/Views/Shared/Breez/BreezNodeInfo.cshtml @@ -103,7 +103,7 @@ BTC receivable
-

@LightMoney.MilliSatoshis(nodeState.inboundLiquidityMsats).ToUnit(LightMoneyUnit.BTC)

+

@LightMoney.MilliSatoshis(nodeState.totalInboundLiquidityMsats).ToUnit(LightMoneyUnit.BTC)

BTC inbound liquidity
diff --git a/Plugins/BTCPayServer.Plugins.Bringin/BTCPayServer.Plugins.Bringin.csproj b/Plugins/BTCPayServer.Plugins.Bringin/BTCPayServer.Plugins.Bringin.csproj index 540090c..c4867bc 100644 --- a/Plugins/BTCPayServer.Plugins.Bringin/BTCPayServer.Plugins.Bringin.csproj +++ b/Plugins/BTCPayServer.Plugins.Bringin/BTCPayServer.Plugins.Bringin.csproj @@ -9,7 +9,7 @@ Bringin Euro Offramp - 1.0.1 + 1.0.2 true @@ -41,6 +41,6 @@ - + diff --git a/Plugins/BTCPayServer.Plugins.Bringin/BringinPlugin.cs b/Plugins/BTCPayServer.Plugins.Bringin/BringinPlugin.cs index ac0058c..17637dd 100644 --- a/Plugins/BTCPayServer.Plugins.Bringin/BringinPlugin.cs +++ b/Plugins/BTCPayServer.Plugins.Bringin/BringinPlugin.cs @@ -11,7 +11,10 @@ public class BringinPlugin : BaseBTCPayServerPlugin { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = { - new() {Identifier = nameof(BTCPayServer), Condition = ">=1.12.0"} + new() + { + Identifier = nameof(BTCPayServer), Condition = ">=2.0.0" + } }; public override void Execute(IServiceCollection applicationBuilder) diff --git a/Plugins/BTCPayServer.Plugins.Bringin/BringinService.cs b/Plugins/BTCPayServer.Plugins.Bringin/BringinService.cs index 7a2dc90..05cd745 100644 --- a/Plugins/BTCPayServer.Plugins.Bringin/BringinService.cs +++ b/Plugins/BTCPayServer.Plugins.Bringin/BringinService.cs @@ -17,6 +17,7 @@ using BTCPayServer.Events; using BTCPayServer.HostedServices; using BTCPayServer.Lightning; using BTCPayServer.Payments; +using BTCPayServer.Payouts; using BTCPayServer.Services; using BTCPayServer.Services.Stores; using Microsoft.Extensions.Logging; @@ -139,13 +140,15 @@ public class BringinService : EventHostedServiceBase invoiceEvent when bringinStoreSettings.Enabled: var pmPayments = invoiceEvent.Invoice.GetPayments("BTC", true) - .GroupBy(payment => payment.GetPaymentMethodId()); + .GroupBy(payment => payment.PaymentMethodId); var update = false; foreach (var pmPayment in pmPayments) { var methodId = pmPayment.Key; - if (methodId.PaymentType == PaymentTypes.LNURLPay) - methodId = new PaymentMethodId(methodId.CryptoCode, PaymentTypes.LightningLike); + if (methodId == PaymentTypes.LNURL.GetPaymentMethodId("BTC")) + { + methodId = PaymentTypes.LN.GetPaymentMethodId("BTC"); + } if (!bringinStoreSettings.MethodSettings.TryGetValue(methodId.ToString(), out var methodSettings)) { @@ -153,7 +156,7 @@ public class BringinService : EventHostedServiceBase } methodSettings.CurrentBalance += - pmPayment.Sum(payment => payment.GetCryptoPaymentData().GetValue()); + pmPayment.Sum(payment => payment.Value); update = true; } @@ -190,14 +193,14 @@ public class BringinService : EventHostedServiceBase foreach (var methodSetting in bringinStoreSetting.MethodSettings) { - var pmi = PaymentMethodId.TryParse(methodSetting.Key); + var pmi = PayoutMethodId.TryParse(methodSetting.Key); if (pmi is null) { continue; } - + var isOnChain = PayoutTypes.CHAIN.GetPayoutMethodId("BTC") == pmi; // if there is a pending payout, try and cancel it if this is onchain as we want to save needless tx fees - if (methodSetting.Value.PendingPayouts.Count > 0 && pmi.PaymentType == BitcoinPaymentType.Instance) + if (methodSetting.Value.PendingPayouts.Count > 0 && isOnChain) { var cancelResult = await _pullPaymentHostedService.Cancel( new PullPaymentHostedService.CancelRequest(methodSetting.Value.PendingPayouts.ToArray(), @@ -252,16 +255,16 @@ public class BringinService : EventHostedServiceBase return result; } - public async Task CreateOrder(string storeId, PaymentMethodId paymentMethodId, Money amountBtc, bool payout) + public async Task CreateOrder(string storeId, PayoutMethodId paymentMethodId, Money amountBtc, bool payout) { - if (SupportedMethods.All(supportedMethod => supportedMethod.PaymentMethod != paymentMethodId)) + if (SupportedMethods.All(supportedMethod => supportedMethod.PayoutMethod != paymentMethodId)) { - throw new NotSupportedException($"{paymentMethodId.ToPrettyString()} Payment method not supported"); + throw new NotSupportedException($"{paymentMethodId} Payment method not supported"); } var settings = _settings[storeId]; - var bringinClient = settings.CreateClient(_httpClientFactory, _btcPayNetworkProvider.GetNetwork(paymentMethodId.CryptoCode).NBitcoinNetwork); + var bringinClient = settings.CreateClient(_httpClientFactory, _btcPayNetworkProvider.GetNetwork("BTC").NBitcoinNetwork); var host = await Dns.GetHostEntryAsync(Dns.GetHostName(), CancellationToken.None); @@ -270,7 +273,7 @@ public class BringinService : EventHostedServiceBase - var supportedMethod = SupportedMethods.First(supportedMethod => supportedMethod.PaymentMethod == paymentMethodId); + var supportedMethod = SupportedMethods.First(supportedMethod => supportedMethod.PayoutMethod == paymentMethodId); //check if amount is enough if (supportedMethod.FiatMinimumAmount > 0) { @@ -297,13 +300,13 @@ public class BringinService : EventHostedServiceBase { return order.Invoice?? order.DepositAddress; } - var network = _btcPayNetworkProvider.GetNetwork(paymentMethodId.CryptoCode); + var network = _btcPayNetworkProvider.GetNetwork("BTC"); var destination = !string.IsNullOrEmpty(order.Invoice)? (IClaimDestination) new BoltInvoiceClaimDestination(order.Invoice, BOLT11PaymentRequest.Parse(order.Invoice, network.NBitcoinNetwork)): new AddressClaimDestination(BitcoinAddress.Create(order.DepositAddress, network.NBitcoinNetwork)); var claim = await _pullPaymentHostedService.Claim(new ClaimRequest() { - PaymentMethodId = paymentMethodId, + PayoutMethodId = paymentMethodId, StoreId = storeId, Destination = destination, Value = orderMoney.ToUnit(MoneyUnit.BTC), @@ -363,17 +366,17 @@ public class BringinService : EventHostedServiceBase { case PayoutState.Completed: // remove from pending payouts list in a setting - return _settings[payout.StoreDataId].MethodSettings[payout.GetPaymentMethodId().ToString()] + return _settings[payout.StoreDataId].MethodSettings[payout.GetPayoutMethodId().ToString()] .PendingPayouts.Remove(payout.Id); case PayoutState.Cancelled: // remove from pending payouts list in a setting and add to a balance - var result = _settings[payout.StoreDataId].MethodSettings[payout.GetPaymentMethodId().ToString()] + var result = _settings[payout.StoreDataId].MethodSettings[payout.GetPayoutMethodId().ToString()] .PendingPayouts.Remove(payout.Id); - var pmi = payout.GetPaymentMethodId(); + var pmi = payout.GetPayoutMethodId(); if (_settings[payout.StoreDataId].MethodSettings .TryGetValue(pmi.ToString(), out var methodSettings)) { - methodSettings.CurrentBalance += payout.GetBlob(_btcPayNetworkJsonSerializerSettings).Amount; + methodSettings.CurrentBalance += payout.Amount ?? payout.OriginalAmount; result = true; } @@ -389,12 +392,12 @@ public class BringinService : EventHostedServiceBase return _settings.TryGetValue(storeId, out var bringinStoreSettings) ? bringinStoreSettings : null; } - public record SupportedMethodOptions(PaymentMethodId PaymentMethod, bool FiatMinimum, decimal FiatMinimumAmount, string bringinMethod); + public record SupportedMethodOptions(PayoutMethodId PayoutMethod, bool FiatMinimum, decimal FiatMinimumAmount, string bringinMethod); public static readonly SupportedMethodOptions[] SupportedMethods = new[] { - new SupportedMethodOptions(new PaymentMethodId("BTC", LightningPaymentType.Instance), true, 22, "LIGHTNING"), - new SupportedMethodOptions(new PaymentMethodId("BTC", BitcoinPaymentType.Instance), true, 22, "ON_CHAIN"), + new SupportedMethodOptions(PayoutTypes.LN.GetPayoutMethodId("BTC"), true, 22, "LIGHTNING"), + new SupportedMethodOptions(PayoutTypes.CHAIN.GetPayoutMethodId("BTC"), true, 22, "ON_CHAIN"), }; private ConcurrentDictionary _editModes = new(); @@ -412,9 +415,9 @@ public class BringinService : EventHostedServiceBase // add or remove any missing methods in result foreach (var supportedMethod in SupportedMethods) { - if (!result.MethodSettings.ContainsKey(supportedMethod.PaymentMethod.ToString())) + if (!result.MethodSettings.ContainsKey(supportedMethod.PayoutMethod.ToString())) { - result.MethodSettings.Add(supportedMethod.PaymentMethod.ToString(), + result.MethodSettings.Add(supportedMethod.PayoutMethod.ToString(), new BringinStoreSettings.PaymentMethodSettings() { FiatThreshold = supportedMethod.FiatMinimum, @@ -424,7 +427,7 @@ public class BringinService : EventHostedServiceBase } result.MethodSettings = result.MethodSettings.Where(pair => - SupportedMethods.Any(supportedMethod => supportedMethod.PaymentMethod.ToString() == pair.Key)) + SupportedMethods.Any(supportedMethod => supportedMethod.PayoutMethod.ToString() == pair.Key)) .ToDictionary(pair => pair.Key, pair => pair.Value); isNew = true; return (storeLock, result, DateTimeOffset.Now.AddMinutes(5)); diff --git a/Plugins/BTCPayServer.Plugins.Bringin/Components/BringinWidget.razor b/Plugins/BTCPayServer.Plugins.Bringin/Components/BringinWidget.razor index ac6d61d..8dea669 100644 --- a/Plugins/BTCPayServer.Plugins.Bringin/Components/BringinWidget.razor +++ b/Plugins/BTCPayServer.Plugins.Bringin/Components/BringinWidget.razor @@ -4,7 +4,9 @@ @using BTCPayServer.Data @using BTCPayServer.Payments @using BTCPayServer.PayoutProcessors +@using BTCPayServer.Payouts @using BTCPayServer.Services +@using BTCPayServer.Services.Invoices @using BTCPayServer.Services.Stores @using Microsoft.AspNetCore.Http @using Microsoft.AspNetCore.Routing @@ -25,6 +27,7 @@ [Inject] private IHttpClientFactory HttpClientFactory { get; set; } [Inject] private PayoutProcessorService PayoutProcessorService { get; set; } [Inject] private IAuthorizationService AuthorizationService { get; set; } + [Inject] private PayoutMethodHandlerDictionary PayoutMethodHandlerDictionary { get; set; } [Parameter] public string StoreId { get; set; } private decimal? LastFiatBalance { get; set; } private DateTimeOffset? LastDataFetch { get; set; } @@ -79,12 +82,13 @@ PmiLink = $"A payout processor has not been configured for this payment method. Payouts generated by Bringin will not be automatically handled. Configure now"; _callbackLink = LinkGenerator.GetUriByAction(HttpContextAccessor.HttpContext, "Callback", "Bringin", new {StoreId}); _settings = BringinService.IsInEditMode(StoreId) ? await BringinService.Update(StoreId) : await BringinService.Get(StoreId); - _pms = (await StoreRepository.FindStore(StoreId)).GetSupportedPaymentMethods(BTCPayNetworkProvider).Select(method => method.PaymentId).Where(id => id.CryptoCode == "BTC").ToArray(); + var store = await StoreRepository.FindStore(StoreId); + _pms = PayoutMethodHandlerDictionary.GetSupportedPayoutMethods(store); _pps = (await PayoutProcessorService.GetProcessors(new PayoutProcessorService.PayoutProcessorQuery() { Stores = new[] {StoreId}, - PaymentMethods = _pms.Select(p => p.ToString()).ToArray() - })).Select(data => PaymentMethodId.TryParse(data.PaymentMethod)).Where(id => id is not null).ToArray(); + PayoutMethods = _pms.Select(p => p).ToArray() + })).Select(data => PayoutMethodId.TryParse(data.PayoutMethodId)).Where(id => id is not null).ToArray(); EditMode = BringinService.IsInEditMode(StoreId); IsLoaded = true; _ = FetchBalanceAndRate(); @@ -148,8 +152,8 @@ } private bool _saving; - private PaymentMethodId[] _pms; - private PaymentMethodId[] _pps; + private HashSet _pms; + private PayoutMethodId[] _pps; private bool _apiKeyError; private async Task Save() @@ -269,7 +273,7 @@ _saving = true; await InvokeAsync(StateHasChanged); - var pm = PaymentMethodId.TryParse(ManualOrderPaymentMethod); + var pm = PayoutMethodId.TryParse(ManualOrderPaymentMethod); if (pm is null) { SaveError = "Invalid payment method"; @@ -391,8 +395,8 @@ } else if (_manualOrder) { - var items = new List(); - items.AddRange(BringinService.SupportedMethods.Where(s => _pms.Contains(s.PaymentMethod)).Select(s => s.PaymentMethod)); + var items = new List(); + items.AddRange(BringinService.SupportedMethods.Where(s => _pms.Contains(s.PayoutMethod)).Select(s => s.PayoutMethod));
@@ -422,7 +426,7 @@ @foreach (var opt in items) { - + }
@@ -472,7 +476,7 @@ @foreach (var method in _settings.MethodSettings) { - var pmi = PaymentMethodId.TryParse(method.Key); + var pmi = PayoutMethodId.TryParse(method.Key); if (pmi is null) continue; if (!_pms.Contains(pmi)) @@ -480,7 +484,7 @@
-
@pmi.ToPrettyString()
+
@pmi
@if (LastFiatRate is null || !method.Value.FiatThreshold) @@ -504,7 +508,7 @@ (@DisplayFormatter.Currency(balanceInFiat.Value, "EUR", DisplayFormatter.CurrencyFormat.Code)) pending to forward once @DisplayFormatter.Currency(thresholdinBtc.Value, "BTC", DisplayFormatter.CurrencyFormat.Code) (@DisplayFormatter.Currency(method.Value.Threshold, "EUR")) is reached. @if (method.Value.CurrentBalance > 0) { - + //Clear balance }
@@ -579,9 +583,9 @@ var pmId = PaymentMethodId.TryParse(method.Key); if (pmId is null) continue; - var supportedMethod = BringinService.SupportedMethods.FirstOrDefault(s => s.PaymentMethod.ToString() == method.Key); + var supportedMethod = BringinService.SupportedMethods.FirstOrDefault(s => s.PayoutMethod.ToString() == method.Key);
-
@pmId.ToPrettyString()
+
@pmId
@@ -644,15 +648,16 @@ @tx.CreatedAt.ToTimeAgo() @tx.SubType.ToHumanReadable() - - @tx.Status.ToHumanReadable() - + @tx.Status.ToHumanReadable() - @(tx.SourceCurrency == "BTC" ? Money.Satoshis(tx.SourceAmount).ToDecimal(MoneyUnit.BTC): tx.SourceAmount)@tx.SourceCurrency -> @tx.DestinationAmount @tx.DestinationCurrency + + @(tx.SourceCurrency == "BTC" ? Money.Satoshis(tx.SourceAmount).ToDecimal(MoneyUnit.BTC) : tx.SourceAmount) @tx.SourceCurrency + -> @tx.DestinationAmount @tx.DestinationCurrency + } - + s
} diff --git a/Plugins/BTCPayServer.Plugins.DataErasure/BTCPayServer.Plugins.DataErasure.csproj b/Plugins/BTCPayServer.Plugins.DataErasure/BTCPayServer.Plugins.DataErasure.csproj index 116b6d7..0e8d526 100644 --- a/Plugins/BTCPayServer.Plugins.DataErasure/BTCPayServer.Plugins.DataErasure.csproj +++ b/Plugins/BTCPayServer.Plugins.DataErasure/BTCPayServer.Plugins.DataErasure.csproj @@ -9,7 +9,7 @@ Data Erasure Allows you to erase user data from invoices after a period of time. - 1.0.2 + 1.0.3 true diff --git a/Plugins/BTCPayServer.Plugins.DataErasure/DataErasureController.cs b/Plugins/BTCPayServer.Plugins.DataErasure/DataErasureController.cs index 56ae86f..7873def 100644 --- a/Plugins/BTCPayServer.Plugins.DataErasure/DataErasureController.cs +++ b/Plugins/BTCPayServer.Plugins.DataErasure/DataErasureController.cs @@ -12,6 +12,7 @@ namespace BTCPayServer.Plugins.DataErasure public class DataErasureController : Controller { private readonly DataErasureService _dataErasureService; + public DataErasureController(DataErasureService dataErasureService) { _dataErasureService = dataErasureService; @@ -31,10 +32,11 @@ namespace BTCPayServer.Plugins.DataErasure { if (_dataErasureService.IsRunning) { - TempData["ErrorMessage"] = "Data erasure is currently running and cannot be changed. Please try again later."; + TempData["ErrorMessage"] = + "Data erasure is currently running and cannot be changed. Please try again later."; } - + if (vm.Enabled) { if (!ModelState.IsValid) @@ -46,7 +48,11 @@ namespace BTCPayServer.Plugins.DataErasure switch (command) { - + case "cleardate": + await _dataErasureService.Set(storeId, vm, true); + + TempData["SuccessMessage"] = "Data erasure settings modified and date cleared"; + return RedirectToAction(nameof(Update), new {storeId}); case "save": await _dataErasureService.Set(storeId, vm); TempData["SuccessMessage"] = "Data erasure settings modified"; @@ -57,4 +63,4 @@ namespace BTCPayServer.Plugins.DataErasure } } } -} +} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.DataErasure/DataErasurePlugin.cs b/Plugins/BTCPayServer.Plugins.DataErasure/DataErasurePlugin.cs index 73c9115..f0869b6 100644 --- a/Plugins/BTCPayServer.Plugins.DataErasure/DataErasurePlugin.cs +++ b/Plugins/BTCPayServer.Plugins.DataErasure/DataErasurePlugin.cs @@ -9,7 +9,7 @@ namespace BTCPayServer.Plugins.DataErasure { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = { - new() { Identifier = nameof(BTCPayServer), Condition = ">=1.12.0" } + new() { Identifier = nameof(BTCPayServer), Condition = ">=2.0.0" } }; public override void Execute(IServiceCollection applicationBuilder) { diff --git a/Plugins/BTCPayServer.Plugins.DataErasure/DataErasureService.cs b/Plugins/BTCPayServer.Plugins.DataErasure/DataErasureService.cs index 4af9e9b..bbe648b 100644 --- a/Plugins/BTCPayServer.Plugins.DataErasure/DataErasureService.cs +++ b/Plugins/BTCPayServer.Plugins.DataErasure/DataErasureService.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using BTCPayServer.Abstractions.Contracts; +using BTCPayServer.Data; using BTCPayServer.Services.Invoices; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -14,13 +15,15 @@ namespace BTCPayServer.Plugins.DataErasure private readonly IStoreRepository _storeRepository; private readonly ILogger _logger; private readonly InvoiceRepository _invoiceRepository; + private readonly ApplicationDbContextFactory _dbContextFactory; public DataErasureService(IStoreRepository storeRepository, ILogger logger, - InvoiceRepository invoiceRepository) + InvoiceRepository invoiceRepository, ApplicationDbContextFactory dbContextFactory) { _storeRepository = storeRepository; _logger = logger; _invoiceRepository = invoiceRepository; + _dbContextFactory = dbContextFactory; } public async Task Get(string storeId) @@ -29,13 +32,16 @@ namespace BTCPayServer.Plugins.DataErasure nameof(DataErasureSettings)); } - public async Task Set(string storeId, DataErasureSettings settings) + public async Task Set(string storeId, DataErasureSettings settings, bool clearDate = false) { + _cts?.Cancel(); await _runningLock.WaitAsync(); var existing = await Get(storeId); - settings.LastRunCutoff = existing?.LastRunCutoff; + settings.LastRunCutoff = clearDate? null: existing?.LastRunCutoff; await SetCore(storeId, settings); _runningLock.Release(); + _cts = new CancellationTokenSource(); + _ = Run(); } private async Task SetCore(string storeId, DataErasureSettings settings) @@ -46,11 +52,11 @@ namespace BTCPayServer.Plugins.DataErasure public bool IsRunning { get; private set; } private readonly SemaphoreSlim _runningLock = new(1, 1); - private async Task Run(CancellationToken cancellationToken) + private async Task Run() { - while (!cancellationToken.IsCancellationRequested) + while (!_cts.IsCancellationRequested) { - await _runningLock.WaitAsync(cancellationToken); + await _runningLock.WaitAsync(_cts.Token); IsRunning = true; @@ -58,53 +64,69 @@ namespace BTCPayServer.Plugins.DataErasure await _storeRepository.GetSettingsAsync(nameof(DataErasureSettings)); foreach (var setting in settings.Where(setting => setting.Value.Enabled)) { - var skip = 0; var count = 0; var cutoffDate = DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(setting.Value.DaysToKeep)); - while (true) + if (setting.Value.EntirelyEraseInvoice) { - var invoices = await _invoiceRepository.GetInvoices(new InvoiceQuery() - { - StartDate = setting.Value.LastRunCutoff, - EndDate = cutoffDate, - StoreId = new[] {setting.Key}, - Skip = skip, - Take = 100 - }); - foreach (var invoice in invoices) - { - //replace all buyer info with "erased" - if (!string.IsNullOrEmpty(invoice.Metadata.BuyerAddress1)) - invoice.Metadata.BuyerAddress1 = "erased"; - if (!string.IsNullOrEmpty(invoice.Metadata.BuyerAddress2)) - invoice.Metadata.BuyerAddress2 = "erased"; - if (!string.IsNullOrEmpty(invoice.Metadata.BuyerCity)) - invoice.Metadata.BuyerCity = "erased"; - if (!string.IsNullOrEmpty(invoice.Metadata.BuyerCountry)) - invoice.Metadata.BuyerCountry = "erased"; - if (!string.IsNullOrEmpty(invoice.Metadata.BuyerEmail)) - invoice.Metadata.BuyerEmail = "erased"; - if (!string.IsNullOrEmpty(invoice.Metadata.BuyerName)) - invoice.Metadata.BuyerName = "erased"; - if (!string.IsNullOrEmpty(invoice.Metadata.BuyerPhone)) - invoice.Metadata.BuyerPhone = "erased"; - if (!string.IsNullOrEmpty(invoice.Metadata.BuyerState)) - invoice.Metadata.BuyerState = "erased"; - if (!string.IsNullOrEmpty(invoice.Metadata.BuyerZip)) - invoice.Metadata.BuyerZip = "erased"; - await _invoiceRepository.UpdateInvoiceMetadata(invoice.Id, invoice.StoreId, - invoice.Metadata.ToJObject()); - count++; - } - - if (invoices.Length < 100) - { - break; - } - - skip += 100; + await using var db = _dbContextFactory.CreateContext(); + db.Invoices.RemoveRange(db.Invoices.Where(i => i.StoreDataId == setting.Key && i.Created < cutoffDate && (setting.Value.LastRunCutoff == null || i.Created > setting.Value.LastRunCutoff))); + count = await db.SaveChangesAsync(_cts.Token); } - if(count > 0) + else + { + + + + var skip = 0; + while (true) + { + var invoices = await _invoiceRepository.GetInvoices(new InvoiceQuery() + { + StartDate = setting.Value.LastRunCutoff, + EndDate = cutoffDate, + StoreId = new[] {setting.Key}, + Skip = skip, + Take = 100 + }, _cts.Token); + + + + foreach (var invoice in invoices) + { + //replace all buyer info with "erased" + if (!string.IsNullOrEmpty(invoice.Metadata.BuyerAddress1)) + invoice.Metadata.BuyerAddress1 = "erased"; + if (!string.IsNullOrEmpty(invoice.Metadata.BuyerAddress2)) + invoice.Metadata.BuyerAddress2 = "erased"; + if (!string.IsNullOrEmpty(invoice.Metadata.BuyerCity)) + invoice.Metadata.BuyerCity = "erased"; + if (!string.IsNullOrEmpty(invoice.Metadata.BuyerCountry)) + invoice.Metadata.BuyerCountry = "erased"; + if (!string.IsNullOrEmpty(invoice.Metadata.BuyerEmail)) + invoice.Metadata.BuyerEmail = "erased"; + if (!string.IsNullOrEmpty(invoice.Metadata.BuyerName)) + invoice.Metadata.BuyerName = "erased"; + if (!string.IsNullOrEmpty(invoice.Metadata.BuyerPhone)) + invoice.Metadata.BuyerPhone = "erased"; + if (!string.IsNullOrEmpty(invoice.Metadata.BuyerState)) + invoice.Metadata.BuyerState = "erased"; + if (!string.IsNullOrEmpty(invoice.Metadata.BuyerZip)) + invoice.Metadata.BuyerZip = "erased"; + await _invoiceRepository.UpdateInvoiceMetadata(invoice.Id, invoice.StoreId, + invoice.Metadata.ToJObject()); + count++; + } + + if (invoices.Length < 100) + { + break; + } + + skip += 100; + } + } + + if (count > 0) _logger.LogInformation($"Erased {count} invoice data for store {setting.Key}"); setting.Value.LastRunCutoff = cutoffDate; await SetCore(setting.Key, setting.Value); @@ -114,18 +136,30 @@ namespace BTCPayServer.Plugins.DataErasure _runningLock.Release(); - await Task.Delay(TimeSpan.FromDays(1), cancellationToken); + await Task.Delay(TimeSpan.FromHours(1), _cts.Token); + } + + try + { + _runningLock.Release(); + } + catch (Exception e) + { } } + private CancellationTokenSource _cts; + public Task StartAsync(CancellationToken cancellationToken) { - _ = Run(cancellationToken); + _cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); + _ = Run(); return Task.CompletedTask; } public Task StopAsync(CancellationToken cancellationToken) { + _cts?.Cancel(); return Task.CompletedTask; } } diff --git a/Plugins/BTCPayServer.Plugins.DataErasure/DataErasureSettings.cs b/Plugins/BTCPayServer.Plugins.DataErasure/DataErasureSettings.cs index 94a2dbb..f1256d5 100644 --- a/Plugins/BTCPayServer.Plugins.DataErasure/DataErasureSettings.cs +++ b/Plugins/BTCPayServer.Plugins.DataErasure/DataErasureSettings.cs @@ -7,5 +7,7 @@ namespace BTCPayServer.Plugins.DataErasure public bool Enabled { get; set; } public int DaysToKeep { get; set; } public DateTimeOffset? LastRunCutoff { get; set; } + + public bool EntirelyEraseInvoice { get; set; } } } diff --git a/Plugins/BTCPayServer.Plugins.DataErasure/Views/DataErasure/Update.cshtml b/Plugins/BTCPayServer.Plugins.DataErasure/Views/DataErasure/Update.cshtml index ba39cc4..d4a444d 100644 --- a/Plugins/BTCPayServer.Plugins.DataErasure/Views/DataErasure/Update.cshtml +++ b/Plugins/BTCPayServer.Plugins.DataErasure/Views/DataErasure/Update.cshtml @@ -36,9 +36,24 @@
+
+
+ + + +
+
+

+ Deleting entire invoices may cause issues with integrations and accounting. Only use this option if you are sure you want to remove the invoice entirely. +

+
+
@if (Model.LastRunCutoff != null) {
Cleared data up to @Model.LastRunCutoff.Value.ToString("g")
+
+ +
}
diff --git a/Plugins/BTCPayServer.Plugins.DynamicRateLimits/BTCPayServer.Plugins.DynamicRateLimits.csproj b/Plugins/BTCPayServer.Plugins.DynamicRateLimits/BTCPayServer.Plugins.DynamicRateLimits.csproj index 4688efe..51b218d 100644 --- a/Plugins/BTCPayServer.Plugins.DynamicRateLimits/BTCPayServer.Plugins.DynamicRateLimits.csproj +++ b/Plugins/BTCPayServer.Plugins.DynamicRateLimits/BTCPayServer.Plugins.DynamicRateLimits.csproj @@ -9,7 +9,7 @@ Dynamic Rate Limit Allows you to override the default rate limiting. - 1.0.1 + 1.0.2 true diff --git a/Plugins/BTCPayServer.Plugins.DynamicRateLimits/DynamicRateLimitsPlugin.cs b/Plugins/BTCPayServer.Plugins.DynamicRateLimits/DynamicRateLimitsPlugin.cs index 8ec223d..f579983 100644 --- a/Plugins/BTCPayServer.Plugins.DynamicRateLimits/DynamicRateLimitsPlugin.cs +++ b/Plugins/BTCPayServer.Plugins.DynamicRateLimits/DynamicRateLimitsPlugin.cs @@ -10,7 +10,7 @@ public class DynamicRateLimitsPlugin : BaseBTCPayServerPlugin { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = { - new() { Identifier = nameof(BTCPayServer), Condition = ">=1.12.0" } + new() { Identifier = nameof(BTCPayServer), Condition = ">=2.0.0" } }; public override void Execute(IServiceCollection applicationBuilder) { diff --git a/Plugins/BTCPayServer.Plugins.DynamicRateLimits/Views/DynamicRatesLimiter/Update.cshtml b/Plugins/BTCPayServer.Plugins.DynamicRateLimits/Views/DynamicRatesLimiter/Update.cshtml index e6dea6e..7fecc54 100644 --- a/Plugins/BTCPayServer.Plugins.DynamicRateLimits/Views/DynamicRatesLimiter/Update.cshtml +++ b/Plugins/BTCPayServer.Plugins.DynamicRateLimits/Views/DynamicRatesLimiter/Update.cshtml @@ -1,11 +1,6 @@ @using BTCPayServer.Plugins.DynamicRateLimits @model DynamicRateLimitSettings -@{ - Layout = "../Shared/_NavLayout.cshtml"; - ViewData["NavPartialName"] = "../UIServer/_Nav"; -} -

Rate limit configuration

diff --git a/Plugins/BTCPayServer.Plugins.DynamicRateLimits/Views/Shared/DynamicRateLimitsPlugin/Nav.cshtml b/Plugins/BTCPayServer.Plugins.DynamicRateLimits/Views/Shared/DynamicRateLimitsPlugin/Nav.cshtml index c3a7eee..1df4dd7 100644 --- a/Plugins/BTCPayServer.Plugins.DynamicRateLimits/Views/Shared/DynamicRateLimitsPlugin/Nav.cshtml +++ b/Plugins/BTCPayServer.Plugins.DynamicRateLimits/Views/Shared/DynamicRateLimitsPlugin/Nav.cshtml @@ -1,7 +1,13 @@ +@using BTCPayServer.Client @using BTCPayServer.Plugins.DynamicRateLimits +@using Microsoft.AspNetCore.Mvc.TagHelpers @{ - var isActive = ViewContext.RouteData.Values.TryGetValue("Controller", out var controller) && controller is not null && + var isActive = ViewContext.RouteData.Values.TryGetValue("Controller", out var controller) && controller is not null && nameof(DynamicRatesLimiterController).StartsWith(controller?.ToString(), StringComparison.InvariantCultureIgnoreCase); } -Rate Limits + + \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.DynamicReports/BTCPayServer.Plugins.DynamicReports.csproj b/Plugins/BTCPayServer.Plugins.DynamicReports/BTCPayServer.Plugins.DynamicReports.csproj index a55af6c..c661c84 100644 --- a/Plugins/BTCPayServer.Plugins.DynamicReports/BTCPayServer.Plugins.DynamicReports.csproj +++ b/Plugins/BTCPayServer.Plugins.DynamicReports/BTCPayServer.Plugins.DynamicReports.csproj @@ -9,7 +9,7 @@ Dynamic Reports Allows you to create custom reports using SQL. - 1.0.1 + 1.0.2 true diff --git a/Plugins/BTCPayServer.Plugins.DynamicReports/DynamicReportsPlugin.cs b/Plugins/BTCPayServer.Plugins.DynamicReports/DynamicReportsPlugin.cs index 495c19b..f78589c 100644 --- a/Plugins/BTCPayServer.Plugins.DynamicReports/DynamicReportsPlugin.cs +++ b/Plugins/BTCPayServer.Plugins.DynamicReports/DynamicReportsPlugin.cs @@ -10,7 +10,7 @@ public class DynamicReportsPlugin : BaseBTCPayServerPlugin { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = { - new() { Identifier = nameof(BTCPayServer), Condition = ">=1.13.0" } + new() { Identifier = nameof(BTCPayServer), Condition = ">=2.0.0" } }; public override void Execute(IServiceCollection applicationBuilder) { diff --git a/Plugins/BTCPayServer.Plugins.DynamicReports/PostgresReportProvider.cs b/Plugins/BTCPayServer.Plugins.DynamicReports/PostgresReportProvider.cs index 0e47df3..a9dea8d 100644 --- a/Plugins/BTCPayServer.Plugins.DynamicReports/PostgresReportProvider.cs +++ b/Plugins/BTCPayServer.Plugins.DynamicReports/PostgresReportProvider.cs @@ -21,19 +21,15 @@ public class PostgresReportProvider : ReportProvider public DynamicReportsSettings.DynamicReportSetting Setting { get; set; } private readonly ApplicationDbContextFactory _dbContextFactory; - private readonly IOptions _options; private readonly IHttpContextAccessor _httpContextAccessor; - public PostgresReportProvider( ApplicationDbContextFactory dbContextFactory, - IOptions options, IHttpContextAccessor httpContextAccessor) + public PostgresReportProvider( ApplicationDbContextFactory dbContextFactory, IHttpContextAccessor httpContextAccessor) { _dbContextFactory = dbContextFactory; - _options = options; _httpContextAccessor = httpContextAccessor; } public override bool IsAvailable() { - return _options.Value.DatabaseType == DatabaseType.Postgres && - Setting.AllowForNonAdmins || _httpContextAccessor.HttpContext?.User.IsInRole(Roles.ServerAdmin) is true; + return Setting.AllowForNonAdmins || _httpContextAccessor.HttpContext?.User.IsInRole(Roles.ServerAdmin) is true; } public override async Task Query(QueryContext queryContext, CancellationToken cancellation) { diff --git a/Plugins/BTCPayServer.Plugins.DynamicReports/Views/DynamicReports/Update.cshtml b/Plugins/BTCPayServer.Plugins.DynamicReports/Views/DynamicReports/Update.cshtml index 0794b62..024ba42 100644 --- a/Plugins/BTCPayServer.Plugins.DynamicReports/Views/DynamicReports/Update.cshtml +++ b/Plugins/BTCPayServer.Plugins.DynamicReports/Views/DynamicReports/Update.cshtml @@ -10,8 +10,6 @@ @inject DynamicReportService DynamicReportService @{ - Layout = "../Shared/_NavLayout.cshtml"; - ViewData["NavPartialName"] = "../UIServer/_Nav"; var storeId = ScopeProvider.GetCurrentStoreId(); var reportName = Context.Request.Query["reportName"].ToString(); reportName = string.IsNullOrEmpty(reportName) ? null : reportName; diff --git a/Plugins/BTCPayServer.Plugins.DynamicReports/Views/Shared/DynamicReportsPlugin/Nav.cshtml b/Plugins/BTCPayServer.Plugins.DynamicReports/Views/Shared/DynamicReportsPlugin/Nav.cshtml index f10a28c..0380119 100644 --- a/Plugins/BTCPayServer.Plugins.DynamicReports/Views/Shared/DynamicReportsPlugin/Nav.cshtml +++ b/Plugins/BTCPayServer.Plugins.DynamicReports/Views/Shared/DynamicReportsPlugin/Nav.cshtml @@ -1,8 +1,15 @@ +@using BTCPayServer.Client @using BTCPayServer.Plugins.DynamicReports +@using Microsoft.AspNetCore.Mvc.TagHelpers @{ var isActive = ViewContext.RouteData.Values.TryGetValue("Controller", out var controller) && controller is not null && nameof(DynamicReportsController).StartsWith(controller?.ToString(), StringComparison.InvariantCultureIgnoreCase); } -Dynamic Reports + + + diff --git a/Plugins/BTCPayServer.Plugins.FileSeller/BTCPayServer.Plugins.FileSeller.csproj b/Plugins/BTCPayServer.Plugins.FileSeller/BTCPayServer.Plugins.FileSeller.csproj index 325043b..3b54d35 100644 --- a/Plugins/BTCPayServer.Plugins.FileSeller/BTCPayServer.Plugins.FileSeller.csproj +++ b/Plugins/BTCPayServer.Plugins.FileSeller/BTCPayServer.Plugins.FileSeller.csproj @@ -9,7 +9,7 @@ File Seller Allows you to sell files through the point of sale/crowdfund apps. - 1.0.4 + 1.0.5 true diff --git a/Plugins/BTCPayServer.Plugins.FileSeller/FileSellerPlugin.cs b/Plugins/BTCPayServer.Plugins.FileSeller/FileSellerPlugin.cs index e2731bb..0dbed6d 100644 --- a/Plugins/BTCPayServer.Plugins.FileSeller/FileSellerPlugin.cs +++ b/Plugins/BTCPayServer.Plugins.FileSeller/FileSellerPlugin.cs @@ -9,8 +9,9 @@ public class FileSellerPlugin : BaseBTCPayServerPlugin { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = { - new() { Identifier = nameof(BTCPayServer), Condition = ">=1.12.0" } + new() {Identifier = nameof(BTCPayServer), Condition = ">=2.0.0"} }; + public override void Execute(IServiceCollection applicationBuilder) { applicationBuilder.AddHostedService(); @@ -20,7 +21,7 @@ public class FileSellerPlugin : BaseBTCPayServerPlugin "checkout-end")); applicationBuilder.AddSingleton(new UIExtension("FileSeller/FileSellerTemplateEditorItemDetail", "app-template-editor-item-detail")); - + base.Execute(applicationBuilder); } diff --git a/Plugins/BTCPayServer.Plugins.FileSeller/Views/Shared/FileSeller/FileSellerTemplateEditorItemDetail.cshtml b/Plugins/BTCPayServer.Plugins.FileSeller/Views/Shared/FileSeller/FileSellerTemplateEditorItemDetail.cshtml index f7c1d57..6f0941f 100644 --- a/Plugins/BTCPayServer.Plugins.FileSeller/Views/Shared/FileSeller/FileSellerTemplateEditorItemDetail.cshtml +++ b/Plugins/BTCPayServer.Plugins.FileSeller/Views/Shared/FileSeller/FileSellerTemplateEditorItemDetail.cshtml @@ -6,16 +6,16 @@ @inject UserManager UserManager @inject UserService UserService @{ - var userId = UserManager.GetUserId(User); + var user = await UserManager.GetUserAsync(User); var files = (await StoredFileRepository.GetFiles(new StoredFileRepository.FilesQuery() { - UserIds = await UserService.IsAdminUser(userId) ? Array.Empty() : new[] {userId}, + UserIds = await UserService.IsAdminUser(user) ? Array.Empty() : new[] {user.Id}, })).Select(file => new SelectListItem(file.FileName, file.Id)).Prepend(new SelectListItem("No file", "")); } \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/BTCPayServer.Plugins.FixedFloat.csproj b/Plugins/BTCPayServer.Plugins.FixedFloat/BTCPayServer.Plugins.FixedFloat.csproj index 61bf667..a763c07 100644 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/BTCPayServer.Plugins.FixedFloat.csproj +++ b/Plugins/BTCPayServer.Plugins.FixedFloat/BTCPayServer.Plugins.FixedFloat.csproj @@ -9,7 +9,7 @@ FixedFloat Allows you to embed a FixedFloat conversion screen to allow customers to pay with altcoins. - 1.1.7 + 1.1.8 true diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatPlugin.cs b/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatPlugin.cs index 93f340d..e1ba5cd 100644 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatPlugin.cs +++ b/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatPlugin.cs @@ -9,29 +9,16 @@ namespace BTCPayServer.Plugins.FixedFloat { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = { - new() { Identifier = nameof(BTCPayServer), Condition = ">=1.12.0" } + new() { Identifier = nameof(BTCPayServer), Condition = ">=2.0.0" } + }; public override void Execute(IServiceCollection applicationBuilder) { applicationBuilder.AddSingleton(); - applicationBuilder.AddSingleton(new UIExtension("FixedFloat/FixedFloatNav", - "store-integrations-nav")); - // Checkout v2 - applicationBuilder.AddSingleton(new UIExtension("FixedFloat/CheckoutPaymentMethodExtension", - "checkout-payment-method")); - applicationBuilder.AddSingleton(new UIExtension("FixedFloat/CheckoutPaymentExtension", - "checkout-payment")); - // Checkout Classic - applicationBuilder.AddSingleton(new UIExtension("FixedFloat/CheckoutContentExtension", - "checkout-bitcoin-post-content")); - applicationBuilder.AddSingleton(new UIExtension("FixedFloat/CheckoutContentExtension", - "checkout-lightning-post-content")); - applicationBuilder.AddSingleton(new UIExtension("FixedFloat/CheckoutTabExtension", - "checkout-bitcoin-post-tabs")); - applicationBuilder.AddSingleton(new UIExtension("FixedFloat/CheckoutTabExtension", - "checkout-lightning-post-tabs")); - applicationBuilder.AddSingleton(new UIExtension("FixedFloat/CheckoutEnd", - "checkout-end")); + applicationBuilder.AddUIExtension("store-integrations-nav", "FixedFloat/FixedFloatNav"); + applicationBuilder.AddUIExtension("checkout-payment-method", "FixedFloat/CheckoutPaymentMethodExtension"); + applicationBuilder.AddUIExtension("checkout-payment", "FixedFloat/CheckoutPaymentExtension"); + base.Execute(applicationBuilder); } } diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatSettings.cs b/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatSettings.cs index eae7714..a2d8883 100644 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatSettings.cs +++ b/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatSettings.cs @@ -20,56 +20,70 @@ namespace BTCPayServer.Plugins.FixedFloat { {"AAVEETH", "Aave (ERC20)"}, {"ADA", "Cardano"}, + {"ADABSC", "Cardano (BEP20)"}, + {"APT", "Aptos"}, {"ATOM", "Cosmos"}, {"AVAX", "Avalanche (C-Chain)"}, {"BAT", "Basic Attention (ERC20)"}, - {"BCH", "Bitcoin Cash"}, - {"BNB", "BNB Beacon Chain (BEP2)"}, {"BSC", "BNB Smart Chain (BEP20)"}, + {"WBNBBSC", "Wrapped BNB (BEP20)"}, {"BTC", "Bitcoin"}, + {"BTCBSC", "Bitcoin (BEP20)"}, {"BTCLN", "Bitcoin (Lightning)"}, {"BTT", "BitTorrent"}, - {"BUSD", "Binance USD (BEP2)"}, - {"BUSDBSC", "Binance USD (BEP20)"}, - {"BUSDETH", "Binance USD (ERC20)"}, {"CAKE", "PancakeSwap (BEP20)"}, + {"DAIBSC", "DAI (BEP20)"}, {"DAIETH", "DAI (ERC20)"}, + {"DAIMATIC", "DAI (Polygon)"}, + {"DASH", "Dash"}, {"DOGE", "Dogecoin"}, {"DOT", "Polkadot"}, {"EOS", "EOS"}, - {"ETC", "Ethereum Classic"}, {"ETH", "Ethereum"}, + {"ETHARBITRUM", "Ethereum (Arbitrum)"}, + {"ETHBASE", "Ethereum (Base)"}, + {"ETHZKSYNC", "Ethereum (ZkSync)"}, + {"WETHARBITRUM", "Wrapped ETH (Arbitrum)"}, + {"WETHETH", "Wrapped ETH (ERC20)"}, {"FTM", "Fantom"}, + {"KCS", "KuCoin Token"}, {"LINK", "Chainlink (ERC20)"}, {"LTC", "Litecoin"}, {"MANAETH", "Decentraland (ERC20)"}, - {"MATIC", "Polygon"}, - {"MATICETH", "Polygon (ERC20)"}, {"MKR", "Maker (ERC20)"}, + {"PAXGETH", "PAX Gold (ERC20)"}, + {"POL", "Polygon"}, + {"POLETH", "Polygon (ERC20)"}, {"SHIB", "SHIBA INU (ERC20)"}, + {"SHIBBSC", "SHIBA INU (BEP20)"}, {"SOL", "Solana"}, + {"WSOL", "Wrapped SOL (Solana)"}, {"TON", "Toncoin"}, {"TRX", "Tron"}, {"TUSD", "TrueUSD (ERC20)"}, - {"TWT", "Trust Wallet Token (BEP2)"}, {"TWTBSC", "Trust Wallet Token (BEP20)"}, + {"USDCARBITRUM", "USD Coin (Arbitrum)"}, + {"USDCBSC", "USD Coin (BEP20)"}, {"USDCETH", "USD Coin (ERC20)"}, + {"USDCMATIC", "USD Coin (Polygon)"}, {"USDCSOL", "USD Coin (Solana)"}, - {"USDCTRC", "USD Coin (TRC20)"}, {"USDP", "Pax Dollar (ERC20)"}, {"USDT", "Tether (ERC20)"}, + {"USDTBSC", "Tether (BEP20)"}, + {"USDTMATIC", "Tether (Polygon)"}, {"USDTSOL", "Tether (Solana)"}, {"USDTTRC", "Tether (TRC20)"}, {"VET", "VeChain"}, + {"XLM", "Stellar Lumens"}, {"XMR", "Monero"}, {"XRP", "Ripple"}, {"XTZ", "Tezos"}, {"ZEC", "Zcash"}, {"ZRX", "0x (ERC20)"} }; - - public static List AllowedSendingOptionsList => AllowedSendingOptions.Select(o => new SelectListItem(o.Value, o.Key)).ToList(); + public static List AllowedSendingOptionsList => + AllowedSendingOptions.Select(o => new SelectListItem(o.Value, o.Key)).ToList(); } -} +} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/FixedFloat/UpdateFixedFloatSettings.cshtml b/Plugins/BTCPayServer.Plugins.FixedFloat/Views/FixedFloat/UpdateFixedFloatSettings.cshtml index 94163bd..6fd5b6f 100644 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/FixedFloat/UpdateFixedFloatSettings.cshtml +++ b/Plugins/BTCPayServer.Plugins.FixedFloat/Views/FixedFloat/UpdateFixedFloatSettings.cshtml @@ -2,15 +2,17 @@ @using BTCPayServer.Abstractions.Extensions @using BTCPayServer.Data @using BTCPayServer.Plugins.FixedFloat +@using BTCPayServer.Services.Invoices @using BTCPayServer.Services.Stores @using Microsoft.AspNetCore.Mvc.TagHelpers @model BTCPayServer.Plugins.FixedFloat.FixedFloatSettings @inject BTCPayNetworkProvider BTCPayNetworkProvider +@inject PaymentMethodHandlerDictionary PaymentMethodHandlerDictionary @{ ViewData.SetActivePage("FixedFloat", "FixedFloat", "FixedFloat"); var store = Context.GetStoreData(); - var allowedPaymentMethods = store.GetEnabledPaymentIds(BTCPayNetworkProvider) - .Select(pmi => new SelectListItem(pmi.ToPrettyString(), pmi.ToString())) + var allowedPaymentMethods = store.GetEnabledPaymentIds() + .Select(pmi => new SelectListItem(pmi.ToString(), pmi.ToString())) .Prepend(new SelectListItem("Any", "")); } diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutContentExtension.cshtml b/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutContentExtension.cshtml deleted file mode 100644 index c315ebf..0000000 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutContentExtension.cshtml +++ /dev/null @@ -1,19 +0,0 @@ -@using BTCPayServer.Plugins.FixedFloat -@model BTCPayServer.Models.InvoicingModels.PaymentModel -@inject FixedFloatService FixedFloatService -@{ - var storeId = Model.StoreId; - var settings = await FixedFloatService.GetFixedFloatForStore(storeId); - - if (settings?.Enabled is true) - { -
- - - -
- } -} diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutEnd.cshtml b/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutEnd.cshtml deleted file mode 100644 index 1796f6e..0000000 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutEnd.cshtml +++ /dev/null @@ -1,12 +0,0 @@ -@using BTCPayServer.Plugins.FixedFloat -@using Newtonsoft.Json -@using Newtonsoft.Json.Linq -@inject FixedFloatService FixedFloatService -@{ - var storeId = ((JObject)JObject.Parse(JsonConvert.SerializeObject(Model)))["StoreId"].Value(); - var settings = await FixedFloatService.GetFixedFloatForStore(storeId); - if (settings?.Enabled is true) - { - - } -} diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutPaymentExtension.cshtml b/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutPaymentExtension.cshtml index 443d5c0..8fbceef 100644 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutPaymentExtension.cshtml +++ b/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutPaymentExtension.cshtml @@ -1,10 +1,15 @@ +@using BTCPayServer.Abstractions.TagHelpers +@using BTCPayServer.Payments @using BTCPayServer.Plugins.FixedFloat @inject FixedFloatService FixedFloatService -@model BTCPayServer.Models.InvoicingModels.PaymentModel +@model BTCPayServer.Models.InvoicingModels.CheckoutModel @{ var storeId = Model.StoreId; var settings = await FixedFloatService.GetFixedFloatForStore(storeId); - var preferredTargetPaymentMethodId = string.IsNullOrEmpty(settings?.PreferredTargetPaymentMethodId) ? null : Model.AvailableCryptos.Any(crypto => crypto.PaymentMethodId == settings.PreferredTargetPaymentMethodId) ? settings.PreferredTargetPaymentMethodId : null; + var preferredTargetPaymentMethodId = + string.IsNullOrEmpty(settings?.PreferredTargetPaymentMethodId) ? null : + Model.AvailablePaymentMethods.Any(crypto => crypto.PaymentMethodId.ToString() == PaymentMethodId.TryParse(settings.PreferredTargetPaymentMethodId)?.ToString()) ? + settings.PreferredTargetPaymentMethodId : null; } @if (settings?.Enabled is true) { @@ -41,7 +46,7 @@ const result = this.$parent.paymentMethodId === "FixedFloat"; if(this.preferredToCurrency && this.model.paymentMethodId !== this.preferredToCurrency){ - if (this.model.onChainWithLnInvoiceFallback && this.model.paymentMethodId === "BTC"){ + if (this.model.onChainWithLnInvoiceFallback && this.model.paymentMethodId === "BTC-CHAIN"){ return result; } this.$parent.paymentMethodId = this.preferredToCurrency; @@ -53,7 +58,7 @@ return result; }, lightning () { - if (!this.model.onChainWithLnInvoiceFallback || this.model.paymentMethodId !== "BTC"){ + if (!this.model.onChainWithLnInvoiceFallback || this.model.paymentMethodId !== "BTC-CHAIN"){ return null; } const index = this.model.invoiceBitcoinUrl.indexOf("lightning="); @@ -63,9 +68,9 @@ return this.model.invoiceBitcoinUrl.slice(index + "lightning=".length); }, url () { - - const address= this.lightning || this.model.btcAddress; - return "https://widget.fixedfloat.com/?" + + debugger; + const address= this.lightning || this.model.address; + return "https://widget.ff.io/?" + `to=${this.settleMethodId}` + "&lockReceive=true&ref=fkbyt39c" + `&address=${address}` + @@ -76,9 +81,9 @@ return this.model.paymentMethodId; }, settleMethodId () { - return this.currency.endsWith('LightningLike') || this.currency.endsWith('LNURLPay') || this.lightning + return this.currency.endsWith('LN') || this.currency.endsWith('LNURL') || this.lightning ? 'BTCLN' - : this.currency.replace('_BTCLike', '').replace('_MoneroLike', '').replace('_ZcashLike', '').toUpperCase(); + : this.currency.replace('-CHAIN', '').replace('_CHAIN', '').toUpperCase(); }, explicitQuery (){ const isExplicit = !!this.explicitId; @@ -91,7 +96,7 @@ : `&lockType=true&hideType=true&lockAmount=true&toAmount=${this.amountDue}`; }, amountDue () { - return this.model.btcDue * (1 + (markupPercentage / 100)); + return this.model.due * (1 + (markupPercentage / 100)); } } }); diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutPaymentMethodExtension.cshtml b/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutPaymentMethodExtension.cshtml index 1401d4a..7b2209e 100644 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutPaymentMethodExtension.cshtml +++ b/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutPaymentMethodExtension.cshtml @@ -1,5 +1,5 @@ @using BTCPayServer.Plugins.FixedFloat -@model BTCPayServer.Models.InvoicingModels.PaymentModel +@model BTCPayServer.Models.InvoicingModels.CheckoutModel @inject FixedFloatService FixedFloatService @{ const string id = "FixedFloat"; diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutTabExtension.cshtml b/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutTabExtension.cshtml deleted file mode 100644 index 13dce2e..0000000 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutTabExtension.cshtml +++ /dev/null @@ -1,13 +0,0 @@ -@using BTCPayServer.Plugins.FixedFloat -@model BTCPayServer.Models.InvoicingModels.PaymentModel -@inject FixedFloatService FixedFloatService -@{ - var storeId = Model.StoreId; - var settings = await FixedFloatService.GetFixedFloatForStore(storeId); - if (settings?.Enabled is true) - { -
- {{$t("Altcoins (FixedFloat)")}} -
- } -} diff --git a/Plugins/BTCPayServer.Plugins.LDK/BTCPayServer.Plugins.LDK.csproj b/Plugins/BTCPayServer.Plugins.LDK/BTCPayServer.Plugins.LDK.csproj deleted file mode 100644 index 090a82f..0000000 --- a/Plugins/BTCPayServer.Plugins.LDK/BTCPayServer.Plugins.LDK.csproj +++ /dev/null @@ -1,43 +0,0 @@ - - - - net8.0 - 10 - - - - - LDK - The way lightning's meant to be - 1.0.0 -true - - - - true - false - true - - - - - - StaticWebAssetsEnabled=false - false - runtime;native;build;buildTransitive;contentFiles - - - - - - - - - - - - - - - - diff --git a/Plugins/BTCPayServer.Plugins.LDK/Program.cs b/Plugins/BTCPayServer.Plugins.LDK/Program.cs deleted file mode 100644 index 24c775c..0000000 --- a/Plugins/BTCPayServer.Plugins.LDK/Program.cs +++ /dev/null @@ -1,232 +0,0 @@ -using System; -using System.IO; -using System.Threading; -using System.Threading.Tasks; -using Amazon.Runtime.Internal.Util; -using BTCPayServer; -using BTCPayServer.Abstractions.Models; -using BTCPayServer.Configuration; -using BTCPayServer.Services; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using NBitcoin; -using NBXplorer; -using org.ldk.enums; -using org.ldk.structs; -using enums_Network = org.ldk.enums.Network; -using ILogger = Microsoft.Extensions.Logging.ILogger; -using Logger = org.ldk.structs.Logger; -using Network = NBitcoin.Network; -using OutPoint = org.ldk.structs.OutPoint; -using Path = System.IO.Path; - -public class LDKService : IHostedService, PersistInterface, BroadcasterInterfaceInterface, FeeEstimatorInterface, EventHandlerInterface, LoggerInterface, FilterInterface -{ - private readonly ILogger _logger; - private readonly IFeeProviderFactory _feeProviderFactory; - private readonly IOptions _dataDirectories; - private readonly BTCPayNetwork _network; - private readonly ExplorerClient _explorerClient; - private readonly string _workDir; - private readonly enums_Network _ldkNetwork; - private readonly Logger _ldklogger; - private readonly FeeEstimator _ldkfeeEstimator; - private readonly BroadcasterInterface _ldkbroadcaster; - private readonly Persist _ldkpersist; - private readonly Filter _ldkfilter; - private readonly NetworkGraph _ldkNetworkGraph; - private readonly ChainMonitor _ldkChainMonitor; - - public LDKService(BTCPayNetworkProvider btcPayNetworkProvider, - ExplorerClientProvider explorerClientProvider, - ILogger logger, - IFeeProviderFactory feeProviderFactory, - IOptions dataDirectories) - { - _logger = logger; - _feeProviderFactory = feeProviderFactory; - _dataDirectories = dataDirectories; - - _network = btcPayNetworkProvider.GetNetwork("BTC"); - _explorerClient = explorerClientProvider.GetExplorerClient(_network); - _workDir = GetWorkDir(); - Directory.CreateDirectory(_workDir); - - _ldkNetwork = GetLdkNetwork(_network.NBitcoinNetwork); - _ldklogger = Logger.new_impl(this); - _ldkfeeEstimator = FeeEstimator.new_impl(this); - _ldkbroadcaster = BroadcasterInterface.new_impl(this); - _ldkpersist = Persist.new_impl(this); - _ldkfilter = Filter.new_impl(this); - - _ldkNetworkGraph = NetworkGraph.of(_ldkNetwork, _ldklogger); - _ldkChainMonitor = ChainMonitor.of( Option_FilterZ.Option_FilterZ_Some.some(_ldkfilter), _ldkbroadcaster, _ldklogger, _ldkfeeEstimator, _ldkpersist); - } - - - private static enums_Network GetLdkNetwork(Network network) - { - enums_Network? ldkNetwork = null; - if (network.ChainName == ChainName.Mainnet) - ldkNetwork = org.ldk.enums.Network.LDKNetwork_Bitcoin; - else if (network.ChainName == ChainName.Testnet) - ldkNetwork = org.ldk.enums.Network.LDKNetwork_Testnet; - else if (network.ChainName == ChainName.Regtest) - ldkNetwork = org.ldk.enums.Network.LDKNetwork_Regtest; - - return ldkNetwork ?? throw new NotSupportedException(); - } - - - private string GetWorkDir() - { - var dir = _dataDirectories.Value.DataDir; - return Path.Combine(dir, "Plugins", "LDK"); - } - - public async Task StartAsync(CancellationToken cancellationToken) - { - } - - public async Task StopAsync(CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - - public int get_est_sat_per_1000_weight(ConfirmationTarget confirmation_target) - { - var feeProvider = _feeProviderFactory.CreateFeeProvider(_network); - var targetBlocks = confirmation_target switch - { - ConfirmationTarget.LDKConfirmationTarget_OnChainSweep => 30, // High priority (10-50 blocks) - ConfirmationTarget - .LDKConfirmationTarget_MaxAllowedNonAnchorChannelRemoteFee => - 20, // Moderate to high priority (small multiple of high-priority estimate) - ConfirmationTarget - .LDKConfirmationTarget_MinAllowedAnchorChannelRemoteFee => - 12, // Moderate priority (long-term mempool minimum or medium-priority) - ConfirmationTarget - .LDKConfirmationTarget_MinAllowedNonAnchorChannelRemoteFee => - 12, // Moderate priority (medium-priority feerate) - ConfirmationTarget.LDKConfirmationTarget_AnchorChannelFee => 6, // Lower priority (can be bumped later) - ConfirmationTarget - .LDKConfirmationTarget_NonAnchorChannelFee => 20, // Moderate to high priority (high-priority feerate) - ConfirmationTarget.LDKConfirmationTarget_ChannelCloseMinimum => 144, // Within a day or so (144-250 blocks) - _ => throw new ArgumentOutOfRangeException(nameof(confirmation_target), confirmation_target, null) - }; - return (int) Math.Max(253, feeProvider.GetFeeRateAsync(targetBlocks).GetAwaiter().GetResult().FeePerK.Satoshi); - } - - public void log(Record record) - { - var level = record.get_level() switch - { - Level.LDKLevel_Trace => LogLevel.Trace, - Level.LDKLevel_Debug => LogLevel.Debug, - Level.LDKLevel_Info => LogLevel.Information, - Level.LDKLevel_Warn => LogLevel.Warning, - Level.LDKLevel_Error => LogLevel.Error, - Level.LDKLevel_Gossip => LogLevel.Trace, - }; - _logger.Log(level, $"[{record.get_module_path()}] {record.get_args()}"); - } - - public void broadcast_transactions(byte[][] txs) - { - foreach (var tx in txs) - { - var loadedTx = Transaction.Load(tx, _explorerClient.Network.NBitcoinNetwork); - - _explorerClient.Broadcast(loadedTx); - } - } - - - public ChannelMonitorUpdateStatus persist_new_channel(OutPoint channel_id, ChannelMonitor data, - MonitorUpdateId update_id) - { - var name = Convert.ToHexString(channel_id.write()); - File.WriteAllBytes(Path.Combine(_workDir, name), data.write()); - return ChannelMonitorUpdateStatus.LDKChannelMonitorUpdateStatus_Completed; - } - - public ChannelMonitorUpdateStatus update_persisted_channel(OutPoint channel_id, ChannelMonitorUpdate update, - ChannelMonitor data, MonitorUpdateId update_id) - { - var name = Convert.ToHexString(channel_id.write()); - File.WriteAllBytes(Path.Combine(_workDir, name), data.write()); - return ChannelMonitorUpdateStatus.LDKChannelMonitorUpdateStatus_Completed; - } - - public void handle_event(Event _event) - { - switch (_event) - { - case Event.Event_BumpTransaction eventBumpTransaction: - switch (eventBumpTransaction.bump_transaction) - { - case BumpTransactionEvent.BumpTransactionEvent_ChannelClose bumpTransactionEventChannelClose: - break; - case BumpTransactionEvent.BumpTransactionEvent_HTLCResolution bumpTransactionEventHtlcResolution: - break; - default: - throw new ArgumentOutOfRangeException(); - } - - break; - case Event.Event_ChannelClosed eventChannelClosed: - break; - case Event.Event_ChannelPending eventChannelPending: - break; - case Event.Event_ChannelReady eventChannelReady: - break; - case Event.Event_DiscardFunding eventDiscardFunding: - break; - case Event.Event_FundingGenerationReady eventFundingGenerationReady: - break; - case Event.Event_HTLCHandlingFailed eventHtlcHandlingFailed: - break; - case Event.Event_HTLCIntercepted eventHtlcIntercepted: - break; - case Event.Event_InvoiceRequestFailed eventInvoiceRequestFailed: - break; - case Event.Event_OpenChannelRequest eventOpenChannelRequest: - break; - case Event.Event_PaymentClaimable eventPaymentClaimable: - break; - case Event.Event_PaymentClaimed eventPaymentClaimed: - break; - case Event.Event_PaymentFailed eventPaymentFailed: - break; - case Event.Event_PaymentForwarded eventPaymentForwarded: - break; - case Event.Event_PaymentPathFailed eventPaymentPathFailed: - break; - case Event.Event_PaymentPathSuccessful eventPaymentPathSuccessful: - break; - case Event.Event_PaymentSent eventPaymentSent: - break; - case Event.Event_PendingHTLCsForwardable eventPendingHtlCsForwardable: - break; - case Event.Event_ProbeFailed eventProbeFailed: - break; - case Event.Event_ProbeSuccessful eventProbeSuccessful: - break; - case Event.Event_SpendableOutputs eventSpendableOutputs: - break; - default: - throw new ArgumentOutOfRangeException(nameof(_event)); - } - } - - public void register_tx(byte[] txid, byte[] script_pubkey) - { - throw new NotImplementedException(); - } - - public void register_output(WatchedOutput output) - { - throw new NotImplementedException(); - } -} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.LiquidPlus/BTCPayServer.Plugins.LiquidPlus.csproj b/Plugins/BTCPayServer.Plugins.LiquidPlus/BTCPayServer.Plugins.LiquidPlus.csproj index f89445d..e0a5867 100644 --- a/Plugins/BTCPayServer.Plugins.LiquidPlus/BTCPayServer.Plugins.LiquidPlus.csproj +++ b/Plugins/BTCPayServer.Plugins.LiquidPlus/BTCPayServer.Plugins.LiquidPlus.csproj @@ -12,7 +12,7 @@ Liquid+ Enhanced support for the liquid network. - 1.1.4 + 1.1.5 true diff --git a/Plugins/BTCPayServer.Plugins.LiquidPlus/Controllers/StoreLiquidController.cs b/Plugins/BTCPayServer.Plugins.LiquidPlus/Controllers/StoreLiquidController.cs index 78196c7..b3fc3aa 100644 --- a/Plugins/BTCPayServer.Plugins.LiquidPlus/Controllers/StoreLiquidController.cs +++ b/Plugins/BTCPayServer.Plugins.LiquidPlus/Controllers/StoreLiquidController.cs @@ -10,7 +10,10 @@ using BTCPayServer.Abstractions.Extensions; using BTCPayServer.Abstractions.Models; using BTCPayServer.Client; using BTCPayServer.Common; +using BTCPayServer.Data; using BTCPayServer.Plugins.Altcoins; +using BTCPayServer.Services.Invoices; +using BTCPayServer.Services.Stores; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ViewFeatures; @@ -25,20 +28,24 @@ namespace BTCPayServer.Plugins.LiquidPlus.Controllers [AutoValidateAntiforgeryToken] public class StoreLiquidController : Controller { + private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary; + private readonly StoreRepository _storeRepository; private readonly BTCPayNetworkProvider _btcPayNetworkProvider; - private readonly BTCPayServerClient _client; private readonly IExplorerClientProvider _explorerClientProvider; - public StoreLiquidController(BTCPayNetworkProvider btcPayNetworkProvider, - BTCPayServerClient client, IExplorerClientProvider explorerClientProvider) + public StoreLiquidController(PaymentMethodHandlerDictionary paymentMethodHandlerDictionary, + StoreRepository storeRepository, BTCPayNetworkProvider btcPayNetworkProvider, + IExplorerClientProvider explorerClientProvider) { + _paymentMethodHandlerDictionary = paymentMethodHandlerDictionary; + _storeRepository = storeRepository; _btcPayNetworkProvider = btcPayNetworkProvider; - _client = client; _explorerClientProvider = explorerClientProvider; } [HttpGet("stores/{storeId}/liquid")] - public async Task GenerateLiquidScript(string storeId, Dictionary bitcoinExtKeys = null) + public async Task GenerateLiquidScript(string storeId, + Dictionary bitcoinExtKeys = null) { Dictionary generated = new Dictionary(); var allNetworks = _btcPayNetworkProvider.GetAll().OfType() @@ -48,13 +55,20 @@ namespace BTCPayServer.Plugins.LiquidPlus.Controllers .ToArray() .Distinct(); Dictionary privKeys = bitcoinExtKeys ?? new Dictionary(); - - - var paymentMethods = (await _client.GetStoreOnChainPaymentMethods(storeId)) - .Where(settings => allNetworkCodes.Contains(settings.CryptoCode)) - .GroupBy(data => _btcPayNetworkProvider.GetNetwork(data.CryptoCode).NetworkCryptoCode); - if (paymentMethods.Any() is false) + var store = await _storeRepository.FindStore(storeId); + var pms = store + .GetPaymentMethodConfigs(_paymentMethodHandlerDictionary) + .Select(pair => (PaymentMethodId: pair.Key, DerivationSchemeSettings: pair.Value, + CryptoCode: pair.Key.ToString().Split("-")[0])).ToArray(); + + var paymentMethodsGroupedByNetworkCode = + pms + .Where(settings => allNetworkCodes.Contains(settings.CryptoCode)) + .GroupBy(data => + _btcPayNetworkProvider.GetNetwork(data.CryptoCode).NetworkCryptoCode); + + if (paymentMethodsGroupedByNetworkCode.Any() is false) { TempData.SetStatusMessageModel(new StatusMessageModel() { @@ -63,12 +77,12 @@ namespace BTCPayServer.Plugins.LiquidPlus.Controllers }); return View(new GenerateLiquidImportScripts()); } - - foreach (var der in paymentMethods) + + foreach (var der in paymentMethodsGroupedByNetworkCode) { var network = _btcPayNetworkProvider.GetNetwork(der.Key); var nbxnet = network.NBXplorerNetwork; - + var sb = new StringBuilder(); var explorerClient = _explorerClientProvider.GetExplorerClient(der.Key); @@ -79,12 +93,12 @@ namespace BTCPayServer.Plugins.LiquidPlus.Controllers generated.Add(der.Key, sb.ToString()); continue; } - var derivationSchemesForNetwork = der.GroupBy(data => data.DerivationScheme); - + + var derivationSchemesForNetwork = der.GroupBy(data => data.DerivationSchemeSettings); + foreach (var paymentMethodDerivationScheme in derivationSchemesForNetwork) { - var derivatonScheme = - nbxnet.DerivationStrategyFactory.Parse(paymentMethodDerivationScheme.Key); + var derivatonScheme = paymentMethodDerivationScheme.Key.AccountDerivation; var sameWalletCryptoCodes = paymentMethodDerivationScheme.Select(data => data.CryptoCode).ToArray(); var matchedExistingKey = privKeys.Where(pair => sameWalletCryptoCodes.Contains(pair.Key)); BitcoinExtKey key = null; @@ -94,22 +108,20 @@ namespace BTCPayServer.Plugins.LiquidPlus.Controllers } else { - key = await explorerClient.GetMetadataAsync(derivatonScheme, WellknownMetadataKeys.AccountHDKey); } if (key != null) { - foreach (var paymentMethodData in paymentMethodDerivationScheme) - { - privKeys.TryAdd(paymentMethodData.CryptoCode, key); - } + { + privKeys.TryAdd(paymentMethodData.CryptoCode, key); + } } var utxos = await explorerClient.GetUTXOsAsync(derivatonScheme, CancellationToken.None); - + foreach (var utxo in utxos.GetUnspentUTXOs()) { var addr = nbxnet.CreateAddress(derivatonScheme, utxo.KeyPath, utxo.ScriptPubKey); @@ -139,21 +151,21 @@ namespace BTCPayServer.Plugins.LiquidPlus.Controllers { sb.AppendLine("elements-cli stop"); sb.AppendLine("elementsd -rescan"); - } + generated.Add(der.Key, sb.ToString()); } return View(new GenerateLiquidImportScripts() { - Wallets = paymentMethods.SelectMany(settings => - settings.Select(data => - new GenerateLiquidImportScripts.GenerateLiquidImportScriptWalletKeyVm() - { - CryptoCode = data.CryptoCode, - KeyPresent = privKeys.ContainsKey(data.CryptoCode), - ManualKey = null - }).ToArray()).ToArray(), + Wallets = paymentMethodsGroupedByNetworkCode.SelectMany(settings => + settings.Select(data => + new GenerateLiquidImportScripts.GenerateLiquidImportScriptWalletKeyVm() + { + CryptoCode = data.CryptoCode, + KeyPresent = privKeys.ContainsKey(data.CryptoCode), + ManualKey = null + }).ToArray()).ToArray(), Scripts = generated }); } @@ -199,10 +211,9 @@ namespace BTCPayServer.Plugins.LiquidPlus.Controllers continue; } + var der = HttpContext.GetStoreData() + .GetDerivationSchemeSettings(_paymentMethodHandlerDictionary, wallet.CryptoCode).AccountDerivation; - - var der = n.NBXplorerNetwork.DerivationStrategyFactory.Parse( - (await _client.GetStoreOnChainPaymentMethod(storeId, wallet.CryptoCode)).DerivationScheme); if (der.GetExtPubKeys().Count() > 1) { vm.AddModelError(scripts => scripts.Wallets[index].ManualKey, "cannot handle multsig", this); @@ -250,7 +261,8 @@ namespace BTCPayServer.Plugins.LiquidPlus.Controllers return await GenerateLiquidScript(storeId, privKeys); } -public class GenerateLiquidImportScripts + + public class GenerateLiquidImportScripts { public class GenerateLiquidImportScriptWalletKeyVm { @@ -266,6 +278,7 @@ public class GenerateLiquidImportScripts } } } + namespace XX { public static class ModelStateExtensions @@ -275,9 +288,11 @@ namespace XX string message, ControllerBase controller) { - var provider = (ModelExpressionProvider)controller.HttpContext.RequestServices.GetService(typeof(ModelExpressionProvider)); + var provider = + (ModelExpressionProvider) controller.HttpContext.RequestServices.GetService( + typeof(ModelExpressionProvider)); var key = provider.GetExpressionText(ex); controller.ModelState.AddModelError(key, message); } } -} +} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.LiquidPlus/LiquidPlusPlugin.cs b/Plugins/BTCPayServer.Plugins.LiquidPlus/LiquidPlusPlugin.cs index 8c8f057..8766c1e 100644 --- a/Plugins/BTCPayServer.Plugins.LiquidPlus/LiquidPlusPlugin.cs +++ b/Plugins/BTCPayServer.Plugins.LiquidPlus/LiquidPlusPlugin.cs @@ -22,7 +22,7 @@ namespace BTCPayServer.Plugins.LiquidPlus { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = { - new() {Identifier = nameof(BTCPayServer), Condition = ">=1.12.0"} + new() {Identifier = nameof(BTCPayServer), Condition = ">=2.0.0"} }; public override void Execute(IServiceCollection applicationBuilder) @@ -31,11 +31,11 @@ namespace BTCPayServer.Plugins.LiquidPlus if (services.BootstrapServices.GetRequiredService() .GetFromCryptoCode("LBTC") is null || !services.BootstrapServices.GetRequiredService().Contains("LBTC")) return; - services.AddSingleton(new UIExtension("LiquidNav", "store-integrations-nav")); - services.AddSingleton(new UIExtension("OnChainWalletSetupLiquidExtension", - "onchain-wallet-setup-post-body")); - services.AddSingleton(new UIExtension("CustomLiquidAssetsNavExtension", "server-nav")); - services.AddSingleton(new UIExtension("StoreNavLiquidExtension", "store-nav")); + services.AddUIExtension("store-integrations-nav", "LiquidNav"); + services.AddUIExtension("onchain-wallet-setup-post-body", "OnChainWalletSetupLiquidExtension"); + services.AddUIExtension("server-nav", "CustomLiquidAssetsNavExtension"); + services.AddUIExtension("store-nav", "StoreNavLiquidExtension"); + services.AddSingleton(); @@ -53,12 +53,11 @@ namespace BTCPayServer.Plugins.LiquidPlus CryptoCode: "LBTC" }) .ImplementationInstance; + + var pmi = PaymentTypes.CHAIN.GetPaymentMethodId("LBTC"); var tlProvider = (TransactionLinkProviders.Entry) services.Single(descriptor => descriptor.ServiceType == typeof(TransactionLinkProviders.Entry) && - descriptor.ImplementationInstance is TransactionLinkProviders.Entry - { - PaymentMethodId: {CryptoCode: "LBTC"} - }) + descriptor.ImplementationInstance is TransactionLinkProviders.Entry entry && entry.PaymentMethodId == pmi) .ImplementationInstance; settings.Items.ForEach(configuration => @@ -80,7 +79,6 @@ namespace BTCPayServer.Plugins.LiquidPlus NetworkCryptoCode = template.NetworkCryptoCode, DefaultSettings = template.DefaultSettings, ElectrumMapping = template.ElectrumMapping, - BlockExplorerLink = template.BlockExplorerLink, ReadonlyWallet = template.ReadonlyWallet, SupportLightning = false, SupportPayJoin = false, @@ -92,7 +90,7 @@ namespace BTCPayServer.Plugins.LiquidPlus VaultSupported = template.VaultSupported, MaxTrackedConfirmation = template.MaxTrackedConfirmation, SupportRBF = template.SupportRBF - }).AddTransactionLinkProvider(new PaymentMethodId(code, PaymentTypes.BTCLike), tlProvider.Provider); + }).AddTransactionLinkProvider(code, tlProvider.Provider); }); } } diff --git a/Plugins/BTCPayServer.Plugins.MicroNode/BTCPayServer.Plugins.MicroNode.csproj b/Plugins/BTCPayServer.Plugins.MicroNode/BTCPayServer.Plugins.MicroNode.csproj index 8455eb3..26ff394 100644 --- a/Plugins/BTCPayServer.Plugins.MicroNode/BTCPayServer.Plugins.MicroNode.csproj +++ b/Plugins/BTCPayServer.Plugins.MicroNode/BTCPayServer.Plugins.MicroNode.csproj @@ -34,7 +34,7 @@ - + diff --git a/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodeContextFactory.cs b/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodeContextFactory.cs index bf62b45..5bbd1a7 100644 --- a/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodeContextFactory.cs +++ b/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodeContextFactory.cs @@ -1,23 +1,29 @@ -using BTCPayServer.Abstractions.Contracts; +using System; +using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Abstractions.Models; -using Laraue.EfCoreTriggers.PostgreSql.Extensions; +using BTCPayServer.Data; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure; namespace BTCPayServer.Plugins.MicroNode; public class MicroNodeContextFactory : BaseDbContextFactory { - public MicroNodeContextFactory(IOptions options) : base(options, "BTCPayServer.Plugins.MicroNode") + private readonly ILoggerFactory _loggerFactory; + + public MicroNodeContextFactory(IOptions options, ILoggerFactory loggerFactory) : base(options, "BTCPayServer.Plugins.MicroNode") { + _loggerFactory = loggerFactory; } - public override MicroNodeContext CreateContext() + public override MicroNodeContext CreateContext(Action npgsqlOptionsAction = null) { var builder = new DbContextOptionsBuilder(); - ConfigureBuilder(builder); - builder.UsePostgreSqlTriggers(); - + builder.UseLoggerFactory(_loggerFactory); + builder.AddInterceptors(MigrationInterceptor.Instance); + ConfigureBuilder(builder, npgsqlOptionsAction); return new MicroNodeContext(builder.Options); } } \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodeController.cs b/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodeController.cs index 952b7c0..950a787 100644 --- a/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodeController.cs +++ b/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodeController.cs @@ -8,6 +8,7 @@ using BTCPayServer.Client; using BTCPayServer.Data; using BTCPayServer.Payments; using BTCPayServer.Payments.Lightning; +using BTCPayServer.Services.Invoices; using BTCPayServer.Services.Stores; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -17,14 +18,17 @@ namespace BTCPayServer.Plugins.MicroNode; [Route("plugins/micronode")] public class MicroNodeController : Controller { + private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary; private readonly MicroNodeService _microNodeService; private readonly StoreRepository _storeRepository; private readonly BTCPayNetworkProvider _networkProvider; private readonly IAuthorizationService _authorizationService; - public MicroNodeController(MicroNodeService microNodeService, StoreRepository storeRepository, + public MicroNodeController( + PaymentMethodHandlerDictionary paymentMethodHandlerDictionary,MicroNodeService microNodeService, StoreRepository storeRepository, BTCPayNetworkProvider networkProvider, IAuthorizationService authorizationService) { + _paymentMethodHandlerDictionary = paymentMethodHandlerDictionary; _microNodeService = microNodeService; _storeRepository = storeRepository; _networkProvider = networkProvider; @@ -66,11 +70,8 @@ public class MicroNodeController : Controller ModelState.AddModelError("masterStoreId", "Master cannot be the same as this store"); return View(settings); } - - var existing = store.GetSupportedPaymentMethods(_networkProvider).OfType() - .FirstOrDefault(method => - method.PaymentId.PaymentType == LightningPaymentType.Instance && - method.PaymentId.CryptoCode == network.CryptoCode); + var pmi = PaymentTypes.LN.GetPaymentMethodId(network.CryptoCode); + var existing = store.GetPaymentMethodConfig(pmi, _paymentMethodHandlerDictionary); var isSet = settings?.Key is not null; settings ??= new MicroNodeStoreSettings(); settings.Key ??= Guid.NewGuid().ToString(); @@ -118,12 +119,10 @@ public class MicroNodeController : Controller } - existing ??= new LightningSupportedPaymentMethod() - { - CryptoCode = "BTC" - }; + existing ??= new(); existing.SetLightningUrl(mlc); - store.SetSupportedPaymentMethod(existing); + + store.SetPaymentMethodConfig(_paymentMethodHandlerDictionary[pmi], existing); await _microNodeService.Set(storeId, settings, masterStoreId); @@ -145,7 +144,7 @@ public class MicroNodeController : Controller if (isStoreSetToThisMicro) { - store.SetSupportedPaymentMethod(existing.PaymentId, null); + store.SetPaymentMethodConfig(_paymentMethodHandlerDictionary[pmi], null); await _storeRepository.UpdateStore(store); } diff --git a/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodePlugin.cs b/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodePlugin.cs index 93b6187..0c0ecb9 100644 --- a/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodePlugin.cs +++ b/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodePlugin.cs @@ -11,7 +11,7 @@ public class MicroNodePlugin:BaseBTCPayServerPlugin { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = { - new () { Identifier = nameof(BTCPayServer), Condition = ">=1.12.0" } + new () { Identifier = nameof(BTCPayServer), Condition = ">=2.0.0" } }; diff --git a/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodeService.cs b/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodeService.cs index 96b8da6..5c5e219 100644 --- a/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodeService.cs +++ b/Plugins/BTCPayServer.Plugins.MicroNode/MicroNodeService.cs @@ -15,7 +15,9 @@ using BTCPayServer.HostedServices; using BTCPayServer.Lightning; using BTCPayServer.Payments; using BTCPayServer.Payments.Lightning; +using BTCPayServer.Payouts; using BTCPayServer.Services; +using BTCPayServer.Services.Invoices; using BTCPayServer.Services.Stores; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; @@ -34,6 +36,7 @@ public class MicroNodeService : EventHostedServiceBase private readonly ILogger _logger; private readonly PullPaymentHostedService _pullPaymentHostedService; private readonly IOptions _lightningNetworkOptions; + private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary; private static readonly ConcurrentDictionary ExpectedCounter = new(); private readonly TaskCompletionSource _init = new(); private Dictionary _ownerSettings; @@ -53,6 +56,7 @@ public class MicroNodeService : EventHostedServiceBase EventAggregator eventAggregator, PullPaymentHostedService pullPaymentHostedService, IOptions lightningNetworkOptions, + PaymentMethodHandlerDictionary paymentMethodHandlerDictionary, IServiceProvider serviceProvider) : base(eventAggregator, logger) { _network = btcPayNetworkProvider.BTC; @@ -63,6 +67,7 @@ public class MicroNodeService : EventHostedServiceBase _logger = logger; _pullPaymentHostedService = pullPaymentHostedService; _lightningNetworkOptions = lightningNetworkOptions; + _paymentMethodHandlerDictionary = paymentMethodHandlerDictionary; _serviceProvider = serviceProvider; } @@ -124,17 +129,20 @@ public class MicroNodeService : EventHostedServiceBase { var b = payout.GetBlob(_btcPayNetworkJsonSerializerSettings); - List res = new(); - res.Add(new MicroTransaction() - { - Id = payout.Id, - AccountId = key, - Amount = -LightMoney.Coins(b.CryptoAmount.Value).MilliSatoshi, - Accounted = payout.State != PayoutState.Cancelled, - Active = payout.State is PayoutState.AwaitingApproval or PayoutState.AwaitingPayment - or PayoutState.InProgress, - Type = "Payout" - }); + List res = + [ + new() + { + Id = payout.Id, + AccountId = key, + Amount = -LightMoney.Coins(payout.Amount!.Value).MilliSatoshi, + Accounted = payout.State != PayoutState.Cancelled, + Active = payout.State is PayoutState.AwaitingApproval or PayoutState.AwaitingPayment + or PayoutState.InProgress, + Type = "Payout" + } + + ]; if (b.Metadata?.TryGetValue("Fee", out var microNode) is true && microNode.Value() is { } payoutFee) { @@ -230,7 +238,7 @@ public class MicroNodeService : EventHostedServiceBase await using var ctx = _microNodeContextFactory.CreateContext(); for (int i = 0; i < 5; i++) { - var account = await ctx.MicroAccounts.FindAsync(key); + var account = await ctx.MicroAccounts.FindAsync(key, cancellation); if (account is null) { return null; @@ -336,9 +344,9 @@ public class MicroNodeService : EventHostedServiceBase return null; } - var lightningConnectionString = store.GetSupportedPaymentMethods(_btcPayNetworkProvider) - .OfType() - .FirstOrDefault(method => method.CryptoCode == _network.CryptoCode)?.CreateLightningClient(_network, + var pmi = PaymentTypes.LN.GetPaymentMethodId(_network.CryptoCode); + var lightningConnectionString = store.GetPaymentMethodConfig(pmi, _paymentMethodHandlerDictionary) + ?.CreateLightningClient(_network, _lightningNetworkOptions.Value, _serviceProvider.GetService()); return lightningConnectionString; } @@ -616,7 +624,7 @@ public class MicroNodeService : EventHostedServiceBase StoreId = masterClients.Key, Destination = new LNURLPayClaimDestinaton(destination), PreApprove = true, - PaymentMethodId = new PaymentMethodId("BTC", LightningPaymentType.Instance), + PayoutMethodId = PayoutTypes.LN.GetPayoutMethodId("BTC"), Metadata = JObject.FromObject(new { Source = $"MicroNode on store {storeId.Key}" @@ -667,7 +675,7 @@ public class MicroNodeService : EventHostedServiceBase await base.StopAsync(cancellationToken); } - private ConcurrentDictionary _keyToMasterStoreId = new(); + private readonly ConcurrentDictionary _keyToMasterStoreId = new(); public async Task Set(string storeId, MicroNodeStoreSettings? settings, string? masterStoreId = null) { diff --git a/Plugins/BTCPayServer.Plugins.NIP05/BTCPayServer.Plugins.NIP05.csproj b/Plugins/BTCPayServer.Plugins.NIP05/BTCPayServer.Plugins.NIP05.csproj index 278f386..266521b 100644 --- a/Plugins/BTCPayServer.Plugins.NIP05/BTCPayServer.Plugins.NIP05.csproj +++ b/Plugins/BTCPayServer.Plugins.NIP05/BTCPayServer.Plugins.NIP05.csproj @@ -11,7 +11,7 @@ Nostr NIP5 addresses, Zap support, Nostr Wallet Connect Lightning support - 1.1.13 + 1.1.14 true diff --git a/Plugins/BTCPayServer.Plugins.NIP05/Nip05Plugin.cs b/Plugins/BTCPayServer.Plugins.NIP05/Nip05Plugin.cs index a7d7dd1..8f849bf 100644 --- a/Plugins/BTCPayServer.Plugins.NIP05/Nip05Plugin.cs +++ b/Plugins/BTCPayServer.Plugins.NIP05/Nip05Plugin.cs @@ -13,7 +13,7 @@ namespace BTCPayServer.Plugins.NIP05 { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = { - new() {Identifier = nameof(BTCPayServer), Condition = ">=1.13.0"} + new() {Identifier = nameof(BTCPayServer), Condition = ">=2.0.0"} }; public override void Execute(IServiceCollection applicationBuilder) diff --git a/Plugins/BTCPayServer.Plugins.NIP05/Views/Nip5/Edit.cshtml b/Plugins/BTCPayServer.Plugins.NIP05/Views/Nip5/Edit.cshtml index 7c0fcde..56313f0 100644 --- a/Plugins/BTCPayServer.Plugins.NIP05/Views/Nip5/Edit.cshtml +++ b/Plugins/BTCPayServer.Plugins.NIP05/Views/Nip5/Edit.cshtml @@ -32,7 +32,7 @@
- +
@@@Context.Request.Host.ToUriComponent()@Context.Request.PathBase diff --git a/Plugins/BTCPayServer.Plugins.NIP05/Zapper.cs b/Plugins/BTCPayServer.Plugins.NIP05/Zapper.cs index 4c6a759..aa5fad4 100644 --- a/Plugins/BTCPayServer.Plugins.NIP05/Zapper.cs +++ b/Plugins/BTCPayServer.Plugins.NIP05/Zapper.cs @@ -5,11 +5,9 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using BTCPayServer.Events; -using BTCPayServer.Models.InvoicingModels; using BTCPayServer.Payments; using BTCPayServer.Services; using BTCPayServer.Services.Invoices; -using BTCPayServer.Services.Stores; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -23,7 +21,8 @@ namespace BTCPayServer.Plugins.NIP05; public class Zapper : IHostedService { record PendingZapEvent(string[] relays, NostrEvent nostrEvent); - + + private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary; private readonly EventAggregator _eventAggregator; private readonly Nip5Controller _nip5Controller; private readonly IMemoryCache _memoryCache; @@ -51,7 +50,9 @@ public class Zapper : IHostedService } - public Zapper(EventAggregator eventAggregator, + public Zapper( + PaymentMethodHandlerDictionary paymentMethodHandlerDictionary, + EventAggregator eventAggregator, Nip5Controller nip5Controller, IMemoryCache memoryCache, ILogger logger, @@ -59,6 +60,7 @@ public class Zapper : IHostedService InvoiceRepository invoiceRepository, NostrClientPool nostrClientPool) { + _paymentMethodHandlerDictionary = paymentMethodHandlerDictionary; _eventAggregator = eventAggregator; _nip5Controller = nip5Controller; _memoryCache = memoryCache; @@ -150,7 +152,8 @@ public class Zapper : IHostedService { if (arg.EventCode != InvoiceEventCode.Completed && arg.EventCode != InvoiceEventCode.MarkedCompleted) return; - var pm = arg.Invoice.GetPaymentMethod(new PaymentMethodId("BTC", LNURLPayPaymentType.Instance)); + var pmi = PaymentTypes.LNURL.GetPaymentMethodId("BTC"); + var pm = arg.Invoice.GetPaymentPrompt(pmi); if (pm is null) { return; @@ -159,8 +162,7 @@ public class Zapper : IHostedService { return; } - - var pmd = (LNURLPayPaymentMethodDetails) pm.GetPaymentMethodDetails(); + var settings = await GetSettings(); var zapRequestEvent = JsonSerializer.Deserialize(zapRequest); @@ -168,13 +170,13 @@ public class Zapper : IHostedService var tags = zapRequestEvent.Tags.Where(a => a.TagIdentifier.Length == 1).ToList(); - + tags.AddRange(new[] { new NostrEventTag { TagIdentifier = "bolt11", - Data = new() {pmd.BOLT11} + Data = new() {pm.Destination} }, new NostrEventTag() diff --git a/Plugins/BTCPayServer.Plugins.Prism/BTCPayServer.Plugins.Prism.csproj b/Plugins/BTCPayServer.Plugins.Prism/BTCPayServer.Plugins.Prism.csproj index d732225..4de88fb 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/BTCPayServer.Plugins.Prism.csproj +++ b/Plugins/BTCPayServer.Plugins.Prism/BTCPayServer.Plugins.Prism.csproj @@ -11,7 +11,7 @@ Prism Automated value splits for Bitcoin. - 1.2.8 + 1.2.9 true diff --git a/Plugins/BTCPayServer.Plugins.Prism/Components/PrismEdit.razor b/Plugins/BTCPayServer.Plugins.Prism/Components/PrismEdit.razor index 8a134d7..d82466a 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/Components/PrismEdit.razor +++ b/Plugins/BTCPayServer.Plugins.Prism/Components/PrismEdit.razor @@ -4,6 +4,7 @@ @using BTCPayServer.HostedServices @using BTCPayServer.Payments @using BTCPayServer.PayoutProcessors +@using BTCPayServer.Payouts @using Microsoft.AspNetCore.Http @using Microsoft.AspNetCore.Routing @using Microsoft.Extensions.Logging @@ -28,7 +29,7 @@ else { - + @foreach (var user in Users) @@ -201,8 +202,8 @@ else public bool Loading { get; set; } = true; public List Users { get; set; } = new(); - public PaymentMethodId pmi { get; set; } = new("BTC", LightningPaymentType.Instance); - public PaymentMethodId pmichain { get; set; } = new("BTC", PaymentTypes.BTCLike); + public PayoutMethodId pmi { get; set; } = PayoutTypes.LN.GetPayoutMethodId("BTC"); + public PayoutMethodId pmichain { get; set; } = PayoutTypes.CHAIN.GetPayoutMethodId("BTC"); public bool NoPayoutProcessors { get; set; } private string PrismEditButtonsFilter { get; set; } @@ -224,7 +225,7 @@ else var fetchProcessors = PayoutProcessorService.GetProcessors(new PayoutProcessorService.PayoutProcessorQuery() { Stores = new[] {StoreId}, - PaymentMethods = new[] {pmi.ToString(), pmichain.ToString()} + PayoutMethods = new[] {pmi, pmichain} }); var tasks = new Task[] @@ -243,8 +244,8 @@ else EditContext.OnFieldChanged += FieldChanged; SatBreaker.PrismUpdated += SatBreakerOnPrismUpdated; //set NoPayoutProcessors to true if there are no configured payout processores for pmi and pmichain - NoPayoutProcessors = PayoutProcessorFactories.Any(factory => factory.GetSupportedPaymentMethods().Contains(pmi)) && (await fetchProcessors).All(data => - !new[] {pmi, pmichain}.Contains(data.GetPaymentMethodId())); + NoPayoutProcessors = PayoutProcessorFactories.Any(factory => factory.GetSupportedPayoutMethods().Contains(pmi)) && (await fetchProcessors).All(data => + !new[] {pmi, pmichain}.Contains(data.GetPayoutMethodId())); Loading = false; await InvokeAsync(StateHasChanged); diff --git a/Plugins/BTCPayServer.Plugins.Prism/LNURLPrismDestinationValidator.cs b/Plugins/BTCPayServer.Plugins.Prism/LNURLPrismDestinationValidator.cs index 8a70d69..23582e5 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/LNURLPrismDestinationValidator.cs +++ b/Plugins/BTCPayServer.Plugins.Prism/LNURLPrismDestinationValidator.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Payments; +using BTCPayServer.Payouts; namespace BTCPayServer.Plugins.Prism; @@ -19,7 +20,7 @@ public class LNURLPrismDestinationValidator : IPluginHookFilter return Task.FromResult(new PrismDestinationValidationResult() { Success = true, - PaymentMethod = new PaymentMethodId("BTC", PaymentTypes.LNURLPay) + PayoutMethodId = PayoutTypes.LN.GetPayoutMethodId("BTC") }); } catch (Exception e) @@ -30,7 +31,7 @@ public class LNURLPrismDestinationValidator : IPluginHookFilter return Task.FromResult(new PrismDestinationValidationResult() { Success = true, - PaymentMethod = new PaymentMethodId("BTC", PaymentTypes.LNURLPay) + PayoutMethodId =PayoutTypes.LN.GetPayoutMethodId("BTC") }); } catch (Exception) @@ -45,5 +46,5 @@ public class LNURLPrismDestinationValidator : IPluginHookFilter public class PrismDestinationValidationResult { public bool Success { get; set; } - public PaymentMethodId PaymentMethod { get; set; } + public PayoutMethodId PayoutMethodId { get; set; } } \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Prism/OnChainPrismClaimCreate.cs b/Plugins/BTCPayServer.Plugins.Prism/OnChainPrismClaimCreate.cs index e4be702..20415e3 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/OnChainPrismClaimCreate.cs +++ b/Plugins/BTCPayServer.Plugins.Prism/OnChainPrismClaimCreate.cs @@ -1,10 +1,9 @@ using System; -using System.Collections; using System.Threading.Tasks; using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Data; using BTCPayServer.HostedServices; -using BTCPayServer.Payments; +using BTCPayServer.Payouts; using NBitcoin; using NBXplorer.DerivationStrategy; @@ -35,7 +34,7 @@ public class OnChainPrismClaimCreate : IPluginHookFilter { claimRequest.Destination = new AddressClaimDestination(BitcoinAddress.Create(destStr, network.NBitcoinNetwork)); - claimRequest.PaymentMethodId = new PaymentMethodId("BTC", BitcoinPaymentType.Instance); + claimRequest.PayoutMethodId = PayoutTypes.CHAIN.GetPayoutMethodId("BTC"); return args; } catch (Exception) @@ -48,7 +47,7 @@ public class OnChainPrismClaimCreate : IPluginHookFilter claimRequest.Destination = new AddressClaimDestination(add.Address); - claimRequest.PaymentMethodId = new PaymentMethodId("BTC", BitcoinPaymentType.Instance); + claimRequest.PayoutMethodId = PayoutTypes.CHAIN.GetPayoutMethodId("BTC"); } catch (Exception exception) { diff --git a/Plugins/BTCPayServer.Plugins.Prism/OnChainPrismDestinationValidator.cs b/Plugins/BTCPayServer.Plugins.Prism/OnChainPrismDestinationValidator.cs index a815eed..55d5971 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/OnChainPrismDestinationValidator.cs +++ b/Plugins/BTCPayServer.Plugins.Prism/OnChainPrismDestinationValidator.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Data; using BTCPayServer.Payments; +using BTCPayServer.Payouts; using NBitcoin; using NBXplorer; @@ -34,7 +35,7 @@ public class OnChainPrismDestinationValidator : IPluginHookFilter return Task.FromResult(new PrismDestinationValidationResult() { Success = true, - PaymentMethod = new PaymentMethodId("BTC", PaymentTypes.BTCLike) + PayoutMethodId = PayoutTypes.CHAIN.GetPayoutMethodId("BTC") }); } catch (Exception e) @@ -46,7 +47,7 @@ public class OnChainPrismDestinationValidator : IPluginHookFilter return Task.FromResult(new PrismDestinationValidationResult() { Success = true, - PaymentMethod = new PaymentMethodId("BTC", PaymentTypes.BTCLike) + PayoutMethodId =PayoutTypes.CHAIN.GetPayoutMethodId("BTC") }); } catch (Exception) diff --git a/Plugins/BTCPayServer.Plugins.Prism/OpenSatsDestinationValidator.cs b/Plugins/BTCPayServer.Plugins.Prism/OpenSatsDestinationValidator.cs index 6613a73..559fb13 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/OpenSatsDestinationValidator.cs +++ b/Plugins/BTCPayServer.Plugins.Prism/OpenSatsDestinationValidator.cs @@ -5,6 +5,7 @@ using System.Threading; using System.Threading.Tasks; using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Payments; +using BTCPayServer.Payouts; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json.Linq; @@ -30,7 +31,7 @@ public class OpenSatsDestinationValidator : IPluginHookFilter var parts = args1.ToLowerInvariant().Split(":", StringSplitOptions.RemoveEmptyEntries); var project = "general_fund"; - var paymentMethod = new PaymentMethodId("BTC", PaymentTypes.LightningLike); + var paymentMethod = PayoutTypes.LN.GetPayoutMethodId("BTC"); if (parts.Length > 1) { project = parts[1]; @@ -38,12 +39,11 @@ public class OpenSatsDestinationValidator : IPluginHookFilter if (parts.Length > 2) { - paymentMethod = PaymentMethodId.Parse(parts[2]); + paymentMethod = PayoutMethodId.Parse(parts[2]); } - - - var handler = _serviceProvider.GetServices().FindPayoutHandler(paymentMethod); - if (handler is null) + + + if (_serviceProvider.GetService().TryGetValue(paymentMethod, out var handler)) { result.Success = false; } @@ -63,7 +63,7 @@ public class OpenSatsDestinationValidator : IPluginHookFilter var invoiceBtcpayModel = JObject.Parse(await httpClient.GetStringAsync(invoiceUrl).ConfigureAwait(false)); var destination = invoiceBtcpayModel.Value("btcAddress"); - var claimDestination = await handler.ParseClaimDestination(paymentMethod,destination, CancellationToken.None); + var claimDestination = await handler.ParseClaimDestination(destination, CancellationToken.None); if (claimDestination.destination is null) { @@ -72,7 +72,7 @@ public class OpenSatsDestinationValidator : IPluginHookFilter result.Success = true; - result.PaymentMethod = paymentMethod; + result.PayoutMethodId = paymentMethod; return result; } catch (Exception e) diff --git a/Plugins/BTCPayServer.Plugins.Prism/OpenSatsPrismClaimCreate.cs b/Plugins/BTCPayServer.Plugins.Prism/OpenSatsPrismClaimCreate.cs index f4854fd..9ed5c70 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/OpenSatsPrismClaimCreate.cs +++ b/Plugins/BTCPayServer.Plugins.Prism/OpenSatsPrismClaimCreate.cs @@ -1,18 +1,12 @@ using System; -using System.Linq; using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; using BTCPayServer.Abstractions.Contracts; -using BTCPayServer.Abstractions.Custodians; -using BTCPayServer.Abstractions.Extensions; -using BTCPayServer.Data; using BTCPayServer.HostedServices; -using BTCPayServer.Payments; -using Microsoft.EntityFrameworkCore; +using BTCPayServer.Payouts; using Microsoft.Extensions.DependencyInjection; -using NBitcoin; using Newtonsoft.Json.Linq; namespace BTCPayServer.Plugins.Prism; @@ -38,10 +32,10 @@ public class OpenSatsPrismClaimCreate : IPluginHookFilter try { - + var parts = args1.Split(":", StringSplitOptions.RemoveEmptyEntries); var project = "opensats"; - var paymentMethod = new PaymentMethodId("BTC", PaymentTypes.LightningLike); + var paymentMethod = PayoutTypes.LN.GetPayoutMethodId("BTC"); if (parts.Length > 1) { project = parts[1]; @@ -49,11 +43,11 @@ public class OpenSatsPrismClaimCreate : IPluginHookFilter if (parts.Length > 2) { - paymentMethod = PaymentMethodId.Parse(parts[2]); + paymentMethod = PayoutMethodId.Parse(parts[2]); } - var handler = _serviceProvider.GetServices().FindPayoutHandler(paymentMethod); + _serviceProvider.GetService().TryGetValue(paymentMethod, out var handler); if (handler is null) { return null; @@ -75,7 +69,7 @@ public class OpenSatsPrismClaimCreate : IPluginHookFilter var destination = invoiceBtcpayModel.Value("btcAddress"); var receiptLink = invoiceBtcpayModel.Value("receiptLink"); - var claimDestination = await handler.ParseClaimDestination(paymentMethod,destination, CancellationToken.None); + var claimDestination = await handler.ParseClaimDestination(destination, CancellationToken.None); if (claimDestination.destination is null) { @@ -88,7 +82,7 @@ public class OpenSatsPrismClaimCreate : IPluginHookFilter }); claimRequest.Destination = claimDestination.destination; - claimRequest.PaymentMethodId = paymentMethod; + claimRequest.PayoutMethodId = paymentMethod; return claimRequest; diff --git a/Plugins/BTCPayServer.Plugins.Prism/PrismPlugin.cs b/Plugins/BTCPayServer.Plugins.Prism/PrismPlugin.cs index 4b814b4..ea4aca5 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/PrismPlugin.cs +++ b/Plugins/BTCPayServer.Plugins.Prism/PrismPlugin.cs @@ -11,7 +11,7 @@ public class PrismPlugin : BaseBTCPayServerPlugin { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = { - new() {Identifier = nameof(BTCPayServer), Condition = ">=1.13.0"} + new() {Identifier = nameof(BTCPayServer), Condition = ">=2.0.0"} }; public override void Execute(IServiceCollection applicationBuilder) diff --git a/Plugins/BTCPayServer.Plugins.Prism/PrismSettings.cs b/Plugins/BTCPayServer.Plugins.Prism/PrismSettings.cs index b6df62f..4d8abb0 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/PrismSettings.cs +++ b/Plugins/BTCPayServer.Plugins.Prism/PrismSettings.cs @@ -20,5 +20,5 @@ public class PrismDestination public string Destination { get; set; } public decimal? Reserve { get; set; } public long? SatThreshold { get; set; } - public string? PaymentMethodId { get; set; } + public string? PayoutMethodId { get; set; } } \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.Prism/SatBreaker.cs b/Plugins/BTCPayServer.Plugins.Prism/SatBreaker.cs index fb318b3..fc4f720 100644 --- a/Plugins/BTCPayServer.Plugins.Prism/SatBreaker.cs +++ b/Plugins/BTCPayServer.Plugins.Prism/SatBreaker.cs @@ -13,6 +13,7 @@ using BTCPayServer.HostedServices; using BTCPayServer.Lightning; using BTCPayServer.Payments; using BTCPayServer.Payments.Lightning; +using BTCPayServer.Payouts; using BTCPayServer.Services; using BTCPayServer.Services.Invoices; using BTCPayServer.Services.Stores; @@ -47,13 +48,13 @@ namespace BTCPayServer.Plugins.Prism { private readonly StoreRepository _storeRepository; private readonly ILogger _logger; - private readonly LightningAddressService _lightningAddressService; private readonly PullPaymentHostedService _pullPaymentHostedService; - private readonly LightningLikePayoutHandler _lightningLikePayoutHandler; private readonly BTCPayNetworkProvider _btcPayNetworkProvider; private readonly LightningClientFactoryService _lightningClientFactoryService; private readonly IOptions _lightningNetworkOptions; private readonly BTCPayNetworkJsonSerializerSettings _btcPayNetworkJsonSerializerSettings; + private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary; + private readonly PayoutMethodHandlerDictionary _payoutMethodHandlerDictionary; private readonly IPluginHookService _pluginHookService; private Dictionary _prismSettings; @@ -62,24 +63,24 @@ namespace BTCPayServer.Plugins.Prism public SatBreaker(StoreRepository storeRepository, EventAggregator eventAggregator, ILogger logger, - LightningAddressService lightningAddressService, PullPaymentHostedService pullPaymentHostedService, - LightningLikePayoutHandler lightningLikePayoutHandler, BTCPayNetworkProvider btcPayNetworkProvider, LightningClientFactoryService lightningClientFactoryService, IOptions lightningNetworkOptions, BTCPayNetworkJsonSerializerSettings btcPayNetworkJsonSerializerSettings, + PaymentMethodHandlerDictionary paymentMethodHandlerDictionary, + PayoutMethodHandlerDictionary payoutMethodHandlerDictionary, IPluginHookService pluginHookService) : base(eventAggregator, logger) { _storeRepository = storeRepository; _logger = logger; - _lightningAddressService = lightningAddressService; _pullPaymentHostedService = pullPaymentHostedService; - _lightningLikePayoutHandler = lightningLikePayoutHandler; _btcPayNetworkProvider = btcPayNetworkProvider; _lightningClientFactoryService = lightningClientFactoryService; _lightningNetworkOptions = lightningNetworkOptions; _btcPayNetworkJsonSerializerSettings = btcPayNetworkJsonSerializerSettings; + _paymentMethodHandlerDictionary = paymentMethodHandlerDictionary; + _payoutMethodHandlerDictionary = payoutMethodHandlerDictionary; _pluginHookService = pluginHookService; } @@ -145,20 +146,28 @@ namespace BTCPayServer.Plugins.Prism { continue; } - + foreach (var payout in storePayouts) { + if (!pendingPayouts.TryGetValue(payout.Id, out var pendingPayout)) { continue; } + + if(payout.GetPayoutMethodId() is not { } payoutMethodId) + continue; + if (!_payoutMethodHandlerDictionary.TryGetValue(payoutMethodId, out var handler)) + { + continue; + } long toCredit = 0; switch (payout.State) { case PayoutState.Completed: - - var proof = _lightningLikePayoutHandler.ParseProof(payout) as PayoutLightningBlob; + + var proof = handler.ParseProof(payout) as PayoutLightningBlob; long? feePaid = null; if (!string.IsNullOrEmpty(proof?.PaymentHash)) @@ -168,10 +177,10 @@ namespace BTCPayServer.Plugins.Prism var store = await _storeRepository.FindStore(payout.StoreDataId); var network = _btcPayNetworkProvider.GetNetwork("BTC"); - var id = new PaymentMethodId("BTC", LightningPaymentType.Instance); - var existing = store.GetSupportedPaymentMethods(_btcPayNetworkProvider) - .OfType() - .FirstOrDefault(d => d.PaymentId == id); + var id = PaymentTypes.LN.GetPaymentMethodId("BTC"); + var existing = + store.GetPaymentMethodConfig(id, + _paymentMethodHandlerDictionary); if (existing?.GetExternalLightningUrl() is { } connectionString) { lnClient = _lightningClientFactoryService.Create(connectionString, @@ -313,29 +322,34 @@ namespace BTCPayServer.Plugins.Prism private (Split, LightMoney)[] DetermineMatches(PrismSettings prismSettings, InvoiceEntity entity) { //first check the primary thing - ln address - var explicitPMI = new PaymentMethodId("BTC", LNURLPayPaymentType.Instance); - var pm = entity.GetPaymentMethod(explicitPMI); - var pmd = pm?.GetPaymentMethodDetails() as LNURLPayPaymentMethodDetails; - List<(Split, LightMoney)> result = new(); + var explicitPMI = PaymentTypes.LNURL.GetPaymentMethodId("BTC"); + var pm = entity.GetPaymentPrompt(explicitPMI); - var payments = entity.GetPayments(true).GroupBy(paymentEntity => paymentEntity.GetPaymentMethodId()).ToArray(); - if (pmd?.ConsumedLightningAddress is not null) + var payments = entity.GetPayments(true).GroupBy(paymentEntity => paymentEntity.PaymentMethodId).ToArray(); + List<(Split, LightMoney)> result = new(); + if(_paymentMethodHandlerDictionary.TryGetValue(explicitPMI, out var handler) && pm is not null) { - var address = pmd.ConsumedLightningAddress.Split("@")[0]; - var matchedExplicit = prismSettings.Splits.FirstOrDefault(s => - s.Source.Equals(address, StringComparison.InvariantCultureIgnoreCase)); - - if (matchedExplicit is not null) + var pmd = handler.ParsePaymentPromptDetails(pm.Details) as LNURLPayPaymentMethodDetails; + + + if (pmd?.ConsumedLightningAddress is not null) { - var explicitPayments = payments.FirstOrDefault(grouping => - grouping.Key == explicitPMI)?.Sum(paymentEntity => paymentEntity.PaidAmount.Net); - payments = payments.Where(grouping => grouping.Key != explicitPMI).ToArray(); + var address = pmd.ConsumedLightningAddress.Split("@")[0]; + var matchedExplicit = prismSettings.Splits.FirstOrDefault(s => + s.Source.Equals(address, StringComparison.InvariantCultureIgnoreCase)); - if (explicitPayments > 0) - { - result.Add((matchedExplicit, LightMoney.FromUnit(explicitPayments.Value, LightMoneyUnit.BTC))); - } - } + if (matchedExplicit is not null) + { + var explicitPayments = payments.FirstOrDefault(grouping => + grouping.Key == explicitPMI)?.Sum(paymentEntity => paymentEntity.PaidAmount.Net); + payments = payments.Where(grouping => grouping.Key != explicitPMI).ToArray(); + + if (explicitPayments > 0) + { + result.Add((matchedExplicit, LightMoney.FromUnit(explicitPayments.Value, LightMoneyUnit.BTC))); + } + } + } } var catchAlls = prismSettings.Splits.Where(split => split.Source.StartsWith("*")).Select(split => @@ -346,20 +360,25 @@ namespace BTCPayServer.Plugins.Prism switch (split.Source) { case "*": - pmi = new PaymentMethodId("BTC", PaymentTypes.LightningLike); + pmi = PaymentTypes.LN.GetPaymentMethodId("BTC"); break; case "*All": break; - case var s when PaymentTypes.TryParse(s.Substring(1), out var pType): - - pmi = new PaymentMethodId("BTC", pType); + case var s when s.StartsWith("*") && s.Substring(1) ==PaymentTypes.CHAIN.ToString(): + pmi = PaymentTypes.CHAIN.GetPaymentMethodId("BTC"); + break; + case var s2 when s2.StartsWith("*") && s2.Substring(1) ==PaymentTypes.LN.ToString(): + pmi = PaymentTypes.LN.GetPaymentMethodId("BTC"); + break; + case var s3 when s3.StartsWith("*") && s3.Substring(1) ==PaymentTypes.LNURL.ToString(): + pmi = PaymentTypes.LNURL.GetPaymentMethodId("BTC"); break; case var s when !PaymentMethodId.TryParse(s.Substring(1), out pmi): valid = false; break; } - if (pmi is not null && pmi.CryptoCode != "BTC") + if (pmi is not null && !pmi.ToString().StartsWith("BTC-")) { valid = false; } @@ -367,6 +386,7 @@ namespace BTCPayServer.Plugins.Prism return (pmi, valid, split); }).Where(tuple => tuple.valid).ToDictionary(split => split.pmi, split => split.split); + while(payments.Any() || catchAlls.Any()) { decimal paymentSum; @@ -511,9 +531,9 @@ namespace BTCPayServer.Plugins.Prism continue; } - var pmi = string.IsNullOrEmpty(destinationSettings?.PaymentMethodId) || - !PaymentMethodId.TryParse(destinationSettings?.PaymentMethodId, out var pmi2) - ? new PaymentMethodId("BTC", LightningPaymentType.Instance) + var pmi = string.IsNullOrEmpty(destinationSettings?.PayoutMethodId) || + !PayoutMethodId.TryParse(destinationSettings?.PayoutMethodId, out var pmi2) + ? PayoutTypes.LN.GetPayoutMethodId("BTC") : pmi2; var source = "Prism"; @@ -526,7 +546,7 @@ namespace BTCPayServer.Plugins.Prism Destination = new PrismPlaceholderClaimDestination(destinationSettings?.Destination ?? destination), PreApprove = true, StoreId = storeId, - PaymentMethodId = pmi, + PayoutMethodId = pmi, Value = Money.Satoshis(payoutAmount).ToDecimal(MoneyUnit.BTC), Metadata = JObject.FromObject(new { diff --git a/Plugins/BTCPayServer.Plugins.SideShift/BTCPayServer.Plugins.SideShift.csproj b/Plugins/BTCPayServer.Plugins.SideShift/BTCPayServer.Plugins.SideShift.csproj index 156dd38..a6df196 100644 --- a/Plugins/BTCPayServer.Plugins.SideShift/BTCPayServer.Plugins.SideShift.csproj +++ b/Plugins/BTCPayServer.Plugins.SideShift/BTCPayServer.Plugins.SideShift.csproj @@ -9,7 +9,7 @@ SideShift Allows you to embed a SideShift conversion screen to allow customers to pay with altcoins. - 1.1.13 + 1.1.14 true diff --git a/Plugins/BTCPayServer.Plugins.SideShift/PrismClaimCreate.cs b/Plugins/BTCPayServer.Plugins.SideShift/PrismClaimCreate.cs deleted file mode 100644 index 2865265..0000000 --- a/Plugins/BTCPayServer.Plugins.SideShift/PrismClaimCreate.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; -using BTCPayServer.Abstractions.Contracts; -using BTCPayServer.Data.Payouts.LightningLike; -using BTCPayServer.HostedServices; -using BTCPayServer.Lightning; -using Newtonsoft.Json.Linq; - -namespace BTCPayServer.Plugins.SideShift; - -public class PrismClaimCreate : IPluginHookFilter -{ - private readonly IHttpClientFactory _httpClientFactory; - private readonly BTCPayNetworkProvider _networkProvider; - public string Hook => "prism-claim-create"; - - public PrismClaimCreate(IHttpClientFactory httpClientFactory, BTCPayNetworkProvider networkProvider) - { - _httpClientFactory = httpClientFactory; - _networkProvider = networkProvider; - } - public async Task Execute(object args) - { - var network = _networkProvider.GetNetwork("BTC"); - if (args is not ClaimRequest claimRequest || network is null) - { - return args; - } - - if (claimRequest.Destination?.ToString() is not { } args1 || !args1.StartsWith("sideshift:")) return args; - var request = JObject.Parse(args1.Substring("sideshift:".Length)).ToObject(); - if (!request.Valid()) - { - return null; - } - var client = _httpClientFactory.CreateClient("sideshift"); - - - var shiftResponse = await client.PostAsJsonAsync("https://sideshift.ai/api/v2/shifts/variable", new - { - settleAddress = request.ShiftDestination, - affiliateId = "qg0OrfHJV", - settleMemo = request.ShiftMemo, - depositCoin = "BTC", - depositNetwork = request.SourceNetwork?? "lightning", - settleCoin = request.ShiftCoin, - settleNetwork = request.ShiftNetwork, - } - ); - if (!shiftResponse.IsSuccessStatusCode) - { - return null; - } - var shift = await shiftResponse.Content.ReadAsAsync(); - try - { - LNURL.LNURL.Parse(shift.depositAddress, out _); - claimRequest.Destination = new LNURLPayClaimDestinaton(shift.depositAddress); - claimRequest.Metadata = JObject.FromObject(new - { - Source = $"Prism->Sideshift", - SourceLink = $"https://sideshift.ai/orders/{shift.id}?openSupport=true", - }); - return claimRequest; - } - catch (Exception e) - { - if (BOLT11PaymentRequest.TryParse(shift.depositAddress, out var bolt11, network.NBitcoinNetwork)) - { - claimRequest.Destination = new BoltInvoiceClaimDestination(shift.depositAddress, bolt11); - claimRequest.Metadata = JObject.FromObject(new - { - Source = $"Prism->Sideshift", - SourceLink = $"https://sideshift.ai/orders/{shift.id}?openSupport=true", - }); - return claimRequest; - } - } - - return null; - - } -} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.SideShift/PrismDestinationValidate.cs b/Plugins/BTCPayServer.Plugins.SideShift/PrismDestinationValidate.cs deleted file mode 100644 index 4bf158f..0000000 --- a/Plugins/BTCPayServer.Plugins.SideShift/PrismDestinationValidate.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Threading.Tasks; -using BTCPayServer.Abstractions.Contracts; -using Newtonsoft.Json.Linq; - -namespace BTCPayServer.Plugins.SideShift; - -public class PrismDestinationValidate : IPluginHookFilter -{ - public string Hook => "prism-destination-validate"; - public async Task Execute(object args) - { - if (args is not string args1 || !args1.StartsWith("sideshift:")) return args; - var json = JObject.Parse(args1.Substring("sideshift:".Length)).ToObject(); - return json.Valid(); - } - -} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.SideShift/PrismEditFiltercs.cs b/Plugins/BTCPayServer.Plugins.SideShift/PrismEditFiltercs.cs deleted file mode 100644 index c730736..0000000 --- a/Plugins/BTCPayServer.Plugins.SideShift/PrismEditFiltercs.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Threading.Tasks; -using BTCPayServer.Abstractions.Contracts; - -namespace BTCPayServer.Plugins.SideShift; - -public class PrismEditFilter : IPluginHookFilter -{ - public string Hook => "prism-edit-buttons"; - - public Task Execute(object args) - { - return Task.FromResult(( args??"") + ""); - - } -} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.SideShift/PrismSideshiftDestination.cs b/Plugins/BTCPayServer.Plugins.SideShift/PrismSideshiftDestination.cs deleted file mode 100644 index 37d571c..0000000 --- a/Plugins/BTCPayServer.Plugins.SideShift/PrismSideshiftDestination.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace BTCPayServer.Plugins.SideShift; - -public class PrismSideshiftDestination -{ - public string ShiftCoin { get; set; } - public string ShiftNetwork { get; set; } - public string ShiftDestination { get; set; } - public string ShiftMemo { get; set; } - public string SourceNetwork { get; set; } - - public bool Valid() - { - return !string.IsNullOrEmpty(ShiftCoin) && !string.IsNullOrEmpty(ShiftNetwork) && - !string.IsNullOrEmpty(ShiftDestination); - } -} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.SideShift/SideShiftController.cs b/Plugins/BTCPayServer.Plugins.SideShift/SideShiftController.cs index 9a0e7eb..b2e3f30 100644 --- a/Plugins/BTCPayServer.Plugins.SideShift/SideShiftController.cs +++ b/Plugins/BTCPayServer.Plugins.SideShift/SideShiftController.cs @@ -9,6 +9,7 @@ using BTCPayServer.Client.Models; using BTCPayServer.Data; using BTCPayServer.HostedServices; using BTCPayServer.Payments; +using BTCPayServer.Payouts; using BTCPayServer.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -26,7 +27,7 @@ namespace BTCPayServer.Plugins.SideShift { private readonly SideShiftService _sideShiftService; private readonly IHttpClientFactory _httpClientFactory; - private readonly IEnumerable _payoutHandlers; + private readonly PayoutMethodHandlerDictionary _payoutMethodHandlerDictionary; private readonly PullPaymentHostedService _pullPaymentHostedService; private readonly BTCPayNetworkJsonSerializerSettings _serializerSettings; private readonly ApplicationDbContextFactory _dbContextFactory; @@ -34,13 +35,13 @@ namespace BTCPayServer.Plugins.SideShift public SideShiftController( SideShiftService sideShiftService, IHttpClientFactory httpClientFactory, - IEnumerable payoutHandlers, + PayoutMethodHandlerDictionary payoutMethodHandlerDictionary, PullPaymentHostedService pullPaymentHostedService, BTCPayNetworkJsonSerializerSettings serializerSettings, ApplicationDbContextFactory dbContextFactory) { _sideShiftService = sideShiftService; _httpClientFactory = httpClientFactory; - _payoutHandlers = payoutHandlers; + _payoutMethodHandlerDictionary = payoutMethodHandlerDictionary; _pullPaymentHostedService = pullPaymentHostedService; _serializerSettings = serializerSettings; _dbContextFactory = dbContextFactory; @@ -111,19 +112,23 @@ namespace BTCPayServer.Plugins.SideShift ModelState.AddModelError(nameof(request.Amount), "Amount must be specified"); } - if (!PaymentMethodId.TryParse(request.PaymentMethod, out var pmi)) + if (!PayoutMethodId.TryParse(request.PayoutMethodId, out var pmi)) { - ModelState.AddModelError(nameof(request.PaymentMethod), "Invalid payment method"); + ModelState.AddModelError(nameof(request.PayoutMethodId), "Invalid payout method"); } else { - handler = _payoutHandlers.FindPayoutHandler(pmi); - if (handler == null) + if (!_payoutMethodHandlerDictionary.TryGetValue(pmi, out handler)) { - ModelState.AddModelError(nameof(request.PaymentMethod), "Invalid payment method"); + ModelState.AddModelError(nameof(request.PayoutMethodId), "Invalid payment method"); } } - + var isLN = pmi.ToString().EndsWith("-" +PayoutTypes.LN.Id); + if (isLN) + { + + ModelState.AddModelError(nameof(request.PayoutMethodId), "SideShift does not support Lightning payouts"); + } if (!ModelState.IsValid) { return this.CreateValidationError(ModelState); @@ -166,13 +171,13 @@ namespace BTCPayServer.Plugins.SideShift // shiftResponse.EnsureSuccessStatusCode(); // var shift = await shiftResponse.Content.ReadAsAsync(); + var cryptoCode = pmi.ToString().Split('-')[0]; var shiftResponse = await client.PostAsJsonAsync("https://sideshift.ai/api/v2/shifts/variable", new { settleAddress = request.Destination, affiliateId = "qg0OrfHJV", settleMemo = request.Memo, - depositCoin = pmi.CryptoCode, - depositNetwork = pmi.PaymentType == LightningPaymentType.Instance ? "lightning" : null, + depositCoin = cryptoCode, settleCoin = request.ShiftCurrency, settleNetwork = request.ShiftNetwork, } @@ -188,20 +193,20 @@ namespace BTCPayServer.Plugins.SideShift var destination = - await handler.ParseAndValidateClaimDestination(pmi, shift.depositAddress, ppBlob, + await handler.ParseAndValidateClaimDestination(shift.depositAddress, ppBlob, CancellationToken.None); var claim = await _pullPaymentHostedService.Claim(new ClaimRequest() { PullPaymentId = pullPaymentId, Destination = destination.destination, - PaymentMethodId = pmi, + PayoutMethodId = pmi, Value = request.Amount }); if (claim.Result == ClaimRequest.ClaimResult.Ok) { await using var ctx = _dbContextFactory.CreateContext(); - ppBlob.Description += $"
The payout of {claim.PayoutData.Destination} will be forwarded to SideShift.ai for further conversion. Please go to the order page for support."; + ppBlob.Description += $"
The payout of {destination.destination} will be forwarded to SideShift.ai for further conversion. Please go to the order page for support."; pp.SetBlob(ppBlob); ctx.Attach(pp).State = EntityState.Modified; await ctx.SaveChangesAsync(); @@ -242,19 +247,21 @@ namespace BTCPayServer.Plugins.SideShift private Client.Models.PayoutData ToModel(Data.PayoutData p) { var blob = p.GetBlob(_serializerSettings); - var model = new Client.Models.PayoutData + var model = new Client.Models.PayoutData() { Id = p.Id, PullPaymentId = p.PullPaymentDataId, Date = p.Date, - Amount = blob.Amount, - PaymentMethodAmount = blob.CryptoAmount, + OriginalCurrency = p.OriginalCurrency, + OriginalAmount = p.OriginalAmount, + PayoutCurrency = p.Currency, + PayoutAmount = p.Amount, Revision = blob.Revision, State = p.State, + PayoutMethodId = p.PayoutMethodId, + PaymentProof = p.GetProofBlobJson(), Destination = blob.Destination, - PaymentMethod = p.PaymentMethodId, - CryptoCode = p.GetPaymentMethodId().CryptoCode, - PaymentProof = p.GetProofBlobJson() + Metadata = blob.Metadata?? new JObject(), }; return model; } diff --git a/Plugins/BTCPayServer.Plugins.SideShift/SideShiftPlugin.cs b/Plugins/BTCPayServer.Plugins.SideShift/SideShiftPlugin.cs index b01eafc..26c259a 100644 --- a/Plugins/BTCPayServer.Plugins.SideShift/SideShiftPlugin.cs +++ b/Plugins/BTCPayServer.Plugins.SideShift/SideShiftPlugin.cs @@ -1,6 +1,5 @@ using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Abstractions.Models; -using BTCPayServer.Abstractions.Services; using Microsoft.Extensions.DependencyInjection; namespace BTCPayServer.Plugins.SideShift @@ -8,41 +7,22 @@ namespace BTCPayServer.Plugins.SideShift public class SideShiftPlugin : BaseBTCPayServerPlugin { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = - { - new() {Identifier = nameof(BTCPayServer), Condition = ">=1.12.0"} + { new() { Identifier = nameof(BTCPayServer), Condition = ">=2.0.0" } + }; public override void Execute(IServiceCollection applicationBuilder) { applicationBuilder.AddSingleton(); applicationBuilder.AddHostedService(provider => provider.GetService()); - applicationBuilder.AddSingleton(new UIExtension("SideShift/SideShiftNav", - "store-integrations-nav")); - applicationBuilder.AddSingleton(new UIExtension("SideShift/PullPaymentViewInsert", - "pullpayment-foot")); - applicationBuilder.AddSingleton(new UIExtension("SideShift/StoreIntegrationSideShiftOption", - "store-integrations-list")); + + applicationBuilder.AddUIExtension("store-integrations-nav","SideShift/SideShiftNav"); + applicationBuilder.AddUIExtension("pullpayment-foot","SideShift/PullPaymentViewInsert"); + applicationBuilder.AddUIExtension("store-integrations-list", "SideShift/StoreIntegrationSideShiftOption"); // Checkout v2 - applicationBuilder.AddSingleton(new UIExtension("SideShift/CheckoutPaymentMethodExtension", - "checkout-payment-method")); - applicationBuilder.AddSingleton(new UIExtension("SideShift/CheckoutPaymentExtension", - "checkout-payment")); - // Checkout Classic - applicationBuilder.AddSingleton(new UIExtension("SideShift/CheckoutContentExtension", - "checkout-bitcoin-post-content")); - applicationBuilder.AddSingleton(new UIExtension("SideShift/CheckoutContentExtension", - "checkout-lightning-post-content")); - applicationBuilder.AddSingleton(new UIExtension("SideShift/CheckoutTabExtension", - "checkout-bitcoin-post-tabs")); - applicationBuilder.AddSingleton(new UIExtension("SideShift/CheckoutTabExtension", - "checkout-lightning-post-tabs")); - applicationBuilder.AddSingleton(new UIExtension("SideShift/CheckoutEnd", - "checkout-end")); - applicationBuilder.AddSingleton(new UIExtension("SideShift/PrismEnhance", - "prism-edit")); - applicationBuilder.AddSingleton(); - applicationBuilder.AddSingleton(); - applicationBuilder.AddSingleton(); + applicationBuilder.AddUIExtension("checkout-payment-method", "SideShift/CheckoutPaymentMethodExtension"); + applicationBuilder.AddUIExtension("checkout-payment","SideShift/CheckoutPaymentExtension"); + base.Execute(applicationBuilder); } } diff --git a/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/CheckoutContentExtension.cshtml b/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/CheckoutContentExtension.cshtml deleted file mode 100644 index 39be6f6..0000000 --- a/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/CheckoutContentExtension.cshtml +++ /dev/null @@ -1,26 +0,0 @@ -@using BTCPayServer.Plugins.SideShift -@inject SideShiftService SideShiftService -@model BTCPayServer.Models.InvoicingModels.PaymentModel - -@{ - var settings = await SideShiftService.GetSideShiftForInvoice(Model.InvoiceId, Model.StoreId); - - if (settings?.Enabled is true) - { -
-
- - {{$t("ConversionTab_BodyTop", srvModel)}} -

- {{$t("ConversionTab_BodyDesc", srvModel)}} -
-
- - {{$t("Pay with SideShift")}} - -
- } -} diff --git a/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/CheckoutEnd.cshtml b/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/CheckoutEnd.cshtml deleted file mode 100644 index 25ed496..0000000 --- a/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/CheckoutEnd.cshtml +++ /dev/null @@ -1,14 +0,0 @@ -@using BTCPayServer.Plugins.SideShift -@inject BTCPayServer.Security.ContentSecurityPolicies csp -@inject SideShiftService SideShiftService -@model BTCPayServer.Models.InvoicingModels.PaymentModel -@{ - var settings = await SideShiftService.GetSideShiftForInvoice(Model.InvoiceId, Model.StoreId); - if (settings?.Enabled is true) - { - csp.Add("script-src", "https://sideshift.ai"); - csp.Add("script-src", "*.sideshift.ai"); - - - } -} diff --git a/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/CheckoutPaymentExtension.cshtml b/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/CheckoutPaymentExtension.cshtml index e1d425b..dd2ee24 100644 --- a/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/CheckoutPaymentExtension.cshtml +++ b/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/CheckoutPaymentExtension.cshtml @@ -2,19 +2,18 @@ @using BTCPayServer.Payments @inject BTCPayServer.Security.ContentSecurityPolicies csp @inject SideShiftService SideShiftService -@model BTCPayServer.Models.InvoicingModels.PaymentModel +@model BTCPayServer.Models.InvoicingModels.CheckoutModel @{ var settings = await SideShiftService.GetSideShiftForInvoice(Model.InvoiceId, Model.StoreId); - var preferredTargetPaymentMethodId = ""; + PaymentMethodId preferredTargetPaymentMethodId = null; if(!PaymentMethodId.TryParse(settings?.PreferredTargetPaymentMethodId, out var preferredPMI)) { preferredTargetPaymentMethodId = null; } else { - preferredTargetPaymentMethodId = Model.AvailableCryptos.FirstOrDefault(crypto => - crypto.PaymentMethodId == settings.PreferredTargetPaymentMethodId || - (crypto.CryptoCode == preferredPMI.CryptoCode && crypto.PaymentMethodId.EndsWith(LNURLPayPaymentType.Instance.GetId()) || crypto.PaymentMethodId.EndsWith(LightningPaymentType.Instance.GetId())))?.PaymentMethodId; + preferredTargetPaymentMethodId = Model.AvailablePaymentMethods.FirstOrDefault(crypto => + crypto.PaymentMethodId == preferredPMI )?.PaymentMethodId; } } @if (settings?.Enabled is true) @@ -25,7 +24,8 @@ - - \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/PullPaymentViewInsert.cshtml b/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/PullPaymentViewInsert.cshtml index 0a6ba1b..21f7e48 100644 --- a/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/PullPaymentViewInsert.cshtml +++ b/Plugins/BTCPayServer.Plugins.SideShift/Views/Shared/SideShift/PullPaymentViewInsert.cshtml @@ -1,4 +1,5 @@ -@using BTCPayServer.Plugins.SideShift +@using BTCPayServer.Payouts +@using BTCPayServer.Plugins.SideShift @model BTCPayServer.Models.ViewPullPaymentModel @inject SideShiftService SideShiftService @{ @@ -14,7 +15,8 @@ return; } - var potentialPaymentMethods = Model.PaymentMethods;//.Where(id => id.CryptoCode.Equals(Model.Currency, StringComparison.OrdinalIgnoreCase)).ToList(); + var potentialPaymentMethods = Model.PayoutMethodIds.ToList();//.Where(id => id.CryptoCode.Equals(Model.Currency, StringComparison.OrdinalIgnoreCase)).ToList(); + potentialPaymentMethods.Remove(PayoutTypes.LN.GetPayoutMethodId("BTC")); if (Model.IsPending && potentialPaymentMethods.Any()) {