diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index fdb50a7b8..c3fe030ee 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -182,6 +182,9 @@ $(IncludeRazorContentInPack) + + $(IncludeRazorContentInPack) + $(IncludeRazorContentInPack) diff --git a/BTCPayServer/Controllers/WalletsController.cs b/BTCPayServer/Controllers/WalletsController.cs index 1af3ca45a..c79dd6947 100644 --- a/BTCPayServer/Controllers/WalletsController.cs +++ b/BTCPayServer/Controllers/WalletsController.cs @@ -247,6 +247,12 @@ namespace BTCPayServer.Controllers try { var psbt = await CreatePSBT(network, derivationScheme, sendModel, cancellation); + if (command == "analyze-psbt") + return View(nameof(WalletPSBT), new WalletPSBTViewModel() + { + Decoded = psbt.PSBT.ToString(), + PSBT = psbt.PSBT.ToBase64() + }); return File(psbt.PSBT.ToBytes(), "application/octet-stream", $"Send-{vm.Amount.Value}-{network.CryptoCode}-to-{destination[0].ToString()}.psbt"); } catch (NBXplorerException ex) @@ -331,6 +337,31 @@ namespace BTCPayServer.Controllers } } + [HttpGet] + [Route("{walletId}/psbt")] + public IActionResult WalletPSBT() + { + return View(new WalletPSBTViewModel()); + } + [HttpPost] + [Route("{walletId}/psbt")] + public IActionResult WalletPSBT( + [ModelBinder(typeof(WalletIdModelBinder))] + WalletId walletId, + WalletPSBTViewModel vm) + { + try + { + if (!string.IsNullOrEmpty(vm.PSBT)) + vm.Decoded = PSBT.Parse(vm.PSBT, NetworkProvider.GetNetwork(walletId.CryptoCode).NBitcoinNetwork).ToString(); + } + catch (FormatException ex) + { + ModelState.AddModelError(nameof(vm.PSBT), ex.Message); + } + return View(vm); + } + [HttpGet] [Route("{walletId}/rescan")] public async Task WalletRescan( diff --git a/BTCPayServer/Models/WalletViewModels/WalletPSBTViewModel.cs b/BTCPayServer/Models/WalletViewModels/WalletPSBTViewModel.cs new file mode 100644 index 000000000..860999d58 --- /dev/null +++ b/BTCPayServer/Models/WalletViewModels/WalletPSBTViewModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace BTCPayServer.Models.WalletViewModels +{ + public class WalletPSBTViewModel + { + public string Decoded { get; set; } + public string PSBT { get; set; } + } +} diff --git a/BTCPayServer/Views/Wallets/WalletPSBT.cshtml b/BTCPayServer/Views/Wallets/WalletPSBT.cshtml new file mode 100644 index 000000000..f530669d3 --- /dev/null +++ b/BTCPayServer/Views/Wallets/WalletPSBT.cshtml @@ -0,0 +1,29 @@ +@model WalletPSBTViewModel +@{ + Layout = "../Shared/_NavLayout.cshtml"; + ViewData["Title"] = "PSBT"; + ViewData.SetActivePageAndTitle(WalletsNavPages.PSBT); +} +
+
+ @if (!string.IsNullOrEmpty(Model.Decoded)) + { +

Decoded PSBT

+
@Model.Decoded
+ } +

PSBT to decode

+
+
+ + +
+ +
+
+
+ +@section Scripts { + + + +} diff --git a/BTCPayServer/Views/Wallets/WalletSend.cshtml b/BTCPayServer/Views/Wallets/WalletSend.cshtml index 8256befee..074cc6a92 100644 --- a/BTCPayServer/Views/Wallets/WalletSend.cshtml +++ b/BTCPayServer/Views/Wallets/WalletSend.cshtml @@ -90,6 +90,7 @@ diff --git a/BTCPayServer/Views/Wallets/WalletsNavPages.cs b/BTCPayServer/Views/Wallets/WalletsNavPages.cs index 98f142778..9b4509933 100644 --- a/BTCPayServer/Views/Wallets/WalletsNavPages.cs +++ b/BTCPayServer/Views/Wallets/WalletsNavPages.cs @@ -9,6 +9,7 @@ namespace BTCPayServer.Views.Wallets { Send, Transactions, - Rescan + Rescan, + PSBT } } diff --git a/BTCPayServer/Views/Wallets/_Nav.cshtml b/BTCPayServer/Views/Wallets/_Nav.cshtml index 521bf2db8..69d85e52c 100644 --- a/BTCPayServer/Views/Wallets/_Nav.cshtml +++ b/BTCPayServer/Views/Wallets/_Nav.cshtml @@ -4,5 +4,6 @@ Transactions Send Rescan + PSBT