Commit 93983ede authored by Jeremy Bokobza's avatar Jeremy Bokobza Committed by GitHub

Merge pull request #57 from bokobza/master

Make sure the right transaction to use is returned when building tran…
parents f924c46f 5735e1f7
...@@ -323,14 +323,17 @@ namespace Breeze.Wallet ...@@ -323,14 +323,17 @@ namespace Breeze.Wallet
} }
/// <summary> /// <summary>
/// Finds the address in which the transaction is contained. /// Finds the addresses in which a transaction is contained.
/// </summary> /// </summary>
/// <param name="transactionId">The transaction identifier.</param> /// <remarks>
/// Returns a collection because a transaction can be contained in a change address as well as in a receive address (as a spend).
/// </remarks>
/// <param name="predicate">A predicate by which to filter the transactions.</param>
/// <returns></returns> /// <returns></returns>
public HdAddress FindAddressForTransaction(uint256 transactionId) public IEnumerable<HdAddress> FindAddressesForTransaction(Func<TransactionData, bool> predicate)
{ {
var addresses = this.ExternalAddresses.Concat(this.InternalAddresses); var addresses = this.ExternalAddresses.Concat(this.InternalAddresses);
return addresses.SingleOrDefault(a => a.Transactions.Any(t => t.Id == transactionId)); return addresses.Where(a => a.Transactions.Any(predicate));
} }
} }
...@@ -412,7 +415,7 @@ namespace Breeze.Wallet ...@@ -412,7 +415,7 @@ namespace Breeze.Wallet
/// <summary> /// <summary>
/// The height of the block including this transaction. /// The height of the block including this transaction.
/// </summary> /// </summary>
[JsonProperty(PropertyName = "blockHeight")] [JsonProperty(PropertyName = "blockHeight", NullValueHandling = NullValueHandling.Ignore)]
public int? BlockHeight { get; set; } public int? BlockHeight { get; set; }
/// <summary> /// <summary>
......
...@@ -359,7 +359,7 @@ namespace Breeze.Wallet ...@@ -359,7 +359,7 @@ namespace Breeze.Wallet
var coins = new List<Coin>(); var coins = new List<Coin>();
foreach (var transactionToUse in calculationResult.transactionsToUse) foreach (var transactionToUse in calculationResult.transactionsToUse)
{ {
var address = account.FindAddressForTransaction(transactionToUse.Id); var address = account.FindAddressesForTransaction(t => t.Id == transactionToUse.Id && t.Amount > 0).Single();
ExtKey addressExtKey = seedExtKey.Derive(new KeyPath(address.HdPath)); ExtKey addressExtKey = seedExtKey.Derive(new KeyPath(address.HdPath));
BitcoinExtKey addressPrivateKey = addressExtKey.GetWif(wallet.Network); BitcoinExtKey addressPrivateKey = addressExtKey.GetWif(wallet.Network);
signingKeys.Add(addressPrivateKey); signingKeys.Add(addressPrivateKey);
......
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