org.bitcoinj.core.Block.getTime()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(99)

本文整理了Java中org.bitcoinj.core.Block.getTime()方法的一些代码示例,展示了Block.getTime()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.getTime()方法的具体详情如下:
包路径:org.bitcoinj.core.Block
类名称:Block
方法名:getTime

Block.getTime介绍

[英]Returns the time at which the block was solved and broadcast, according to the clock of the solving node.
[中]根据解算节点的时钟,返回块解算和广播的时间。

代码示例

代码示例来源:origin: HashEngineering/dashj

@Override
  public void notifyNewBestBlock(StoredBlock block) throws VerificationException {
    int height = block.getHeight();
    if (height % CoinDefinition.getIntervalCheckpoints() == 0 && block.getHeader().getTimeSeconds() <= timeAgo) {
      System.out.println(String.format("Checkpointing block %s at height %d, time %s",
          block.getHeader().getHash(), block.getHeight(), Utils.dateTimeFormat(block.getHeader().getTime())));
      checkpoints.put(height, block);
    }
  }
});

代码示例来源:origin: Multibit-Legacy/multibit-hd

} else {
 while (cursor != null) {
  if (cursor.getHeader().getTime().before(replayDateTime.get().toDate())) {

代码示例来源:origin: HashEngineering/dashj

@Override
public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock,
  final BlockStore blockStore) throws VerificationException, BlockStoreException {
  if (!isDifficultyTransitionPoint(storedPrev) && nextBlock.getTime().after(testnetDiffDate)) {
    Block prev = storedPrev.getHeader();

代码示例来源:origin: greenaddress/GreenBits

@SuppressWarnings("deprecation")
@Test
public void testDate() throws Exception {
  Block block = PARAMS.getDefaultSerializer().makeBlock(blockBytes);
  assertEquals("4 Nov 2010 16:06:04 GMT", block.getTime().toGMTString());
}

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

@Override
public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock,
                    final BlockStore blockStore, AbstractBlockChain blockChain) throws VerificationException, BlockStoreException {
  if (storedPrev.getHeight() < daaHeight && !isDifficultyTransitionPoint(storedPrev) && nextBlock.getTime().after(testnetDiffDate)) {
    Block prev = storedPrev.getHeader();

代码示例来源:origin: fr.acinq/bitcoinj-core

@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);
  }
}

代码示例来源:origin: greenaddress/GreenBits

@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);
  }
}

相关文章

微信公众号

最新文章

更多