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

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

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

Block.getVersion介绍

[英]Returns the version of the block data structure as defined by the Bitcoin protocol.
[中]返回比特币协议定义的块数据结构版本。

代码示例

代码示例来源:origin: dogecoin/libdohj

/**
 * Return block version without applying any filtering (i.e. for AuxPoW blocks
 * which structure version differently to pack in additional data).
 */
public final long getRawVersion() {
  return super.getVersion();
}

代码示例来源:origin: dogecoin/libdohj

@Override
public long getVersion() {
  // TODO: Can we cache the individual parts on parse?
  if (this.params instanceof AltcoinNetworkParameters) {
    // AuxPoW networks use the higher block version bits for flags and
    // chain ID.
    return getBaseVersion(super.getVersion());
  } else {
    return super.getVersion();
  }
}

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

/**
 * 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());
  }
}

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

/**
 * 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());
  }
}

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

/**
 * 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());
  }
}

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

/**
 * 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());
  }
}

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

/**
 * 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;
}

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

/**
 * 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;
}

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

/**
 * 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;
}

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

/**
 * 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;
}

代码示例来源:origin: dogecoin/libdohj

/**
 * Extract from Litecoin source code, definition of regtest params.
 * https://github.com/litecoin-project/litecoin/blob/edc66b374ea68107c721062152dd95e6aa037d53/src/chainparams.cpp
 */
@Override
public Block getGenesisBlock() {
  synchronized (LitecoinRegTestParams.class) {
    if (genesis == null) {
      genesis = super.getGenesisBlock();
      genesis.setNonce(0);
      genesis.setDifficultyTarget(0x207fffffL);
      genesis.setTime(1296688602L);
      checkState(genesis.getVersion() == 1);
      checkState(genesis.getMerkleRoot().toString().equals("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9"));
      checkState(genesis.getHashAsString().toLowerCase().equals("530827f38f93b43ed12af0b3ad25a288dc02ed74d6d7857862df51fc56c416f9"));
      genesis.verifyHeader();
    }
    return genesis;
  }
}

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

if (block.getVersion() == Block.BLOCK_VERSION_BIP34
  || block.getVersion() == Block.BLOCK_VERSION_BIP66) {
  final Integer count = versionTally.getCountAtOrAbove(block.getVersion() + 1);
  if (count != null
    && count >= params.getMajorityRejectBlockOutdated()) {
    throw new VerificationException.BlockVersionOutOfDate(block.getVersion());
StoredBlock newStoredBlock = addToBlockStore(storedPrev,
    block.transactions == null ? block : block.cloneAsHeader(), txOutChanges);
versionTally.add(block.getVersion());
setChainHead(newStoredBlock);
log.debug("Chain is now {} blocks high, running listeners", newStoredBlock.getHeight());

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

if (block.getVersion() == Block.BLOCK_VERSION_BIP34
  || block.getVersion() == Block.BLOCK_VERSION_BIP66) {
  final Integer count = versionTally.getCountAtOrAbove(block.getVersion() + 1);
  if (count != null
    && count >= params.getMajorityRejectBlockOutdated()) {
    throw new VerificationException.BlockVersionOutOfDate(block.getVersion());
StoredBlock newStoredBlock = addToBlockStore(storedPrev,
    block.transactions == null ? block : block.cloneAsHeader(), txOutChanges);
versionTally.add(block.getVersion());
setChainHead(newStoredBlock);
log.debug("Chain is now {} blocks high, running listeners", newStoredBlock.getHeight());

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

if (block.getVersion() == Block.BLOCK_VERSION_BIP34
  || block.getVersion() == Block.BLOCK_VERSION_BIP66) {
  final Integer count = versionTally.getCountAtOrAbove(block.getVersion() + 1);
  if (count != null
    && count >= params.getMajorityRejectBlockOutdated()) {
    throw new VerificationException.BlockVersionOutOfDate(block.getVersion());
StoredBlock newStoredBlock = addToBlockStore(storedPrev,
    block.transactions == null ? block : block.cloneAsHeader(), txOutChanges);
versionTally.add(block.getVersion());
setChainHead(newStoredBlock);
log.debug("Chain is now {} blocks high, running listeners", newStoredBlock.getHeight());

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

if (block.getVersion() == Block.BLOCK_VERSION_BIP34
  || block.getVersion() == Block.BLOCK_VERSION_BIP66) {
  final Integer count = versionTally.getCountAtOrAbove(block.getVersion() + 1);
  if (count != null
    && count >= params.getMajorityRejectBlockOutdated()) {
    throw new VerificationException.BlockVersionOutOfDate(block.getVersion());
StoredBlock newStoredBlock = addToBlockStore(storedPrev,
    block.transactions == null ? block : block.cloneAsHeader(), txOutChanges);
versionTally.add(block.getVersion());
setChainHead(newStoredBlock);
log.debug("Chain is now {} blocks high, running listeners", newStoredBlock.getHeight());

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

throw new RuntimeException(e); // Cannot happen.
if (b.getVersion() != version) {
  throw new RuntimeException();

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

throw new RuntimeException(e); // Cannot happen.
if (b.getVersion() != version) {
  throw new RuntimeException();

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

throw new RuntimeException(e); // Cannot happen.
if (b.getVersion() != version) {
  throw new RuntimeException();

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

throw new RuntimeException(e); // Cannot happen.
if (b.getVersion() != version) {
  throw new RuntimeException();

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

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

相关文章