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

Function chain_transaction

test/functional/test_framework/util.py:535–555  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

533
534
535def 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

Callers 2

run_testMethod · 0.90
run_testMethod · 0.90

Calls 2

sendrawtransactionMethod · 0.80
satoshi_roundFunction · 0.70

Tested by

no test coverage detected