Commit a71da1b8 authored by Andreas Schildbach's avatar Andreas Schildbach

Fix wrong balance calculation if identical (apart from the index) outputs are involved.

This regression was triggered by a53b5080, though before that change it only worked by luck.
parent 0fb042b3
......@@ -419,8 +419,8 @@ public class TransactionOutput extends ChildMessage {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TransactionOutput other = (TransactionOutput) o;
return value == other.value && (parent == null || parent == other.parent)
&& Arrays.equals(scriptBytes, other.scriptBytes);
return value == other.value && (parent == null || (parent == other.parent && getIndex() == other.getIndex()))
&& Arrays.equals(scriptBytes, other.scriptBytes);
......@@ -545,6 +545,16 @@ public class WalletTest extends TestWithWallet {
assertEquals(v4, wallet.getBalance(Wallet.BalanceType.AVAILABLE));
public void balanceWithIdenticalOutputs() {
assertEquals(Coin.ZERO, wallet.getBalance(BalanceType.ESTIMATED));
Transaction tx = new Transaction(PARAMS);
tx.addOutput(Coin.COIN, myAddress);
tx.addOutput(Coin.COIN, myAddress); // identical to the above
wallet.addWalletTransaction(new WalletTransaction(Pool.UNSPENT, tx));
assertEquals(, wallet.getBalance(BalanceType.ESTIMATED));
// Intuitively you'd expect to be able to create a transaction with identical inputs and outputs and get an
// identical result to Bitcoin Core. However the signatures are not deterministic - signing the same data
// with the same key twice gives two different outputs. So we cannot prove bit-for-bit compatibility in this test
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