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

Function bulk_transaction

test/functional/test_framework/wallet.py:316–334  ·  view source on GitHub ↗

Pad a transaction with extra outputs until it reaches a target weight (or higher). returns CTransaction object

(tx, node, target_weight, privkeys, prevtxs=None)

Source from the content-addressed store, hash-verified

314 return (chain_hex, chain_txns)
315
316def bulk_transaction(tx, node, target_weight, privkeys, prevtxs=None):
317 """Pad a transaction with extra outputs until it reaches a target weight (or higher).
318 returns CTransaction object
319 """
320 tx_heavy = deepcopy(tx)
321 assert_greater_than_or_equal(target_weight, tx_heavy.get_weight())
322 while tx_heavy.get_weight() < target_weight:
323 random_spk = "6a4d0200" # OP_RETURN OP_PUSH2 512 bytes
324 for _ in range(512*2):
325 random_spk += choice("0123456789ABCDEF")
326 tx_heavy.vout.append(CTxOut(0, bytes.fromhex(random_spk)))
327 # Re-sign the transaction
328 if privkeys:
329 signed = node.signrawtransactionwithkey(tx_heavy.serialize().hex(), privkeys, prevtxs)
330 return tx_from_hex(signed["hex"])
331 # OP_TRUE
332 tx_heavy.wit.vtxinwit = [CTxInWitness()]
333 tx_heavy.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
334 return tx_heavy

Callers 2

test_anc_size_limitsMethod · 0.90
test_desc_size_limitsMethod · 0.90

Calls 8

CTxOutClass · 0.90
tx_from_hexFunction · 0.90
CTxInWitnessClass · 0.90
CScriptClass · 0.90
hexMethod · 0.80
get_weightMethod · 0.45
serializeMethod · 0.45

Tested by 2

test_anc_size_limitsMethod · 0.72
test_desc_size_limitsMethod · 0.72