|
|
@ -8,42 +8,33 @@ |
|
|
|
|
|
|
|
struct bitcoin_tx *create_close_tx(secp256k1_context *secpctx, |
|
|
|
const tal_t *ctx, |
|
|
|
OpenChannel *ours, |
|
|
|
OpenChannel *theirs, |
|
|
|
OpenAnchor *anchor, |
|
|
|
const struct pubkey *our_final, |
|
|
|
const struct pubkey *their_final, |
|
|
|
const struct sha256_double *anchor_txid, |
|
|
|
unsigned int anchor_index, |
|
|
|
u64 anchor_satoshis, |
|
|
|
uint64_t to_us, uint64_t to_them) |
|
|
|
{ |
|
|
|
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. */ |
|
|
|
proto_to_sha256(anchor->txid, &tx->input[0].txid.sha); |
|
|
|
tx->input[0].index = anchor->output_index; |
|
|
|
tx->input[0].input_amount = anchor->amount; |
|
|
|
|
|
|
|
/* Outputs goes to final pubkey */ |
|
|
|
if (!proto_to_pubkey(secpctx, ours->final_key, &ourkey)) |
|
|
|
return tal_free(tx); |
|
|
|
if (!proto_to_pubkey(secpctx, theirs->final_key, &theirkey)) |
|
|
|
return tal_free(tx); |
|
|
|
|
|
|
|
|
|
|
|
proto_to_sha256(ours->revocation_hash, &redeem); |
|
|
|
tx->input[0].txid = *anchor_txid; |
|
|
|
tx->input[0].index = anchor_index; |
|
|
|
tx->input[0].input_amount = anchor_satoshis; |
|
|
|
|
|
|
|
/* One output is to us. */ |
|
|
|
tx->output[0].amount = to_us; |
|
|
|
redeemscript = bitcoin_redeem_single(tx, &ourkey); |
|
|
|
redeemscript = bitcoin_redeem_single(tx, our_final); |
|
|
|
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 = to_them; |
|
|
|
redeemscript = bitcoin_redeem_single(tx, &theirkey); |
|
|
|
redeemscript = bitcoin_redeem_single(tx, their_final); |
|
|
|
tx->output[1].script = scriptpubkey_p2sh(tx, redeemscript); |
|
|
|
tx->output[1].script_length = tal_count(tx->output[1].script); |
|
|
|
|
|
|
|