public class NativeBlockChainListener extends Object implements BlockChainListener
Modifier and Type | Field and Description |
---|---|
long |
ptr |
Constructor and Description |
---|
NativeBlockChainListener() |
Modifier and Type | Method and Description |
---|---|
boolean |
isTransactionRelevant(Transaction tx)
Returns true if the given transaction is interesting to the listener.
|
void |
notifyNewBestBlock(StoredBlock block)
Called when a new block on the best chain is seen, after relevant transactions are extracted and sent to
us via either
#receiveFromBlock(Transaction, StoredBlock, org.bitcoinj.core.BlockChain.NewBlockType, int)
or #notifyTransactionIsInBlock(Sha256Hash, StoredBlock, org.bitcoinj.core.BlockChain.NewBlockType, int) . |
boolean |
notifyTransactionIsInBlock(Sha256Hash txHash,
StoredBlock block,
AbstractBlockChain.NewBlockType blockType,
int relativityOffset)
Called by the
BlockChain when we receive a new FilteredBlock that contains the given
transaction hash in its merkle tree. |
void |
receiveFromBlock(Transaction tx,
StoredBlock block,
AbstractBlockChain.NewBlockType blockType,
int relativityOffset)
Called by the
BlockChain when we receive a new block that contains a relevant transaction. |
void |
reorganize(StoredBlock splitPoint,
List<StoredBlock> oldBlocks,
List<StoredBlock> newBlocks)
Called by the
BlockChain when the best chain (representing total work done) has changed. |
public void notifyNewBestBlock(StoredBlock block) throws VerificationException
BlockChainListener
#receiveFromBlock(Transaction, StoredBlock, org.bitcoinj.core.BlockChain.NewBlockType, int)
or #notifyTransactionIsInBlock(Sha256Hash, StoredBlock, org.bitcoinj.core.BlockChain.NewBlockType, int)
.
If this block is causing a re-organise to a new chain, this method is NOT called even though the block may be
the new best block: your reorganize implementation is expected to do whatever would normally be done do for a new
best block in this case.notifyNewBestBlock
in interface BlockChainListener
VerificationException
public void reorganize(StoredBlock splitPoint, List<StoredBlock> oldBlocks, List<StoredBlock> newBlocks) throws VerificationException
BlockChainListener
BlockChain
when the best chain (representing total work done) has changed. In this case,
we need to go through our transactions and find out if any have become invalid. It's possible for our balance
to go down in this case: money we thought we had can suddenly vanish if the rest of the network agrees it
should be so.The oldBlocks/newBlocks lists are ordered height-wise from top first to bottom last (i.e. newest blocks first).
reorganize
in interface BlockChainListener
VerificationException
public boolean isTransactionRelevant(Transaction tx) throws ScriptException
BlockChainListener
isTransactionRelevant
in interface BlockChainListener
ScriptException
public void receiveFromBlock(Transaction tx, StoredBlock block, AbstractBlockChain.NewBlockType blockType, int relativityOffset) throws VerificationException
BlockChainListener
Called by the BlockChain
when we receive a new block that contains a relevant transaction.
A transaction may be received multiple times if is included into blocks in parallel chains. The blockType parameter describes whether the containing block is on the main/best chain or whether it's on a presently inactive side chain.
The relativityOffset parameter is an arbitrary number used to establish an ordering between transactions within the same block. In the case where full blocks are being downloaded, it is simply the index of the transaction within that block. When Bloom filtering is in use, we don't find out the exact offset into a block that a transaction occurred at, so the relativity count is not reflective of anything in an absolute sense but rather exists only to order the transaction relative to the others.
receiveFromBlock
in interface BlockChainListener
VerificationException
public boolean notifyTransactionIsInBlock(Sha256Hash txHash, StoredBlock block, AbstractBlockChain.NewBlockType blockType, int relativityOffset) throws VerificationException
BlockChainListener
Called by the BlockChain
when we receive a new FilteredBlock
that contains the given
transaction hash in its merkle tree.
A transaction may be received multiple times if is included into blocks in parallel chains. The blockType parameter describes whether the containing block is on the main/best chain or whether it's on a presently inactive side chain.
The relativityOffset parameter in this case is an arbitrary (meaningless) number, that is useful only when compared to the relativity count of another transaction received inside the same block. It is used to establish an ordering of transactions relative to one another.
This method should return false if the given tx hash isn't known about, e.g. because the the transaction was a Bloom false positive. If it was known about and stored, it should return true. The caller may need to know this to calculate the effective FP rate.
notifyTransactionIsInBlock
in interface BlockChainListener
VerificationException
Copyright © 2014. All rights reserved.