Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-p2p-fullblocktest.py
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | def add_transactions_to_block(self, block, tx_list): | ||||
block.vtx.extend(tx_list) | block.vtx.extend(tx_list) | ||||
# this is a little handier to use than the version in blocktools.py | # this is a little handier to use than the version in blocktools.py | ||||
def create_tx(self, spend, value, script=CScript([OP_TRUE])): | def create_tx(self, spend, value, script=CScript([OP_TRUE])): | ||||
tx = create_tx_with_script(spend.tx, spend.n, b"", value, script) | tx = create_tx_with_script(spend.tx, spend.n, b"", value, script) | ||||
return tx | return tx | ||||
def next_block(self, number, spend=None, script=CScript([OP_TRUE]), block_size=0): | def next_block(self, number, spend=None, script=CScript([OP_TRUE]), block_size=0): | ||||
if self.tip == None: | if self.tip is None: | ||||
base_block_hash = self.genesis_hash | base_block_hash = self.genesis_hash | ||||
block_time = int(time.time()) + 1 | block_time = int(time.time()) + 1 | ||||
else: | else: | ||||
base_block_hash = self.tip.sha256 | base_block_hash = self.tip.sha256 | ||||
block_time = self.tip.nTime + 1 | block_time = self.tip.nTime + 1 | ||||
# First create the coinbase | # First create the coinbase | ||||
height = self.block_heights[base_block_hash] + 1 | height = self.block_heights[base_block_hash] + 1 | ||||
coinbase = create_coinbase(height) | coinbase = create_coinbase(height) | ||||
coinbase.rehash() | coinbase.rehash() | ||||
if spend == None: | if spend is None: | ||||
# We need to have something to spend to fill the block. | # We need to have something to spend to fill the block. | ||||
assert_equal(block_size, 0) | assert_equal(block_size, 0) | ||||
block = create_block(base_block_hash, coinbase, block_time) | block = create_block(base_block_hash, coinbase, block_time) | ||||
else: | else: | ||||
# all but one satoshi to fees | # all but one satoshi to fees | ||||
coinbase.vout[0].nValue += spend.tx.vout[spend.n].nValue - 1 | coinbase.vout[0].nValue += spend.tx.vout[spend.n].nValue - 1 | ||||
coinbase.rehash() | coinbase.rehash() | ||||
block = create_block(base_block_hash, coinbase, block_time) | block = create_block(base_block_hash, coinbase, block_time) | ||||
Show All 16 Lines | def next_block(self, number, spend=None, script=CScript([OP_TRUE]), block_size=0): | ||||
tx = get_base_transaction() | tx = get_base_transaction() | ||||
# Make it the same format as transaction added for padding and save the size. | # Make it the same format as transaction added for padding and save the size. | ||||
# It's missing the padding output, so we add a constant to account for it. | # It's missing the padding output, so we add a constant to account for it. | ||||
tx.rehash() | tx.rehash() | ||||
base_tx_size = len(tx.serialize()) + 18 | base_tx_size = len(tx.serialize()) + 18 | ||||
# If a specific script is required, add it. | # If a specific script is required, add it. | ||||
if script != None: | if script is not None: | ||||
tx.vout.append(CTxOut(1, script)) | tx.vout.append(CTxOut(1, script)) | ||||
# Put some random data into the first transaction of the chain to randomize ids. | # Put some random data into the first transaction of the chain to randomize ids. | ||||
tx.vout.append( | tx.vout.append( | ||||
CTxOut(0, CScript([random.randint(0, 256), OP_RETURN]))) | CTxOut(0, CScript([random.randint(0, 256), OP_RETURN]))) | ||||
# Add the transaction to the block | # Add the transaction to the block | ||||
self.add_transactions_to_block(block, [tx]) | self.add_transactions_to_block(block, [tx]) | ||||
▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines |