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


Java Block.getTimeSeconds方法代码示例

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


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

示例1: onBlocksDownloaded

import org.bitcoinj.core.Block; //导入方法依赖的package包/类
public void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) {
    if(!this.caughtUp) {
        if(blocksLeft == 0) {
            this.caughtUp = true;
            this.doneDownload();
            this.future.set(Long.valueOf(peer.getBestHeight()));
        }

        if(blocksLeft >= 0 && this.originalBlocksLeft > 0) {
            double pct = 100.0D - 100.0D * ((double)blocksLeft / (double)this.originalBlocksLeft);
            if((int)pct != this.lastPercent) {

                this.lastBlockDate = new Date(block.getTimeSeconds() * 1000L);
                this.progress(pct, blocksLeft, this.lastBlockDate);
                this.lastPercent = (int)pct;
            }

        }
    }
}
 
开发者ID:ehanoc,项目名称:xwallet,代码行数:21,代码来源:DownloadProgressListener.java

示例2: getTransactionVerificationFlags

import org.bitcoinj.core.Block; //导入方法依赖的package包/类
/**
 * The flags indicating which script validation tests should be applied to
 * the given transaction. Enables support for alternative blockchains which enable
 * tests based on different criteria.
 *
 * @param block block the transaction belongs to.
 * @param transaction to determine flags for.
 * @param height height of the block, if known, null otherwise. Returned
 * tests should be a safe subset if block height is unknown.
 */
public EnumSet<Script.VerifyFlag> getTransactionVerificationFlags(final Block block,
        final Transaction transaction, final VersionTally tally, final Integer height) {
    final EnumSet<Script.VerifyFlag> verifyFlags = EnumSet.noneOf(Script.VerifyFlag.class);
    if (block.getTimeSeconds() >= NetworkParameters.BIP16_ENFORCE_TIME)
        verifyFlags.add(Script.VerifyFlag.P2SH);

    // Start enforcing CHECKLOCKTIMEVERIFY, (BIP65) for block.nVersion=4
    // blocks, when 75% of the network has upgraded:
    if (block.getVersion() >= Block.BLOCK_VERSION_BIP65 &&
        tally.getCountAtOrAbove(Block.BLOCK_VERSION_BIP65) > this.getMajorityEnforceBlockUpgrade()) {
        verifyFlags.add(Script.VerifyFlag.CHECKLOCKTIMEVERIFY);
    }

    return verifyFlags;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:26,代码来源:NetworkParameters.java

示例3: checkDifficultyTransitions

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

示例4: allowDigishieldMinDifficultyForBlock

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

示例5: checkDifficultyTransitions

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

示例6: onBindViewHolder

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

示例7: checkDifficultyTransitions

import org.bitcoinj.core.Block; //导入方法依赖的package包/类
@Override
public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock,
	final BlockStore blockStore) throws VerificationException, BlockStoreException {
    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();
    StoredBlock cursor = blockStore.get(prev.getHash());
    for (int i = 0; i < this.getInterval() - 1; i++) {
        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 genesis block.");
        }
        cursor = blockStore.get(cursor.getHeader().getPrevBlockHash());
    }
    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:Grant-Redmond,项目名称:cryptwallet,代码行数:63,代码来源:AbstractBitcoinNetParams.java

示例8: onBindViewHolder

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

    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:soapboxsys,项目名称:ombuds-android,代码行数:61,代码来源:BlockListAdapter.java

示例9: checkDifficultyTransitions

import org.bitcoinj.core.Block; //导入方法依赖的package包/类
@Override
public void checkDifficultyTransitions(StoredBlock storedPrev, Block nextBlock, BlockStore blockStore)
    throws VerificationException, BlockStoreException {        
    // This is copied verbatim from Bitcoin except for the Namecoin changes marked accordingly
    Block prev = storedPrev.getHeader();

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

        // 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();
    StoredBlock cursor = blockStore.get(prev.getHash());
    
    // Namecoin addition
    int blocksBack = this.getInterval() - 1;
    if (storedPrev.getHeight() >= this.getAuxpowStartHeight() && (storedPrev.getHeight() + 1 > this.getInterval())) {
 blocksBack = this.getInterval();
    }
    
    // Namecoin modification
    //for (int i = 0; i < this.getInterval() - 1; i++) {
    for (int i = 0; i < blocksBack; i++) {
        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 genesis block.");
        }
        cursor = blockStore.get(cursor.getHeader().getPrevBlockHash());
    }
    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:dogecoin,项目名称:libdohj,代码行数:73,代码来源:AbstractNamecoinParams.java


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