3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-13 02:35:52 +00:00

Change the parameter of BlockChainListener.notifyNewBestBlock to be StoredBlock instead of Block, so listeners can get height/work information as well. The Wallet doesn't need this but other listeners may do.

This commit is contained in:
Mike Hearn 2013-03-01 17:38:23 +01:00
parent 00071d3cfc
commit 1175fe9588
5 changed files with 15 additions and 15 deletions

View File

@ -408,7 +408,7 @@ public abstract class AbstractBlockChain {
i--; // Listener removed itself and it was not the last one.
break;
}
listener.notifyNewBestBlock(newStoredBlock.getHeader());
listener.notifyNewBestBlock(newStoredBlock);
if (i == listeners.size()) {
break; // Listener removed itself and it was the last one.
} else if (listeners.get(i) != listener) {

View File

@ -22,7 +22,7 @@ import java.util.List;
* Default no-op implementation of {@link BlockChainListener}.
*/
public class AbstractBlockChainListener implements BlockChainListener {
public void notifyNewBestBlock(Block block) throws VerificationException {
public void notifyNewBestBlock(StoredBlock block) throws VerificationException {
}
public void reorganize(StoredBlock splitPoint, List<StoredBlock> oldBlocks, List<StoredBlock> newBlocks) throws VerificationException {

View File

@ -29,8 +29,9 @@ public interface BlockChainListener {
* transactions are extracted and sent to us UNLESS the new block caused a re-org, in which case this will
* not be called (the {@link Wallet#reorganize(StoredBlock, java.util.List, java.util.List)} method will
* call this one in that case).</p>
* @param block
*/
void notifyNewBestBlock(Block block) throws VerificationException;
void notifyNewBestBlock(StoredBlock block) throws VerificationException;
/**
* Called by the {@link BlockChain} when the best chain (representing total work done) has changed. In this case,

View File

@ -1053,10 +1053,11 @@ public class Wallet implements Serializable, BlockChainListener {
*
* <p>Used to update confidence data in each transaction and last seen block hash. Triggers auto saving.
* Invokes the onWalletChanged event listener if there were any affected transactions.</p>
* @param block
*/
public synchronized void notifyNewBestBlock(Block block) throws VerificationException {
public synchronized void notifyNewBestBlock(StoredBlock block) throws VerificationException {
// Check to see if this block has been seen before.
Sha256Hash newBlockHash = block.getHash();
Sha256Hash newBlockHash = block.getHeader().getHash();
if (newBlockHash.equals(getLastBlockSeenHash()))
return;
// Store the new block hash.
@ -1072,7 +1073,7 @@ public class Wallet implements Serializable, BlockChainListener {
// notify the tx confidence of work done twice, it'd result in miscounting.
ignoreNextNewBlock.remove(tx.getHash());
} else {
tx.getConfidence().notifyWorkDone(block);
tx.getConfidence().notifyWorkDone(block.getHeader());
}
}
queueAutoSave();
@ -2207,7 +2208,7 @@ public class Wallet implements Serializable, BlockChainListener {
}
}
}
notifyNewBestBlock(b.getHeader());
notifyNewBestBlock(b);
}
// Find the transactions that didn't make it into the new chain yet. For each input, try to connect it to the
@ -2409,10 +2410,8 @@ public class Wallet implements Serializable, BlockChainListener {
}
/**
* Gets a bloom filter that contains all of the public keys from this wallet,
* and which will provide the given false-positive rate.
*
* See the docs for {@link BloomFilter#BloomFilter(int, double)} for a brief explanation of anonymity when using bloom filters.
* Gets a bloom filter that contains all of the public keys from this wallet, and which will provide the given
* false-positive rate. See the docs for {@link BloomFilter} for a brief explanation of anonymity when using filters.
*/
public BloomFilter getBloomFilter(double falsePositiveRate) {
return getBloomFilter(getBloomFilterElementCount(), falsePositiveRate, (long)(Math.random()*Long.MAX_VALUE));

View File

@ -71,7 +71,7 @@ public class WalletTest {
BlockPair bp = createFakeBlock(blockStore, tx);
wallet.receiveFromBlock(tx, bp.storedBlock, type);
if (type == AbstractBlockChain.NewBlockType.BEST_CHAIN)
wallet.notifyNewBestBlock(bp.block);
wallet.notifyNewBestBlock(bp.storedBlock);
}
return tx;
}
@ -154,7 +154,7 @@ public class WalletTest {
BlockPair bp = createFakeBlock(blockStore, t2, t3);
wallet.receiveFromBlock(t2, bp.storedBlock, AbstractBlockChain.NewBlockType.BEST_CHAIN);
wallet.receiveFromBlock(t3, bp.storedBlock, AbstractBlockChain.NewBlockType.BEST_CHAIN);
wallet.notifyNewBestBlock(bp.block);
wallet.notifyNewBestBlock(bp.storedBlock);
assertTrue(wallet.isConsistent());
}
@ -308,9 +308,9 @@ public class WalletTest {
wallet.commitTx(send2);
sendMoneyToWallet(send2, AbstractBlockChain.NewBlockType.BEST_CHAIN);
assertEquals(bitcoinValueToFriendlyString(wallet.getBalance()), "0.80");
Block b4 = createFakeBlock(blockStore).block;
BlockPair b4 = createFakeBlock(blockStore);
confTxns.clear();
wallet.notifyNewBestBlock(b4);
wallet.notifyNewBestBlock(b4.storedBlock);
assertEquals(3, confTxns.size());
}