mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
script: Use pkh to construct p2pkh output scripts
So far we always needed to know the public key, which was not the case for addresses that we don't own. Moving the hashing outside of the script construction allows us to send to arbitrary addresses. I also added the hash computation to the pubkey primitives.
This commit is contained in:
committed by
Rusty Russell
parent
f10b779c83
commit
40165ba6d5
@@ -212,15 +212,13 @@ u8 *scriptpubkey_p2sh(const tal_t *ctx, const u8 *redeemscript)
|
||||
}
|
||||
|
||||
/* Create an output script using p2pkh */
|
||||
u8 *scriptpubkey_p2pkh(const tal_t *ctx, const struct pubkey *pubkey)
|
||||
u8 *scriptpubkey_p2pkh(const tal_t *ctx, const struct bitcoin_address *addr)
|
||||
{
|
||||
struct bitcoin_address addr;
|
||||
u8 *script = tal_arr(ctx, u8, 0);
|
||||
|
||||
hash160_key(&addr.addr, pubkey);
|
||||
add_op(&script, OP_DUP);
|
||||
add_op(&script, OP_HASH160);
|
||||
add_push_bytes(&script, &addr.addr, sizeof(addr.addr));
|
||||
add_push_bytes(&script, &addr->addr, sizeof(addr->addr));
|
||||
add_op(&script, OP_EQUALVERIFY);
|
||||
add_op(&script, OP_CHECKSIG);
|
||||
return script;
|
||||
|
||||
Reference in New Issue
Block a user