本文整理汇总了Java中com.google.bitcoin.store.BlockStoreException类的典型用法代码示例。如果您正苦于以下问题:Java BlockStoreException类的具体用法?Java BlockStoreException怎么用?Java BlockStoreException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BlockStoreException类属于com.google.bitcoin.store包,在下文中一共展示了BlockStoreException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import com.google.bitcoin.store.BlockStoreException; //导入依赖的package包/类
@Override
public void start(Stage mainWindow) throws Exception {
instance = this;
// Show the crash dialog for any exceptions that we don't handle and that hit the main loop.
GuiUtils.handleCrashesOnThisThread();
try {
init(mainWindow);
} catch (Throwable t) {
// Nicer message for the case where the block store file is locked.
if (Throwables.getRootCause(t) instanceof BlockStoreException) {
GuiUtils.informationalAlert("Already running", "This application is already running and cannot be started twice.");
} else {
throw t;
}
}
}
示例2: checkTestnetDifficulty
import com.google.bitcoin.store.BlockStoreException; //导入依赖的package包/类
private void checkTestnetDifficulty(StoredBlock storedPrev, Block prev, Block next) throws VerificationException, BlockStoreException {
checkState(lock.isHeldByCurrentThread());
// After 15th February 2012 the rules on the testnet change to avoid people running up the difficulty
// and then leaving, making it too hard to mine a block. On non-difficulty transition points, easy
// blocks are allowed if there has been a span of 20 minutes without one.
final long timeDelta = next.getTimeSeconds() - prev.getTimeSeconds();
// There is an integer underflow bug in bitcoin-qt that means mindiff blocks are accepted when time
// goes backwards.
if (timeDelta >= 0 && timeDelta <= NetworkParameters.TARGET_SPACING * 2) {
// Walk backwards until we find a block that doesn't have the easiest proof of work, then check
// that difficulty is equal to that one.
StoredBlock cursor = storedPrev;
while (!cursor.getHeader().equals(params.getGenesisBlock()) &&
cursor.getHeight() % params.getInterval() != 0 &&
cursor.getHeader().getDifficultyTargetAsInteger().equals(params.getProofOfWorkLimit()))
cursor = cursor.getPrev(blockStore);
BigInteger cursorDifficulty = cursor.getHeader().getDifficultyTargetAsInteger();
BigInteger newDifficulty = next.getDifficultyTargetAsInteger();
if (!cursorDifficulty.equals(newDifficulty))
throw new VerificationException("Testnet block transition that is not allowed: " +
Long.toHexString(cursor.getHeader().getDifficultyTarget()) + " vs " +
Long.toHexString(next.getDifficultyTarget()));
}
}
示例3: findSplit
import com.google.bitcoin.store.BlockStoreException; //导入依赖的package包/类
/**
* Locates the point in the chain at which newStoredBlock and chainHead diverge. Returns null if no split point was
* found (ie they are not part of the same chain). Returns newChainHead or chainHead if they don't actually diverge
* but are part of the same chain.
*/
private static StoredBlock findSplit(StoredBlock newChainHead, StoredBlock oldChainHead,
BlockStore store) throws BlockStoreException {
StoredBlock currentChainCursor = oldChainHead;
StoredBlock newChainCursor = newChainHead;
// Loop until we find the block both chains have in common. Example:
//
// A -> B -> C -> D
// \--> E -> F -> G
//
// findSplit will return block B. oldChainHead = D and newChainHead = G.
while (!currentChainCursor.equals(newChainCursor)) {
if (currentChainCursor.getHeight() > newChainCursor.getHeight()) {
currentChainCursor = currentChainCursor.getPrev(store);
checkNotNull(currentChainCursor, "Attempt to follow an orphan chain");
} else {
newChainCursor = newChainCursor.getPrev(store);
checkNotNull(newChainCursor, "Attempt to follow an orphan chain");
}
}
return currentChainCursor;
}
示例4: checkDifficultyTransitions
import com.google.bitcoin.store.BlockStoreException; //导入依赖的package包/类
private void checkDifficultyTransitions(StoredBlock storedPrev, Block nextBlock) throws BlockStoreException, VerificationException {
checkState(lock.isHeldByCurrentThread());
//long now = System.currentTimeMillis();
int DiffMode = 1;
if (params.getId().equals(NetworkParameters.ID_TESTNET)) {
if (storedPrev.getHeight()+1 >= 2237) { DiffMode = 2; }
}
else {
if (storedPrev.getHeight()+1 >= 62773) { DiffMode = 2; }
}
if (DiffMode == 1) { checkDifficultyTransitions_V1(storedPrev, nextBlock);/* return;*/}
else if (DiffMode == 2) { checkDifficultyTransitions_V2(storedPrev, nextBlock);/* return;*/}
//checkDifficultyTransitions_V2(storedPrev, nextBlock);
//long elapsed = System.currentTimeMillis() - now;
//log.info("Megacoin checkDifficultyTransitions({}) is {} seconds", storedPrev.getHeight(), elapsed/1000);
}
示例5: shutDown
import com.google.bitcoin.store.BlockStoreException; //导入依赖的package包/类
@Override
protected void shutDown() throws Exception {
// Runs in a separate thread.
try {
vPeerGroup.stopAsync();
vPeerGroup.awaitTerminated();
vWallet.saveToFile(vWalletFile);
vStore.close();
vPeerGroup = null;
vWallet = null;
vStore = null;
vChain = null;
} catch (BlockStoreException e) {
throw new IOException(e);
}
}
示例6: GetLastBlockForAlgo
import com.google.bitcoin.store.BlockStoreException; //导入依赖的package包/类
private StoredBlock GetLastBlockForAlgo(StoredBlock block, int algo)
{
for(;;)
{
if(block == null || block.getHeader().getPrevBlockHash().equals(Sha256Hash.ZERO_HASH))
return null;
if(block.getHeader().getAlgo() == algo)
return block;
try {
block = block.getPrev(blockStore);
}
catch(BlockStoreException x)
{
return null;
}
}
}
示例7: shutDown
import com.google.bitcoin.store.BlockStoreException; //导入依赖的package包/类
@Override
protected void shutDown() throws Exception {
// Runs in a separate thread.
try {
vPeerGroup.stopAndWait();
vWallet.saveToFile(vWalletFile);
vStore.close();
vPeerGroup = null;
vWallet = null;
vStore = null;
vChain = null;
} catch (BlockStoreException e) {
throw new IOException(e);
}
}
示例8: getRecentBlocks
import com.google.bitcoin.store.BlockStoreException; //导入依赖的package包/类
@Override
public List<StoredBlock> getRecentBlocks(final int maxBlocks)
{
final List<StoredBlock> blocks = new ArrayList<StoredBlock>(maxBlocks);
try
{
StoredBlock block = blockChain.getChainHead();
while (block != null)
{
blocks.add(block);
if (blocks.size() >= maxBlocks)
break;
block = block.getPrev(blockStore);
}
}
catch (final BlockStoreException x)
{
// swallow
}
return blocks;
}
示例9: addToBlockStore
import com.google.bitcoin.store.BlockStoreException; //导入依赖的package包/类
@Override
protected StoredBlock addToBlockStore(StoredBlock storedPrev, Block block)
throws BlockStoreException, VerificationException {
StoredBlock newBlock = storedPrev.build(block);
blockStore.put(newBlock, new StoredUndoableBlock(newBlock.getHeader().getHash(), block.transactions));
return newBlock;
}
示例10: getMedianTimestampOfRecentBlocks
import com.google.bitcoin.store.BlockStoreException; //导入依赖的package包/类
/**
* Gets the median timestamp of the last 11 blocks
*/
private static long getMedianTimestampOfRecentBlocks(StoredBlock storedBlock,
BlockStore store) throws BlockStoreException {
long[] timestamps = new long[11];
int unused = 9;
timestamps[10] = storedBlock.getHeader().getTimeSeconds();
while (unused >= 0 && (storedBlock = storedBlock.getPrev(store)) != null)
timestamps[unused--] = storedBlock.getHeader().getTimeSeconds();
Arrays.sort(timestamps, unused+1, 11);
return timestamps[unused + (11-unused)/2];
}
示例11: FullPrunedBlockChain
import com.google.bitcoin.store.BlockStoreException; //导入依赖的package包/类
/**
* Constructs a BlockChain connected to the given list of wallets and a store.
*/
public FullPrunedBlockChain(NetworkParameters params, List<BlockChainListener> listeners,
FullPrunedBlockStore blockStore) throws BlockStoreException {
super(params, listeners, blockStore);
this.blockStore = blockStore;
// Ignore upgrading for now
this.chainHead = blockStore.getVerifiedChainHead();
}
示例12: tryConnectingOrphans
import com.google.bitcoin.store.BlockStoreException; //导入依赖的package包/类
/**
* For each block in orphanBlocks, see if we can now fit it on top of the chain and if so, do so.
*/
private void tryConnectingOrphans() throws VerificationException, BlockStoreException, PrunedException {
checkState(lock.isHeldByCurrentThread());
// For each block in our orphan list, try and fit it onto the head of the chain. If we succeed remove it
// from the list and keep going. If we changed the head of the list at the end of the round try again until
// we can't fit anything else on the top.
//
// This algorithm is kind of crappy, we should do a topo-sort then just connect them in order, but for small
// numbers of orphan blocks it does OK.
int blocksConnectedThisRound;
do {
blocksConnectedThisRound = 0;
Iterator<OrphanBlock> iter = orphanBlocks.values().iterator();
while (iter.hasNext()) {
OrphanBlock orphanBlock = iter.next();
log.debug("Trying to connect {}", orphanBlock.block.getHash());
// Look up the blocks previous.
StoredBlock prev = getStoredBlockInCurrentScope(orphanBlock.block.getPrevBlockHash());
if (prev == null) {
// This is still an unconnected/orphan block.
log.debug(" but it is not connectable right now");
continue;
}
// Otherwise we can connect it now.
// False here ensures we don't recurse infinitely downwards when connecting huge chains.
add(orphanBlock.block, false, orphanBlock.filteredTxHashes, orphanBlock.filteredTxn);
iter.remove();
blocksConnectedThisRound++;
}
if (blocksConnectedThisRound > 0) {
log.info("Connected {} orphan blocks.", blocksConnectedThisRound);
}
} while (blocksConnectedThisRound > 0);
}
示例13: createStore
import com.google.bitcoin.store.BlockStoreException; //导入依赖的package包/类
@Override
public FullPrunedBlockStore createStore(NetworkParameters params, int blockCount)
throws BlockStoreException {
if(useSchema) {
return new PostgresFullPrunedBlockStore(params, blockCount, DB_HOSTNAME, DB_NAME, DB_USERNAME, DB_PASSWORD, DB_SCHEMA);
}
else {
return new PostgresFullPrunedBlockStore(params, blockCount, DB_HOSTNAME, DB_NAME, DB_USERNAME, DB_PASSWORD);
}
}
示例14: AbstractBlockChain
import com.google.bitcoin.store.BlockStoreException; //导入依赖的package包/类
/**
* Constructs a BlockChain connected to the given list of listeners (eg, wallets) and a store.
*/
public AbstractBlockChain(NetworkParameters params, List<BlockChainListener> listeners,
BlockStore blockStore) throws BlockStoreException {
this.blockStore = blockStore;
chainHead = blockStore.getChainHead();
log.info("chain head is at height {}:\n{}", chainHead.getHeight(), chainHead.getHeader());
this.params = params;
this.listeners = new CopyOnWriteArrayList<ListenerRegistration<BlockChainListener>>();
for (BlockChainListener l : listeners) addListener(l, Threading.SAME_THREAD);
}
示例15: getPartialChain
import com.google.bitcoin.store.BlockStoreException; //导入依赖的package包/类
/**
* Returns the set of contiguous blocks between 'higher' and 'lower'. Higher is included, lower is not.
*/
private static LinkedList<StoredBlock> getPartialChain(StoredBlock higher, StoredBlock lower, BlockStore store) throws BlockStoreException {
checkArgument(higher.getHeight() > lower.getHeight(), "higher and lower are reversed");
LinkedList<StoredBlock> results = new LinkedList<StoredBlock>();
StoredBlock cursor = higher;
while (true) {
results.add(cursor);
cursor = checkNotNull(cursor.getPrev(store), "Ran off the end of the chain");
if (cursor.equals(lower)) break;
}
return results;
}