Make scripts properties
MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -547,7 +547,7 @@ namespace WalletWasabi.Tests
Assert.InRange(firstCoin.Index, 0U, 1U);
Assert.False(firstCoin.SpentOrCoinJoinInProgress);
Assert.Equal("foo label", firstCoin.Label);
- Assert.Equal(key.GetP2wpkhScript(), firstCoin.ScriptPubKey);
+ Assert.Equal(key.P2wpkhScript, firstCoin.ScriptPubKey);
Assert.Null(firstCoin.SpenderTransactionId);
Assert.NotNull(firstCoin.SpentOutputs);
Assert.NotEmpty(firstCoin.SpentOutputs);
@@ -579,9 +579,9 @@ namespace WalletWasabi.Tests
Assert.Equal("foo label", firstCoin.Label);
Assert.Equal("bar label", secondCoin.Label);
Assert.Equal("bar label", thirdCoin.Label);
- Assert.Equal(key.GetP2wpkhScript(), firstCoin.ScriptPubKey);
- Assert.Equal(key2.GetP2wpkhScript(), secondCoin.ScriptPubKey);
- Assert.Equal(key2.GetP2wpkhScript(), thirdCoin.ScriptPubKey);
+ Assert.Equal(key.P2wpkhScript, firstCoin.ScriptPubKey);
+ Assert.Equal(key2.P2wpkhScript, secondCoin.ScriptPubKey);
+ Assert.Equal(key2.P2wpkhScript, thirdCoin.ScriptPubKey);
Assert.Null(thirdCoin.SpenderTransactionId);
Assert.NotNull(firstCoin.SpentOutputs);
Assert.NotNull(secondCoin.SpentOutputs);
@@ -634,7 +634,7 @@ namespace WalletWasabi.Tests
Assert.Equal(synchronizer.BestKnownFilter.BlockHeight.Value - 2, rbfCoin.Height.Value);
Assert.False(rbfCoin.SpentOrCoinJoinInProgress);
Assert.Equal("bar label", rbfCoin.Label);
- Assert.Equal(key2.GetP2wpkhScript(), rbfCoin.ScriptPubKey);
+ Assert.Equal(key2.P2wpkhScript, rbfCoin.ScriptPubKey);
Assert.Null(rbfCoin.SpenderTransactionId);
Assert.NotNull(rbfCoin.SpentOutputs);
Assert.NotEmpty(rbfCoin.SpentOutputs);
@@ -794,7 +794,7 @@ namespace WalletWasabi.Tests
Assert.True(res2.Fee > Money.Satoshis(2 * 100)); // since there is a sanity check of 2sat/vb in the server
Assert.InRange(res2.FeePercentOfSent, 0, 1);
Assert.Single(res2.SpentCoins);
- Assert.Equal(key.GetP2wpkhScript(), res2.SpentCoins.Single().ScriptPubKey);
+ Assert.Equal(key.P2wpkhScript, res2.SpentCoins.Single().ScriptPubKey);
Assert.Equal(Money.Coins(1m), res2.SpentCoins.Single().Amount);
Assert.False(res2.SpendsUnconfirmed);
@@ -804,7 +804,7 @@ namespace WalletWasabi.Tests
#region Basic
- Script receive = wallet.GetReceiveKey("Basic").GetP2wpkhScript();
+ Script receive = wallet.GetReceiveKey("Basic").P2wpkhScript;
Money amountToSend = wallet.Coins.Where(x => !x.SpentOrCoinJoinInProgress).Sum(x => x.Amount) / 2;
var res = wallet.BuildTransaction(password, new[] { new WalletService.Operation(receive, amountToSend, "foo") }, 1008, allowUnconfirmed: true);
@@ -852,7 +852,7 @@ namespace WalletWasabi.Tests
#region SubtractFeeFromAmount
- receive = wallet.GetReceiveKey("SubtractFeeFromAmount").GetP2wpkhScript();
+ receive = wallet.GetReceiveKey("SubtractFeeFromAmount").P2wpkhScript;
amountToSend = wallet.Coins.Where(x => !x.SpentOrCoinJoinInProgress).Sum(x => x.Amount) / 3;
res = wallet.BuildTransaction(password, new[] { new WalletService.Operation(receive, amountToSend, "foo") }, 1008, allowUnconfirmed: true, subtractFeeFromAmountIndex: 0);
@@ -991,7 +991,7 @@ namespace WalletWasabi.Tests
#region MaxAmount
- receive = wallet.GetReceiveKey("MaxAmount").GetP2wpkhScript();
+ receive = wallet.GetReceiveKey("MaxAmount").P2wpkhScript;
res = wallet.BuildTransaction(password, new[] { new WalletService.Operation(receive, Money.Zero, "foo") }, 1008, allowUnconfirmed: true);
Assert.Single(res.InnerWalletOutputs);
@@ -1017,7 +1017,7 @@ namespace WalletWasabi.Tests
#region InputSelection
- receive = wallet.GetReceiveKey("InputSelection").GetP2wpkhScript();
+ receive = wallet.GetReceiveKey("InputSelection").P2wpkhScript;
var inputCountBefore = res.SpentCoins.Count();
res = wallet.BuildTransaction(password, new[] { new WalletService.Operation(receive, Money.Zero, "foo") }, 1008,
@@ -1092,7 +1092,7 @@ namespace WalletWasabi.Tests
inputCountBefore = res.SpentCoins.Count();
- receive = wallet.GetReceiveKey("AllowedInputsDisallowUnconfirmed").GetP2wpkhScript();
+ receive = wallet.GetReceiveKey("AllowedInputsDisallowUnconfirmed").P2wpkhScript;
var allowedInputs = wallet.Coins.Where(x => !x.SpentOrCoinJoinInProgress).Select(x => new TxoRef(x.TransactionId, x.Index)).Take(1);
var toSend = new[] { new WalletService.Operation(receive, Money.Zero, "fizz") };
@@ -1554,12 +1554,12 @@ namespace WalletWasabi.Tests
// Test mixin
var operations = new[] {
- new WalletService.Operation(key.GetP2wpkhScript(), Money.Coins(0.01m), ""),
+ new WalletService.Operation(key.P2wpkhScript, Money.Coins(0.01m), ""),
new WalletService.Operation(new Key().ScriptPubKey, Money.Coins(0.01m), ""),
new WalletService.Operation(new Key().ScriptPubKey, Money.Coins(0.01m), "")
};
var tx1Res = wallet.BuildTransaction(password, operations, 2, allowUnconfirmed: true);
- Assert.Equal(2, tx1Res.OuterWalletOutputs.Single(x => x.ScriptPubKey == key.GetP2wpkhScript()).Mixin);
+ Assert.Equal(2, tx1Res.OuterWalletOutputs.Single(x => x.ScriptPubKey == key.P2wpkhScript).Mixin);
// Spend the unconfirmed coin (send it to ourself)
operations = new[] { new WalletService.Operation(key.PubKey.WitHash.ScriptPubKey, Money.Coins(0.5m), "") };
@@ -1624,7 +1624,7 @@ namespace WalletWasabi.Tests
// Test coin basic count.
var coinCount = wallet.Coins.Count;
var to = wallet.GetReceiveKey("foo");
- var res = wallet.BuildTransaction(password, new[] { new WalletService.Operation(to.GetP2wpkhScript(), Money.Coins(0.2345m), "bar") }, 2, allowUnconfirmed: true);
+ var res = wallet.BuildTransaction(password, new[] { new WalletService.Operation(to.P2wpkhScript, Money.Coins(0.2345m), "bar") }, 2, allowUnconfirmed: true);
await wallet.SendTransactionAsync(res.Transaction);
Assert.Equal(coinCount + 2, wallet.Coins.Count);
Assert.Equal(2, wallet.Coins.Count(x => !x.Confirmed));

MODIFY
WalletWasabi/KeyManagement/HdPubKey.cs
WalletWasabi/KeyManagement/HdPubKey.cs
@@ -30,6 +30,11 @@ namespace WalletWasabi.KeyManagement
FullKeyPath = Guard.NotNull(nameof(fullKeyPath), fullKeyPath);
Label = Guard.Correct(label);
KeyState = keyState;
+
+ P2pkScript = PubKey.ScriptPubKey;
+ P2pkhScript = PubKey.Hash.ScriptPubKey;
+ P2wpkhScript = PubKey.WitHash.ScriptPubKey;
+ P2shOverP2wpkhScript = P2wpkhScript.Hash.ScriptPubKey;
}
public void SetLabel(string label, KeyManager kmToFile = null)
@@ -49,39 +54,19 @@ namespace WalletWasabi.KeyManagement
kmToFile?.ToFile();
}
- private Script _p2pkScript = null;
-
- public Script GetP2pkScript()
- {
- return _p2pkScript ?? (_p2pkScript = PubKey.ScriptPubKey);
- }
+ public Script P2pkScript { get; }
- private Script _p2pkhScript = null;
-
- public Script GetP2pkhScript()
- {
- return _p2pkhScript ?? (_p2pkhScript = PubKey.Hash.ScriptPubKey);
- }
+ public Script P2pkhScript { get; }
- private Script _p2wpkhScript = null;
+ public Script P2wpkhScript { get; }
- public Script GetP2wpkhScript()
- {
- return _p2wpkhScript ?? (_p2wpkhScript = PubKey.WitHash.ScriptPubKey);
- }
-
- private Script _p2shOverP2wpkhScript = null;
-
- public Script GetP2shOverP2wpkhScript()
- {
- return _p2shOverP2wpkhScript ?? (_p2shOverP2wpkhScript = GetP2wpkhScript().Hash.ScriptPubKey);
- }
+ public Script P2shOverP2wpkhScript { get; }
public BitcoinPubKeyAddress GetP2pkhAddress(Network network) => PubKey.GetAddress(network);
public BitcoinWitPubKeyAddress GetP2wpkhAddress(Network network) => PubKey.GetSegwitAddress(network);
- public BitcoinScriptAddress GetP2shOverP2wpkhAddress(Network network) => GetP2wpkhScript().GetScriptAddress(network);
+ public BitcoinScriptAddress GetP2shOverP2wpkhAddress(Network network) => P2wpkhScript.GetScriptAddress(network);
private int? _index = null;
@@ -92,7 +77,7 @@ namespace WalletWasabi.KeyManagement
private KeyPath _nonHardenedKeyPath = null;
- public KeyPath GetNonHardenedKeyPath()
+ public KeyPath NonHardenedKeyPath()
{
return _nonHardenedKeyPath ?? (_nonHardenedKeyPath = new KeyPath(FullKeyPath[3], FullKeyPath[4]));
}

MODIFY
WalletWasabi/KeyManagement/KeyManager.cs
WalletWasabi/KeyManagement/KeyManager.cs
@@ -158,14 +158,14 @@ namespace WalletWasabi.KeyManagement
km.SetFilePath(filePath);
lock (km.HdPubKeyScriptBytesLock)
{
- km.HdPubKeyScriptBytes.AddRange(km.GetKeys(x => true).Select(x => x.GetP2wpkhScript().ToCompressedBytes()));
+ km.HdPubKeyScriptBytes.AddRange(km.GetKeys(x => true).Select(x => x.P2wpkhScript.ToCompressedBytes()));
}
lock (km.ScriptHdPubkeyMapLock)
{
foreach (var key in km.GetKeys())
{
- km.ScriptHdPubkeyMap.Add(key.GetP2wpkhScript(), key);
+ km.ScriptHdPubkeyMap.Add(key.P2wpkhScript, key);
}
}
return km;
@@ -201,11 +201,11 @@ namespace WalletWasabi.KeyManagement
if (missingIndexes.Any())
{
int smallestMissingIndex = missingIndexes.Min();
- path = relevantHdPubKeys.First(x => x.GetIndex() == (smallestMissingIndex - 1)).GetNonHardenedKeyPath().Increment();
+ path = relevantHdPubKeys.First(x => x.GetIndex() == (smallestMissingIndex - 1)).NonHardenedKeyPath().Increment();
}
else
{
- path = relevantHdPubKeys.First(x => x.GetIndex() == largestIndex).GetNonHardenedKeyPath().Increment();
+ path = relevantHdPubKeys.First(x => x.GetIndex() == largestIndex).NonHardenedKeyPath().Increment();
}
}
@@ -216,12 +216,12 @@ namespace WalletWasabi.KeyManagement
HdPubKeys.Add(hdPubKey);
lock (HdPubKeyScriptBytesLock)
{
- HdPubKeyScriptBytes.Add(hdPubKey.GetP2wpkhScript().ToCompressedBytes());
+ HdPubKeyScriptBytes.Add(hdPubKey.P2wpkhScript.ToCompressedBytes());
}
lock (ScriptHdPubkeyMapLock)
{
- ScriptHdPubkeyMap.Add(hdPubKey.GetP2wpkhScript(), hdPubKey);
+ ScriptHdPubkeyMap.Add(hdPubKey.P2wpkhScript, hdPubKey);
}
if (toFile)
@@ -298,10 +298,10 @@ namespace WalletWasabi.KeyManagement
lock (HdPubKeysLock)
{
foreach (HdPubKey key in HdPubKeys.Where(x =>
- scripts.Contains(x.GetP2wpkhScript())
- || scripts.Contains(x.GetP2shOverP2wpkhScript())
- || scripts.Contains(x.GetP2pkhScript())
- || scripts.Contains(x.GetP2pkScript())))
+ scripts.Contains(x.P2wpkhScript)
+ || scripts.Contains(x.P2shOverP2wpkhScript)
+ || scripts.Contains(x.P2pkhScript)
+ || scripts.Contains(x.P2pkScript)))
{
ExtKey ek = extKey.Derive(key.FullKeyPath);
extKeysAndPubs.Add((ek, key));

MODIFY
WalletWasabi/Services/CcjClient.cs
WalletWasabi/Services/CcjClient.cs
@@ -794,7 +794,7 @@ namespace WalletWasabi.Services
foreach (SmartCoin coin in coinsExcept)
{
- coin.Secret = secPubs.Single(x => x.pubKey.GetP2wpkhScript() == coin.ScriptPubKey).secret;
+ coin.Secret = secPubs.Single(x => x.pubKey.P2wpkhScript == coin.ScriptPubKey).secret;
coin.CoinJoinInProgress = true;
@@ -1009,7 +1009,7 @@ namespace WalletWasabi.Services
if (coinWaitingForMix.Label == "ZeroLink Change" && coinWaitingForMix.Unspent)
{
coinWaitingForMix.Label = "ZeroLink Dequeued Change";
- var key = KeyManager.GetKeys(x => x.GetP2wpkhScript() == coinWaitingForMix.ScriptPubKey).SingleOrDefault();
+ var key = KeyManager.GetKeys(x => x.P2wpkhScript == coinWaitingForMix.ScriptPubKey).SingleOrDefault();
if (key != null)
{
key.SetLabel(coinWaitingForMix.Label, KeyManager);

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -1080,7 +1080,7 @@ namespace WalletWasabi.Services
var changeHdPubKey = KeyManager.GetKeys(KeyState.Clean, true).RandomElement();
changeHdPubKey.SetLabel(changeLabel, KeyManager);
- changeScriptPubKey = changeHdPubKey.GetP2wpkhScript();
+ changeScriptPubKey = changeHdPubKey.P2wpkhScript;
}
else
{
@@ -1151,7 +1151,7 @@ namespace WalletWasabi.Services
{
TxOut output = tx.Outputs[i];
var mixin = tx.GetMixin(i) + spentCoins.Min(x => x.Mixin);
- var foundKey = KeyManager.GetKeys(KeyState.Clean).FirstOrDefault(x => output.ScriptPubKey == x.GetP2wpkhScript());
+ var foundKey = KeyManager.GetKeys(KeyState.Clean).FirstOrDefault(x => output.ScriptPubKey == x.P2wpkhScript);
var coin = new SmartCoin(tx.GetHash(), i, output.ScriptPubKey, output.Value, tx.Inputs.ToTxoRefs().ToArray(), Height.Unknown, tx.RBF, mixin, pubKey: foundKey);
if (foundKey != null)
@@ -1221,7 +1221,7 @@ namespace WalletWasabi.Services
{
newLabel = Guard.Correct(newLabel);
coin.Label = newLabel;
- var key = KeyManager.GetKeys(x => x.GetP2wpkhScript() == coin.ScriptPubKey).SingleOrDefault();
+ var key = KeyManager.GetKeys(x => x.P2wpkhScript == coin.ScriptPubKey).SingleOrDefault();
if (key != null)
{
key.SetLabel(newLabel, KeyManager);

Make scripts properties