You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
50 lines
1.5 KiB
10 years ago
|
#include "close_tx.h"
|
||
|
#include "shadouble.h"
|
||
|
#include "bitcoin_tx.h"
|
||
|
#include "bitcoin_script.h"
|
||
|
#include "permute_tx.h"
|
||
|
#include "pubkey.h"
|
||
|
#include "pkt.h"
|
||
|
|
||
|
struct bitcoin_tx *create_close_tx(const tal_t *ctx,
|
||
|
OpenChannel *ours,
|
||
|
OpenChannel *theirs,
|
||
|
const struct sha256_double *anchor_txid,
|
||
|
unsigned int anchor_output)
|
||
|
{
|
||
|
struct bitcoin_tx *tx;
|
||
|
const u8 *redeemscript;
|
||
|
struct pubkey ourkey, theirkey;
|
||
|
struct sha256 redeem;
|
||
|
|
||
|
/* Now create close tx: one input, two outputs. */
|
||
|
tx = bitcoin_tx(ctx, 1, 2);
|
||
|
|
||
|
/* Our input spends the anchor tx output. */
|
||
|
tx->input[0].txid = *anchor_txid;
|
||
|
tx->input[0].index = anchor_output;
|
||
|
|
||
|
/* Outputs goes to final pubkey */
|
||
|
if (!proto_to_pubkey(ours->final, &ourkey))
|
||
|
return tal_free(tx);
|
||
|
if (!proto_to_pubkey(theirs->final, &theirkey))
|
||
|
return tal_free(tx);
|
||
|
|
||
|
proto_to_sha256(ours->revocation_hash, &redeem);
|
||
|
|
||
|
/* One output is to us. */
|
||
|
tx->output[0].amount = ours->anchor->total - ours->commitment_fee;
|
||
|
redeemscript = bitcoin_redeem_single(tx, &ourkey);
|
||
|
tx->output[0].script = scriptpubkey_p2sh(tx, redeemscript);
|
||
|
tx->output[0].script_length = tal_count(tx->output[0].script);
|
||
|
|
||
|
/* Other output is to them. */
|
||
|
tx->output[1].amount = theirs->anchor->total - theirs->commitment_fee;
|
||
|
redeemscript = bitcoin_redeem_single(tx, &theirkey);
|
||
|
tx->output[1].script = scriptpubkey_p2sh(tx, redeemscript);
|
||
|
tx->output[1].script_length = tal_count(tx->output[1].script);
|
||
|
|
||
|
permute_outputs(ours->seed, theirs->seed, 1, tx->output, 2, NULL);
|
||
|
return tx;
|
||
|
}
|