mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
script: add csv_lock to scripts
This commit is contained in:
parent
7a6f84ae63
commit
e992b54410
@ -327,13 +327,24 @@ u8 *scriptpubkey_witness_raw(const tal_t *ctx, u8 version,
|
||||
* block csv lock.
|
||||
* <remote_pubkey> OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY
|
||||
*/
|
||||
/* BOLT- #3
|
||||
* ##### Leased channel (`option_will_fund`)
|
||||
*
|
||||
* If a `lease` applies to the channel, the `to_remote` output
|
||||
* of the `initiator` ensures the `leasor` funds are not
|
||||
* spendable until the lease expires.
|
||||
*
|
||||
* <remote_pubkey> OP_CHECKSIGVERIFY MAX(1, lease_end - blockheight) OP_CHECKSEQUENCEVERIFY
|
||||
*/
|
||||
|
||||
u8 *anchor_to_remote_redeem(const tal_t *ctx,
|
||||
const struct pubkey *remote_key)
|
||||
const struct pubkey *remote_key,
|
||||
u32 csv_lock)
|
||||
{
|
||||
u8 *script = tal_arr(ctx, u8, 0);
|
||||
add_push_key(&script, remote_key);
|
||||
add_op(&script, OP_CHECKSIGVERIFY);
|
||||
add_number(&script, 1);
|
||||
add_number(&script, csv_lock);
|
||||
add_op(&script, OP_CHECKSEQUENCEVERIFY);
|
||||
|
||||
assert(is_anchor_witness_script(script, tal_bytelen(script)));
|
||||
|
@ -69,7 +69,8 @@ u8 *scriptpubkey_witness_raw(const tal_t *ctx, u8 version,
|
||||
|
||||
/* To-remotekey with csv 1 delay. */
|
||||
u8 *anchor_to_remote_redeem(const tal_t *ctx,
|
||||
const struct pubkey *remote_key);
|
||||
const struct pubkey *remote_key,
|
||||
u32 csv_lock);
|
||||
|
||||
/* Create a witness which spends the 2of2. */
|
||||
u8 **bitcoin_witness_2of2(const tal_t *ctx,
|
||||
|
@ -276,7 +276,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
||||
*/
|
||||
if (option_anchor_outputs) {
|
||||
scriptpubkey = scriptpubkey_p2wsh(tmpctx,
|
||||
anchor_to_remote_redeem(tmpctx, &keyset->other_payment_key));
|
||||
anchor_to_remote_redeem(tmpctx, &keyset->other_payment_key, 1));
|
||||
} else {
|
||||
scriptpubkey = scriptpubkey_p2wpkh(tmpctx,
|
||||
&keyset->other_payment_key);
|
||||
|
@ -242,7 +242,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
||||
amount = amount_msat_to_sat_round_down(other_pay);
|
||||
if (option_anchor_outputs) {
|
||||
scriptpubkey = scriptpubkey_p2wsh(tmpctx,
|
||||
anchor_to_remote_redeem(tmpctx, &keyset->other_payment_key));
|
||||
anchor_to_remote_redeem(tmpctx, &keyset->other_payment_key, 1));
|
||||
} else {
|
||||
scriptpubkey = scriptpubkey_p2wpkh(tmpctx,
|
||||
&keyset->other_payment_key);
|
||||
|
@ -388,7 +388,7 @@ static void sign_our_inputs(struct utxo **utxos, struct wally_psbt *psbt)
|
||||
|
||||
/* It's actually a P2WSH in this case. */
|
||||
if (utxo->close_info && utxo->close_info->option_anchor_outputs) {
|
||||
const u8 *wscript = anchor_to_remote_redeem(tmpctx, &pubkey);
|
||||
const u8 *wscript = anchor_to_remote_redeem(tmpctx, &pubkey, 1);
|
||||
psbt_input_set_witscript(psbt, j, wscript);
|
||||
psbt_input_set_wit_utxo(psbt, j,
|
||||
scriptpubkey_p2wsh(psbt, wscript),
|
||||
|
@ -2557,7 +2557,8 @@ static void get_anchor_scriptpubkeys(const tal_t *ctx, u8 **anchor)
|
||||
}
|
||||
|
||||
static u8 *scriptpubkey_to_remote(const tal_t *ctx,
|
||||
const struct pubkey *remotekey)
|
||||
const struct pubkey *remotekey,
|
||||
u32 csv_lock)
|
||||
{
|
||||
/* BOLT #3:
|
||||
*
|
||||
@ -2574,7 +2575,8 @@ static u8 *scriptpubkey_to_remote(const tal_t *ctx,
|
||||
if (option_anchor_outputs) {
|
||||
return scriptpubkey_p2wsh(ctx,
|
||||
anchor_to_remote_redeem(tmpctx,
|
||||
remotekey));
|
||||
remotekey,
|
||||
csv_lock));
|
||||
} else {
|
||||
return scriptpubkey_p2wpkh(ctx, remotekey);
|
||||
}
|
||||
@ -2649,7 +2651,8 @@ static void handle_our_unilateral(const struct tx_parts *tx,
|
||||
|
||||
/* Figure out what direct to-them output looks like. */
|
||||
script[REMOTE] = scriptpubkey_to_remote(tmpctx,
|
||||
&keyset->other_payment_key);
|
||||
&keyset->other_payment_key,
|
||||
1);
|
||||
|
||||
/* Calculate all the HTLC scripts so we can match them */
|
||||
htlc_scripts = derive_htlc_scripts(htlcs, LOCAL);
|
||||
@ -3087,7 +3090,7 @@ static void handle_their_cheat(const struct tx_parts *tx,
|
||||
|
||||
/* Figure out what direct to-us output looks like. */
|
||||
script[LOCAL] = scriptpubkey_to_remote(tmpctx,
|
||||
&keyset->other_payment_key);
|
||||
&keyset->other_payment_key, 1);
|
||||
|
||||
/* Calculate all the HTLC scripts so we can match them */
|
||||
htlc_scripts = derive_htlc_scripts(htlcs, REMOTE);
|
||||
@ -3369,7 +3372,7 @@ static void handle_their_unilateral(const struct tx_parts *tx,
|
||||
|
||||
/* Figure out what direct to-us output looks like. */
|
||||
script[LOCAL] = scriptpubkey_to_remote(tmpctx,
|
||||
&keyset->other_payment_key);
|
||||
&keyset->other_payment_key, 1);
|
||||
|
||||
/* Calculate all the HTLC scripts so we can match them */
|
||||
htlc_scripts = derive_htlc_scripts(htlcs, REMOTE);
|
||||
@ -3624,7 +3627,8 @@ static void handle_unknown_commitment(const struct tx_parts *tx,
|
||||
|
||||
/* Other possible local script is for option_static_remotekey */
|
||||
local_scripts[1] = scriptpubkey_to_remote(tmpctx,
|
||||
&basepoints[LOCAL].payment);
|
||||
&basepoints[LOCAL].payment,
|
||||
1);
|
||||
|
||||
for (size_t i = 0; i < tal_count(tx->outputs); i++) {
|
||||
struct tracked_output *out;
|
||||
|
Loading…
Reference in New Issue
Block a user