Commit 636cc76a authored by Jeremy Bokobza's avatar Jeremy Bokobza

whether a block is confirmed is now deduced from the block details.

parent 705a20cf
......@@ -196,7 +196,7 @@ namespace Breeze.Wallet.Controllers
model.Transactions.Add(new TransactionItem
{
Amount = transaction.Amount,
Confirmed = transaction.Confirmed,
Confirmed = transaction.IsConfirmed(),
Timestamp = transaction.CreationTime,
TransactionId = transaction.Id,
Address = address.Address
......@@ -244,8 +244,8 @@ namespace Breeze.Wallet.Controllers
CoinType = request.CoinType,
Name = account.Name,
HdPath = account.HdPath,
AmountConfirmed = allTransactions.Where(t => t.Confirmed).Sum(t => t.Amount),
AmountUnconfirmed = allTransactions.Where(t => !t.Confirmed).Sum(t => t.Amount)
AmountConfirmed = allTransactions.Where(t => t.IsConfirmed()).Sum(t => t.Amount),
AmountUnconfirmed = allTransactions.Where(t => !t.IsConfirmed()).Sum(t => t.Amount)
};
model.AccountsBalances.Add(balance);
}
......
......@@ -428,19 +428,20 @@ namespace Breeze.Wallet
/// </summary>
[JsonProperty(PropertyName = "blockHeight", NullValueHandling = NullValueHandling.Ignore)]
public int? BlockHeight { get; set; }
/// <summary>
/// Whether this transaction has been confirmed or not.
/// </summary>
[JsonProperty(PropertyName = "confirmed")]
public bool Confirmed { get; set; }
/// <summary>
/// Gets or sets the creation time.
/// </summary>
[JsonProperty(PropertyName = "creationTime")]
[JsonConverter(typeof(DateTimeOffsetConverter))]
public DateTimeOffset CreationTime { get; set; }
/// <summary>
/// Determines whether this transaction is confirmed.
/// </summary>
public bool IsConfirmed()
{
return this.BlockHeight != null;
}
}
}
\ No newline at end of file
......@@ -506,7 +506,6 @@ namespace Breeze.Wallet
{
Amount = amount,
BlockHeight = blockHeight,
Confirmed = blockHeight.HasValue,
Id = transactionHash,
CreationTime = DateTimeOffset.FromUnixTimeMilliseconds(blockTime ?? time),
Index = index
......@@ -522,13 +521,21 @@ namespace Breeze.Wallet
}
}
}
else if (trans.Any(t => t.Id == transactionHash && !t.Confirmed)) // if this is an unconfirmed transaction now received in a block
else if (trans.Any(t => t.Id == transactionHash)) // if this is an unconfirmed transaction now received in a block
{
var foundTransaction = trans.Single(t => t.Id == transactionHash && !t.Confirmed);
if (blockHeight != null)
var foundTransaction = trans.Single(t => t.Id == transactionHash);
// update the block height
if (foundTransaction.BlockHeight == null && blockHeight != null)
{
foundTransaction.Confirmed = true;
foundTransaction.BlockHeight = blockHeight;
}
// update the block time
if (blockTime != null)
{
foundTransaction.CreationTime = DateTimeOffset.FromUnixTimeMilliseconds(blockTime.Value);
}
}
// notify a transaction has been found
......
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