Pad a transaction with extra outputs until it reaches a target weight (or higher). returns CTransaction object
(tx, node, target_weight, privkeys, prevtxs=None)
| 314 | return (chain_hex, chain_txns) |
| 315 | |
| 316 | def 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 |