Implements p2wpkh script cache
MODIFY
WalletWasabi/KeyManagement/KeyManager.cs
WalletWasabi/KeyManagement/KeyManager.cs
@@ -27,6 +27,7 @@ namespace WalletWasabi.KeyManagement
[JsonProperty(Order = 4)]
private List<HdPubKey> HdPubKeys { get; }
+ private List<byte[]> HdPubKeyScriptBytes { get; }
// BIP84-ish derivation scheme
// m / purpose' / coin_type' / account' / change / address_index
@@ -42,6 +43,7 @@ namespace WalletWasabi.KeyManagement
public KeyManager(BitcoinEncryptedSecretNoEC encryptedSecret, byte[] chainCode, ExtPubKey extPubKey, string filePath = null)
{
HdPubKeys = new List<HdPubKey>();
+ HdPubKeyScriptBytes = new List<byte[]>();
HdPubKeysLock = new object();
EncryptedSecret = Guard.NotNull(nameof(encryptedSecret), encryptedSecret);
@@ -55,6 +57,7 @@ namespace WalletWasabi.KeyManagement
public KeyManager(BitcoinEncryptedSecretNoEC encryptedSecret, byte[] chainCode, string password, string filePath = null)
{
HdPubKeys = new List<HdPubKey>();
+ HdPubKeyScriptBytes = new List<byte[]>();
HdPubKeysLock = new object();
if (password is null)
@@ -136,6 +139,7 @@ namespace WalletWasabi.KeyManagement
string jsonString = File.ReadAllText(safestFile, Encoding.UTF8);
var km = JsonConvert.DeserializeObject<KeyManager>(jsonString);
km.SetFilePath(filePath);
+ km.HdPubKeyScriptBytes.AddRange(km.GetKeys().Select(x=>x.GetP2wpkhScript().ToCompressedBytes()));
return km;
}
@@ -182,6 +186,7 @@ namespace WalletWasabi.KeyManagement
var hdPubKey = new HdPubKey(pubKey, fullPath, label, keyState);
HdPubKeys.Add(hdPubKey);
+ HdPubKeyScriptBytes.Add(hdPubKey.GetP2wpkhScript().ToCompressedBytes());
if (toFile)
{
@@ -214,6 +219,16 @@ namespace WalletWasabi.KeyManagement
}
}
+ public IEnumerable<byte[]> GetPubKeyScriptBytes()
+ {
+ // BIP44-ish derivation scheme
+ // m / purpose' / coin_type' / account' / change / address_index
+ lock (HdPubKeysLock)
+ {
+ return HdPubKeyScriptBytes;
+ }
+ }
+
public IEnumerable<ExtKey> GetSecrets(string password, params Script[] scripts)
{
Key secret;

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -243,7 +243,7 @@ namespace WalletWasabi.Services
return;
}
- var matchFound = filterModel.Filter.MatchAny(KeyManager.GetKeys().Select(x => x.GetP2wpkhScript().ToCompressedBytes()), filterModel.FilterKey);
+ var matchFound = filterModel.Filter.MatchAny(KeyManager.GetPubKeyScriptBytes(), filterModel.FilterKey);
if (!matchFound)
{
return;

Implements p2wpkh script cache