diff --git a/src/com/google/bitcoin/core/Wallet.java b/src/com/google/bitcoin/core/Wallet.java index 8df2c82ae..214ffe865 100644 --- a/src/com/google/bitcoin/core/Wallet.java +++ b/src/com/google/bitcoin/core/Wallet.java @@ -802,13 +802,14 @@ public class Wallet implements Serializable { isDead = true; // This transaction was replaced by a double spend on the new chain. Did you just reverse // your own transaction? I hope not!! - log.info(" ->dead, will not confirm now unless there's another re-org", - tx.getHashAsString()); + log.info(" ->dead, will not confirm now unless there's another re-org", tx.getHashAsString()); + TransactionOutput doubleSpent = input.getConnectedOutput(pool); + Transaction replacement = doubleSpent.getSpentBy().parentTransaction; dead.put(tx.getHash(), tx); // Inform the event listeners of the newly dead tx. for (WalletEventListener listener : eventListeners) { synchronized (listener) { - listener.onDeadTransaction(input.outpoint.fromTx, tx); + listener.onDeadTransaction(tx, replacement); } } break; diff --git a/tests/com/google/bitcoin/core/ChainSplitTests.java b/tests/com/google/bitcoin/core/ChainSplitTests.java index 8c01c4317..c5eed2dc1 100644 --- a/tests/com/google/bitcoin/core/ChainSplitTests.java +++ b/tests/com/google/bitcoin/core/ChainSplitTests.java @@ -222,11 +222,13 @@ public class ChainSplitTests { // Check what happens when a re-org happens and one of our UNconfirmed transactions becomes invalidated by a // double spend on the new best chain. - final boolean[] eventCalled = new boolean[1]; + final Transaction[] eventDead = new Transaction[1]; + final Transaction[] eventReplacement = new Transaction[1]; wallet.addEventListener(new WalletEventListener() { @Override public void onDeadTransaction(Transaction deadTx, Transaction replacementTx) { - eventCalled[0] = true; + eventDead[0] = deadTx; + eventReplacement[0] = replacementTx; } }); @@ -255,7 +257,8 @@ public class ChainSplitTests { chain.add(b4); // New best chain. // Should have seen a double spend against the pending pool. - assertTrue(eventCalled[0]); + assertEquals(t1, eventDead[0]); + assertEquals(t2, eventReplacement[0]); assertEquals(Utils.toNanoCoins(30, 0), wallet.getBalance()); // ... and back to our own parallel universe.