mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
common: expose low-level htlc_tx function.
We'll want this, as lightningd will want to produce htlc txs based on what it's told from onchaind, so we need a lower-level accessor. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
3e53c6e359
commit
2f6be4e6bb
@ -4,24 +4,21 @@
|
||||
#include <common/htlc_tx.h>
|
||||
#include <common/keyset.h>
|
||||
|
||||
static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
|
||||
const struct chainparams *chainparams,
|
||||
const struct bitcoin_outpoint *commit,
|
||||
const u8 *commit_wscript,
|
||||
struct amount_msat msat,
|
||||
u16 to_self_delay,
|
||||
const struct pubkey *revocation_pubkey,
|
||||
const struct pubkey *local_delayedkey,
|
||||
struct amount_sat htlc_fee,
|
||||
u32 locktime,
|
||||
bool option_anchor_outputs)
|
||||
/* Low-level tx creator: used when onchaind has done most of the work! */
|
||||
struct bitcoin_tx *htlc_tx(const tal_t *ctx,
|
||||
const struct chainparams *chainparams,
|
||||
const struct bitcoin_outpoint *commit,
|
||||
const u8 *commit_wscript,
|
||||
struct amount_sat amount,
|
||||
const u8 *htlc_tx_wscript,
|
||||
struct amount_sat htlc_fee,
|
||||
u32 locktime,
|
||||
bool option_anchor_outputs)
|
||||
{
|
||||
/* BOLT #3:
|
||||
* * locktime: `0` for HTLC-success, `cltv_expiry` for HTLC-timeout
|
||||
*/
|
||||
struct bitcoin_tx *tx = bitcoin_tx(ctx, chainparams, 1, 1, locktime);
|
||||
u8 *wscript;
|
||||
struct amount_sat amount;
|
||||
|
||||
/* BOLT #3:
|
||||
*
|
||||
@ -45,7 +42,6 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
|
||||
* transaction
|
||||
* * `txin[0]` sequence: `0` (set to `1` for `option_anchors`)
|
||||
*/
|
||||
amount = amount_msat_to_sat_round_down(msat);
|
||||
bitcoin_tx_add_input(tx, commit,
|
||||
option_anchor_outputs ? 1 : 0,
|
||||
NULL, amount, NULL, commit_wscript);
|
||||
@ -59,18 +55,14 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
|
||||
* below
|
||||
*/
|
||||
if (!amount_sat_sub(&amount, amount, htlc_fee))
|
||||
abort();
|
||||
return tal_free(tx);
|
||||
|
||||
wscript = bitcoin_wscript_htlc_tx(tx, to_self_delay, revocation_pubkey,
|
||||
local_delayedkey);
|
||||
bitcoin_tx_add_output(tx, scriptpubkey_p2wsh(tmpctx, wscript),
|
||||
wscript, amount);
|
||||
bitcoin_tx_add_output(tx, scriptpubkey_p2wsh(tmpctx, htlc_tx_wscript),
|
||||
htlc_tx_wscript, amount);
|
||||
|
||||
bitcoin_tx_finalize(tx);
|
||||
assert(bitcoin_tx_check(tx));
|
||||
|
||||
tal_free(wscript);
|
||||
|
||||
return tx;
|
||||
}
|
||||
|
||||
@ -84,14 +76,19 @@ struct bitcoin_tx *htlc_success_tx(const tal_t *ctx,
|
||||
const struct keyset *keyset,
|
||||
bool option_anchor_outputs)
|
||||
{
|
||||
const u8 *htlc_wscript;
|
||||
|
||||
htlc_wscript = bitcoin_wscript_htlc_tx(tmpctx,
|
||||
to_self_delay,
|
||||
&keyset->self_revocation_key,
|
||||
&keyset->self_delayed_payment_key);
|
||||
/* BOLT #3:
|
||||
* * locktime: `0` for HTLC-success, `cltv_expiry` for HTLC-timeout
|
||||
*/
|
||||
return htlc_tx(ctx, chainparams, commit,
|
||||
commit_wscript, htlc_msatoshi,
|
||||
to_self_delay,
|
||||
&keyset->self_revocation_key,
|
||||
&keyset->self_delayed_payment_key,
|
||||
commit_wscript,
|
||||
amount_msat_to_sat_round_down(htlc_msatoshi),
|
||||
htlc_wscript,
|
||||
htlc_success_fee(feerate_per_kw,
|
||||
option_anchor_outputs),
|
||||
0,
|
||||
@ -137,13 +134,19 @@ struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx,
|
||||
const struct keyset *keyset,
|
||||
bool option_anchor_outputs)
|
||||
{
|
||||
const u8 *htlc_wscript;
|
||||
|
||||
htlc_wscript = bitcoin_wscript_htlc_tx(tmpctx,
|
||||
to_self_delay,
|
||||
&keyset->self_revocation_key,
|
||||
&keyset->self_delayed_payment_key);
|
||||
/* BOLT #3:
|
||||
* * locktime: `0` for HTLC-success, `cltv_expiry` for HTLC-timeout
|
||||
*/
|
||||
return htlc_tx(ctx, chainparams, commit,
|
||||
commit_wscript, htlc_msatoshi, to_self_delay,
|
||||
&keyset->self_revocation_key,
|
||||
&keyset->self_delayed_payment_key,
|
||||
commit_wscript,
|
||||
amount_msat_to_sat_round_down(htlc_msatoshi),
|
||||
htlc_wscript,
|
||||
htlc_timeout_fee(feerate_per_kw,
|
||||
option_anchor_outputs),
|
||||
cltv_expiry,
|
||||
|
@ -115,4 +115,14 @@ u8 *htlc_offered_wscript(const tal_t *ctx,
|
||||
const struct keyset *keyset,
|
||||
bool option_anchor_outputs);
|
||||
|
||||
/* Low-level HTLC tx creator */
|
||||
struct bitcoin_tx *htlc_tx(const tal_t *ctx,
|
||||
const struct chainparams *chainparams,
|
||||
const struct bitcoin_outpoint *commit,
|
||||
const u8 *commit_wscript,
|
||||
struct amount_sat amount,
|
||||
const u8 *htlc_tx_wscript,
|
||||
struct amount_sat htlc_fee,
|
||||
u32 locktime,
|
||||
bool option_anchor_outputs);
|
||||
#endif /* LIGHTNING_COMMON_HTLC_TX_H */
|
||||
|
Loading…
Reference in New Issue
Block a user