mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-08 16:44:22 +01:00
open-channel: use pubkey, not arbitrary script for final outout address.
We need to pay to this from two places: on their side, it's a simple payment, on our side, it's a complex timeout-or-mutual-or-hval script, which doesn't lend itself to arbitrary scripts. Use P2SH, of course. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
14
commit_tx.c
14
commit_tx.c
@@ -14,7 +14,7 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
|
||||
{
|
||||
struct bitcoin_tx *tx;
|
||||
const u8 *redeemscript;
|
||||
struct pubkey ourkey, theirkey;
|
||||
struct pubkey ourkey, theirkey, to_me;
|
||||
struct sha256 redeem;
|
||||
|
||||
/* Now create commitment tx: one input, two outputs. */
|
||||
@@ -42,10 +42,14 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
|
||||
return tal_free(tx);
|
||||
tx->output[0].amount = ours->anchor->total - ours->commitment_fee;
|
||||
|
||||
/* Second output is a simple payment to them. */
|
||||
tx->output[1].script = theirs->script_to_me.data;
|
||||
tx->output[1].script_length = theirs->script_to_me.len;
|
||||
|
||||
/* Second output is a P2SH payment to them. */
|
||||
if (!proto_to_pubkey(theirs->to_me, &to_me))
|
||||
return tal_free(tx);
|
||||
tx->output[1].script = scriptpubkey_p2sh(ctx,
|
||||
bitcoin_redeem_single(ctx,
|
||||
&to_me));
|
||||
tx->output[1].script_length = tal_count(tx->output[1].script);
|
||||
|
||||
if (theirs->anchor->total < theirs->commitment_fee)
|
||||
return tal_free(tx);
|
||||
tx->output[1].amount = theirs->anchor->total - theirs->commitment_fee;
|
||||
|
||||
Reference in New Issue
Block a user