From 89fd044b004aaf916c423e08101cc4a91c42979e Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Thu, 7 Oct 2021 16:54:22 +0900 Subject: [PATCH] Replace pruning wallet by wipe transactions (#2857) --- BTCPayServer.Common/BTCPayServer.Common.csproj | 2 +- BTCPayServer/Controllers/WalletsController.cs | 18 ++++++++++++++++-- .../Views/Wallets/WalletSettings.cshtml | 6 +++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/BTCPayServer.Common/BTCPayServer.Common.csproj b/BTCPayServer.Common/BTCPayServer.Common.csproj index 8211f1c57..d2c4d24f3 100644 --- a/BTCPayServer.Common/BTCPayServer.Common.csproj +++ b/BTCPayServer.Common/BTCPayServer.Common.csproj @@ -1,4 +1,4 @@ - + diff --git a/BTCPayServer/Controllers/WalletsController.cs b/BTCPayServer/Controllers/WalletsController.cs index ae588b7dc..78d0ae7d2 100644 --- a/BTCPayServer/Controllers/WalletsController.cs +++ b/BTCPayServer/Controllers/WalletsController.cs @@ -1169,8 +1169,7 @@ namespace BTCPayServer.Controllers } else if (command == "prune") { - var result = await ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode) - .PruneAsync(derivationScheme.AccountDerivation, new PruneRequest(), cancellationToken); + var result = await ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode).PruneAsync(derivationScheme.AccountDerivation, new PruneRequest(), cancellationToken); if (result.TotalPruned == 0) { TempData[WellKnownTempData.SuccessMessage] = $"The wallet is already pruned"; @@ -1183,6 +1182,21 @@ namespace BTCPayServer.Controllers return RedirectToAction(nameof(WalletSettings)); } + else if (command == "clear" && User.IsInRole(Roles.ServerAdmin)) + { + if (Version.TryParse(_dashboard.Get(walletId.CryptoCode)?.Status?.Version ?? "0.0.0.0", out var v) && + v < new Version(2, 2, 4)) + { + TempData[WellKnownTempData.ErrorMessage] = $"This version of NBXplorer doesn't support this operation, please upgrade to 2.2.4 or above"; + } + else + { + await ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode) + .WipeAsync(derivationScheme.AccountDerivation, cancellationToken); + TempData[WellKnownTempData.SuccessMessage] = $"The transactions have been wiped out, to restore your balance, rescan the wallet."; + } + return RedirectToAction(nameof(WalletSettings)); + } else if (command == "view-seed" && await CanUseHotWallet()) { if (await GetSeed(walletId, derivationScheme.Network) != null) diff --git a/BTCPayServer/Views/Wallets/WalletSettings.cshtml b/BTCPayServer/Views/Wallets/WalletSettings.cshtml index 078a17cc5..f964772c8 100644 --- a/BTCPayServer/Views/Wallets/WalletSettings.cshtml +++ b/BTCPayServer/Views/Wallets/WalletSettings.cshtml @@ -1,4 +1,4 @@ -@using Newtonsoft.Json +@using Newtonsoft.Json @using System.Text @using NBitcoin.DataEncoders @model WalletSettingsViewModel @@ -71,6 +71,10 @@