Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/txtools.py
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | while required_padding > 0: | ||||
break | break | ||||
# The total padding size, for a payload < 0x4c, is: | # The total padding size, for a payload < 0x4c, is: | ||||
# vout.value (8 bytes) + script_length (1) + OP_RETURN (1) + | # vout.value (8 bytes) + script_length (1) + OP_RETURN (1) + | ||||
# + data length (1) + data | # + data length (1) + data | ||||
data_size = required_padding - VOUT_VALUE_SIZE - 3 | data_size = required_padding - VOUT_VALUE_SIZE - 3 | ||||
was_op_pushdata1_used = True | was_op_pushdata1_used = True | ||||
script_operations = [] | |||||
if data_size <= 0x4c: | if data_size <= 0x4c: | ||||
was_op_pushdata1_used = False | was_op_pushdata1_used = False | ||||
if data_size == 0x4c: | if data_size == 0x4c: | ||||
# Adding one more byte to the data causes two more bytes to be | # Adding one more byte to the data causes two more bytes to be | ||||
# added to the tx size, because of the need for OP_PUSHDATA1. | # added to the tx size, because of the need for OP_PUSHDATA1. | ||||
# So remove 10 bytes to add an empty OP_RETURN vout instead in | # So remove 10 bytes to add an empty OP_RETURN vout instead in | ||||
# the next iteration. | # the next iteration. | ||||
data_size -= 10 | data_size -= 10 | ||||
elif MAX_OP_RETURN_PAYLOAD < data_size <= MAX_OP_RETURN_PAYLOAD + 10: | elif MAX_OP_RETURN_PAYLOAD < data_size <= MAX_OP_RETURN_PAYLOAD + 10: | ||||
# We require more than one VOUT, but the extra space needed is | # We require more than one VOUT, but the extra space needed is | ||||
# less than the VOUT footprint. Remove 10 bytes from the current | # less than the VOUT footprint. Remove 10 bytes from the current | ||||
# data to avoid overpadding in next iteration. | # data to avoid overpadding in next iteration. | ||||
data_size -= 10 | data_size -= 10 | ||||
elif data_size > MAX_OP_RETURN_PAYLOAD + 10: | elif data_size > MAX_OP_RETURN_PAYLOAD + 10: | ||||
# Use a full OP_RETURN. | # Use a full OP_RETURN. | ||||
data_size = MAX_OP_RETURN_PAYLOAD + 1 | data_size = MAX_OP_RETURN_PAYLOAD + 1 | ||||
if was_op_pushdata1_used: | if was_op_pushdata1_used: | ||||
# OP_PUSHDATA1 adds 1 extra byte to the transaction size. | # OP_PUSHDATA1 adds 1 extra byte to the transaction size. | ||||
data_size -= 1 | data_size -= 1 | ||||
required_padding -= 1 | required_padding -= 1 | ||||
required_padding -= data_size + VOUT_VALUE_SIZE + 3 | required_padding -= data_size + VOUT_VALUE_SIZE + 3 | ||||
script_operations += [ | tx.vout.append( | ||||
OP_RETURN, | CTxOut(0, CScript([OP_RETURN, get_random_bytes(data_size)])) | ||||
get_random_bytes(data_size) | ) | ||||
] | |||||
tx.vout.append(CTxOut(0, CScript(script_operations))) | |||||
tx.rehash() | tx.rehash() | ||||
def pad_raw_tx(rawtx_hex, min_size=MIN_TX_SIZE): | def pad_raw_tx(rawtx_hex, min_size=MIN_TX_SIZE): | ||||
""" | """ | ||||
Pad a raw transaction with OP_RETURN data until it reaches at least min_size | Pad a raw transaction with OP_RETURN data until it reaches at least min_size | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |