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

Function p2wpkh_scriptcode

bitcoin/script.c:455–476  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

453
454/* Create scriptcode (fake witness, basically) for P2WPKH */
455u8 *p2wpkh_scriptcode(const tal_t *ctx, const struct pubkey *key)
456{
457 struct ripemd160 pkhash;
458 u8 *script = tal_arr(ctx, u8, 0);
459 pubkey_to_hash160(key, &pkhash);
460
461 /* BIP143:
462 *
463 * For P2WPKH witness program, the scriptCode is
464 * 0x1976a914{20-byte-pubkey-hash}88ac.
465 */
466
467 /* PUSH(25): OP_DUP OP_HASH160 PUSH(20) 20-byte-pubkey-hash
468 * OP_EQUALVERIFY OP_CHECKSIG */
469 add_op(&script, OP_DUP);
470 add_op(&script, OP_HASH160);
471 script_push_bytes(&script, &pkhash, sizeof(pkhash));
472 add_op(&script, OP_EQUALVERIFY);
473 add_op(&script, OP_CHECKSIG);
474
475 return script;
476}
477
478bool is_p2pkh(const u8 *script, size_t script_len, struct bitcoin_address *addr)
479{

Callers 1

mainFunction · 0.85

Calls 3

pubkey_to_hash160Function · 0.85
add_opFunction · 0.85
script_push_bytesFunction · 0.85

Tested by

no test coverage detected