MCPcopy Create free account
hub / github.com/ElementsProject/elements / create_block

Function create_block

test/functional/test_framework/blocktools.py:75–99  ·  view source on GitHub ↗

Create a block (with regtest difficulty).

(hashprev=None, coinbase=None, ntime=None, *, version=None, tmpl=None, txlist=None)

Source from the content-addressed store, hash-verified

73
74
75def create_block(hashprev=None, coinbase=None, ntime=None, *, version=None, tmpl=None, txlist=None):
76 """Create a block (with regtest difficulty)."""
77 block = CBlock()
78 if tmpl is None:
79 tmpl = {}
80 block.nVersion = version or tmpl.get('version') or VERSIONBITS_LAST_OLD_BLOCK_VERSION
81 block.nTime = ntime or tmpl.get('curtime') or int(time.time() + 600)
82 block.hashPrevBlock = hashprev or int(tmpl['previousblockhash'], 0x10)
83 if tmpl and not tmpl.get('bits') is None:
84 block.nBits = struct.unpack('>I', bytes.fromhex(tmpl['bits']))[0]
85 else:
86 block.nBits = 0x207fffff # difficulty retargeting is disabled in REGTEST chainparams
87 if coinbase is None:
88 coinbase = create_coinbase(height=tmpl['height'])
89 block.vtx.append(coinbase)
90 block.proof = CProof(bytearray.fromhex('51'), bytearray.fromhex(''))
91 block.block_height = get_coinbase_height(coinbase)
92 if txlist:
93 for tx in txlist:
94 if not hasattr(tx, 'calc_sha256'):
95 tx = tx_from_hex(tx)
96 block.vtx.append(tx)
97 block.hashMerkleRoot = block.calc_merkle_root()
98 block.calc_sha256()
99 return block
100
101def get_witness_script(witness_root, witness_nonce):
102 witness_commitment = uint256_from_str(hash256(ser_uint256(witness_root) + ser_uint256(witness_nonce)))

Callers 15

test_null_locatorsMethod · 0.90
test_nonnull_locatorsMethod · 0.90
run_testMethod · 0.90
block_submitMethod · 0.90
run_testMethod · 0.90
run_testMethod · 0.90
run_testMethod · 0.90
run_testMethod · 0.90
run_testMethod · 0.90
build_chainMethod · 0.90
build_block_on_tipMethod · 0.90

Calls 8

calc_merkle_rootMethod · 0.95
get_coinbase_heightFunction · 0.85
CBlockClass · 0.70
create_coinbaseFunction · 0.70
CProofClass · 0.70
tx_from_hexFunction · 0.70
getMethod · 0.45
calc_sha256Method · 0.45

Tested by 6

test_null_locatorsMethod · 0.72
test_nonnull_locatorsMethod · 0.72
run_testMethod · 0.72
test_sequenceMethod · 0.72