From b56fea8b2a7054fcece81600419571226683f97e Mon Sep 17 00:00:00 2001 From: ZmnSCPxj Date: Sun, 10 Dec 2017 06:24:38 +0000 Subject: [PATCH] Modify hsm_sign_withdrawal to transmit scriptpubkey to withdraw to, rather than pkh. --- hsmd/hsm.c | 4 +--- hsmd/hsm_client_wire_csv | 3 ++- wallet/walletrpc.c | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/hsmd/hsm.c b/hsmd/hsm.c index 6d22e88ed..e0eba7529 100644 --- a/hsmd/hsm.c +++ b/hsmd/hsm.c @@ -599,7 +599,6 @@ static void sign_withdrawal_tx(struct daemon_conn *master, const u8 *msg) const tal_t *tmpctx = tal_tmpctx(master); u64 satoshi_out, change_out; u32 change_keyindex; - struct bitcoin_address destination; struct utxo *utxos; secp256k1_ecdsa_signature *sigs; u8 *wscript; @@ -610,7 +609,7 @@ static void sign_withdrawal_tx(struct daemon_conn *master, const u8 *msg) if (!fromwire_hsm_sign_withdrawal(tmpctx, msg, NULL, &satoshi_out, &change_out, &change_keyindex, - destination.addr.u.u8, &utxos)) { + &scriptpubkey, &utxos)) { status_trace("Failed to parse sign_withdrawal: %s", tal_hex(trc, msg)); return; @@ -624,7 +623,6 @@ static void sign_withdrawal_tx(struct daemon_conn *master, const u8 *msg) } pubkey_from_der(ext.pub_key, sizeof(ext.pub_key), &changekey); - scriptpubkey = scriptpubkey_p2pkh(tmpctx, &destination); tx = withdraw_tx( tmpctx, to_utxoptr_arr(tmpctx, utxos), scriptpubkey, satoshi_out, &changekey, change_out, NULL); diff --git a/hsmd/hsm_client_wire_csv b/hsmd/hsm_client_wire_csv index 6789ef8e5..db0ebada5 100644 --- a/hsmd/hsm_client_wire_csv +++ b/hsmd/hsm_client_wire_csv @@ -51,7 +51,8 @@ hsm_sign_withdrawal,7 hsm_sign_withdrawal,,satoshi_out,u64 hsm_sign_withdrawal,,change_out,u64 hsm_sign_withdrawal,,change_keyindex,u32 -hsm_sign_withdrawal,,pkh,20*u8 +hsm_sign_withdrawal,,scriptpubkey_len,u16 +hsm_sign_withdrawal,,scriptpubkey,scriptpubkey_len*u8 hsm_sign_withdrawal,,num_inputs,u16 hsm_sign_withdrawal,,inputs,num_inputs*struct utxo diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 81ed71db2..c6875acea 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -114,6 +114,8 @@ static void json_withdraw(struct command *cmd, command_fail(cmd, "Could not parse destination address"); return; } + withdraw->destination + = scriptpubkey_p2pkh(withdraw, &p2pkh_destination); /* Check address given is compatible with the chain we are on. */ if (testnet != get_chainparams(cmd->ld)->testnet) { @@ -148,7 +150,7 @@ static void json_withdraw(struct command *cmd, withdraw->amount, withdraw->changesatoshi, withdraw->change_key_index, - p2pkh_destination.addr.u.u8, + withdraw->destination, utxos); tal_free(utxos); @@ -170,8 +172,6 @@ static void json_withdraw(struct command *cmd, } pubkey_from_der(ext.pub_key, sizeof(ext.pub_key), &changekey); - withdraw->destination - = scriptpubkey_p2pkh(withdraw, &p2pkh_destination); tx = withdraw_tx(withdraw, withdraw->utxos, withdraw->destination, withdraw->amount, &changekey, withdraw->changesatoshi, cmd->ld->wallet->bip32_base);