From 39a4be56416861fa38d1521e10ffac1b2f37a68b Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Thu, 17 Jun 2021 14:11:01 +0900 Subject: [PATCH] Remove HintAddress --- .../AltcoinTests/AltcoinTests.cs | 22 -------- .../Controllers/StoresController.Onchain.cs | 40 +-------------- BTCPayServer/Controllers/StoresController.cs | 3 +- BTCPayServer/DerivationSchemeParser.cs | 50 +------------------ .../DerivationSchemeViewModel.cs | 2 - .../ImportWallet/ConfirmAddresses.cshtml | 15 ------ 6 files changed, 4 insertions(+), 128 deletions(-) diff --git a/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs b/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs index 8ec19f555..da38b633f 100644 --- a/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs +++ b/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs @@ -954,28 +954,6 @@ normal: result = testnetParser.Parse(tpub); Assert.Equal(tpub, result.ToString()); - testnetParser.HintScriptPubKey = BitcoinAddress - .Create("tb1q4s33amqm8l7a07zdxcunqnn3gcsjcfz3xc573l", testnetParser.Network).ScriptPubKey; - result = testnetParser.Parse(tpub); - Assert.Equal(tpub, result.ToString()); - - testnetParser.HintScriptPubKey = BitcoinAddress - .Create("2N2humNio3YTApSfY6VztQ9hQwDnhDvaqFQ", testnetParser.Network).ScriptPubKey; - result = testnetParser.Parse(tpub); - Assert.Equal($"{tpub}-[p2sh]", result.ToString()); - - testnetParser.HintScriptPubKey = BitcoinAddress - .Create("mwD8bHS65cdgUf6rZUUSoVhi3wNQFu1Nfi", testnetParser.Network).ScriptPubKey; - result = testnetParser.Parse(tpub); - Assert.Equal($"{tpub}-[legacy]", result.ToString()); - - testnetParser.HintScriptPubKey = BitcoinAddress - .Create("2N2humNio3YTApSfY6VztQ9hQwDnhDvaqFQ", testnetParser.Network).ScriptPubKey; - result = testnetParser.Parse($"{tpub}-[legacy]"); - Assert.Equal($"{tpub}-[p2sh]", result.ToString()); - - result = testnetParser.Parse(tpub); - Assert.Equal($"{tpub}-[p2sh]", result.ToString()); var regtestParser = new DerivationSchemeParser(regtestNetworkProvider.GetNetwork("BTC")); var parsed = diff --git a/BTCPayServer/Controllers/StoresController.Onchain.cs b/BTCPayServer/Controllers/StoresController.Onchain.cs index 4cfc9e1ae..bd7ee0326 100644 --- a/BTCPayServer/Controllers/StoresController.Onchain.cs +++ b/BTCPayServer/Controllers/StoresController.Onchain.cs @@ -114,7 +114,7 @@ namespace BTCPayServer.Controllers { try { - var newStrategy = ParseDerivationStrategy(vm.DerivationScheme, null, network); + var newStrategy = ParseDerivationStrategy(vm.DerivationScheme, network); if (newStrategy.AccountDerivation != strategy?.AccountDerivation) { var accountKey = string.IsNullOrEmpty(vm.AccountKey) @@ -160,8 +160,6 @@ namespace BTCPayServer.Controllers var willBeExcluded = !vm.Enabled; var showAddress = // Show addresses if: - // - If the user is testing the hint address in confirmation screen - (vm.Confirmation && !string.IsNullOrWhiteSpace(vm.HintAddress)) || // - The user is clicking on continue after changing the config (!vm.Confirmation && configChanged); @@ -191,42 +189,6 @@ namespace BTCPayServer.Controllers // This is success case when derivation scheme is added to the store return RedirectToAction(nameof(UpdateStore), new {storeId = vm.StoreId}); } - - if (!string.IsNullOrEmpty(vm.HintAddress)) - { - BitcoinAddress address; - try - { - address = BitcoinAddress.Create(vm.HintAddress, network.NBitcoinNetwork); - } - catch - { - ModelState.AddModelError(nameof(vm.HintAddress), "Invalid hint address"); - return ConfirmAddresses(vm, strategy); - } - - try - { - var newStrategy = ParseDerivationStrategy(vm.DerivationScheme, address.ScriptPubKey, network); - if (newStrategy.AccountDerivation != strategy.AccountDerivation) - { - strategy.AccountDerivation = newStrategy.AccountDerivation; - strategy.AccountOriginal = null; - } - } - catch - { - ModelState.AddModelError(nameof(vm.HintAddress), "Impossible to find a match with this address. Are you sure the wallet and address provided are correct and from the same source?"); - return ConfirmAddresses(vm, strategy); - } - - vm.HintAddress = ""; - TempData[WellKnownTempData.SuccessMessage] = - "Address successfully found, please verify that the rest is correct and click on \"Confirm\""; - ModelState.Remove(nameof(vm.HintAddress)); - ModelState.Remove(nameof(vm.DerivationScheme)); - } - return ConfirmAddresses(vm, strategy); } diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index d95cfd37d..1c270f7b6 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -689,10 +689,9 @@ namespace BTCPayServer.Controllers } - private DerivationSchemeSettings ParseDerivationStrategy(string derivationScheme, Script hint, BTCPayNetwork network) + private DerivationSchemeSettings ParseDerivationStrategy(string derivationScheme, BTCPayNetwork network) { var parser = new DerivationSchemeParser(network); - parser.HintScriptPubKey = hint; try { var derivationSchemeSettings = new DerivationSchemeSettings(); diff --git a/BTCPayServer/DerivationSchemeParser.cs b/BTCPayServer/DerivationSchemeParser.cs index bd79c9634..7e8d9845f 100644 --- a/BTCPayServer/DerivationSchemeParser.cs +++ b/BTCPayServer/DerivationSchemeParser.cs @@ -13,8 +13,6 @@ namespace BTCPayServer public Network Network => BtcPayNetwork.NBitcoinNetwork; - public Script HintScriptPubKey { get; set; } - public DerivationSchemeParser(BTCPayNetwork expectedNetwork) { if (expectedNetwork == null) @@ -131,19 +129,6 @@ namespace BTCPayServer HashSet hintedLabels = new HashSet(); - var hintDestination = HintScriptPubKey?.GetDestination(); - if (hintDestination != null) - { - if (hintDestination is KeyId) - { - hintedLabels.Add("legacy"); - } - if (hintDestination is ScriptId) - { - hintedLabels.Add("p2sh"); - } - } - if (!Network.Consensus.SupportSegwit) { hintedLabels.Add("legacy"); @@ -152,8 +137,7 @@ namespace BTCPayServer try { - var result = BtcPayNetwork.NBXplorerNetwork.DerivationStrategyFactory.Parse(str); - return FindMatch(hintedLabels, result); + return BtcPayNetwork.NBXplorerNetwork.DerivationStrategyFactory.Parse(str); } catch { @@ -205,22 +189,13 @@ namespace BTCPayServer catch { continue; } } - if (hintDestination != null) - { - if (hintDestination is WitKeyId) - { - hintedLabels.Remove("legacy"); - hintedLabels.Remove("p2sh"); - } - } - str = string.Join('-', parts.Where(p => !IsLabel(p))); foreach (var label in hintedLabels) { str = $"{str}-[{label}]"; } - return FindMatch(hintedLabels, BtcPayNetwork.NBXplorerNetwork.DerivationStrategyFactory.Parse(str)); + return BtcPayNetwork.NBXplorerNetwork.DerivationStrategyFactory.Parse(str); } public static BitcoinExtPubKey GetBitcoinExtPubKeyByNetwork(Network network, byte[] data) @@ -235,27 +210,6 @@ namespace BTCPayServer } } - private DerivationStrategyBase FindMatch(HashSet hintLabels, DerivationStrategyBase result) - { - var firstKeyPath = new KeyPath("0/0"); - if (HintScriptPubKey == null) - return result; - if (HintScriptPubKey == result.GetDerivation(firstKeyPath).ScriptPubKey) - return result; - - if (result is MultisigDerivationStrategy) - hintLabels.Add("keeporder"); - - var resultNoLabels = result.ToString(); - resultNoLabels = string.Join('-', resultNoLabels.Split('-').Where(p => !IsLabel(p))); - foreach (var labels in ItemCombinations(hintLabels.ToList())) - { - var hinted = BtcPayNetwork.NBXplorerNetwork.DerivationStrategyFactory.Parse(resultNoLabels + '-' + string.Join('-', labels.Select(l => $"[{l}]").ToArray())); - if (HintScriptPubKey == hinted.GetDerivation(firstKeyPath).ScriptPubKey) - return hinted; - } - throw new FormatException("Could not find any match"); - } private static bool IsLabel(string v) { diff --git a/BTCPayServer/Models/StoreViewModels/DerivationSchemeViewModel.cs b/BTCPayServer/Models/StoreViewModels/DerivationSchemeViewModel.cs index a88b277ef..1b0408548 100644 --- a/BTCPayServer/Models/StoreViewModels/DerivationSchemeViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/DerivationSchemeViewModel.cs @@ -20,8 +20,6 @@ namespace BTCPayServer.Models.StoreViewModels public string KeyPath { get; set; } [Display(Name = "Root fingerprint")] public string RootFingerprint { get; set; } - [Display(Name = "Hint address")] - public string HintAddress { get; set; } public bool Confirmation { get; set; } public bool Enabled { get; set; } = true; diff --git a/BTCPayServer/Views/Stores/ImportWallet/ConfirmAddresses.cshtml b/BTCPayServer/Views/Stores/ImportWallet/ConfirmAddresses.cshtml index cbdc1a32d..f795e4243 100644 --- a/BTCPayServer/Views/Stores/ImportWallet/ConfirmAddresses.cshtml +++ b/BTCPayServer/Views/Stores/ImportWallet/ConfirmAddresses.cshtml @@ -83,21 +83,6 @@ -
- -
-
-
- - - -
-
-
-
-