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


Java StoredBlock类代码示例

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


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

示例1: receiveFromBlock

import org.bitcoinj.core.StoredBlock; //导入依赖的package包/类
@Override
public void receiveFromBlock(Transaction tx, StoredBlock block, AbstractBlockChain.NewBlockType blockType, int relativityOffset) throws VerificationException {
    //Log.d("TransactionIsInBlock",block.toString());

    synchronized (transactions) {
        countTransactions++;
        transactions.add(tx);
        if (transactions.size() >= 30) {
            transactions.remove(10);
        }
    }

    if(System.currentTimeMillis()-lastTimestamp>1000) {
        refreshUI();
        lastTimestamp = System.currentTimeMillis();
    }
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:18,代码来源:FragmentTxs.java

示例2: refresh

import org.bitcoinj.core.StoredBlock; //导入依赖的package包/类
private void refresh(final StoredBlock storedBlock){
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // Update info
            mDataset.clear();
            if(storedBlock!=null){
                mDataset.put("Hash",storedBlock.getHeader().getHashAsString());
                mDataset.put("Height",String.valueOf(storedBlock.getHeight()));
                //mDataset.put("Prev",storedBlock.getPrev(blockStore).getHeader().getHashAsString());
                mDataset.put("MerkleRoot",storedBlock.getHeader().getMerkleRoot().toString());
                mDataset.put("DifficultyTarget",String.valueOf(storedBlock.getHeader().getDifficultyTarget()));
                mDataset.put("Nonce",String.valueOf(storedBlock.getHeader().getNonce()));
                mDataset.put("Date",storedBlock.getHeader().getTime().toLocaleString());
                mDataset.put("Version",String.valueOf(storedBlock.getHeader().getVersion()));
                mDataset.put("Work",String.valueOf(storedBlock.getHeader().getWork()));
                //mDataset.put("Transactions",String.valueOf(storedBlock.getHeader().getTransactions().size()));
                mAdapter.notifyDataSetChanged();
        }
    }
});
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:23,代码来源:BlockActivity.java

示例3: SQLiteBlockStore

import org.bitcoinj.core.StoredBlock; //导入依赖的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

示例4: put

import org.bitcoinj.core.StoredBlock; //导入依赖的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

示例5: get

import org.bitcoinj.core.StoredBlock; //导入依赖的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

示例6: currentBitcoinBIP113Time

import org.bitcoinj.core.StoredBlock; //导入依赖的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.core.StoredBlock; //导入依赖的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: notifyTransactionIsInBlock

import org.bitcoinj.core.StoredBlock; //导入依赖的package包/类
/**
 * Called by the {@link BlockChain} when we receive a new filtered block that contains a transactions previously
 * received by a call to {@link #receivePending}.<p>
 *
 * This is necessary for the internal book-keeping Wallet does. When a transaction is received that sends us
 * coins it is added to a pool so we can use it later to create spends. When a transaction is received that
 * consumes outputs they are marked as spent so they won't be used in future.<p>
 *
 * A transaction that spends our own coins can be received either because a spend we created was accepted by the
 * network and thus made it into a block, or because our keys are being shared between multiple instances and
 * some other node spent the coins instead. We still have to know about that to avoid accidentally trying to
 * double spend.<p>
 *
 * 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. We must still record these transactions and the blocks they appear in because a future
 * block might change which chain is best causing a reorganize. A re-org can totally change our balance!
 */
@Override
public boolean notifyTransactionIsInBlock(Sha256Hash txHash, StoredBlock block,
                                          BlockChain.NewBlockType blockType,
                                          int relativityOffset) throws VerificationException {
    lock.lock();
    try {
        Transaction tx = transactions.get(txHash);
        if (tx == null) {
            tx = riskDropped.get(txHash);
            if (tx != null) {
                // If this happens our risk analysis is probably wrong and should be improved.
                log.info("Risk analysis dropped tx {} but was included in block anyway", tx.getHash());
            } else {
                // False positive that was broadcast to us and ignored by us because it was irrelevant to our keys.
                return false;
            }
        }
        receive(tx, block, blockType, relativityOffset);
        return true;
    } finally {
        lock.unlock();
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:42,代码来源:Wallet.java

示例9: createNewStore

import org.bitcoinj.core.StoredBlock; //导入依赖的package包/类
private void createNewStore(NetworkParameters params) throws BlockStoreException {
    try {
        // Set up the genesis block. When we start out fresh, it is by
        // definition the top of the chain.
        StoredBlock storedGenesisHeader = new StoredBlock(params.getGenesisBlock().cloneAsHeader(),
                params.getGenesisBlock().getWork(), 0);
        // The coinbase in the genesis block is not spendable. This is
        // because of how the reference client inits
        // its database - the genesis transaction isn't actually in the db
        // so its spent flags can never be updated.
        List<Transaction> genesisTransactions = Lists.newLinkedList();
        StoredUndoableBlock storedGenesis = new StoredUndoableBlock(params.getGenesisBlock().getHash(),
                genesisTransactions);
        beginDatabaseBatchWrite();
        put(storedGenesisHeader, storedGenesis);
        setChainHead(storedGenesisHeader);
        setVerifiedChainHead(storedGenesisHeader);
        batchPut(getKey(KeyType.CREATED), bytes("done"));
        commitDatabaseBatchWrite();
    } catch (VerificationException e) {
        throw new RuntimeException(e); // Cannot happen.
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:24,代码来源:LevelDBFullPrunedBlockStore.java

示例10: getRecentBlocks

import org.bitcoinj.core.StoredBlock; //导入依赖的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

示例11: onBlockMenuClick

import org.bitcoinj.core.StoredBlock; //导入依赖的package包/类
@Override
public void onBlockMenuClick(final View view, final StoredBlock block) {
    final PopupMenu popupMenu = new PopupMenu(activity, view);
    popupMenu.inflate(R.menu.blocks_context);
    popupMenu.getMenu().findItem(R.id.blocks_context_browse).setVisible(Constants.ENABLE_BROWSE);
    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.blocks_context_browse:
                final String blockHash = block.getHeader().getHashAsString();
                final Uri blockExplorerUri = config.getBlockExplorer();
                log.info("Viewing block {} on {}", blockHash, blockExplorerUri);
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.withAppendedPath(blockExplorerUri, "block/" + blockHash)));
                return true;
            }
            return false;
        }
    });
    popupMenu.show();
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:23,代码来源:BlockListFragment.java

示例12: initialize

import org.bitcoinj.core.StoredBlock; //导入依赖的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

示例13: testInitialize

import org.bitcoinj.core.StoredBlock; //导入依赖的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

示例14: testCategory2WithChange

import org.bitcoinj.core.StoredBlock; //导入依赖的package包/类
@Test
public void testCategory2WithChange() throws Exception {
    // Specifically target case 2 with significant change

    // Generate a ton of small outputs
    StoredBlock block = new StoredBlock(makeSolvedTestBlock(blockStore, OTHER_ADDRESS), BigInteger.ONE, 1);
    int i = 0;
    while (i <= CENT.divide(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.multiply(10))) {
        Transaction tx = createFakeTxWithChangeAddress(PARAMS, Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.multiply(10), myAddress, OTHER_ADDRESS);
        tx.getInput(0).setSequenceNumber(i++); // Keep every transaction unique
        wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, i);
    }

    // The selector will choose 2 with MIN_TX_FEE fee
    SendRequest request1 = SendRequest.to(OTHER_ADDRESS, CENT.add(SATOSHI));
    request1.ensureMinRequiredFee = true;
    wallet.completeTx(request1);
    assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE, request1.tx.getFee());
    assertEquals(request1.tx.getInputs().size(), i); // We should have spent all inputs
    assertEquals(2, request1.tx.getOutputs().size()); // and gotten change back
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:22,代码来源:WalletTest.java

示例15: getRecentBlocks

import org.bitcoinj.core.StoredBlock; //导入依赖的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:soapboxsys,项目名称:ombuds-android,代码行数:27,代码来源:BlockchainServiceImpl.java


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