3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 06:44:16 +00:00

Remove dead code that was used for appearsIn -> appearsInHashes migration, which pre-dates protobuf wallets. Make a few package-private members fully private.

This commit is contained in:
Mike Hearn 2012-09-29 16:37:04 +02:00
parent cca393eea5
commit 946d25548f
3 changed files with 14 additions and 44 deletions

View File

@ -57,30 +57,25 @@ public class Transaction extends ChildMessage implements Serializable {
private long lockTime;
// This is being migrated to appearsInHashes. It's set to null after migration.
Set<StoredBlock> appearsIn;
// Stored only in Java serialization. This is either the time the transaction was broadcast as measured from the
// local clock, or the time from the block in which it was included. Note that this can be changed by re-orgs so
// the wallet may update this field. Old serialized transactions don't have this field, thus null is valid.
// It is used for returning an ordered list of transactions from a wallet, which is helpful for presenting to
// users.
Date updatedAt;
// This is either the time the transaction was broadcast as measured from the local clock, or the time from the
// block in which it was included. Note that this can be changed by re-orgs so the wallet may update this field.
// Old serialized transactions don't have this field, thus null is valid. It is used for returning an ordered
// list of transactions from a wallet, which is helpful for presenting to users.
private Date updatedAt;
// This is an in memory helper only.
transient Sha256Hash hash;
private transient Sha256Hash hash;
// Data about how confirmed this tx is. Serialized, may be null.
private TransactionConfidence confidence;
// This records which blocks the transaction
// has been included in. For most transactions this set will have a single member. In the case of a chain split a
// transaction may appear in multiple blocks but only one of them is part of the best chain. It's not valid to
// have an identical transaction appear in two blocks in the same chain but this invariant is expensive to check,
// so it's not directly enforced anywhere.
// This records which blocks the transaction has been included in. For most transactions this set will have a
// single member. In the case of a chain split a transaction may appear in multiple blocks but only one of them
// is part of the best chain. It's not valid to have an identical transaction appear in two blocks in the same chain
// but this invariant is expensive to check, so it's not directly enforced anywhere.
//
// If this transaction is not stored in the wallet, appearsInHashes is null.
Set<Sha256Hash> appearsInHashes;
private Set<Sha256Hash> appearsInHashes;
public Transaction(NetworkParameters params) {
super(params);
@ -218,18 +213,6 @@ public class Transaction extends ChildMessage implements Serializable {
* because it's not stored in the wallet or because it has never appeared in a block.
*/
public Collection<Sha256Hash> getAppearsInHashes() {
if (appearsInHashes != null)
return appearsInHashes;
if (appearsIn != null) {
log.info("Migrating a tx to appearsInHashes");
appearsInHashes = new HashSet<Sha256Hash>(appearsIn.size());
for (StoredBlock block : appearsIn) {
appearsInHashes.add(block.getHeader().getHash());
}
appearsIn = null;
}
return appearsInHashes;
}

View File

@ -1028,7 +1028,7 @@ public class Wallet implements Serializable {
checkArgument(!pending.containsKey(tx.getHash()), "commitTx called on the same transaction twice");
log.info("commitTx of {}", tx.getHashAsString());
BigInteger balance = getBalance();
tx.updatedAt = Utils.now();
tx.setUpdateTime(Utils.now());
// Mark the outputs we're spending as spent so we won't try and use them in future creations. This will also
// move any transactions that are now fully spent to the spent map so we can skip them when creating future
// spends.

View File

@ -26,7 +26,6 @@ import org.junit.Test;
import java.io.File;
import java.math.BigInteger;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
@ -616,8 +615,8 @@ public class WalletTest {
// Verify we can handle the case of older wallets in which the timestamp is null (guessed from the
// block appearances list).
tx1.updatedAt = null;
tx3.updatedAt = null;
tx1.setUpdateTime(null);
tx3.setUpdateTime(null);
// Check we got them back in order.
transactions = wallet.getTransactionsByTime();
assertEquals(tx2, transactions.get(0));
@ -637,18 +636,6 @@ public class WalletTest {
wallet.addKey(new ECKey());
assertEquals(now + 60, wallet.getEarliestKeyCreationTime());
}
@Test
public void transactionAppearsInMigration() throws Exception {
// Test migration from appearsIn to appearsInHashes
Transaction tx1 = createFakeTx(params, Utils.toNanoCoins(1, 0), myAddress);
StoredBlock b1 = createFakeBlock(params, blockStore, tx1).storedBlock;
tx1.appearsIn = new HashSet<StoredBlock>();
tx1.appearsIn.add(b1);
assertEquals(1, tx1.getAppearsInHashes().size());
assertTrue(tx1.getAppearsInHashes().contains(b1.getHeader().getHash()));
assertNull(tx1.appearsIn);
}
@Test
public void spendToSameWallet() throws Exception {