mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-13 10:45:51 +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:
parent
00071d3cfc
commit
1175fe9588
@ -408,7 +408,7 @@ public abstract class AbstractBlockChain {
|
|||||||
i--; // Listener removed itself and it was not the last one.
|
i--; // Listener removed itself and it was not the last one.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
listener.notifyNewBestBlock(newStoredBlock.getHeader());
|
listener.notifyNewBestBlock(newStoredBlock);
|
||||||
if (i == listeners.size()) {
|
if (i == listeners.size()) {
|
||||||
break; // Listener removed itself and it was the last one.
|
break; // Listener removed itself and it was the last one.
|
||||||
} else if (listeners.get(i) != listener) {
|
} else if (listeners.get(i) != listener) {
|
||||||
|
@ -22,7 +22,7 @@ import java.util.List;
|
|||||||
* Default no-op implementation of {@link BlockChainListener}.
|
* Default no-op implementation of {@link BlockChainListener}.
|
||||||
*/
|
*/
|
||||||
public class AbstractBlockChainListener implements 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 {
|
public void reorganize(StoredBlock splitPoint, List<StoredBlock> oldBlocks, List<StoredBlock> newBlocks) throws VerificationException {
|
||||||
|
@ -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
|
* 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
|
* not be called (the {@link Wallet#reorganize(StoredBlock, java.util.List, java.util.List)} method will
|
||||||
* call this one in that case).</p>
|
* 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,
|
* Called by the {@link BlockChain} when the best chain (representing total work done) has changed. In this case,
|
||||||
|
@ -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.
|
* <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>
|
* 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.
|
// Check to see if this block has been seen before.
|
||||||
Sha256Hash newBlockHash = block.getHash();
|
Sha256Hash newBlockHash = block.getHeader().getHash();
|
||||||
if (newBlockHash.equals(getLastBlockSeenHash()))
|
if (newBlockHash.equals(getLastBlockSeenHash()))
|
||||||
return;
|
return;
|
||||||
// Store the new block hash.
|
// 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.
|
// notify the tx confidence of work done twice, it'd result in miscounting.
|
||||||
ignoreNextNewBlock.remove(tx.getHash());
|
ignoreNextNewBlock.remove(tx.getHash());
|
||||||
} else {
|
} else {
|
||||||
tx.getConfidence().notifyWorkDone(block);
|
tx.getConfidence().notifyWorkDone(block.getHeader());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
queueAutoSave();
|
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
|
// 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,
|
* Gets a bloom filter that contains all of the public keys from this wallet, and which will provide the given
|
||||||
* and which will provide the given false-positive rate.
|
* false-positive rate. See the docs for {@link BloomFilter} for a brief explanation of anonymity when using filters.
|
||||||
*
|
|
||||||
* See the docs for {@link BloomFilter#BloomFilter(int, double)} for a brief explanation of anonymity when using bloom filters.
|
|
||||||
*/
|
*/
|
||||||
public BloomFilter getBloomFilter(double falsePositiveRate) {
|
public BloomFilter getBloomFilter(double falsePositiveRate) {
|
||||||
return getBloomFilter(getBloomFilterElementCount(), falsePositiveRate, (long)(Math.random()*Long.MAX_VALUE));
|
return getBloomFilter(getBloomFilterElementCount(), falsePositiveRate, (long)(Math.random()*Long.MAX_VALUE));
|
||||||
|
@ -71,7 +71,7 @@ public class WalletTest {
|
|||||||
BlockPair bp = createFakeBlock(blockStore, tx);
|
BlockPair bp = createFakeBlock(blockStore, tx);
|
||||||
wallet.receiveFromBlock(tx, bp.storedBlock, type);
|
wallet.receiveFromBlock(tx, bp.storedBlock, type);
|
||||||
if (type == AbstractBlockChain.NewBlockType.BEST_CHAIN)
|
if (type == AbstractBlockChain.NewBlockType.BEST_CHAIN)
|
||||||
wallet.notifyNewBestBlock(bp.block);
|
wallet.notifyNewBestBlock(bp.storedBlock);
|
||||||
}
|
}
|
||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ public class WalletTest {
|
|||||||
BlockPair bp = createFakeBlock(blockStore, t2, t3);
|
BlockPair bp = createFakeBlock(blockStore, t2, t3);
|
||||||
wallet.receiveFromBlock(t2, bp.storedBlock, AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
wallet.receiveFromBlock(t2, bp.storedBlock, AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
||||||
wallet.receiveFromBlock(t3, 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());
|
assertTrue(wallet.isConsistent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,9 +308,9 @@ public class WalletTest {
|
|||||||
wallet.commitTx(send2);
|
wallet.commitTx(send2);
|
||||||
sendMoneyToWallet(send2, AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
sendMoneyToWallet(send2, AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
||||||
assertEquals(bitcoinValueToFriendlyString(wallet.getBalance()), "0.80");
|
assertEquals(bitcoinValueToFriendlyString(wallet.getBalance()), "0.80");
|
||||||
Block b4 = createFakeBlock(blockStore).block;
|
BlockPair b4 = createFakeBlock(blockStore);
|
||||||
confTxns.clear();
|
confTxns.clear();
|
||||||
wallet.notifyNewBestBlock(b4);
|
wallet.notifyNewBestBlock(b4.storedBlock);
|
||||||
assertEquals(3, confTxns.size());
|
assertEquals(3, confTxns.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user