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


Java StoredBlock.getPrev方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: initBlockHashCache

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
protected void initBlockHashCache() throws BlockStoreException {
    blockHashCache = new ConcurrentHashMap<Integer, Sha256Hash>(72000);
    
    StoredBlock blockPointer = chain.getChainHead();
    
    int headHeight = blockPointer.getHeight();
    int reorgSafety = 120;
    int newestHeight = headHeight - reorgSafety;
    int oldestHeight = headHeight - 36000 - reorgSafety; // 36000 = name expiration
    
    while (blockPointer.getHeight() >= oldestHeight) {
        
        if (blockPointer.getHeight() <= newestHeight) {
            blockHashCache.put(new Integer(blockPointer.getHeight()), blockPointer.getHeader().getHash());
        }
    
        blockPointer = blockPointer.getPrev(store);
    }
}
 
开发者ID:dogecoin,项目名称:libdohj,代码行数:20,代码来源:NameLookupByBlockHeightHashCache.java

示例7: getBlockHash

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
public Sha256Hash getBlockHash(int height) throws BlockStoreException {
    Sha256Hash maybeResult = blockHashCache.get(new Integer(height));
    
    if (maybeResult != null) {
        return maybeResult;
    }
    
    // If we got this far, the block height is uncached.
    // This could be because the block is immature, 
    // or it could be because the cache is only initialized on initial startup.
    
    StoredBlock blockPointer = chain.getChainHead();
    
    while (blockPointer.getHeight() != height) {
        blockPointer = blockPointer.getPrev(store);
    }
    
    return blockPointer.getHeader().getHash();
}
 
开发者ID:dogecoin,项目名称:libdohj,代码行数:20,代码来源:NameLookupByBlockHeightHashCache.java

示例8: getLastBlockForAlgo

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
public static StoredBlock getLastBlockForAlgo(StoredBlock block, int algo, BlockStore blockStore)
{
    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;
        }
    }

}
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:19,代码来源:Utils.java

示例9: getChainHead

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
public StoredBlock getChainHead()
    throws org.bitcoinj.store.BlockStoreException
{
    StoredBlock head_blk =  file_db.getSpecialBlockStoreMap().get("head");


    StoredBlock curr = head_blk;
    int stepback=0;
    if (file_db.getBlockSavedMap()==null) throw new RuntimeException("BlockMap is null");

    while((!file_db.getBlockSavedMap().containsKey(curr.getHeader().getHash())) && (curr.getHeight()>=1))
    {   
        int step_size=10;
        if (curr.getHeight() < 1000) step_size=1;
        for(int i=0; i<step_size; i++)
        {
            stepback++;
            curr = curr.getPrev(this);
        }
    }
    setChainHead(curr);
    jelly.getEventLog().alarm("Current Head: " + curr.getHeader().getHash().toString() + " - " + curr.getHeight() + " stepback " + stepback);
    return curr;
}
 
开发者ID:fireduck64,项目名称:jelectrum,代码行数:25,代码来源:MapBlockStore.java

示例10: updateTable

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
/** Updates table for blocks
 * @throws BlockStoreException Occurs when requested Block is not available. */
public void updateTable() throws BlockStoreException {
	DefaultTableModel model = (DefaultTableModel) table.getModel();
	model.setRowCount(0);
	StoredBlock working = kit.getChainHead();
	StoredBlock previous = working.getPrev(kit.getBlockStore());
	for (int i = 0; i < 200; i++) {
		kit.getBlockStoreVersion(working);
		Object[] row = { Integer.toString(working.getHeight()), working.getHeader().getHashAsString(),
				kit.getBlockStoreTime(working).trim(), kit.getBlockStoreVersion(working).trim() };
		working = previous;
		previous = working.getPrev(kit.getBlockStore());
		model.addRow(row);
	}
}
 
开发者ID:FrankieF,项目名称:FJSTSeniorProjectSpring2017,代码行数:17,代码来源:BlockchainGUI.java

示例11: getBlockHashByHeight

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
private Sha256Hash getBlockHashByHeight(BlockChain bc, int appearedInChainheight2) {
	int bestchainheight = bc.getBestChainHeight();
	StoredBlock block = bc.getChainHead();
	assert(block != null);
	for(int i=0; i < bestchainheight-appearedInChainheight2; i++) {
		try {
			System.out.println("iteration: " + i);
			assert(block != null);
			block = block.getPrev(bc.getBlockStore());
		} catch (BlockStoreException e) {
			e.printStackTrace();
		}
	}
	return block.getHeader().getHash();
}
 
开发者ID:kit-tm,项目名称:bitnym,代码行数:16,代码来源:ProofMessage.java

示例12: checkDifficultyTransitions

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
@Override
public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock,
    final BlockStore blockStore) throws VerificationException, BlockStoreException {
    if (!isDifficultyTransitionPoint(storedPrev.getHeight()) && nextBlock.getTime().after(testnetDiffDate)) {
        Block prev = storedPrev.getHeader();

        // 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 = nextBlock.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(getGenesisBlock()) &&
                   cursor.getHeight() % getInterval() != 0 &&
                   cursor.getHeader().getDifficultyTargetAsInteger().equals(getMaxTarget()))
                cursor = cursor.getPrev(blockStore);
    	BigInteger cursorTarget = cursor.getHeader().getDifficultyTargetAsInteger();
    	BigInteger newTarget = nextBlock.getDifficultyTargetAsInteger();
    	if (!cursorTarget.equals(newTarget))
                throw new VerificationException("Testnet block transition that is not allowed: " +
            	Long.toHexString(cursor.getHeader().getDifficultyTarget()) + " vs " +
            	Long.toHexString(nextBlock.getDifficultyTarget()));
        }
    } else {
        super.checkDifficultyTransitions(storedPrev, nextBlock, blockStore);
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:32,代码来源:TestNet3Params.java

示例13: getSafeBlock

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
protected StoredBlock getSafeBlock(StoredBlock block) throws BlockStoreException {
    
    StoredBlock result = block;
    
    int safetyCount;
    for (safetyCount = 0; safetyCount < 12; safetyCount++) {
        result = result.getPrev(store);
    }
    
    return result;
}
 
开发者ID:dogecoin,项目名称:libdohj,代码行数:12,代码来源:NameLookupLatestLevelDBTransactionCache.java

示例14: getNetworkHashRate

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
public static double getNetworkHashRate(StoredBlock currentBlock, BlockStore blockStore)
{
    double totalHash = 0.0;
    long totalTime = 0;
    long lastTime = currentBlock.getHeader().getTimeSeconds();
    double lastDiff = ConvertBitsToDouble(currentBlock.getHeader().getDifficultyTarget());

    StoredBlock block = currentBlock;
    for (int i = 0; i < 10; ++i)
    {
        try {
            block = block.getPrev(blockStore);
            block = getLastBlockForAlgo(block, currentBlock.getHeader().getAlgo(), blockStore);
            if(block == null)
                return 0.0;
        }
        catch(BlockStoreException x)
        {
            return 0.0;
        }
        totalHash += lastDiff * (lastTime - block.getHeader().getTimeSeconds());
        totalTime += lastTime - block.getHeader().getTimeSeconds();
        lastTime = block.getHeader().getTimeSeconds();
        lastDiff = ConvertBitsToDouble(block.getHeader().getDifficultyTarget());
    }
    return ((totalHash * Math.pow(2.0, 32)) / totalTime)/(totalTime/10);
}
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:28,代码来源:Utils.java

示例15: undumbSelf

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
public void undumbSelf(NetworkParameters params, BlockStore block_store)
  throws org.bitcoinj.store.BlockStoreException
{
  Sha256Hash genesis_hash = params.getGenesisBlock().getHash();
  StoredBlock cur = block_store.get(head);
  synchronized(update_lock)
  {
    while(true)
    {
      int height = cur.getHeight();

      if (!height_map.containsKey(height))
      {
        System.out.println("Height map missing: " + height);
        height_map.put(height, cur.getHeader().getHash());
      }
      if (main_chain.contains(cur.getHeader().getHash()))
      {
        System.out.println("Main chain missing: " + height);
        main_chain.add(cur.getHeader().getHash());
      }
      
      if (cur.getHeader().getHash().equals(genesis_hash)) return;
      
      cur = cur.getPrev(block_store);

    }


  }

}
 
开发者ID:fireduck64,项目名称:jelectrum,代码行数:33,代码来源:BlockChainCache.java


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