mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Remove HintAddress
This commit is contained in:
@@ -954,28 +954,6 @@ normal:
|
|||||||
|
|
||||||
result = testnetParser.Parse(tpub);
|
result = testnetParser.Parse(tpub);
|
||||||
Assert.Equal(tpub, result.ToString());
|
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<BTCPayNetwork>("BTC"));
|
var regtestParser = new DerivationSchemeParser(regtestNetworkProvider.GetNetwork<BTCPayNetwork>("BTC"));
|
||||||
var parsed =
|
var parsed =
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var newStrategy = ParseDerivationStrategy(vm.DerivationScheme, null, network);
|
var newStrategy = ParseDerivationStrategy(vm.DerivationScheme, network);
|
||||||
if (newStrategy.AccountDerivation != strategy?.AccountDerivation)
|
if (newStrategy.AccountDerivation != strategy?.AccountDerivation)
|
||||||
{
|
{
|
||||||
var accountKey = string.IsNullOrEmpty(vm.AccountKey)
|
var accountKey = string.IsNullOrEmpty(vm.AccountKey)
|
||||||
@@ -160,8 +160,6 @@ namespace BTCPayServer.Controllers
|
|||||||
var willBeExcluded = !vm.Enabled;
|
var willBeExcluded = !vm.Enabled;
|
||||||
|
|
||||||
var showAddress = // Show addresses if:
|
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
|
// - The user is clicking on continue after changing the config
|
||||||
(!vm.Confirmation && configChanged);
|
(!vm.Confirmation && configChanged);
|
||||||
|
|
||||||
@@ -191,42 +189,6 @@ namespace BTCPayServer.Controllers
|
|||||||
// This is success case when derivation scheme is added to the store
|
// This is success case when derivation scheme is added to the store
|
||||||
return RedirectToAction(nameof(UpdateStore), new {storeId = vm.StoreId});
|
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);
|
return ConfirmAddresses(vm, strategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
var parser = new DerivationSchemeParser(network);
|
||||||
parser.HintScriptPubKey = hint;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var derivationSchemeSettings = new DerivationSchemeSettings();
|
var derivationSchemeSettings = new DerivationSchemeSettings();
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ namespace BTCPayServer
|
|||||||
|
|
||||||
public Network Network => BtcPayNetwork.NBitcoinNetwork;
|
public Network Network => BtcPayNetwork.NBitcoinNetwork;
|
||||||
|
|
||||||
public Script HintScriptPubKey { get; set; }
|
|
||||||
|
|
||||||
public DerivationSchemeParser(BTCPayNetwork expectedNetwork)
|
public DerivationSchemeParser(BTCPayNetwork expectedNetwork)
|
||||||
{
|
{
|
||||||
if (expectedNetwork == null)
|
if (expectedNetwork == null)
|
||||||
@@ -131,19 +129,6 @@ namespace BTCPayServer
|
|||||||
|
|
||||||
HashSet<string> hintedLabels = new HashSet<string>();
|
HashSet<string> hintedLabels = new HashSet<string>();
|
||||||
|
|
||||||
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)
|
if (!Network.Consensus.SupportSegwit)
|
||||||
{
|
{
|
||||||
hintedLabels.Add("legacy");
|
hintedLabels.Add("legacy");
|
||||||
@@ -152,8 +137,7 @@ namespace BTCPayServer
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = BtcPayNetwork.NBXplorerNetwork.DerivationStrategyFactory.Parse(str);
|
return BtcPayNetwork.NBXplorerNetwork.DerivationStrategyFactory.Parse(str);
|
||||||
return FindMatch(hintedLabels, result);
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -205,22 +189,13 @@ namespace BTCPayServer
|
|||||||
catch { continue; }
|
catch { continue; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hintDestination != null)
|
|
||||||
{
|
|
||||||
if (hintDestination is WitKeyId)
|
|
||||||
{
|
|
||||||
hintedLabels.Remove("legacy");
|
|
||||||
hintedLabels.Remove("p2sh");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
str = string.Join('-', parts.Where(p => !IsLabel(p)));
|
str = string.Join('-', parts.Where(p => !IsLabel(p)));
|
||||||
foreach (var label in hintedLabels)
|
foreach (var label in hintedLabels)
|
||||||
{
|
{
|
||||||
str = $"{str}-[{label}]";
|
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)
|
public static BitcoinExtPubKey GetBitcoinExtPubKeyByNetwork(Network network, byte[] data)
|
||||||
@@ -235,27 +210,6 @@ namespace BTCPayServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private DerivationStrategyBase FindMatch(HashSet<string> 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)
|
private static bool IsLabel(string v)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ namespace BTCPayServer.Models.StoreViewModels
|
|||||||
public string KeyPath { get; set; }
|
public string KeyPath { get; set; }
|
||||||
[Display(Name = "Root fingerprint")]
|
[Display(Name = "Root fingerprint")]
|
||||||
public string RootFingerprint { get; set; }
|
public string RootFingerprint { get; set; }
|
||||||
[Display(Name = "Hint address")]
|
|
||||||
public string HintAddress { get; set; }
|
|
||||||
public bool Confirmation { get; set; }
|
public bool Confirmation { get; set; }
|
||||||
public bool Enabled { get; set; } = true;
|
public bool Enabled { get; set; } = true;
|
||||||
|
|
||||||
|
|||||||
@@ -83,21 +83,6 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="text-center mb-4">
|
|
||||||
<button class="btn btn-link" type="button" data-bs-toggle="collapse" data-bs-target="#wrong-addresses" aria-expanded="false" aria-controls="wrong-addresses">
|
|
||||||
Wrong addresses?
|
|
||||||
</button>
|
|
||||||
<div id="wrong-addresses" class="collapse @(ViewContext.ModelState.IsValid ? "" : "show")">
|
|
||||||
<div class="pb-1">
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="HintAddress" class="form-label">Help us to find the correct settings by telling us the first address of your wallet.</label>
|
|
||||||
<input asp-for="HintAddress" class="form-control"/>
|
|
||||||
<span asp-validation-for="HintAddress" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<button name="command" type="submit" class="btn btn-primary" value="save" id="Confirm">Confirm</button>
|
<button name="command" type="submit" class="btn btn-primary" value="save" id="Confirm">Confirm</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user