Commit 090e6c33 authored by Jeremy Bokobza's avatar Jeremy Bokobza

Fixed problem happening when user paid to himself

parent 365152b5
...@@ -229,6 +229,8 @@ namespace Breeze.Wallet.Controllers ...@@ -229,6 +229,8 @@ namespace Breeze.Wallet.Controllers
{ {
item.Type = TransactionItemType.Send; item.Type = TransactionItemType.Send;
item.Amount = Money.Zero; item.Amount = Money.Zero;
if (transaction.Payments != null)
{
item.Payments = new List<PaymentDetailModel>(); item.Payments = new List<PaymentDetailModel>();
foreach (var payment in transaction.Payments) foreach (var payment in transaction.Payments)
{ {
...@@ -240,6 +242,7 @@ namespace Breeze.Wallet.Controllers ...@@ -240,6 +242,7 @@ namespace Breeze.Wallet.Controllers
item.Amount += payment.Amount; item.Amount += payment.Amount;
} }
}
var changeAddress = addresses.Single(a => a.IsChangeAddress() && a.Transactions.Any(t => t.Id == transaction.Id)); var changeAddress = addresses.Single(a => a.IsChangeAddress() && a.Transactions.Any(t => t.Id == transaction.Id));
item.Fee = transaction.Amount.Abs() - item.Amount - changeAddress.Transactions.First(t => t.Id == transaction.Id).Amount; item.Fee = transaction.Amount.Abs() - item.Amount - changeAddress.Transactions.First(t => t.Id == transaction.Id).Amount;
......
...@@ -479,8 +479,9 @@ namespace Breeze.Wallet ...@@ -479,8 +479,9 @@ namespace Breeze.Wallet
// find the script this input references // find the script this input references
var keyToSpend = this.keysLookup.Single(v => v.Value.Transactions.Contains(tTx)).Key; var keyToSpend = this.keysLookup.Single(v => v.Value.Transactions.Contains(tTx)).Key;
// get the details of the outputs paid out // get the details of the outputs paid out.
IEnumerable<TxOut> paidoutto = transaction.Outputs.Where(o => !this.keysLookup.Keys.Contains(o.ScriptPubKey)); // We first include the keys we don't hold and then we include the keys we do hold but that are for receiving addresses (which would mean the user paid itself).
IEnumerable<TxOut> paidoutto = transaction.Outputs.Where(o => !this.keysLookup.Keys.Contains(o.ScriptPubKey) || (this.keysLookup.ContainsKey(o.ScriptPubKey) && !this.keysLookup[o.ScriptPubKey].IsChangeAddress()));
AddTransactionToWallet(transaction.GetHash(), transaction.Time, null, -tTx.Amount, keyToSpend, blockHeight, blockTime, tTx.Id, tTx.Index, paidoutto); AddTransactionToWallet(transaction.GetHash(), transaction.Time, null, -tTx.Amount, keyToSpend, blockHeight, blockTime, tTx.Id, tTx.Index, paidoutto);
} }
......
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