From eb14111cd045e256331a3c28f47fa5e351574afc Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 12 Apr 2016 14:17:46 +0930 Subject: [PATCH] daemon/wallet: supply a p2wpkh address (as P2SH address). This is an address that bitcoind will happily pay to, but we know it's a witness output so our inputs to the anchor are immalleable. Signed-off-by: Rusty Russell --- daemon/peer.c | 7 +++++-- daemon/wallet.c | 18 ++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/daemon/peer.c b/daemon/peer.c index abe0f59a1..0d9490f23 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -857,8 +857,10 @@ static void commit_tx_depth(struct peer *peer, int depth, } /* Don't yet know the median start time? */ - if (!peer->cur_commit.start_time) + if (!peer->cur_commit.start_time) { + log_debug(peer->log, "... but we don't know start_time"); return; + } /* FIXME: We should really use bitcoin time here. */ if (controlled_time().ts.tv_sec > peer->cur_commit.start_time @@ -866,7 +868,8 @@ static void commit_tx_depth(struct peer *peer, int depth, /* Free this watch; we're done */ peer->cur_commit.watch = tal_free(peer->cur_commit.watch); state_event(peer, ptr2int(canspend), NULL); - } + } else + log_debug(peer->log, "... still CSV locked"); } /* FIXME: We tell bitcoind to watch all the outputs, which is overkill */ diff --git a/daemon/wallet.c b/daemon/wallet.c index d0420bf52..9ee5e8c15 100644 --- a/daemon/wallet.c +++ b/daemon/wallet.c @@ -40,23 +40,21 @@ void wallet_add_signed_input(struct lightningd_state *dstate, struct bitcoin_signature sig; assert(input_num < tx->input_count); - redeemscript = bitcoin_redeem_single(tx, &w->pubkey); + redeemscript = bitcoin_redeem_p2wpkh(tx, &w->pubkey); sig.stype = SIGHASH_ALL; sign_tx_input(dstate->secpctx, tx, input_num, redeemscript, tal_count(redeemscript), - NULL, + p2wpkh_scriptcode(redeemscript, &w->pubkey), &w->privkey, &w->pubkey, &sig.sig); - tx->input[input_num].script - = scriptsig_p2sh_single_sig(tx->input, - redeemscript, - tal_count(redeemscript), - &sig); - tx->input[input_num].script_length - = tal_count(tx->input[input_num].script); + bitcoin_witness_p2sh_p2wpkh(tx->input, + &tx->input[input_num], + &sig, + &w->pubkey); + tal_free(redeemscript); } struct wallet *wallet_can_spend(struct lightningd_state *dstate, @@ -85,7 +83,7 @@ static void json_newaddr(struct command *cmd, struct sha256 h; new_keypair(cmd->dstate, &w->privkey, &w->pubkey); - redeemscript = bitcoin_redeem_single(cmd, &w->pubkey); + redeemscript = bitcoin_redeem_p2wpkh(cmd, &w->pubkey); sha256(&h, redeemscript, tal_count(redeemscript)); ripemd160(&w->p2sh, h.u.u8, sizeof(h));