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

Function create_witness_tx

test/functional/test_framework/blocktools.py:239–252  ·  view source on GitHub ↗

Return a transaction (in hex) that spends the given utxo to a segwit output. Optionally wrap the segwit output using P2SH.

(node, use_p2wsh, utxo, pubkey, encode_p2sh, amount)

Source from the content-addressed store, hash-verified

237 return pkscript.hex()
238
239def create_witness_tx(node, use_p2wsh, utxo, pubkey, encode_p2sh, amount):
240 """Return a transaction (in hex) that spends the given utxo to a segwit output.
241
242 Optionally wrap the segwit output using P2SH."""
243 if use_p2wsh:
244 program = keys_to_multisig_script([pubkey])
245 addr = script_to_p2sh_p2wsh(program) if encode_p2sh else script_to_p2wsh(program)
246 else:
247 addr = key_to_p2sh_p2wpkh(pubkey) if encode_p2sh else key_to_p2wpkh(pubkey)
248 if not encode_p2sh:
249 assert_equal(node.getaddressinfo(addr)['scriptPubKey'], witness_script(use_p2wsh, pubkey))
250 if "amount" not in utxo:
251 utxo["amount"] = node.gettxout(utxo["txid"], utxo["vout"])["value"]
252 return node.createrawtransaction([utxo], [{addr: amount}, {"fee": utxo["amount"]-amount}])
253
254def send_to_witness(use_p2wsh, node, utxo, pubkey, encode_p2sh, amount, sign=True, insert_redeem_script=""):
255 """Create a transaction spending a given utxo to a segwit output.

Callers 1

send_to_witnessFunction · 0.70

Calls 7

keys_to_multisig_scriptFunction · 0.85
script_to_p2sh_p2wshFunction · 0.70
script_to_p2wshFunction · 0.70
key_to_p2sh_p2wpkhFunction · 0.70
key_to_p2wpkhFunction · 0.70
assert_equalFunction · 0.70
witness_scriptFunction · 0.70

Tested by

no test coverage detected