MCPcopy Create free account
hub / github.com/ElementsProject/lightning / p2wpkh_scriptcode

Function p2wpkh_scriptcode

bitcoin/script.c:393–414  ·  view source on GitHub ↗

Create scriptcode (fake witness, basically) for P2WPKH */

Source from the content-addressed store, hash-verified

391
392/* Create scriptcode (fake witness, basically) for P2WPKH */
393u8 *p2wpkh_scriptcode(const tal_t *ctx, const struct pubkey *key)
394{
395 struct ripemd160 pkhash;
396 u8 *script = tal_arr(ctx, u8, 0);
397 pubkey_to_hash160(key, &pkhash);
398
399 /* BIP143:
400 *
401 * For P2WPKH witness program, the scriptCode is
402 * 0x1976a914{20-byte-pubkey-hash}88ac.
403 */
404
405 /* PUSH(25): OP_DUP OP_HASH160 PUSH(20) 20-byte-pubkey-hash
406 * OP_EQUALVERIFY OP_CHECKSIG */
407 add_op(&script, OP_DUP);
408 add_op(&script, OP_HASH160);
409 script_push_bytes(&script, &pkhash, sizeof(pkhash));
410 add_op(&script, OP_EQUALVERIFY);
411 add_op(&script, OP_CHECKSIG);
412
413 return script;
414}
415
416bool is_p2pkh(const u8 *script, struct bitcoin_address *addr)
417{

Callers 1

mainFunction · 0.85

Calls 3

add_opFunction · 0.85
pubkey_to_hash160Function · 0.70
script_push_bytesFunction · 0.70

Tested by

no test coverage detected