3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-12 02:05:53 +00:00

Second part ... refresh timestamp when confirming a spend to the wallet.

This commit is contained in:
Mike Hearn 2011-09-18 19:46:25 +00:00
parent 3191d5684b
commit ba2255a185
2 changed files with 16 additions and 3 deletions

View File

@ -429,6 +429,8 @@ public class Wallet implements Serializable {
connectedOutput.markAsSpent(input);
maybeMoveTxToSpent(connectedTx, "spent tx");
}
// Refresh the timestamp.
tx.updatedAt = new Date();
// Add to the pending pool. It'll be moved out once we receive this transaction on the best chain.
pending.put(tx.getHash(), tx);
}

View File

@ -296,14 +296,25 @@ public class WalletTest {
assertEquals(1, transactions.size());
assertEquals(tx2, transactions.get(0));
// Create a spend.
Transaction tx3 = wallet.createSend(new ECKey().toAddress(params), Utils.toNanoCoins(0, 5));
// Does not appear in list yet.
assertEquals(2, wallet.getTransactionsByTime().size());
wallet.confirmSend(tx3);
// Now it does.
transactions = wallet.getTransactionsByTime();
assertEquals(3, transactions.size());
assertEquals(tx3, transactions.get(0));
// Verify we can handle the case of older wallets in which the timestamp is null (guessed from the
// block appearances list).
tx1.updatedAt = null;
tx2.updatedAt = null;
// Check we got them back in order.
transactions = wallet.getTransactionsByTime();
assertEquals(tx2, transactions.get(0));
assertEquals(tx1, transactions.get(1));
assertEquals(2, transactions.size());
assertEquals(tx3, transactions.get(0));
assertEquals(tx2, transactions.get(1));
assertEquals(tx1, transactions.get(2));
assertEquals(3, transactions.size());
}
}