Build and send a transaction that spends the given inputs (specified by lists of parent_txid:vout each), with the desired total value and fee, equally divided up to the desired number of outputs. Returns a tuple with the txid and the amount sent per output.
(node, parent_txids, vouts, value, fee, num_outputs)
| 533 | |
| 534 | |
| 535 | def chain_transaction(node, parent_txids, vouts, value, fee, num_outputs): |
| 536 | """Build and send a transaction that spends the given inputs (specified |
| 537 | by lists of parent_txid:vout each), with the desired total value and fee, |
| 538 | equally divided up to the desired number of outputs. |
| 539 | |
| 540 | Returns a tuple with the txid and the amount sent per output. |
| 541 | """ |
| 542 | send_value = satoshi_round((value - fee)/num_outputs) |
| 543 | inputs = [] |
| 544 | for (txid, vout) in zip(parent_txids, vouts): |
| 545 | inputs.append({'txid' : txid, 'vout' : vout}) |
| 546 | outputs = [] |
| 547 | for _ in range(num_outputs): |
| 548 | outputs.append({node.getnewaddress(): send_value}) |
| 549 | outputs.append({"fee": value - (num_outputs * send_value)}) |
| 550 | rawtx = node.createrawtransaction(inputs, outputs, 0, True) |
| 551 | signedtx = node.signrawtransactionwithwallet(rawtx) |
| 552 | txid = node.sendrawtransaction(signedtx['hex']) |
| 553 | fulltx = node.getrawtransaction(txid, 1) |
| 554 | assert len(fulltx['vout']) == num_outputs + 1 # make sure we didn't generate a change output |
| 555 | return (txid, send_value) |
| 556 | |
| 557 | |
| 558 | # Create large OP_RETURN txouts that can be appended to a transaction |
no test coverage detected