Java Code Examples for org.bitcoinj.utils.VersionTally

The following examples show how to use org.bitcoinj.utils.VersionTally. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * 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;
}
 
Example 2
/**
 * 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;
}
 
Example 3
Source Project: GreenBits   Source File: NetworkParameters.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
/**
 * The flags indicating which block validation tests should be applied to
 * the given block. Enables support for alternative blockchains which enable
 * tests based on different criteria.
 *
 * @param block  block 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<Block.VerifyFlag> getBlockVerificationFlags(final Block block,
                                                           final VersionTally tally, final Integer height) {
    final EnumSet<Block.VerifyFlag> flags = EnumSet.noneOf(Block.VerifyFlag.class);

    if (block.isBIP34()) {
        final Integer count = tally.getCountAtOrAbove(Block.BLOCK_VERSION_BIP34);
        if (null != count && count >= getMajorityEnforceBlockUpgrade()) {
            flags.add(Block.VerifyFlag.HEIGHT_IN_COINBASE);
        }
    }
    return flags;
}
 
Example 5
Source Project: green_android   Source File: TestNet3Params.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public EnumSet<Script.VerifyFlag> getTransactionVerificationFlags(
    final Block block,
    final Transaction transaction,
    final VersionTally tally,
    final Integer height)
{
    final EnumSet<Script.VerifyFlag> flags = super.getTransactionVerificationFlags(block, transaction, tally, height);
    if (height >= SEGWIT_ENFORCE_HEIGHT) flags.add(Script.VerifyFlag.SEGWIT);
    return flags;
}
 
Example 6
/**
 * The flags indicating which block validation tests should be applied to
 * the given block. Enables support for alternative blockchains which enable
 * tests based on different criteria.
 * 
 * @param block block 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<Block.VerifyFlag> getBlockVerificationFlags(final Block block,
        final VersionTally tally, final Integer height) {
    final EnumSet<Block.VerifyFlag> flags = EnumSet.noneOf(Block.VerifyFlag.class);

    if (block.isBIP34()) {
        final Integer count = tally.getCountAtOrAbove(Block.BLOCK_VERSION_BIP34);
        if (null != count && count >= getMajorityEnforceBlockUpgrade()) {
            flags.add(Block.VerifyFlag.HEIGHT_IN_COINBASE);
        }
    }
    return flags;
}
 
Example 7
Source Project: GreenBits   Source File: TestNet3Params.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public EnumSet<Script.VerifyFlag> getTransactionVerificationFlags(
    final Block block,
    final Transaction transaction,
    final VersionTally tally,
    final Integer height)
{
    final EnumSet<Script.VerifyFlag> flags = super.getTransactionVerificationFlags(block, transaction, tally, height);
    if (height >= SEGWIT_ENFORCE_HEIGHT) flags.add(Script.VerifyFlag.SEGWIT);
    return flags;
}
 
Example 8
Source Project: GreenBits   Source File: NetworkParameters.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * The flags indicating which block validation tests should be applied to
 * the given block. Enables support for alternative blockchains which enable
 * tests based on different criteria.
 * 
 * @param block block 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<Block.VerifyFlag> getBlockVerificationFlags(final Block block,
        final VersionTally tally, final Integer height) {
    final EnumSet<Block.VerifyFlag> flags = EnumSet.noneOf(Block.VerifyFlag.class);

    if (block.isBIP34()) {
        final Integer count = tally.getCountAtOrAbove(Block.BLOCK_VERSION_BIP34);
        if (null != count && count >= getMajorityEnforceBlockUpgrade()) {
            flags.add(Block.VerifyFlag.HEIGHT_IN_COINBASE);
        }
    }
    return flags;
}