Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/txtools.py
Show All 17 Lines | while curr_size < min_size: | ||||
# txout.value + txout.pk_script bytes + op_return | # txout.value + txout.pk_script bytes + op_return | ||||
extra_bytes = 8 + 1 + 1 | extra_bytes = 8 + 1 + 1 | ||||
padding_len = max(0, min_size - curr_size - extra_bytes) | padding_len = max(0, min_size - curr_size - extra_bytes) | ||||
padding_len = min(padding_len, MAX_TXOUT_PUBKEY_SCRIPT) | padding_len = min(padding_len, MAX_TXOUT_PUBKEY_SCRIPT) | ||||
if padding_len == 0: | if padding_len == 0: | ||||
tx.vout.append(CTxOut(0, CScript([OP_RETURN]))) | tx.vout.append(CTxOut(0, CScript([OP_RETURN]))) | ||||
else: | else: | ||||
padding = random.randrange( | padding = random.randrange( | ||||
1 << 8 * padding_len - 1, 1 << 8 * padding_len) | 1 << 8 * padding_len - 2, 1 << 8 * padding_len - 1) | ||||
tx.vout.append( | tx.vout.append( | ||||
CTxOut(0, CScript([padding, OP_RETURN]))) | CTxOut(0, CScript([padding, OP_RETURN]))) | ||||
curr_size = len(tx.serialize()) | curr_size = len(tx.serialize()) | ||||
tx.rehash() | tx.rehash() | ||||
# Pad outputs until it reaches at least min_size | # Pad outputs until it reaches at least min_size | ||||
def pad_raw_tx(rawtx_hex, min_size=None): | def pad_raw_tx(rawtx_hex, min_size=None): | ||||
tx = CTransaction() | tx = CTransaction() | ||||
FromHex(tx, rawtx_hex) | FromHex(tx, rawtx_hex) | ||||
pad_tx(tx, min_size) | pad_tx(tx, min_size) | ||||
return ToHex(tx) | return ToHex(tx) |