Browse Source

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 <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
eb14111cd0
  1. 7
      daemon/peer.c
  2. 18
      daemon/wallet.c

7
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 */

18
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));

Loading…
Cancel
Save