Make keypath related things properties.
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabViewModel.cs
@@ -106,7 +106,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
foreach (HdPubKey key in Global.WalletService.KeyManager.GetKeys(x =>
x.HasLabel()
- && !x.IsInternal()
+ && !x.IsInternal
&& x.KeyState == KeyState.Clean)
.Reverse())
{

MODIFY
WalletWasabi.Tests/KeyManagementTests.cs
WalletWasabi.Tests/KeyManagementTests.cs
@@ -146,7 +146,7 @@ namespace WalletWasabi.Tests
var keyState = (KeyState)random.Next(3);
var generatedKey = manager.GenerateNewKey(label, keyState, isInternal);
- Assert.Equal(isInternal, generatedKey.IsInternal());
+ Assert.Equal(isInternal, generatedKey.IsInternal);
Assert.Equal(label, generatedKey.Label);
Assert.Equal(keyState, generatedKey.KeyState);
Assert.StartsWith("84'/0'/0'", generatedKey.FullKeyPath.ToString());

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -604,8 +604,8 @@ namespace WalletWasabi.Tests
Assert.Equal(42, keyManager.GetKeys(KeyState.Clean).Count());
Assert.Equal(58, keyManager.GetKeys().Count());
- Assert.Single(keyManager.GetKeys(x => x.Label == "foo label" && x.KeyState == KeyState.Used && !x.IsInternal()));
- Assert.Single(keyManager.GetKeys(x => x.Label == "bar label" && x.KeyState == KeyState.Used && !x.IsInternal()));
+ Assert.Single(keyManager.GetKeys(x => x.Label == "foo label" && x.KeyState == KeyState.Used && !x.IsInternal));
+ Assert.Single(keyManager.GetKeys(x => x.Label == "bar label" && x.KeyState == KeyState.Used && !x.IsInternal));
// REORG TESTS
var txid4 = await rpc.SendToAddressAsync(key2.GetP2wpkhAddress(network), Money.Coins(0.03m), replaceable: true);

MODIFY
WalletWasabi/KeyManagement/HdPubKey.cs
WalletWasabi/KeyManagement/HdPubKey.cs
@@ -35,6 +35,20 @@ namespace WalletWasabi.KeyManagement
P2pkhScript = PubKey.Hash.ScriptPubKey;
P2wpkhScript = PubKey.WitHash.ScriptPubKey;
P2shOverP2wpkhScript = P2wpkhScript.Hash.ScriptPubKey;
+
+ Index = (int)FullKeyPath.Indexes[4];
+ NonHardenedKeyPath = new KeyPath(FullKeyPath[3], FullKeyPath[4]);
+
+ int change = (int)FullKeyPath.Indexes[3];
+ if (change == 0)
+ {
+ IsInternal = false;
+ }
+ else if (change == 1)
+ {
+ IsInternal = true;
+ }
+ else throw new ArgumentException(nameof(FullKeyPath));
}
public void SetLabel(string label, KeyManager kmToFile = null)
@@ -55,53 +69,20 @@ namespace WalletWasabi.KeyManagement
}
public Script P2pkScript { get; }
-
public Script P2pkhScript { get; }
-
public Script P2wpkhScript { get; }
-
public Script P2shOverP2wpkhScript { get; }
+ public int Index { get; }
+ public KeyPath NonHardenedKeyPath { get; }
+ public bool IsInternal { get; }
+
public BitcoinPubKeyAddress GetP2pkhAddress(Network network) => PubKey.GetAddress(network);
public BitcoinWitPubKeyAddress GetP2wpkhAddress(Network network) => PubKey.GetSegwitAddress(network);
public BitcoinScriptAddress GetP2shOverP2wpkhAddress(Network network) => P2wpkhScript.GetScriptAddress(network);
- private int? _index = null;
-
- public int GetIndex()
- {
- return (int)(_index ?? (_index = (int)FullKeyPath.Indexes[4]));
- }
-
- private KeyPath _nonHardenedKeyPath = null;
-
- public KeyPath NonHardenedKeyPath()
- {
- return _nonHardenedKeyPath ?? (_nonHardenedKeyPath = new KeyPath(FullKeyPath[3], FullKeyPath[4]));
- }
-
- private bool? _isInternal = null;
-
- public bool IsInternal()
- {
- if (_isInternal is null)
- {
- int change = (int)FullKeyPath.Indexes[3];
- if (change == 0)
- {
- _isInternal = false;
- }
- else if (change == 1)
- {
- _isInternal = true;
- }
- else throw new ArgumentException(nameof(FullKeyPath));
- }
- return (bool)_isInternal;
- }
-
public bool HasLabel() => !string.IsNullOrEmpty(Label);
#region Equality

MODIFY
WalletWasabi/KeyManagement/KeyManager.cs
WalletWasabi/KeyManagement/KeyManager.cs
@@ -182,11 +182,11 @@ namespace WalletWasabi.KeyManagement
IEnumerable<HdPubKey> relevantHdPubKeys;
if (isInternal)
{
- relevantHdPubKeys = HdPubKeys.Where(x => x.IsInternal());
+ relevantHdPubKeys = HdPubKeys.Where(x => x.IsInternal);
}
else
{
- relevantHdPubKeys = HdPubKeys.Where(x => !x.IsInternal());
+ relevantHdPubKeys = HdPubKeys.Where(x => !x.IsInternal);
}
KeyPath path;
@@ -196,16 +196,16 @@ namespace WalletWasabi.KeyManagement
}
else
{
- int largestIndex = relevantHdPubKeys.Max(x => x.GetIndex());
- List<int> missingIndexes = Enumerable.Range(0, largestIndex).Except(relevantHdPubKeys.Select(x => x.GetIndex())).ToList();
+ int largestIndex = relevantHdPubKeys.Max(x => x.Index);
+ List<int> missingIndexes = Enumerable.Range(0, largestIndex).Except(relevantHdPubKeys.Select(x => x.Index)).ToList();
if (missingIndexes.Any())
{
int smallestMissingIndex = missingIndexes.Min();
- path = relevantHdPubKeys.First(x => x.GetIndex() == (smallestMissingIndex - 1)).NonHardenedKeyPath().Increment();
+ path = relevantHdPubKeys.First(x => x.Index == (smallestMissingIndex - 1)).NonHardenedKeyPath.Increment();
}
else
{
- path = relevantHdPubKeys.First(x => x.GetIndex() == largestIndex).NonHardenedKeyPath().Increment();
+ path = relevantHdPubKeys.First(x => x.Index == largestIndex).NonHardenedKeyPath.Increment();
}
}
@@ -262,9 +262,9 @@ namespace WalletWasabi.KeyManagement
}
else if (keyState is null)
{
- return GetKeys(x => x.IsInternal() == isInternal);
+ return GetKeys(x => x.IsInternal == isInternal);
}
- return GetKeys(x => x.IsInternal() == isInternal && x.KeyState == keyState);
+ return GetKeys(x => x.IsInternal == isInternal && x.KeyState == keyState);
}
public IEnumerable<byte[]> GetPubKeyScriptBytes()

MODIFY
WalletWasabi/Services/CcjClient.cs
WalletWasabi/Services/CcjClient.cs
@@ -666,7 +666,7 @@ namespace WalletWasabi.Services
// Get all locked internal keys we have and assert we have enough.
KeyManager.AssertLockedInternalKeysIndexed(howMany: maximumMixingLevelCount + 1);
- IEnumerable<HdPubKey> allLockedInternalKeys = KeyManager.GetKeys(x => x.IsInternal() && x.KeyState == KeyState.Locked && !keysTryNotToRegister.Contains(x));
+ IEnumerable<HdPubKey> allLockedInternalKeys = KeyManager.GetKeys(x => x.IsInternal && x.KeyState == KeyState.Locked && !keysTryNotToRegister.Contains(x));
// If any of our inputs have exposed address relationship then prefer that.
allLockedInternalKeys = keysToSurelyRegister.Concat(allLockedInternalKeys).Distinct();

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -561,9 +561,9 @@ namespace WalletWasabi.Services
}
// Make sure there's always 21 clean keys generated and indexed.
- KeyManager.AssertCleanKeysIndexed(21, foundKey.IsInternal());
+ KeyManager.AssertCleanKeysIndexed(21, foundKey.IsInternal);
- if (foundKey.IsInternal())
+ if (foundKey.IsInternal)
{
// Make sure there's always 14 internal locked keys generated and indexed.
KeyManager.AssertLockedInternalKeysIndexed(14);

Make keypath related things properties.