|
|
@ -14,7 +14,8 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx, |
|
|
|
const struct pubkey *revocation_pubkey, |
|
|
|
const struct pubkey *local_delayedkey, |
|
|
|
struct amount_sat htlc_fee, |
|
|
|
u32 locktime) |
|
|
|
u32 locktime, |
|
|
|
bool option_anchor_outputs) |
|
|
|
{ |
|
|
|
/* BOLT #3:
|
|
|
|
* * locktime: `0` for HTLC-success, `cltv_expiry` for HTLC-timeout |
|
|
@ -38,15 +39,16 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx, |
|
|
|
*/ |
|
|
|
assert(tx->wtx->version == 2); |
|
|
|
|
|
|
|
/* BOLT #3:
|
|
|
|
/* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #3:
|
|
|
|
* * txin count: 1 |
|
|
|
* * `txin[0]` outpoint: `txid` of the commitment transaction and |
|
|
|
* `output_index` of the matching HTLC output for the HTLC |
|
|
|
* transaction |
|
|
|
* * `txin[0]` sequence: `0` |
|
|
|
* * `txin[0]` sequence: `0` (set to `1` for `option_anchor_outputs`) |
|
|
|
*/ |
|
|
|
amount = amount_msat_to_sat_round_down(msat); |
|
|
|
bitcoin_tx_add_input(tx, commit_txid, commit_output_number, 0, |
|
|
|
bitcoin_tx_add_input(tx, commit_txid, commit_output_number, |
|
|
|
option_anchor_outputs ? 1 : 0, |
|
|
|
NULL, amount, NULL, commit_wscript); |
|
|
|
|
|
|
|
/* BOLT #3:
|
|
|
@ -80,7 +82,8 @@ struct bitcoin_tx *htlc_success_tx(const tal_t *ctx, |
|
|
|
struct amount_msat htlc_msatoshi, |
|
|
|
u16 to_self_delay, |
|
|
|
u32 feerate_per_kw, |
|
|
|
const struct keyset *keyset) |
|
|
|
const struct keyset *keyset, |
|
|
|
bool option_anchor_outputs) |
|
|
|
{ |
|
|
|
/* BOLT #3:
|
|
|
|
* * locktime: `0` for HTLC-success, `cltv_expiry` for HTLC-timeout |
|
|
@ -90,7 +93,9 @@ struct bitcoin_tx *htlc_success_tx(const tal_t *ctx, |
|
|
|
to_self_delay, |
|
|
|
&keyset->self_revocation_key, |
|
|
|
&keyset->self_delayed_payment_key, |
|
|
|
htlc_success_fee(feerate_per_kw), 0); |
|
|
|
htlc_success_fee(feerate_per_kw), |
|
|
|
0, |
|
|
|
option_anchor_outputs); |
|
|
|
} |
|
|
|
|
|
|
|
/* Fill in the witness for HTLC-success tx produced above. */ |
|
|
@ -101,7 +106,8 @@ void htlc_success_tx_add_witness(struct bitcoin_tx *htlc_success, |
|
|
|
const struct bitcoin_signature *localhtlcsig, |
|
|
|
const struct bitcoin_signature *remotehtlcsig, |
|
|
|
const struct preimage *payment_preimage, |
|
|
|
const struct pubkey *revocationkey) |
|
|
|
const struct pubkey *revocationkey, |
|
|
|
bool option_anchor_outputs) |
|
|
|
{ |
|
|
|
struct sha256 hash; |
|
|
|
u8 *wscript, **witness; |
|
|
@ -110,7 +116,8 @@ void htlc_success_tx_add_witness(struct bitcoin_tx *htlc_success, |
|
|
|
wscript = bitcoin_wscript_htlc_receive(htlc_success, |
|
|
|
htlc_abstimeout, |
|
|
|
localhtlckey, remotehtlckey, |
|
|
|
&hash, revocationkey); |
|
|
|
&hash, revocationkey, |
|
|
|
option_anchor_outputs); |
|
|
|
|
|
|
|
witness = bitcoin_witness_htlc_success_tx(htlc_success, |
|
|
|
localhtlcsig, remotehtlcsig, |
|
|
@ -128,7 +135,8 @@ struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx, |
|
|
|
u32 cltv_expiry, |
|
|
|
u16 to_self_delay, |
|
|
|
u32 feerate_per_kw, |
|
|
|
const struct keyset *keyset) |
|
|
|
const struct keyset *keyset, |
|
|
|
bool option_anchor_outputs) |
|
|
|
{ |
|
|
|
/* BOLT #3:
|
|
|
|
* * locktime: `0` for HTLC-success, `cltv_expiry` for HTLC-timeout |
|
|
@ -137,7 +145,9 @@ struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx, |
|
|
|
commit_wscript, htlc_msatoshi, to_self_delay, |
|
|
|
&keyset->self_revocation_key, |
|
|
|
&keyset->self_delayed_payment_key, |
|
|
|
htlc_timeout_fee(feerate_per_kw), cltv_expiry); |
|
|
|
htlc_timeout_fee(feerate_per_kw), |
|
|
|
cltv_expiry, |
|
|
|
option_anchor_outputs); |
|
|
|
} |
|
|
|
|
|
|
|
/* Fill in the witness for HTLC-timeout tx produced above. */ |
|
|
@ -147,12 +157,14 @@ void htlc_timeout_tx_add_witness(struct bitcoin_tx *htlc_timeout, |
|
|
|
const struct sha256 *payment_hash, |
|
|
|
const struct pubkey *revocationkey, |
|
|
|
const struct bitcoin_signature *localhtlcsig, |
|
|
|
const struct bitcoin_signature *remotehtlcsig) |
|
|
|
const struct bitcoin_signature *remotehtlcsig, |
|
|
|
bool option_anchor_outputs) |
|
|
|
{ |
|
|
|
u8 **witness; |
|
|
|
u8 *wscript = bitcoin_wscript_htlc_offer(htlc_timeout, |
|
|
|
localhtlckey, remotehtlckey, |
|
|
|
payment_hash, revocationkey); |
|
|
|
payment_hash, revocationkey, |
|
|
|
option_anchor_outputs); |
|
|
|
|
|
|
|
witness = bitcoin_witness_htlc_timeout_tx(htlc_timeout, localhtlcsig, |
|
|
|
remotehtlcsig, wscript); |
|
|
@ -162,24 +174,28 @@ void htlc_timeout_tx_add_witness(struct bitcoin_tx *htlc_timeout, |
|
|
|
|
|
|
|
u8 *htlc_offered_wscript(const tal_t *ctx, |
|
|
|
const struct ripemd160 *ripemd, |
|
|
|
const struct keyset *keyset) |
|
|
|
const struct keyset *keyset, |
|
|
|
bool option_anchor_outputs) |
|
|
|
{ |
|
|
|
return bitcoin_wscript_htlc_offer_ripemd160(ctx, |
|
|
|
&keyset->self_htlc_key, |
|
|
|
&keyset->other_htlc_key, |
|
|
|
ripemd, |
|
|
|
&keyset->self_revocation_key); |
|
|
|
&keyset->self_revocation_key, |
|
|
|
option_anchor_outputs); |
|
|
|
} |
|
|
|
|
|
|
|
u8 *htlc_received_wscript(const tal_t *ctx, |
|
|
|
const struct ripemd160 *ripemd, |
|
|
|
const struct abs_locktime *expiry, |
|
|
|
const struct keyset *keyset) |
|
|
|
const struct keyset *keyset, |
|
|
|
bool option_anchor_outputs) |
|
|
|
{ |
|
|
|
return bitcoin_wscript_htlc_receive_ripemd(ctx, |
|
|
|
expiry, |
|
|
|
&keyset->self_htlc_key, |
|
|
|
&keyset->other_htlc_key, |
|
|
|
ripemd, |
|
|
|
&keyset->self_revocation_key); |
|
|
|
&keyset->self_revocation_key, |
|
|
|
option_anchor_outputs); |
|
|
|
} |
|
|
|