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 ...@@ -196,7 +196,7 @@ namespace Breeze.Wallet.Controllers
model.Transactions.Add(new TransactionItem model.Transactions.Add(new TransactionItem
{ {
Amount = transaction.Amount, Amount = transaction.Amount,
Confirmed = transaction.Confirmed, Confirmed = transaction.IsConfirmed(),
Timestamp = transaction.CreationTime, Timestamp = transaction.CreationTime,
TransactionId = transaction.Id, TransactionId = transaction.Id,
Address = address.Address Address = address.Address
...@@ -244,8 +244,8 @@ namespace Breeze.Wallet.Controllers ...@@ -244,8 +244,8 @@ namespace Breeze.Wallet.Controllers
CoinType = request.CoinType, CoinType = request.CoinType,
Name = account.Name, Name = account.Name,
HdPath = account.HdPath, HdPath = account.HdPath,
AmountConfirmed = allTransactions.Where(t => t.Confirmed).Sum(t => t.Amount), AmountConfirmed = allTransactions.Where(t => t.IsConfirmed()).Sum(t => t.Amount),
AmountUnconfirmed = allTransactions.Where(t => !t.Confirmed).Sum(t => t.Amount) AmountUnconfirmed = allTransactions.Where(t => !t.IsConfirmed()).Sum(t => t.Amount)
}; };
model.AccountsBalances.Add(balance); model.AccountsBalances.Add(balance);
} }
......
...@@ -429,12 +429,6 @@ namespace Breeze.Wallet ...@@ -429,12 +429,6 @@ namespace Breeze.Wallet
[JsonProperty(PropertyName = "blockHeight", NullValueHandling = NullValueHandling.Ignore)] [JsonProperty(PropertyName = "blockHeight", NullValueHandling = NullValueHandling.Ignore)]
public int? BlockHeight { get; set; } public int? BlockHeight { get; set; }
/// <summary>
/// Whether this transaction has been confirmed or not.
/// </summary>
[JsonProperty(PropertyName = "confirmed")]
public bool Confirmed { get; set; }
/// <summary> /// <summary>
/// Gets or sets the creation time. /// Gets or sets the creation time.
/// </summary> /// </summary>
...@@ -442,5 +436,12 @@ namespace Breeze.Wallet ...@@ -442,5 +436,12 @@ namespace Breeze.Wallet
[JsonConverter(typeof(DateTimeOffsetConverter))] [JsonConverter(typeof(DateTimeOffsetConverter))]
public DateTimeOffset CreationTime { get; set; } 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 ...@@ -506,7 +506,6 @@ namespace Breeze.Wallet
{ {
Amount = amount, Amount = amount,
BlockHeight = blockHeight, BlockHeight = blockHeight,
Confirmed = blockHeight.HasValue,
Id = transactionHash, Id = transactionHash,
CreationTime = DateTimeOffset.FromUnixTimeMilliseconds(blockTime ?? time), CreationTime = DateTimeOffset.FromUnixTimeMilliseconds(blockTime ?? time),
Index = index Index = index
...@@ -522,12 +521,20 @@ namespace Breeze.Wallet ...@@ -522,12 +521,20 @@ 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); var foundTransaction = trans.Single(t => t.Id == transactionHash);
if (blockHeight != null)
// update the block height
if (foundTransaction.BlockHeight == null && blockHeight != null)
{
foundTransaction.BlockHeight = blockHeight;
}
// update the block time
if (blockTime != null)
{ {
foundTransaction.Confirmed = true; foundTransaction.CreationTime = DateTimeOffset.FromUnixTimeMilliseconds(blockTime.Value);
} }
} }
......
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