Refactor spent stuff
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/CoinViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/CoinViewModel.cs
@@ -26,7 +26,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
private bool _isSelected;
private SmartCoinStatus _status;
private ObservableAsPropertyHelper<bool> _coinJoinInProgress;
- private ObservableAsPropertyHelper<bool> _unspent;
private ObservableAsPropertyHelper<bool> _confirmed;
private ObservableAsPropertyHelper<string> _cluster;
@@ -49,11 +48,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
.ToProperty(this, x => x.CoinJoinInProgress, scheduler: RxApp.MainThreadScheduler)
.DisposeWith(Disposables);
- _unspent = Model
- .WhenAnyValue(x => x.Unspent)
- .ToProperty(this, x => x.Unspent, scheduler: RxApp.MainThreadScheduler)
- .DisposeWith(Disposables);
-
_confirmed = Model
.WhenAnyValue(x => x.Confirmed)
.ToProperty(this, x => x.Confirmed, scheduler: RxApp.MainThreadScheduler)
@@ -136,8 +130,6 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
public bool CoinJoinInProgress => _coinJoinInProgress?.Value ?? false;
- public bool Unspent => _unspent?.Value ?? false;
-
public string Address => Model.ScriptPubKey.GetDestinationAddress(Global.Network).ToString();
public int Confirmations => Model.Height.Type == HeightType.Chain

MODIFY
WalletWasabi.Gui/Rpc/WasabiJsonRpcService.cs
WalletWasabi.Gui/Rpc/WasabiJsonRpcService.cs
@@ -31,7 +31,7 @@ namespace WalletWasabi.Gui.Rpc
{
AssertWalletIsLoaded();
var serverTipHeight = ActiveWallet.BitcoinStore.SmartHeaderChain.ServerTipHeight;
- return ActiveWallet.Coins.Where(x => x.Unspent).Select(x => new
+ return ActiveWallet.Coins.Where(x => !x.IsSpent()).Select(x => new
{
txid = x.TransactionId.ToString(),
index = x.Index,
@@ -70,7 +70,7 @@ namespace WalletWasabi.Gui.Rpc
accountKeyPath = $"m/{km.AccountKeyPath}",
masterKeyFingerprint = km.MasterFingerprint?.ToString() ?? "",
balance = ActiveWallet.Coins
- .Where(c => c.Unspent && !c.SpentAccordingToBackend)
+ .Where(c => !c.IsSpent() && !c.SpentAccordingToBackend)
.Sum(c => c.Amount.Satoshi)
};
}

MODIFY
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
@@ -1491,10 +1491,10 @@ namespace WalletWasabi.Tests.RegressionTests
Assert.Equal(4, allCoins.Count(x => x.Label.IsEmpty && x.IsAvailable()));
Assert.Equal(3, allCoins2.Count(x => x.Label.IsEmpty && x.IsAvailable()));
- Assert.Equal(2, allCoins.Count(x => x.Label.IsEmpty && !x.Unspent));
- Assert.Equal(0, allCoins2.Count(x => x.Label.IsEmpty && !x.Unspent));
+ Assert.Equal(2, allCoins.Count(x => x.Label.IsEmpty && x.IsSpent()));
+ Assert.Equal(0, allCoins2.Count(x => x.Label.IsEmpty && x.IsSpent()));
Assert.Equal(3, allCoins2.Count(x => x.Label.IsEmpty));
- Assert.Equal(4, allCoins.Count(x => x.Label.IsEmpty && x.Unspent));
+ Assert.Equal(4, allCoins.Count(x => x.Label.IsEmpty && !x.IsSpent()));
}
finally
{

MODIFY
WalletWasabi.Tests/RegressionTests/SendTests.cs
WalletWasabi.Tests/RegressionTests/SendTests.cs
@@ -131,7 +131,7 @@ namespace WalletWasabi.Tests.RegressionTests
Assert.False(coin.CoinJoinInProgress);
Assert.True(coin.Confirmed);
Assert.Null(coin.SpenderTransactionId);
- Assert.True(coin.Unspent);
+ Assert.True(!coin.IsSpent());
}
Assert.Equal(2, res.InnerWalletOutputs.Count());

MODIFY
WalletWasabi.Tests/UnitTests/Transactions/TransactionProcessorTests.cs
WalletWasabi.Tests/UnitTests/Transactions/TransactionProcessorTests.cs
@@ -211,8 +211,8 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
var relevant = transactionProcessor.Process(tx0, tx1, tx2).Last();
Assert.False(relevant.IsNews);
- Assert.Single(transactionProcessor.Coins, coin => coin.Unspent);
- Assert.Single(transactionProcessor.Coins.AsAllCoinsView(), coin => !coin.Unspent);
+ Assert.Single(transactionProcessor.Coins, coin => !coin.IsSpent());
+ Assert.Single(transactionProcessor.Coins.AsAllCoinsView(), coin => coin.IsSpent());
// Transaction store assertions
Assert.True(transactionProcessor.TransactionStore.ConfirmedStore.IsEmpty());
@@ -280,8 +280,8 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
Assert.Equal(1, doubleSpendReceived);
Assert.True(relevant.IsNews);
- Assert.Single(transactionProcessor.Coins, coin => coin.Unspent && coin.Confirmed);
- Assert.Single(transactionProcessor.Coins.AsAllCoinsView(), coin => !coin.Unspent && coin.Confirmed);
+ Assert.Single(transactionProcessor.Coins, coin => !coin.IsSpent() && coin.Confirmed);
+ Assert.Single(transactionProcessor.Coins.AsAllCoinsView(), coin => coin.IsSpent() && coin.Confirmed);
// Transaction store assertions
var matureTxs = transactionProcessor.TransactionStore.ConfirmedStore.GetTransactions();
@@ -612,7 +612,7 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
Assert.True(relevant.IsNews);
var coin = Assert.Single(transactionProcessor.Coins.AsAllCoinsView());
- Assert.False(coin.Unspent);
+ Assert.True(coin.IsSpent());
Assert.NotNull(spentCoin);
Assert.Equal(coin, spentCoin);

MODIFY
WalletWasabi/Blockchain/TransactionOutputs/CoinsView.cs
WalletWasabi/Blockchain/TransactionOutputs/CoinsView.cs
@@ -17,7 +17,7 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
private IEnumerable<SmartCoin> Coins { get; }
- public ICoinsView Unspent() => new CoinsView(Coins.Where(x => x.Unspent && !x.SpentAccordingToBackend));
+ public ICoinsView Unspent() => new CoinsView(Coins.Where(x => !x.IsSpent() && !x.SpentAccordingToBackend));
public ICoinsView Available() => new CoinsView(Coins.Where(x => x.IsAvailable()));

MODIFY
WalletWasabi/Blockchain/TransactionOutputs/SmartCoin.cs
WalletWasabi/Blockchain/TransactionOutputs/SmartCoin.cs
@@ -28,8 +28,6 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
private Cluster _cluster;
private bool _confirmed;
- private bool _unavailable;
- private bool _unspent;
private bool _isBanned;
#endregion Fields
@@ -67,7 +65,6 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
Cluster = new Cluster(this);
- SetUnspent();
SetIsBanned();
}
@@ -120,13 +117,7 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
public uint256 SpenderTransactionId
{
get => _spenderTransactionId;
- set
- {
- if (RaiseAndSetIfChanged(ref _spenderTransactionId, value))
- {
- SetUnspent();
- }
- }
+ set => RaiseAndSetIfChanged(ref _spenderTransactionId, value);
}
public bool CoinJoinInProgress
@@ -185,12 +176,6 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
private set => RaiseAndSetIfChanged(ref _confirmed, value);
}
- public bool Unspent
- {
- get => _unspent;
- private set => RaiseAndSetIfChanged(ref _unspent, value);
- }
-
public bool IsBanned
{
get => _isBanned;
@@ -201,11 +186,6 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
#region PropertySetters
- private void SetUnspent()
- {
- Unspent = SpenderTransactionId is null;
- }
-
public void SetIsBanned()
{
IsBanned = BannedUntilUtc is { } && BannedUntilUtc > DateTimeOffset.UtcNow;
@@ -217,10 +197,12 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
#region Methods
+ public bool IsSpent() => SpenderTransactionId is { };
+
/// <summary>
- /// Unspent AND !SpentAccordingToBackend AND !CoinJoinInProgress
+ /// IsUnspent() AND !SpentAccordingToBackend AND !CoinJoinInProgress
/// </summary>
- public bool IsAvailable() => Unspent && !SpentAccordingToBackend && !CoinJoinInProgress;
+ public bool IsAvailable() => SpenderTransactionId is null && !SpentAccordingToBackend && !CoinJoinInProgress;
public bool IsReplaceable() => WasReplaceable && !Confirmed;

MODIFY
WalletWasabi/Blockchain/Transactions/TransactionHistoryBuilder.cs
WalletWasabi/Blockchain/Transactions/TransactionHistoryBuilder.cs
@@ -58,7 +58,7 @@ namespace WalletWasabi.Blockchain.Transactions
});
}
- if (!coin.Unspent)
+ if (coin.IsSpent())
{
if (!wallet.BitcoinStore.TransactionStore.TryGetTransaction(coin.SpenderTransactionId, out SmartTransaction foundSpenderTransaction))
{

MODIFY
WalletWasabi/CoinJoin/Client/Clients/CoinJoinClient.cs
WalletWasabi/CoinJoin/Client/Clients/CoinJoinClient.cs
@@ -915,7 +915,7 @@ namespace WalletWasabi.CoinJoin.Client.Clients
}
catch (Exception ex)
{
- if (coinToDequeue.Unspent)
+ if (!coinToDequeue.IsSpent())
{
exception = ex;
}
@@ -924,7 +924,7 @@ namespace WalletWasabi.CoinJoin.Client.Clients
else
{
// If coin is unspent we cannot dequeue.
- if (coinToDequeue.Unspent)
+ if (!coinToDequeue.IsSpent())
{
exception = new NotSupportedException($"Cannot deque coin in {round.State.Phase} phase. Coin: {coinToDequeue.Index}:{coinToDequeue.TransactionId}.");
}

MODIFY
WalletWasabi/CoinJoin/Client/Rounds/ClientState.cs
WalletWasabi/CoinJoin/Client/Rounds/ClientState.cs
@@ -46,7 +46,7 @@ namespace WalletWasabi.CoinJoin.Client.Rounds
{
lock (StateLock)
{
- return WaitingList.Keys.Concat(Rounds.SelectMany(x => x.CoinsRegistered)).Where(x => !x.Unspent).Select(x => x.OutPoint).ToArray();
+ return WaitingList.Keys.Concat(Rounds.SelectMany(x => x.CoinsRegistered)).Where(x => x.IsSpent()).Select(x => x.OutPoint).ToArray();
}
}

MODIFY
WalletWasabi/Wallets/Wallet.cs
WalletWasabi/Wallets/Wallet.cs
@@ -289,7 +289,7 @@ namespace WalletWasabi.Wallets
foreach (var newCoin in newCoins)
{
// If it's being mixed and anonset is not sufficient, then queue it.
- if (newCoin.Unspent && ChaumianClient.HasIngredients
+ if (!newCoin.IsSpent() && ChaumianClient.HasIngredients
&& newCoin.AnonymitySet < ServiceConfiguration.GetMixUntilAnonymitySetValue())
{
coinsToQueue.Add(newCoin);

Refactor spent stuff