|
19 | 19 |
|
20 | 20 | from . import coverage
|
21 | 21 | from .authproxy import AuthServiceProxy, JSONRPCException
|
| 22 | +from io import BytesIO |
22 | 23 |
|
23 | 24 | logger = logging.getLogger("TestFramework.utils")
|
24 | 25 |
|
@@ -515,31 +516,33 @@ def gen_return_txouts():
|
515 | 516 | for i in range(512):
|
516 | 517 | script_pubkey = script_pubkey + "01"
|
517 | 518 | # concatenate 128 txouts of above script_pubkey which we'll insert before the txout for change
|
518 |
| - txouts = "81" |
| 519 | + txouts = [] |
| 520 | + from .messages import CTxOut |
| 521 | + txout = CTxOut() |
| 522 | + txout.nValue = 0 |
| 523 | + txout.scriptPubKey = hex_str_to_bytes(script_pubkey) |
519 | 524 | for k in range(128):
|
520 |
| - # add txout value |
521 |
| - txouts = txouts + "0000000000000000" |
522 |
| - # add length of script_pubkey |
523 |
| - txouts = txouts + "fd0402" |
524 |
| - # add script_pubkey |
525 |
| - txouts = txouts + script_pubkey |
| 525 | + txouts.append(txout) |
526 | 526 | return txouts
|
527 | 527 |
|
528 | 528 | # Create a spend of each passed-in utxo, splicing in "txouts" to each raw
|
529 | 529 | # transaction to make it large. See gen_return_txouts() above.
|
530 | 530 | def create_lots_of_big_transactions(node, txouts, utxos, num, fee):
|
531 | 531 | addr = node.getnewaddress()
|
532 | 532 | txids = []
|
| 533 | + from .messages import CTransaction |
533 | 534 | for _ in range(num):
|
534 | 535 | t = utxos.pop()
|
535 | 536 | inputs = [{"txid": t["txid"], "vout": t["vout"]}]
|
536 | 537 | outputs = {}
|
537 | 538 | change = t['amount'] - fee
|
538 | 539 | outputs[addr] = satoshi_round(change)
|
539 | 540 | rawtx = node.createrawtransaction(inputs, outputs)
|
540 |
| - newtx = rawtx[0:92] |
541 |
| - newtx = newtx + txouts |
542 |
| - newtx = newtx + rawtx[94:] |
| 541 | + tx = CTransaction() |
| 542 | + tx.deserialize(BytesIO(hex_str_to_bytes(rawtx))) |
| 543 | + for txout in txouts: |
| 544 | + tx.vout.append(txout) |
| 545 | + newtx = tx.serialize().hex() |
543 | 546 | signresult = node.signrawtransactionwithwallet(newtx, None, "NONE")
|
544 | 547 | txid = node.sendrawtransaction(signresult["hex"], 0)
|
545 | 548 | txids.append(txid)
|
|
0 commit comments