diff --git a/BTCPayServer/Controllers/WalletsController.cs b/BTCPayServer/Controllers/WalletsController.cs index 51ff32933..aa1f6409e 100644 --- a/BTCPayServer/Controllers/WalletsController.cs +++ b/BTCPayServer/Controllers/WalletsController.cs @@ -233,25 +233,19 @@ namespace BTCPayServer.Controllers if (command == "ledger") { - return View("WalletSendLedger", new WalletSendLedgerModel() - { - PSBT = psbt.PSBT.ToBase64(), - HintChange = psbt.ChangeAddress?.ToString(), - WebsocketPath = this.Url.Action(nameof(LedgerConnection)), - SuccessPath = this.Url.Action(nameof(WalletSendLedgerSuccess)) - }); + return ViewWalletSendLedger(psbt.PSBT, psbt.ChangeAddress); } else { try - { + { 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"); + return FilePSBT(psbt.PSBT, $"Send-{vm.Amount.Value}-{network.CryptoCode}-to-{destination[0].ToString()}.psbt"); } catch (NBXplorerException ex) { @@ -266,6 +260,22 @@ namespace BTCPayServer.Controllers } } + private IActionResult FilePSBT(PSBT psbt, string fileName) + { + return File(psbt.ToBytes(), "application/octet-stream", fileName); + } + + private ViewResult ViewWalletSendLedger(PSBT psbt, BitcoinAddress hintChange = null) + { + return View("WalletSendLedger", new WalletSendLedgerModel() + { + PSBT = psbt.ToBase64(), + HintChange = hintChange?.ToString(), + WebsocketPath = this.Url.Action(nameof(LedgerConnection)), + SuccessPath = this.Url.Action(nameof(WalletSendLedgerSuccess)) + }); + } + [NonAction] public async Task CreatePSBT(BTCPayNetwork network, DerivationSchemeSettings derivationSettings, WalletSendModel sendModel, CancellationToken cancellationToken) { @@ -342,6 +352,26 @@ namespace BTCPayServer.Controllers return View(vm); } + [HttpPost] + [Route("{walletId}/psbt/sign")] + public IActionResult WalletPSBTSign( + [ModelBinder(typeof(WalletIdModelBinder))] + WalletId walletId, + WalletPSBTViewModel vm, + string command = null + ) + { + var psbt = PSBT.Parse(vm.PSBT, NetworkProvider.GetNetwork(walletId.CryptoCode).NBitcoinNetwork); + if (command == "ledger") + { + return ViewWalletSendLedger(psbt); + } + else + { + return FilePSBT(psbt, "psbt-export.psbt"); + } + } + [HttpGet] [Route("{walletId}/rescan")] public async Task WalletRescan( diff --git a/BTCPayServer/Views/Wallets/WalletPSBT.cshtml b/BTCPayServer/Views/Wallets/WalletPSBT.cshtml index f530669d3..94d92b85c 100644 --- a/BTCPayServer/Views/Wallets/WalletPSBT.cshtml +++ b/BTCPayServer/Views/Wallets/WalletPSBT.cshtml @@ -10,6 +10,20 @@ {

Decoded PSBT

@Model.Decoded
+
+ +
}

PSBT to decode