Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/blocktools.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2016 The Bitcoin Core developers | # Copyright (c) 2015-2016 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Utilities for manipulating blocks and transactions.""" | """Utilities for manipulating blocks and transactions.""" | ||||
from .mininode import * | from .mininode import * | ||||
from .script import CScript, OP_TRUE, OP_CHECKSIG, OP_RETURN, OP_PUSHDATA2, OP_DUP, OP_HASH160, OP_EQUALVERIFY | from .script import CScript, OP_TRUE, OP_CHECKSIG, OP_RETURN, OP_PUSHDATA2, OP_DUP, OP_HASH160, OP_EQUALVERIFY | ||||
from .mininode import CTransaction, CTxOut, CTxIn | from .mininode import CTransaction, CTxOut, CTxIn | ||||
from .util import satoshi_round | from .util import satoshi_round | ||||
from .txtools import pad_tx | |||||
# Create a block (with regtest difficulty) | # Create a block (with regtest difficulty) | ||||
def create_block(hashprev, coinbase, nTime=None): | def create_block(hashprev, coinbase, nTime=None): | ||||
block = CBlock() | block = CBlock() | ||||
if nTime is None: | if nTime is None: | ||||
import time | import time | ||||
Show All 38 Lines | def create_coinbase(height, pubkey=None): | ||||
coinbaseoutput.nValue >>= halvings | coinbaseoutput.nValue >>= halvings | ||||
if (pubkey != None): | if (pubkey != None): | ||||
coinbaseoutput.scriptPubKey = CScript([pubkey, OP_CHECKSIG]) | coinbaseoutput.scriptPubKey = CScript([pubkey, OP_CHECKSIG]) | ||||
else: | else: | ||||
coinbaseoutput.scriptPubKey = CScript([OP_TRUE]) | coinbaseoutput.scriptPubKey = CScript([OP_TRUE]) | ||||
coinbase.vout = [coinbaseoutput] | coinbase.vout = [coinbaseoutput] | ||||
# Make sure the coinbase is at least 100 bytes | # Make sure the coinbase is at least 100 bytes | ||||
coinbase_size = len(coinbase.serialize()) | pad_tx(coinbase) | ||||
deadalnix: I think we should keep the old school style padding here. It's how it's done by miners in… | |||||
if coinbase_size < 100: | |||||
coinbase.vin[0].scriptSig += b'x' * (100 - coinbase_size) | |||||
coinbase.calc_sha256() | coinbase.calc_sha256() | ||||
return coinbase | return coinbase | ||||
# Create a transaction. | # Create a transaction. | ||||
# If the scriptPubKey is not specified, make it anyone-can-spend. | # If the scriptPubKey is not specified, make it anyone-can-spend. | ||||
def create_transaction(prevtx, n, sig, value, scriptPubKey=CScript()): | def create_transaction(prevtx, n, sig, value, scriptPubKey=CScript()): | ||||
tx = CTransaction() | tx = CTransaction() | ||||
assert(n < len(prevtx.vout)) | assert(n < len(prevtx.vout)) | ||||
tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), sig, 0xffffffff)) | tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), sig, 0xffffffff)) | ||||
tx.vout.append(CTxOut(value, scriptPubKey)) | tx.vout.append(CTxOut(value, scriptPubKey)) | ||||
pad_tx(tx) | |||||
tx.calc_sha256() | tx.calc_sha256() | ||||
return tx | return tx | ||||
def get_legacy_sigopcount_block(block, fAccurate=True): | def get_legacy_sigopcount_block(block, fAccurate=True): | ||||
count = 0 | count = 0 | ||||
for tx in block.vtx: | for tx in block.vtx: | ||||
count += get_legacy_sigopcount_tx(tx, fAccurate) | count += get_legacy_sigopcount_tx(tx, fAccurate) | ||||
▲ Show 20 Lines • Show All 87 Lines • Show Last 20 Lines |
I think we should keep the old school style padding here. It's how it's done by miners in practice.