Commit a17b5dd1 authored by Pieterjan Vanhoof's avatar Pieterjan Vanhoof Committed by GitHub

Merge pull request #53 from bokobza/feature/build-transaction

Fixed inserting the tx twice
parents 36cf64fb 821cc8c8
...@@ -491,24 +491,38 @@ namespace Breeze.Wallet ...@@ -491,24 +491,38 @@ namespace Breeze.Wallet
/// <param name="spendingTransactionIndex">The index of the output in the transaction being referenced, if this is a spending transaction.</param> /// <param name="spendingTransactionIndex">The index of the output in the transaction being referenced, if this is a spending transaction.</param>
private void AddTransactionToWallet(uint256 transactionHash, uint time, int? index, Money amount, Script script, int? blockHeight = null, uint? blockTime = null, uint256 spendingTransactionId = null, int? spendingTransactionIndex = null) private void AddTransactionToWallet(uint256 transactionHash, uint time, int? index, Money amount, Script script, int? blockHeight = null, uint? blockTime = null, uint256 spendingTransactionId = null, int? spendingTransactionIndex = null)
{ {
// get the collection of transactions to add to.
this.keysLookup.TryGetValue(script, out ICollection<TransactionData> trans); this.keysLookup.TryGetValue(script, out ICollection<TransactionData> trans);
trans.Add(new TransactionData
// if it's the first time we see this transaction
if (trans != null && trans.All(t => t.Id != transactionHash))
{ {
Amount = amount, trans.Add(new TransactionData
BlockHeight = blockHeight, {
Confirmed = blockHeight.HasValue, Amount = amount,
Id = transactionHash, BlockHeight = blockHeight,
CreationTime = DateTimeOffset.FromUnixTimeMilliseconds(blockTime ?? time), Confirmed = blockHeight.HasValue,
Index = index Id = transactionHash,
}); CreationTime = DateTimeOffset.FromUnixTimeMilliseconds(blockTime ?? time),
Index = index
});
// if this is a spending transaction, mark the spent transaction as such // if this is a spending transaction, mark the spent transaction as such
if (spendingTransactionId != null) if (spendingTransactionId != null)
{
var transactions = this.keysLookup.Values.SelectMany(v => v).Where(t => t.Id == spendingTransactionId);
if (transactions.Any())
{
transactions.Single(t => t.Index == spendingTransactionIndex).SpentInTransaction = transactionHash;
}
}
}
else if (trans.Any(t => t.Id == transactionHash && !t.Confirmed)) // if this is an unconfirmed transaction now received in a block
{ {
var transactions = this.keysLookup.Values.SelectMany(v => v).Where(t => t.Id == spendingTransactionId); var foundTransaction = trans.Single(t => t.Id == transactionHash && !t.Confirmed);
if (transactions.Any()) if (blockHeight != null)
{ {
transactions.Single(t => t.Index == spendingTransactionIndex).SpentInTransaction = transactionHash; foundTransaction.Confirmed = true;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment