MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / witness_script

Function witness_script

test/functional/test_framework/blocktools.py:171–186  ·  view source on GitHub ↗

Create a scriptPubKey for a pay-to-wtiness TxOut. This is either a P2WPKH output for the given pubkey, or a P2WSH output of a 1-of-1 multisig for the given pubkey. Returns the hex encoding of the scriptPubKey.

(use_p2wsh, pubkey)

Source from the content-addressed store, hash-verified

169 return count
170
171def witness_script(use_p2wsh, pubkey):
172 """Create a scriptPubKey for a pay-to-wtiness TxOut.
173
174 This is either a P2WPKH output for the given pubkey, or a P2WSH output of a
175 1-of-1 multisig for the given pubkey. Returns the hex encoding of the
176 scriptPubKey."""
177 if not use_p2wsh:
178 # P2WPKH instead
179 pubkeyhash = hash160(hex_str_to_bytes(pubkey))
180 pkscript = CScript([OP_0, pubkeyhash])
181 else:
182 # 1-of-1 multisig
183 witness_program = CScript([OP_1, hex_str_to_bytes(pubkey), OP_1, OP_CHECKMULTISIG])
184 scripthash = sha256(witness_program)
185 pkscript = CScript([OP_0, scripthash])
186 return bytes_to_hex_str(pkscript)
187
188def create_witness_tx(node, use_p2wsh, utxo, pubkey, encode_p2sh, amount):
189 """Return a transaction (in hex) that spends the given utxo to a segwit output.

Callers 2

run_testMethod · 0.90
create_witness_txFunction · 0.85

Calls 5

hash160Function · 0.85
hex_str_to_bytesFunction · 0.85
sha256Function · 0.85
bytes_to_hex_strFunction · 0.85
CScriptClass · 0.70

Tested by

no test coverage detected