From 19bc511f393908491fc3a16ab2dfb8f64e1bc002 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Thu, 30 May 2019 23:16:05 +0900 Subject: [PATCH] Can update PSBT, fix the PSBT review page --- .../BTCPayServer.Common.csproj | 4 +-- BTCPayServer.Tests/docker-compose.yml | 2 +- .../Controllers/WalletsController.PSBT.cs | 32 +++++++++++++++++-- BTCPayServer/Views/Wallets/WalletPSBT.cshtml | 17 +++++++--- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/BTCPayServer.Common/BTCPayServer.Common.csproj b/BTCPayServer.Common/BTCPayServer.Common.csproj index 7455f1833..cafcb6ed6 100644 --- a/BTCPayServer.Common/BTCPayServer.Common.csproj +++ b/BTCPayServer.Common/BTCPayServer.Common.csproj @@ -7,7 +7,7 @@ - - + + diff --git a/BTCPayServer.Tests/docker-compose.yml b/BTCPayServer.Tests/docker-compose.yml index 8b5e32664..a16136d61 100644 --- a/BTCPayServer.Tests/docker-compose.yml +++ b/BTCPayServer.Tests/docker-compose.yml @@ -71,7 +71,7 @@ services: nbxplorer: - image: nicolasdorier/nbxplorer:2.0.0.45 + image: nicolasdorier/nbxplorer:2.0.0.48 restart: unless-stopped ports: - "32838:32838" diff --git a/BTCPayServer/Controllers/WalletsController.PSBT.cs b/BTCPayServer/Controllers/WalletsController.PSBT.cs index 7933cbeca..7200fc131 100644 --- a/BTCPayServer/Controllers/WalletsController.PSBT.cs +++ b/BTCPayServer/Controllers/WalletsController.PSBT.cs @@ -86,6 +86,20 @@ namespace BTCPayServer.Controllers return View(vm); case "ledger": return ViewWalletSendLedger(psbt); + case "update": + var derivationSchemeSettings = await GetDerivationSchemeSettings(walletId); + psbt = await UpdatePSBT(derivationSchemeSettings, psbt, network); + if (psbt == null) + { + StatusMessage = "Error: You need to update NBXplorer"; + return View(vm); + } + ModelState.Remove(nameof(vm.PSBT)); + ModelState.Remove(nameof(vm.UploadedPSBTFile)); + vm.PSBT = psbt.ToBase64(); + vm.Decoded = psbt.ToString(); + StatusMessage = "PSBT updated!"; + return View(vm); case "seed": return SignWithSeed(walletId, psbt.ToBase64()); case "broadcast": @@ -102,6 +116,19 @@ namespace BTCPayServer.Controllers } } + private async Task UpdatePSBT(DerivationSchemeSettings derivationSchemeSettings, PSBT psbt, BTCPayNetwork network) + { + var result = await ExplorerClientProvider.GetExplorerClient(network).UpdatePSBTAsync(new UpdatePSBTRequest() + { + PSBT = psbt, + DerivationScheme = derivationSchemeSettings.AccountDerivation, + }); + if (result == null) + return null; + derivationSchemeSettings.RebaseKeyPaths(result.PSBT); + return result.PSBT; + } + [HttpGet] [Route("{walletId}/psbt/ready")] public async Task WalletPSBTReady( @@ -122,12 +149,12 @@ namespace BTCPayServer.Controllers return View(nameof(WalletPSBTReady), vm); } - private Task FetchTransactionDetails(DerivationSchemeSettings derivationSchemeSettings, WalletPSBTReadyViewModel vm, BTCPayNetwork network) + private async Task FetchTransactionDetails(DerivationSchemeSettings derivationSchemeSettings, WalletPSBTReadyViewModel vm, BTCPayNetwork network) { var psbtObject = PSBT.Parse(vm.PSBT, network.NBitcoinNetwork); + psbtObject = await UpdatePSBT(derivationSchemeSettings, psbtObject, network) ?? psbtObject; IHDKey signingKey = null; RootedKeyPath signingKeyPath = null; - try { signingKey = new BitcoinExtPubKey(vm.SigningKey, network.NBitcoinNetwork); @@ -203,7 +230,6 @@ namespace BTCPayServer.Controllers { vm.SetErrors(errors); } - return Task.CompletedTask; } [HttpPost] diff --git a/BTCPayServer/Views/Wallets/WalletPSBT.cshtml b/BTCPayServer/Views/Wallets/WalletPSBT.cshtml index 8878c9b13..24292c3c2 100644 --- a/BTCPayServer/Views/Wallets/WalletPSBT.cshtml +++ b/BTCPayServer/Views/Wallets/WalletPSBT.cshtml @@ -27,19 +27,28 @@

Decoded PSBT

+ + + +