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

Method next_block

test/functional/feature_block.py:1394–1421  ·  view source on GitHub ↗
(self, number, spend=None, additional_coinbase_value=0, script=CScript([OP_TRUE]), *, version=4)

Source from the content-addressed store, hash-verified

1392 return tx
1393
1394 def next_block(self, number, spend=None, additional_coinbase_value=0, script=CScript([OP_TRUE]), *, version=4):
1395 if self.tip is None:
1396 base_block_hash = self.genesis_hash
1397 block_time = int(time.time()) + 1
1398 else:
1399 base_block_hash = self.tip.sha256
1400 block_time = self.tip.nTime + 1
1401 # First create the coinbase
1402 height = self.block_heights[base_block_hash] + 1
1403 coinbase = create_coinbase(height, self.coinbase_pubkey)
1404 coinbase.vout[0].nValue.setToAmount(coinbase.vout[0].nValue.getAmount() + additional_coinbase_value)
1405 coinbase.rehash()
1406 if spend is None:
1407 block = create_block(base_block_hash, coinbase, block_time, version=version)
1408 else:
1409 coinbase.vout[0].nValue.setToAmount(coinbase.vout[0].nValue.getAmount() + spend.vout[0].nValue.getAmount() - 1) # all but one satoshi to fees
1410 coinbase.rehash()
1411 tx = self.create_tx(spend, 0, 1, script) # spend 1 satoshi
1412 self.sign_tx(tx, spend)
1413 tx.rehash()
1414 block = create_block(base_block_hash, coinbase, block_time, version=version, txlist=[tx])
1415 # Block is created. Find a valid nonce.
1416 block.solve()
1417 self.tip = block
1418 self.block_heights[block.sha256] = height
1419 assert number not in self.blocks
1420 self.blocks[number] = block
1421 return block
1422
1423 # save the current tip so it can be spent by a later block
1424 def save_spendable_output(self):

Callers 1

run_testMethod · 0.95

Calls 9

create_txMethod · 0.95
sign_txMethod · 0.95
CScriptClass · 0.90
create_coinbaseFunction · 0.90
create_blockFunction · 0.90
setToAmountMethod · 0.80
getAmountMethod · 0.80
rehashMethod · 0.45
solveMethod · 0.45

Tested by

no test coverage detected