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


Java StoredBlock.getHeight方法代码示例

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


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

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

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

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

示例4: equals

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
public boolean equals (StoredBlock storedBlock){
    if (storedBlock == null )
        return false;

    return storedBlock.getHeight() == this.height &&
            storedBlock.getHeader().getHashAsString().equals(this.hash) &&
            storedBlock.getHeader().getMerkleRoot().toString().equals(this.merkleroot) &&
            storedBlock.getHeader().getNonce() == this.nonce &&
            storedBlock.getHeader().getTimeSeconds() == this.time &&
            //storedBlock.getHeader().getTransactions().size() == this.tx.size() &&
            storedBlock.getHeader().getVersion() == this.version;

}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:14,代码来源:Block.java

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

示例6: setVerifiedChainHead

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
@Override
public void setVerifiedChainHead(StoredBlock chainHead) throws BlockStoreException {
    if (instrument)
        beginMethod("setVerifiedChainHead");
    Sha256Hash hash = chainHead.getHeader().getHash();
    this.verifiedChainHeadHash = hash;
    this.verifiedChainHeadBlock = chainHead;
    batchPut(getKey(KeyType.VERIFIED_CHAIN_HEAD_SETTING), hash.getBytes());
    if (this.chainHeadBlock.getHeight() < chainHead.getHeight())
        setChainHead(chainHead);
    removeUndoableBlocksWhereHeightIsLessThan(chainHead.getHeight() - fullStoreDepth);
    if (instrument)
        endMethod("setVerifiedChainHead");
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:15,代码来源:LevelDBFullPrunedBlockStore.java

示例7: getBlockchainState

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
@Override
public BlockchainState getBlockchainState() {
    final StoredBlock chainHead = blockChain.getChainHead();
    final Date bestChainDate = chainHead.getHeader().getTime();
    final int bestChainHeight = chainHead.getHeight();
    final boolean replaying = chainHead.getHeight() < config.getBestChainHeightEver();

    return new BlockchainState(bestChainDate, bestChainHeight, replaying, impediments);
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:10,代码来源:BlockchainServiceImpl.java

示例8: truncate

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
public void truncate(StoredBlock checkpoint) {
    int index = checkpoint.getHeight();
    lock.lock();
    try {
        Block block = get(index);
        if (block == null)
            channel.write(ByteBuffer.wrap(checkpoint.getHeader().cloneAsHeader().bitcoinSerialize()), index * HEADER_SIZE);
        channel.truncate((index + 1) * HEADER_SIZE);
    } catch (IOException e) {
        propagate(e);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:devrandom,项目名称:java-stratum,代码行数:15,代码来源:HeadersStore.java

示例9: getBlockchainState

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
@Override
public BlockchainState getBlockchainState()
{
    final StoredBlock chainHead = blockChain.getChainHead();
    final Date bestChainDate = chainHead.getHeader().getTime();
    final int bestChainHeight = chainHead.getHeight();
    final boolean replaying = chainHead.getHeight() < config.getBestChainHeightEver();

    return new BlockchainState(bestChainDate, bestChainHeight, replaying, impediments);
}
 
开发者ID:soapboxsys,项目名称:ombuds-android,代码行数:11,代码来源:BlockchainServiceImpl.java

示例10: putBlockChain

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
protected synchronized void putBlockChain(StoredBlock block) throws Exception {
    
    // TODO: use BIP 113 timestamps
    if ( (new Date().getTime() / 1000 ) - block.getHeader().getTimeSeconds() > 366 * 24 * 60 * 60) {
        log.debug("NameDB halting walkbalk due to timestamp expiration, height " + block.getHeight());
        return;
    }
    
    if (block.getHeight() > getChainHead() + 1) {
        putBlockChain(block.getPrev(store));
    }
    
    putBlock(block);
}
 
开发者ID:dogecoin,项目名称:libdohj,代码行数:15,代码来源:NameLookupLatestLevelDBTransactionCache.java

示例11: allowDigishieldMinDifficultyForBlock

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
/** Dogecoin: Normally minimum difficulty blocks can only occur in between
 * retarget blocks. However, once we introduce Digishield every block is
 * a retarget, so we need to handle minimum difficulty on all blocks.
 */
private boolean allowDigishieldMinDifficultyForBlock(final StoredBlock pindexLast, final Block pblock) {
    // check if the chain allows minimum difficulty blocks
    if (!this.allowMinDifficultyBlocks())
        return false;

    // check if the chain allows minimum difficulty blocks on recalc blocks
    if (pindexLast.getHeight() < 157500)
        return false;

    // Allow for a minimum block time if the elapsed time > 2*nTargetSpacing
    return (pblock.getTimeSeconds() > pindexLast.getHeader().getTimeSeconds() + this.getTargetSpacing(pindexLast.getHeight() + 1) * 2);
}
 
开发者ID:dogecoin,项目名称:libdohj,代码行数:17,代码来源:AbstractDogecoinParams.java

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

示例13: isBlockInMainChain

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
public boolean isBlockInMainChain(Sha256Hash hash)
{
  try
  {
    StoredBlock sb = store.get(hash);
    int h = sb.getHeight();

    return (hash.equals(getBlockHashAtHeight(h)));
  }
  catch(org.bitcoinj.store.BlockStoreException e)
  {
    throw new RuntimeException(e);
  }

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

示例14: checkDifficultyTransitions

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

    // Is this supposed to be a difficulty transition point?
    if (!isDifficultyTransitionPoint(storedPrev.getHeight())) {

        // No ... so check the difficulty didn't actually change.
        if (nextBlock.getDifficultyTarget() != prev.getDifficultyTarget())
            throw new VerificationException("Unexpected change in difficulty at height " + storedPrev.getHeight() +
                    ": " + Long.toHexString(nextBlock.getDifficultyTarget()) + " vs " +
                    Long.toHexString(prev.getDifficultyTarget()));
        return;
    }

    // We need to find a block far back in the chain. It's OK that this is expensive because it only occurs every
    // two weeks after the initial block chain download.
    final Stopwatch watch = Stopwatch.createStarted();
    Sha256Hash hash = prev.getHash();
    StoredBlock cursor = null;
    final int interval = this.getInterval();
    for (int i = 0; i < interval; i++) {
        cursor = blockStore.get(hash);
        if (cursor == null) {
            // This should never happen. If it does, it means we are following an incorrect or busted chain.
            throw new VerificationException(
                    "Difficulty transition point but we did not find a way back to the last transition point. Not found: " + hash);
        }
        hash = cursor.getHeader().getPrevBlockHash();
    }
    checkState(cursor != null && isDifficultyTransitionPoint(cursor.getHeight() - 1),
            "Didn't arrive at a transition point.");
    watch.stop();
    if (watch.elapsed(TimeUnit.MILLISECONDS) > 50)
        log.info("Difficulty transition traversal took {}", watch);

    Block blockIntervalAgo = cursor.getHeader();
    int timespan = (int) (prev.getTimeSeconds() - blockIntervalAgo.getTimeSeconds());
    // Limit the adjustment step.
    final int targetTimespan = this.getTargetTimespan();
    if (timespan < targetTimespan / 4)
        timespan = targetTimespan / 4;
    if (timespan > targetTimespan * 4)
        timespan = targetTimespan * 4;

    BigInteger newTarget = Utils.decodeCompactBits(prev.getDifficultyTarget());
    newTarget = newTarget.multiply(BigInteger.valueOf(timespan));
    newTarget = newTarget.divide(BigInteger.valueOf(targetTimespan));

    if (newTarget.compareTo(this.getMaxTarget()) > 0) {
        log.info("Difficulty hit proof of work limit: {}", newTarget.toString(16));
        newTarget = this.getMaxTarget();
    }

    int accuracyBytes = (int) (nextBlock.getDifficultyTarget() >>> 24) - 3;
    long receivedTargetCompact = nextBlock.getDifficultyTarget();

    // The calculated difficulty is to a higher precision than received, so reduce here.
    BigInteger mask = BigInteger.valueOf(0xFFFFFFL).shiftLeft(accuracyBytes * 8);
    newTarget = newTarget.and(mask);
    long newTargetCompact = Utils.encodeCompactBits(newTarget);

    if (newTargetCompact != receivedTargetCompact)
        throw new VerificationException("Network provided difficulty bits do not match what was calculated: " +
                Long.toHexString(newTargetCompact) + " vs " + Long.toHexString(receivedTargetCompact));
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:68,代码来源:AbstractBitcoinNetParams.java

示例15: onBindViewHolder

import org.bitcoinj.core.StoredBlock; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(final BlockViewHolder holder, final int position) {
    final StoredBlock storedBlock = getItem(position);
    final Block header = storedBlock.getHeader();

    holder.miningRewardAdjustmentView
            .setVisibility(isMiningRewardHalvingPoint(storedBlock) ? View.VISIBLE : View.GONE);
    holder.miningDifficultyAdjustmentView
            .setVisibility(isDifficultyTransitionPoint(storedBlock) ? View.VISIBLE : View.GONE);

    final int height = storedBlock.getHeight();
    holder.heightView.setText(Integer.toString(height));

    final long timeMs = header.getTimeSeconds() * DateUtils.SECOND_IN_MILLIS;
    if (timeMs < System.currentTimeMillis() - DateUtils.MINUTE_IN_MILLIS)
        holder.timeView.setText(DateUtils.getRelativeDateTimeString(context, timeMs, DateUtils.MINUTE_IN_MILLIS,
                DateUtils.WEEK_IN_MILLIS, 0));
    else
        holder.timeView.setText(R.string.block_row_now);

    holder.hashView.setText(WalletUtils.formatHash(null, header.getHashAsString(), 8, 0, ' '));

    final int transactionChildCount = holder.transactionsViewGroup.getChildCount() - ROW_BASE_CHILD_COUNT;
    int iTransactionView = 0;

    if (transactions != null) {
        for (final Transaction tx : transactions) {
            if (tx.getAppearsInHashes().containsKey(header.getHash())) {
                final View view;
                if (iTransactionView < transactionChildCount) {
                    view = holder.transactionsViewGroup.getChildAt(ROW_INSERT_INDEX + iTransactionView);
                } else {
                    view = inflater.inflate(R.layout.block_row_transaction, null);
                    holder.transactionsViewGroup.addView(view, ROW_INSERT_INDEX + iTransactionView);
                }

                bindView(view, tx);

                iTransactionView++;
            }
        }
    }

    final int leftoverTransactionViews = transactionChildCount - iTransactionView;
    if (leftoverTransactionViews > 0)
        holder.transactionsViewGroup.removeViews(ROW_INSERT_INDEX + iTransactionView, leftoverTransactionViews);

    if (onClickListener != null) {
        holder.menuView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                onClickListener.onBlockMenuClick(v, storedBlock);
            }
        });
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:57,代码来源:BlockListAdapter.java


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