当前位置: 首页>>代码示例>>Java>>正文


Java BlockStoreException类代码示例

本文整理汇总了Java中org.bitcoinj.store.BlockStoreException的典型用法代码示例。如果您正苦于以下问题:Java BlockStoreException类的具体用法?Java BlockStoreException怎么用?Java BlockStoreException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BlockStoreException类属于org.bitcoinj.store包,在下文中一共展示了BlockStoreException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: refreshUI

import org.bitcoinj.store.BlockStoreException; //导入依赖的package包/类
private synchronized void refreshUI(){
    getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            try {
                if(peerGroup==null || blockStore==null){
                    tvStatus.setText("0 "+ getResources().getString(R.string.current_height));
                }else {
                    Integer maxHeight = peerGroup.getMostCommonChainHeight();
                    Integer curHeight = 0;
                    if(blockStore.getChainHead()!=null) {
                        curHeight = blockStore.getChainHead().getHeight();
                    }

                    tvStatus.setText(curHeight + "/" + maxHeight + " " + getResources().getString(R.string.current_height));
                    mAdapter.notifyDataSetChanged();
                }
            } catch (BlockStoreException e) {
                e.printStackTrace();
            }
        }
    });
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:24,代码来源:FragmentBlocks.java

示例2: SQLiteBlockStore

import org.bitcoinj.store.BlockStoreException; //导入依赖的package包/类
public SQLiteBlockStore(NetworkParameters params, Context context) throws BlockStoreException {
    this.params = params;
    blocksDataSource = new BlocksDataSource(context);

    blocksDataSource.open();
    if (blocksDataSource.count()==0){
        createNewBlockStore(params);
    } else{
        try {
            DBBlock block = blocksDataSource.getLast();
            Block b = new Block(params, block.getHeader());
            StoredBlock s = build(b);
            this.chainHead = s.getHeader().getHash();
        } catch (Exception e) {
            throw new BlockStoreException("Invalid BlockStore chainHead");
        }
    }
    blocksDataSource.close();
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:20,代码来源:SQLiteBlockStore.java

示例3: put

import org.bitcoinj.store.BlockStoreException; //导入依赖的package包/类
@Override
public synchronized void put(StoredBlock block) throws BlockStoreException {

    blocksDataSource.open();
    Sha256Hash hash = block.getHeader().getHash();
    try {
        blocksDataSource.getHash(hash.toString());
    } catch (Exception e) {
        DBBlock dbBlock = new DBBlock();
        dbBlock.setHash(hash.toString());
        dbBlock.setHeight(block.getHeight());
        dbBlock.setHeader(block.getHeader().bitcoinSerialize());
        dbBlock.setChainWork(block.getChainWork());
        blocksDataSource.insert(dbBlock);
    }
    blocksDataSource.close();
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:18,代码来源:SQLiteBlockStore.java

示例4: get

import org.bitcoinj.store.BlockStoreException; //导入依赖的package包/类
@Override
public synchronized StoredBlock get(Sha256Hash hash) throws BlockStoreException {

    if(hash==null)
        throw new BlockStoreException("Invalid hash");

    blocksDataSource.open();
    DBBlock block = null;
    try {
        block = blocksDataSource.getHash(hash.toString());
    } catch (Exception e) {
        blocksDataSource.close();
        return null;
    }

    Block b = new Block(params, block.getHeader());
    StoredBlock s = build(b);

    blocksDataSource.close();
    return s;
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:22,代码来源:SQLiteBlockStore.java

示例5: lock

import org.bitcoinj.store.BlockStoreException; //导入依赖的package包/类
private void lock() throws IOException, BlockStoreException {
    if (!semaphores.tryAcquire()) {
        throw new BlockStoreException("File in use");
    }
    try {
        lock = file.getChannel().tryLock();
    } catch (OverlappingFileLockException e) {
        semaphores.release();
        lock = null;
    }
    if (lock == null) {
        try {
            this.file.close();
        } finally {
            this.file = null;
        }
        throw new BlockStoreException("Could not lock file");
    }
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:20,代码来源:DiskBlockStore.java

示例6: currentBitcoinBIP113Time

import org.bitcoinj.store.BlockStoreException; //导入依赖的package包/类
public static long currentBitcoinBIP113Time(BlockChain bc) {
	StoredBlock headBlock = bc.getChainHead();
	StoredBlock iteratingBlock = headBlock;
	long[] blockTimeStamps = new long[11];
	for(int i=0; i < 11; i++) {
		blockTimeStamps[i] = iteratingBlock.getHeader().getTimeSeconds();
		try {
			iteratingBlock = iteratingBlock.getPrev(bc.getBlockStore());
		} catch (BlockStoreException e) {
			e.printStackTrace();
		}
	}
	Arrays.sort(blockTimeStamps);
	System.out.println("current bitcoinbip113time yielded " + new Date(blockTimeStamps[5]*1000));
	return blockTimeStamps[5];
}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:17,代码来源:CLTVScriptPair.java

示例7: initialize

import org.bitcoinj.store.BlockStoreException; //导入依赖的package包/类
/**
 * Initialize the version tally from the block store. Note this does not
 * search backwards past the start of the block store, so if starting from
 * a checkpoint this may not fill the window.
 *
 * @param blockStore block store to load blocks from.
 * @param chainHead current chain tip.
 */
public void initialize(final BlockStore blockStore, final StoredBlock chainHead)
    throws BlockStoreException {
    StoredBlock versionBlock = chainHead;
    final Stack<Long> versions = new Stack<>();

    // We don't know how many blocks back we can go, so load what we can first
    versions.push(versionBlock.getHeader().getVersion());
    for (int headOffset = 0; headOffset < versionWindow.length; headOffset++) {
        versionBlock = versionBlock.getPrev(blockStore);
        if (null == versionBlock) {
            break;
        }
        versions.push(versionBlock.getHeader().getVersion());
    }

    // Replay the versions into the tally
    while (!versions.isEmpty()) {
        add(versions.pop());
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:29,代码来源:VersionTally.java

示例8: rollbackBlockStore

import org.bitcoinj.store.BlockStoreException; //导入依赖的package包/类
@Override
protected void rollbackBlockStore(int height) throws BlockStoreException {
    lock.lock();
    try {
        int currentHeight = getBestChainHeight();
        checkArgument(height >= 0 && height <= currentHeight, "Bad height: %s", height);
        if (height == currentHeight)
            return; // nothing to do

        // Look for the block we want to be the new chain head
        StoredBlock newChainHead = blockStore.getChainHead();
        while (newChainHead.getHeight() > height) {
            newChainHead = newChainHead.getPrev(blockStore);
            if (newChainHead == null)
                throw new BlockStoreException("Unreachable height");
        }

        // Modify store directly
        blockStore.put(newChainHead);
        this.setChainHead(newChainHead);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:25,代码来源:BlockChain.java

示例9: getRecentBlocks

import org.bitcoinj.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;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:22,代码来源:BlockchainServiceImpl.java

示例10: initialize

import org.bitcoinj.store.BlockStoreException; //导入依赖的package包/类
/**
 * Initialize the version tally from the block store. Note this does not
 * search backwards past the start of the block store, so if starting from
 * a checkpoint this may not fill the window.
 *
 * @param blockStore block store to load blocks from.
 * @param chainHead current chain tip.
 */
public void initialize(final BlockStore blockStore, final StoredBlock chainHead)
    throws BlockStoreException {
    StoredBlock versionBlock = chainHead;
    final Stack<Long> versions = new Stack<Long>();

    // We don't know how many blocks back we can go, so load what we can first
    versions.push(versionBlock.getHeader().getVersion());
    for (int headOffset = 0; headOffset < versionWindow.length; headOffset++) {
        versionBlock = versionBlock.getPrev(blockStore);
        if (null == versionBlock) {
            break;
        }
        versions.push(versionBlock.getHeader().getVersion());
    }

    // Replay the versions into the tally
    while (!versions.isEmpty()) {
        add(versions.pop());
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:29,代码来源:VersionTally.java

示例11: testInitialize

import org.bitcoinj.store.BlockStoreException; //导入依赖的package包/类
@Test
public void testInitialize() throws BlockStoreException {
    final BlockStore blockStore = new MemoryBlockStore(PARAMS);
    final BlockChain chain = new BlockChain(PARAMS, blockStore);

    // Build a historical chain of version 2 blocks
    long timeSeconds = 1231006505;
    StoredBlock chainHead = null;
    for (int height = 0; height < PARAMS.getMajorityWindow(); height++) {
        chainHead = FakeTxBuilder.createFakeBlock(blockStore, 2, timeSeconds, height).storedBlock;
        assertEquals(2, chainHead.getHeader().getVersion());
        timeSeconds += 60;
    }

    VersionTally instance = new VersionTally(PARAMS);
    instance.initialize(blockStore, chainHead);
    assertEquals(PARAMS.getMajorityWindow(), instance.getCountAtOrAbove(2).intValue());
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:19,代码来源:VersionTallyTest.java

示例12: retrieveFromUtxo

import org.bitcoinj.store.BlockStoreException; //导入依赖的package包/类
@Nullable
private static StoredTransactionOutput retrieveFromUtxo(AbstractBlockChain blockChain, TransactionOutPoint txInOutpoint) {
    final BlockStore bs = blockChain.getBlockStore();
    if (bs instanceof FullPrunedBlockStore) {
        FullPrunedBlockStore blockStore = (FullPrunedBlockStore) bs;
        try {
            return blockStore.getTransactionOutput(txInOutpoint.getHash(), txInOutpoint.getIndex());
        } catch (BlockStoreException e) {
            logger.error("blockStore.getTransactionOutput(Sha256Hash, long) lookup exception", e);
        }
    } else {
        logger.warn("Masternode code active despite that BlockStore is not an instance of FullPrunedBlockStore");
    }

    return null;
}
 
开发者ID:btcsoft,项目名称:coinj-dash,代码行数:17,代码来源:VerificationUtils.java

示例13: createMarriedWallet

import org.bitcoinj.store.BlockStoreException; //导入依赖的package包/类
private void createMarriedWallet(int threshold, int numKeys, boolean addSigners) throws BlockStoreException {
    wallet = new Wallet(params);
    blockStore = new MemoryBlockStore(params);
    chain = new BlockChain(params, wallet, blockStore);

    List<DeterministicKey> followingKeys = Lists.newArrayList();
    for (int i = 0; i < numKeys - 1; i++) {
        final DeterministicKeyChain keyChain = new DeterministicKeyChain(new SecureRandom());
        DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, keyChain.getWatchingKey().serializePubB58());
        followingKeys.add(partnerKey);
        if (addSigners && i < threshold - 1)
            wallet.addTransactionSigner(new KeyChainTransactionSigner(keyChain));
    }

    wallet.addFollowingAccountKeys(followingKeys, threshold);
}
 
开发者ID:egordon,项目名称:CoinJoin,代码行数:17,代码来源:WalletTest.java

示例14: shutDown

import org.bitcoinj.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);
    }
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:18,代码来源:WalletAppKit.java

示例15: checkTestnetDifficulty

import org.bitcoinj.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.getMaxTarget()))
            cursor = cursor.getPrev(blockStore);
        BigInteger cursorTarget = cursor.getHeader().getDifficultyTargetAsInteger();
        BigInteger newTarget = next.getDifficultyTargetAsInteger();
        if (!cursorTarget.equals(newTarget))
            throw new VerificationException("Testnet block transition that is not allowed: " +
                Long.toHexString(cursor.getHeader().getDifficultyTarget()) + " vs " +
                Long.toHexString(next.getDifficultyTarget()));
    }
}
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:25,代码来源:AbstractBlockChain.java


注:本文中的org.bitcoinj.store.BlockStoreException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。