public class BlockChain extends AbstractBlockChain
AbstractBlockChain.NewBlockType
Modifier and Type | Field and Description |
---|---|
protected BlockStore |
blockStore
Keeps a map of block hashes to StoredBlocks.
|
chainHead, FP_ESTIMATOR_ALPHA, FP_ESTIMATOR_BETA, lock, params
Constructor and Description |
---|
BlockChain(Context context,
BlockStore blockStore)
Constructs a BlockChain that has no wallet at all.
|
BlockChain(Context params,
java.util.List<? extends Wallet> wallets,
BlockStore blockStore)
Constructs a BlockChain connected to the given list of listeners and a store.
|
BlockChain(Context context,
Wallet wallet,
BlockStore blockStore)
Constructs a BlockChain connected to the given wallet and store.
|
BlockChain(NetworkParameters params,
BlockStore blockStore)
|
BlockChain(NetworkParameters params,
java.util.List<? extends Wallet> wallets,
BlockStore blockStore)
|
BlockChain(NetworkParameters params,
Wallet wallet,
BlockStore blockStore)
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(FilteredBlock block)
Processes a received block and tries to add it to the chain.
|
protected StoredBlock |
addToBlockStore(StoredBlock storedPrev,
Block blockHeader)
Adds/updates the given
Block with the block store. |
protected StoredBlock |
addToBlockStore(StoredBlock storedPrev,
Block blockHeader,
TransactionOutputChanges txOutChanges)
Adds/updates the given
StoredBlock with the block store. |
protected TransactionOutputChanges |
connectTransactions(int height,
Block block)
Connect each transaction in block.transactions, verifying them as we go and removing spent outputs
If an error is encountered in a transaction, no changes should be made to the underlying BlockStore.
|
protected TransactionOutputChanges |
connectTransactions(StoredBlock newBlock)
Load newBlock from BlockStore and connect its transactions, returning changes to the set of unspent transactions.
|
protected void |
disconnectTransactions(StoredBlock block)
Disconnect each transaction in the block (after reading it from the block store)
Only called if(shouldVerifyTransactions())
|
protected void |
doSetChainHead(StoredBlock chainHead)
Called before setting chain head in memory.
|
protected StoredBlock |
getStoredBlockInCurrentScope(Sha256Hash hash)
For a standard BlockChain, this should return blockStore.get(hash),
for a FullPrunedBlockChain blockStore.getOnceUndoableStoredBlock(hash)
|
protected void |
notSettingChainHead()
Called if we (possibly) previously called disconnectTransaction/connectTransactions,
but will not be calling preSetChainHead as a block failed verification.
|
protected void |
rollbackBlockStore(int height)
Rollback the block store to a given height.
|
protected boolean |
shouldVerifyTransactions()
Whether or not we are maintaining a set of unspent outputs and are verifying all transactions.
|
add, addNewBestBlockListener, addNewBestBlockListener, addReorganizeListener, addReorganizeListener, addTransactionReceivedListener, addTransactionReceivedListener, addWallet, drainOrphanBlocks, estimateBlockTime, getBestChainHeight, getBlockStore, getChainHead, getFalsePositiveRate, getHeightFuture, getOrphanRoot, getVersionTally, isOrphan, removeNewBestBlockListener, removeReorganizeListener, removeTransactionReceivedListener, removeWallet, resetFalsePositiveEstimate, setChainHead, trackFilteredTransactions
protected final BlockStore blockStore
public BlockChain(Context context, Wallet wallet, BlockStore blockStore) throws BlockStoreException
Constructs a BlockChain connected to the given wallet and store. To obtain a Wallet
you can construct
one from scratch, or you can deserialize a saved wallet from disk using
Wallet.loadFromFile(File, WalletExtension...)
For the store, you should use SPVBlockStore
or you could also try a
MemoryBlockStore
if you want to hold all headers in RAM and don't care about
disk serialization (this is rare).
BlockStoreException
public BlockChain(NetworkParameters params, Wallet wallet, BlockStore blockStore) throws BlockStoreException
BlockStoreException
public BlockChain(Context context, BlockStore blockStore) throws BlockStoreException
BlockStoreException
public BlockChain(NetworkParameters params, BlockStore blockStore) throws BlockStoreException
BlockStoreException
public BlockChain(Context params, java.util.List<? extends Wallet> wallets, BlockStore blockStore) throws BlockStoreException
BlockStoreException
public BlockChain(NetworkParameters params, java.util.List<? extends Wallet> wallets, BlockStore blockStore) throws BlockStoreException
BlockStoreException
protected StoredBlock addToBlockStore(StoredBlock storedPrev, Block blockHeader, TransactionOutputChanges txOutChanges) throws BlockStoreException, VerificationException
AbstractBlockChain
StoredBlock
with the block store.
This version is used when the transactions have already been verified to properly spend txOutputChanges.addToBlockStore
in class AbstractBlockChain
storedPrev
- The StoredBlock
which immediately precedes block.blockHeader
- The StoredBlock
to add/update.txOutChanges
- The total sum of all changes made by this block to the set of open transaction outputs
(from a call to connectTransactions), if in fully verifying mode (null otherwise).StoredBlock
BlockStoreException
VerificationException
protected StoredBlock addToBlockStore(StoredBlock storedPrev, Block blockHeader) throws BlockStoreException, VerificationException
AbstractBlockChain
Block
with the block store.
This version is used when the transactions have not been verified.addToBlockStore
in class AbstractBlockChain
storedPrev
- The StoredBlock
which immediately precedes block.blockHeader
- The Block
to add/update.StoredBlock
BlockStoreException
VerificationException
protected void rollbackBlockStore(int height) throws BlockStoreException
AbstractBlockChain
BlockChain
instances.rollbackBlockStore
in class AbstractBlockChain
BlockStoreException
- if the operation fails or is unsupported.protected boolean shouldVerifyTransactions()
AbstractBlockChain
shouldVerifyTransactions
in class AbstractBlockChain
protected TransactionOutputChanges connectTransactions(int height, Block block)
AbstractBlockChain
connectTransactions
in class AbstractBlockChain
protected TransactionOutputChanges connectTransactions(StoredBlock newBlock)
AbstractBlockChain
connectTransactions
in class AbstractBlockChain
protected void disconnectTransactions(StoredBlock block)
AbstractBlockChain
disconnectTransactions
in class AbstractBlockChain
protected void doSetChainHead(StoredBlock chainHead) throws BlockStoreException
AbstractBlockChain
doSetChainHead
in class AbstractBlockChain
BlockStoreException
protected void notSettingChainHead() throws BlockStoreException
AbstractBlockChain
notSettingChainHead
in class AbstractBlockChain
BlockStoreException
protected StoredBlock getStoredBlockInCurrentScope(Sha256Hash hash) throws BlockStoreException
AbstractBlockChain
getStoredBlockInCurrentScope
in class AbstractBlockChain
BlockStoreException
public boolean add(FilteredBlock block) throws VerificationException, PrunedException
AbstractBlockChain
add
in class AbstractBlockChain
VerificationException
PrunedException