Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-magnetic-anomaly-activation.py
Show First 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | def next_block(self, number, spend=None, tx_size=0, pushonly=True, cleanstack=True): | ||||
tx.vout.append(CTxOut(0, CScript([OP_RETURN]))) | tx.vout.append(CTxOut(0, CScript([OP_RETURN]))) | ||||
# Estimate the size of the padding. | # Estimate the size of the padding. | ||||
push_size = tx_size - len(tx.serialize()) - 1 | push_size = tx_size - len(tx.serialize()) - 1 | ||||
# Because several field are of variable size, we grow the push slowly | # Because several field are of variable size, we grow the push slowly | ||||
# up to the requested size. | # up to the requested size. | ||||
while len(tx.serialize()) < tx_size: | while len(tx.serialize()) < tx_size: | ||||
tx.vout[2] = CTxOut(0, CScript( | # Ensure the padding has a left most bit on, so it's | ||||
[random.getrandbits(8 * push_size - 1), OP_RETURN])) | # exactly the correct number of bits. | ||||
padding = random.randrange( | |||||
1 << 8 * push_size - 2, 1 << 8 * push_size - 1) | |||||
tx.vout[2] = CTxOut(0, CScript([padding, OP_RETURN])) | |||||
push_size += 1 | push_size += 1 | ||||
assert_equal(len(tx.serialize()), tx_size) | assert_equal(len(tx.serialize()), tx_size) | ||||
# 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() | ||||
▲ Show 20 Lines • Show All 148 Lines • Show Last 20 Lines |