Introduce BlockHash and BlockIndex knowledge of SmartTransaction
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
@@ -372,7 +372,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
IsHardwareBusy = false;
}
- signedTransaction = signedPsbt.ExtractSmartTransaction(result.Transaction.Height);
+ signedTransaction = signedPsbt.ExtractSmartTransaction(result.Transaction.Height, result.Transaction.BlockHash, result.Transaction.BlockIndex, result.Transaction.Label, result.Transaction.FirstSeenIfMemPoolTime, result.Transaction.IsReplacement);
}
MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.BroadcastingTransaction);

MODIFY
WalletWasabi/Extensions/NBitcoinExtensions.cs
WalletWasabi/Extensions/NBitcoinExtensions.cs
@@ -250,7 +250,7 @@ namespace NBitcoin
return psbt.ExtractSmartTransaction(Height.Unknown);
}
- public static SmartTransaction ExtractSmartTransaction(this PSBT psbt, Height height)
+ public static SmartTransaction ExtractSmartTransaction(this PSBT psbt, Height height, uint256 blockHash = null, int blockIndex = 0, string label = "", DateTimeOffset? firstSeenIfMemPoolTime = null, bool isReplacement = false)
{
var extractedTx = psbt.ExtractTransaction();
return new SmartTransaction(extractedTx, height);

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -294,9 +294,8 @@ namespace WalletWasabi.Services
string jsonString = File.ReadAllText(TransactionsFilePath, Encoding.UTF8);
transactions = JsonConvert.DeserializeObject<IEnumerable<SmartTransaction>>(jsonString)?
.Where(x => !x.Confirmed)? // Only unconfirmed ones.
- .OrderBy(x => x.Height)? // Order by height first (it's mempool or unknown)
- .ThenBy(x => x.FirstSeenIfMemPoolTime ?? DateTime.UtcNow)
- .ToArray(); // Order by the time of first seen.
+ .OrderByBlockchain()?
+ .ToArray();
}
catch (Exception ex)
{
@@ -488,7 +487,7 @@ namespace WalletWasabi.Services
for (int i = 0; i < block.Transactions.Count; i++)
{
Transaction tx = block.Transactions[i];
- if (await ProcessTransactionAsync(new SmartTransaction(tx, height)))
+ if (await ProcessTransactionAsync(new SmartTransaction(tx, height, block.GetHash(), i)))
{
relevantIndicies.Add(i);
ret = true;
@@ -510,7 +509,7 @@ namespace WalletWasabi.Services
foreach (var i in filterByTxIds.OrderBy(x => x))
{
Transaction tx = block.Transactions[i];
- if (await ProcessTransactionAsync(new SmartTransaction(tx, height)))
+ if (await ProcessTransactionAsync(new SmartTransaction(tx, height, block.GetHash(), i)))
{
ret = true;
}
@@ -545,7 +544,7 @@ namespace WalletWasabi.Services
SmartTransaction foundTx = TransactionCache.FirstOrDefault(x => x == tx);
if (foundTx != default(SmartTransaction)) // Must check again, because it's a concurrent collection!
{
- foundTx.SetHeight(tx.Height);
+ foundTx.SetHeight(tx.Height, tx.BlockHash, tx.BlockIndex);
walletRelevant = true;
justUpdate = true; // No need to check for double spend, we already processed this transaction, just update it.
}
@@ -1597,7 +1596,7 @@ namespace WalletWasabi.Services
}
IoHelpers.EnsureContainingDirectoryExists(TransactionsFilePath);
- string jsonString = JsonConvert.SerializeObject(TransactionCache.OrderBy(x => x.Height).ThenBy(x => x.FirstSeenIfMemPoolTime ?? DateTime.UtcNow), Formatting.Indented);
+ string jsonString = JsonConvert.SerializeObject(TransactionCache.OrderByBlockchain(), Formatting.Indented);
File.WriteAllText(TransactionsFilePath,
jsonString,
Encoding.UTF8);

Introduce BlockHash and BlockIndex knowledge of SmartTransaction