<commit_before>#!/usr/bin/env python3
# Copyright (c) 2015-2019 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Utilities for manipulating blocks and transactions."""

import unittest

from .address import (
    key_to_p2sh_p2wpkh,
    key_to_p2wpkh,
    script_to_p2sh_p2wsh,
    script_to_p2wsh,
)
from .messages import (
    CBlock,
    COIN,
    COutPoint,
    CTransaction,
    CTxIn,
    CTxInWitness,
    CTxOut,
    FromHex,
    ToHex,
    hash256,
    hex_str_to_bytes,
    ser_uint256,
    sha256,
    uint256_from_str,
    CCbTx,
)
from .script import (
    CScript,
    CScriptNum,
    CScriptOp,
    OP_0,
    OP_1,
    OP_CHECKMULTISIG,
    OP_CHECKSIG,
    OP_RETURN,
    OP_TRUE,
    hash160,
)
from .util import assert_equal
from io import BytesIO

MAX_BLOCK_SIGOPS = 20000

# Genesis block time (regtest)
# SYSCOIN
TIME_GENESIS_BLOCK = 1553040331
SYSCOIN_TX_VERSION_MN_REGISTER = 80
SYSCOIN_TX_VERSION_MN_UPDATE_SERVICE = 81
SYSCOIN_TX_VERSION_MN_UPDATE_REGISTRAR = 82
SYSCOIN_TX_VERSION_MN_UPDATE_REVOKE = 83
SYSCOIN_TX_VERSION_MN_COINBASE = 84
SYSCOIN_TX_VERSION_MN_QUORUM_COMMITMENT = 85

SYSCOIN_TX_VERSION_ALLOCATION_BURN_TO_SYSCOIN = 128
SYSCOIN_TX_VERSION_SYSCOIN_BURN_TO_ALLOCATION = 129
SYSCOIN_TX_VERSION_ASSET_ACTIVATE = 130
SYSCOIN_TX_VERSION_ASSET_UPDATE = 131
SYSCOIN_TX_VERSION_ASSET_SEND = 132
SYSCOIN_TX_VERSION_ALLOCATION_MINT = 133
SYSCOIN_TX_VERSION_ALLOCATION_BURN_TO_ETHEREUM = 134
SYSCOIN_TX_VERSION_ALLOCATION_SEND = 135
# From BIP141
WITNESS_COMMITMENT_HEADER = b"\xaa\x21\xa9\xed"

# SYSCOIN
def create_block(hashprev, coinbase, ntime=None, *, version=1):
    """Create a block (with regtest difficulty)."""
    block = CBlock()
    block.set_base_version(version)
    if ntime is None:
        import time
        # SYSCOIN
        block.nTime = int(time.time() + 60)
    else:
        block.nTime = ntime
    block.hashPrevBlock = hashprev
    block.nBits = 0x207fffff  # difficulty retargeting is disabled in REGTEST chainparams
    block.vtx.append(coinbase)
    block.hashMerkleRoot = block.calc_merkle_root()
    block.calc_sha256()
    return block

def get_witness_script(witness_root, witness_nonce, extraData=None):
    witness_commitment = uint256_from_str(hash256(ser_uint256(witness_root) + ser_uint256(witness_nonce)))
    output_data = WITNESS_COMMITMENT_HEADER + ser_uint256(witness_commitment)
    return CScript([OP_RETURN, output_data, extraData])

def add_witness_commitment(block, nonce=0):
    """Add a witness commitment to the block's coinbase transaction.
<commit_msg>deal with none<commit_after>#!/usr/bin/env python3
# Copyright (c) 2015-2019 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Utilities for manipulating blocks and transactions."""

import unittest

from .address import (
    key_to_p2sh_p2wpkh,
    key_to_p2wpkh,
    script_to_p2sh_p2wsh,
    script_to_p2wsh,
)
from .messages import (
    CBlock,
    COIN,
    COutPoint,
    CTransaction,
    CTxIn,
    CTxInWitness,
    CTxOut,
    FromHex,
    ToHex,
    hash256,
    hex_str_to_bytes,
    ser_uint256,
    sha256,
    uint256_from_str,
    CCbTx,
)
from .script import (
    CScript,
    CScriptNum,
    CScriptOp,
    OP_0,
    OP_1,
    OP_CHECKMULTISIG,
    OP_CHECKSIG,
    OP_RETURN,
    OP_TRUE,
    hash160,
)
from .util import assert_equal
from io import BytesIO

MAX_BLOCK_SIGOPS = 20000

# Genesis block time (regtest)
# SYSCOIN
TIME_GENESIS_BLOCK = 1553040331
SYSCOIN_TX_VERSION_MN_REGISTER = 80
SYSCOIN_TX_VERSION_MN_UPDATE_SERVICE = 81
SYSCOIN_TX_VERSION_MN_UPDATE_REGISTRAR = 82
SYSCOIN_TX_VERSION_MN_UPDATE_REVOKE = 83
SYSCOIN_TX_VERSION_MN_COINBASE = 84
SYSCOIN_TX_VERSION_MN_QUORUM_COMMITMENT = 85

SYSCOIN_TX_VERSION_ALLOCATION_BURN_TO_SYSCOIN = 128
SYSCOIN_TX_VERSION_SYSCOIN_BURN_TO_ALLOCATION = 129
SYSCOIN_TX_VERSION_ASSET_ACTIVATE = 130
SYSCOIN_TX_VERSION_ASSET_UPDATE = 131
SYSCOIN_TX_VERSION_ASSET_SEND = 132
SYSCOIN_TX_VERSION_ALLOCATION_MINT = 133
SYSCOIN_TX_VERSION_ALLOCATION_BURN_TO_ETHEREUM = 134
SYSCOIN_TX_VERSION_ALLOCATION_SEND = 135
# From BIP141
WITNESS_COMMITMENT_HEADER = b"\xaa\x21\xa9\xed"

# SYSCOIN
def create_block(hashprev, coinbase, ntime=None, *, version=1):
    """Create a block (with regtest difficulty)."""
    block = CBlock()
    block.set_base_version(version)
    if ntime is None:
        import time
        # SYSCOIN
        block.nTime = int(time.time() + 60)
    else:
        block.nTime = ntime
    block.hashPrevBlock = hashprev
    block.nBits = 0x207fffff  # difficulty retargeting is disabled in REGTEST chainparams
    block.vtx.append(coinbase)
    block.hashMerkleRoot = block.calc_merkle_root()
    block.calc_sha256()
    return block

def get_witness_script(witness_root, witness_nonce, extraData=None):
    witness_commitment = uint256_from_str(hash256(ser_uint256(witness_root) + ser_uint256(witness_nonce)))
    output_data = WITNESS_COMMITMENT_HEADER + ser_uint256(witness_commitment)
    if extraData is None:
        return CScript([OP_RETURN, output_data])
    else
        return CScript([OP_RETURN, output_data, extraData])

def add_witness_commitment(block, nonce=0):
    """Add a witness commitment to the block's coinbase transaction.

{'fraction_non_alphanumeric': 0.07181195632056266, 'fraction_numerical': 0.04256894317971497, 'mean_word_length': 4.40940940940941, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5516986', 'n_tokens_mistral': 2177, 'n_tokens_neox': 2009, 'n_words': 386}