diff --git a/close_tx.c b/close_tx.c index cb8d9dff5..c4bd1f4bd 100644 --- a/close_tx.c +++ b/close_tx.c @@ -12,6 +12,7 @@ struct bitcoin_tx *create_close_tx(const tal_t *ctx, OpenChannel *theirs, int64_t delta, const struct sha256_double *anchor_txid, + uint64_t input_amount, unsigned int anchor_output) { struct bitcoin_tx *tx; @@ -25,6 +26,7 @@ struct bitcoin_tx *create_close_tx(const tal_t *ctx, /* Our input spends the anchor tx output. */ tx->input[0].txid = *anchor_txid; tx->input[0].index = anchor_output; + tx->input[0].input_amount = input_amount; /* Outputs goes to final pubkey */ if (!proto_to_pubkey(ours->final, &ourkey)) @@ -52,6 +54,7 @@ struct bitcoin_tx *create_close_tx(const tal_t *ctx, tx->output[1].script = scriptpubkey_p2sh(tx, redeemscript); tx->output[1].script_length = tal_count(tx->output[1].script); + tx->fee = ours->commitment_fee + theirs->commitment_fee; permute_outputs(ours->seed, theirs->seed, 1, tx->output, 2, NULL); return tx; } diff --git a/close_tx.h b/close_tx.h index 77f75269e..feb81086c 100644 --- a/close_tx.h +++ b/close_tx.h @@ -12,5 +12,6 @@ struct bitcoin_tx *create_close_tx(const tal_t *ctx, OpenChannel *theirs, int64_t delta, const struct sha256_double *anchor_txid, + uint64_t input_amount, unsigned int anchor_output); #endif diff --git a/test-cli/close-channel.c b/test-cli/close-channel.c index 54ca4617b..eef274fab 100644 --- a/test-cli/close-channel.c +++ b/test-cli/close-channel.c @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) struct pubkey pubkey1, pubkey2; u8 *redeemscript; int64_t delta; - size_t i; + size_t i, anchor_out; err_set_progname(argv[0]); @@ -81,9 +81,11 @@ int main(int argc, char *argv[]) /* Now create the close tx to spend 2/2 output of anchor. */ /* Assumes that updates are all from closer -> closee */ + anchor_out = find_p2sh_out(anchor, redeemscript); close_tx = create_close_tx(ctx, o1, o2, complete ? -delta : delta, - &anchor_txid, - find_p2sh_out(anchor, redeemscript)); + &anchor_txid, + anchor->output[anchor_out].amount, + anchor_out); /* Sign it for them. */ sign_tx_input(ctx, close_tx, 0, redeemscript, tal_count(redeemscript), diff --git a/test-cli/create-close-tx.c b/test-cli/create-close-tx.c index f5a924c31..e7f081691 100644 --- a/test-cli/create-close-tx.c +++ b/test-cli/create-close-tx.c @@ -28,7 +28,7 @@ int main(int argc, char *argv[]) u8 *redeemscript; CloseChannel *close; CloseChannelComplete *closecomplete; - size_t i; + size_t i, anchor_out; int64_t delta; err_set_progname(argv[0]); @@ -69,8 +69,10 @@ int main(int argc, char *argv[]) redeemscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2); /* Now create the close tx to spend 2/2 output of anchor. */ + anchor_out = find_p2sh_out(anchor, redeemscript); close_tx = create_close_tx(ctx, o1, o2, delta, &anchor_txid, - find_p2sh_out(anchor, redeemscript)); + anchor->output[anchor_out].amount, + anchor_out); /* Signatures well-formed? */ sig1.stype = sig2.stype = SIGHASH_ALL;