Skip to content
Permalink
Browse files

implement spentaccordingtobackend (both for cj response and send resp…

…onse)
  • Loading branch information...
nopara73 committed Nov 18, 2018
1 parent 0ae7e6d commit a60361018fcbea441e8f840619cc681d7de496c6
@@ -44,6 +44,11 @@ public CoinViewModel(SmartCoin model)
this.RaisePropertyChanged(nameof(BannedCoinToolTip));
});

model.WhenAnyValue(x => x.SpentAccordingToBackend).ObserveOn(RxApp.MainThreadScheduler).Subscribe(_ =>
{
this.RaisePropertyChanged(nameof(Status));
});

Global.IndexDownloader.WhenAnyValue(x => x.BestHeight).ObserveOn(RxApp.MainThreadScheduler).Subscribe(_ =>
{
this.RaisePropertyChanged(nameof(Confirmations));
@@ -142,6 +147,11 @@ public SmartCoinStatus Status
}
}

if (Model.SpentAccordingToBackend)
{
return SmartCoinStatus.SpentAccordingToBackend;
}

if (Model.Confirmed)
{
if (Model.CoinJoinInProgress)
@@ -19,6 +19,7 @@ public class SmartCoin : IEquatable<SmartCoin>, INotifyPropertyChanged
private uint256 _spenderTransactionId;
private bool _coinJoinInProgress;
private DateTimeOffset? _bannedUntilUtc;
private bool _spentAccordingToBackend;

[JsonProperty(Order = 1)]
[JsonConverter(typeof(Uint256JsonConverter))]
@@ -157,14 +158,8 @@ public bool CoinJoinInProgress
}
}

/// <summary>
/// If the backend thinks it's spent, but Wasabi doesn't yet know.
/// </summary>
[JsonProperty(Order = 13)]
public bool SpentAccordingToBackend { get; set; }

public bool SpentOrCoinJoinInProgress => !(SpenderTransactionId is null) || CoinJoinInProgress || SpentAccordingToBackend;
public bool Unspent => SpenderTransactionId is null && !SpentAccordingToBackend;
public bool SpentOrCoinJoinInProgress => !Unspent || CoinJoinInProgress;
public bool Unspent => SpenderTransactionId is null;
public bool Confirmed => Height != Height.MemPool && Height != Height.Unknown;
public bool IsBanned => BannedUntilUtc != null && BannedUntilUtc > DateTimeOffset.UtcNow;

@@ -178,8 +173,24 @@ public bool CoinJoinInProgress
/// </summary>
public ISecret Secret { get; set; }

/// <summary>
/// If the backend thinks it's spent, but Wasabi doesn't yet know.
/// </summary>
public bool SpentAccordingToBackend
{
get { return _spentAccordingToBackend; }
set
{
if (value != _spentAccordingToBackend)
{
_spentAccordingToBackend = value;
OnPropertyChanged(nameof(SpentAccordingToBackend));
}
}
}

[JsonConstructor]
public SmartCoin(uint256 transactionId, uint index, Script scriptPubKey, Money amount, TxoRef[] spentOutputs, Height height, bool rbf, int mixin, string label = "", uint256 spenderTransactionId = null, bool coinJoinInProgress = false, bool spentAccordingToBackend = false)
public SmartCoin(uint256 transactionId, uint index, Script scriptPubKey, Money amount, TxoRef[] spentOutputs, Height height, bool rbf, int mixin, string label = "", uint256 spenderTransactionId = null, bool coinJoinInProgress = false)
{
TransactionId = Guard.NotNull(nameof(transactionId), transactionId);
Index = Guard.NotNull(nameof(index), index);
@@ -193,11 +204,11 @@ public SmartCoin(uint256 transactionId, uint index, Script scriptPubKey, Money a
RBF = rbf;
CoinJoinInProgress = coinJoinInProgress;
Secret = null;
SpentAccordingToBackend = false;
BannedUntilUtc = null;
SpentAccordingToBackend = spentAccordingToBackend;
}

public SmartCoin(Coin coin, TxoRef[] spentOutputs, Height height, bool rbf, int mixin, string label = "", uint256 spenderTransactionId = null, bool coinJoinInProgress = false, bool spentAccordingToBackend = false)
public SmartCoin(Coin coin, TxoRef[] spentOutputs, Height height, bool rbf, int mixin, string label = "", uint256 spenderTransactionId = null, bool coinJoinInProgress = false)
{
Guard.NotNull(nameof(coin), coin);
TransactionId = coin.Outpoint.Hash;
@@ -212,7 +223,8 @@ public SmartCoin(Coin coin, TxoRef[] spentOutputs, Height height, bool rbf, int
RBF = rbf;
CoinJoinInProgress = coinJoinInProgress;
Secret = null;
SpentAccordingToBackend = spentAccordingToBackend;
SpentAccordingToBackend = false;
BannedUntilUtc = null;
}

public event PropertyChangedEventHandler PropertyChanged;
@@ -525,7 +525,7 @@ private async Task TryRegisterCoinsAsync(CcjClientRound inputRegistrableRound)
await DequeueCoinsFromMixNoLockAsync(coinReference);
return;
}
catch (HttpRequestException ex) when (ex.Message.StartsWith("Provided input is not unspent", StringComparison.InvariantCultureIgnoreCase))
catch (HttpRequestException ex) when (ex.Message.Contains("Provided input is not unspent", StringComparison.InvariantCultureIgnoreCase))
{
string[] parts = ex.Message.Split(new[] { "Provided input is not unspent: " }, StringSplitOptions.RemoveEmptyEntries);
string spentInputString = parts[1].TrimEnd('.');
@@ -21,6 +21,7 @@
using Newtonsoft.Json;
using System.Collections.Concurrent;
using NBitcoin.DataEncoders;
using System.Net.Http;

namespace WalletWasabi.Services
{
@@ -1029,7 +1030,23 @@ public async Task SendTransactionAsync(SmartTransaction transaction)
{
using (var client = new WasabiClient(IndexDownloader.WasabiClient.TorClient.DestinationUri, IndexDownloader.WasabiClient.TorClient.TorSocks5EndPoint))
{
await client.BroadcastAsync(transaction);
try
{
await client.BroadcastAsync(transaction);
}
catch (HttpRequestException ex) when (ex.Message.Contains("txn-mempool-conflict", StringComparison.InvariantCultureIgnoreCase))
{
if (transaction.Transaction.Inputs.Count == 1)
{
OutPoint input = transaction.Transaction.Inputs.First().PrevOut;
SmartCoin coin = Coins.FirstOrDefault(x => x.TransactionId == input.Hash && x.Index == input.N);
if (coin != default)
{
coin.SpentAccordingToBackend = true;
}
}
throw;
}
}

ProcessTransaction(new SmartTransaction(transaction.Transaction, Height.MemPool));

0 comments on commit a603610

Please sign in to comment.
You can’t perform that action at this time.