mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
coins: re-write API interface for htlc notices
Wrap up more logic internally to the method call for htlcs. Also, don't touch part id if we're not the 'origin' Suggested-By: @rustyrussell
This commit is contained in:
parent
4bfbb58c56
commit
8537e77ac7
@ -36,7 +36,7 @@ struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx,
|
||||
struct bitcoin_txid *funding_txid,
|
||||
u32 funding_outnum,
|
||||
struct sha256 payment_hash,
|
||||
u32 part_id,
|
||||
u64 *part_id,
|
||||
struct amount_msat amount,
|
||||
enum mvt_tag tag,
|
||||
bool is_credit,
|
||||
|
@ -45,7 +45,7 @@ struct channel_coin_mvt {
|
||||
|
||||
/* mutlti-part payments may share a payment hash,
|
||||
* so we should also record a 'part-id' for them */
|
||||
u32 part_id;
|
||||
u64 *part_id;
|
||||
|
||||
/* label / tag */
|
||||
enum mvt_tag tag;
|
||||
@ -86,7 +86,7 @@ struct chain_coin_mvt {
|
||||
/* differs depending on type!? */
|
||||
struct mvt_id {
|
||||
struct sha256 *payment_hash;
|
||||
u32 part_id;
|
||||
u64 *part_id;
|
||||
const struct bitcoin_txid *tx_txid;
|
||||
const struct bitcoin_txid *output_txid;
|
||||
u32 vout;
|
||||
@ -130,7 +130,7 @@ struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx,
|
||||
struct bitcoin_txid *funding_txid,
|
||||
u32 funding_outnum,
|
||||
struct sha256 payment_hash,
|
||||
u32 part_id,
|
||||
u64 *part_id,
|
||||
struct amount_msat amount,
|
||||
enum mvt_tag tag,
|
||||
bool is_credit,
|
||||
|
@ -36,6 +36,50 @@ void notify_chain_mvt(struct lightningd *ld, const struct chain_coin_mvt *mvt)
|
||||
notify_coin_mvt(ld, cm);
|
||||
}
|
||||
|
||||
struct channel_coin_mvt *new_channel_mvt_invoice_hin(const tal_t *ctx,
|
||||
struct htlc_in *hin,
|
||||
struct channel *channel)
|
||||
{
|
||||
return new_channel_coin_mvt(ctx, &channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
hin->payment_hash, NULL,
|
||||
hin->msat, INVOICE,
|
||||
true, BTC);
|
||||
}
|
||||
|
||||
struct channel_coin_mvt *new_channel_mvt_routed_hin(const tal_t *ctx,
|
||||
struct htlc_in *hin,
|
||||
struct channel *channel)
|
||||
{
|
||||
return new_channel_coin_mvt(ctx, &channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
hin->payment_hash, NULL,
|
||||
hin->msat, ROUTED,
|
||||
true, BTC);
|
||||
}
|
||||
|
||||
struct channel_coin_mvt *new_channel_mvt_invoice_hout(const tal_t *ctx,
|
||||
struct htlc_out *hout,
|
||||
struct channel *channel)
|
||||
{
|
||||
return new_channel_coin_mvt(ctx, &channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
hout->payment_hash, &hout->partid,
|
||||
hout->msat, INVOICE,
|
||||
false, BTC);
|
||||
}
|
||||
|
||||
struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx,
|
||||
struct htlc_out *hout,
|
||||
struct channel *channel)
|
||||
{
|
||||
return new_channel_coin_mvt(ctx, &channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
hout->payment_hash, NULL,
|
||||
hout->msat, ROUTED,
|
||||
false, BTC);
|
||||
}
|
||||
|
||||
void coin_mvts_init_count(struct lightningd *ld)
|
||||
{
|
||||
s64 count;
|
||||
|
@ -3,11 +3,26 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <common/coin_mvt.h>
|
||||
#include <lightningd/channel.h>
|
||||
#include <lightningd/htlc_end.h>
|
||||
#include <lightningd/lightningd.h>
|
||||
|
||||
void notify_channel_mvt(struct lightningd *ld, const struct channel_coin_mvt *mvt);
|
||||
void notify_chain_mvt(struct lightningd *ld, const struct chain_coin_mvt *mvt);
|
||||
|
||||
struct channel_coin_mvt *new_channel_mvt_invoice_hin(const tal_t *ctx,
|
||||
struct htlc_in *hin,
|
||||
struct channel *channel);
|
||||
struct channel_coin_mvt *new_channel_mvt_routed_hin(const tal_t *ctx,
|
||||
struct htlc_in *hin,
|
||||
struct channel *channel);
|
||||
struct channel_coin_mvt *new_channel_mvt_invoice_hout(const tal_t *ctx,
|
||||
struct htlc_out *hout,
|
||||
struct channel *channel);
|
||||
struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx,
|
||||
struct htlc_out *hout,
|
||||
struct channel *channel);
|
||||
|
||||
/* Initialize the coin movement counter on lightningd */
|
||||
void coin_mvts_init_count(struct lightningd *ld);
|
||||
#endif /* LIGHTNING_LIGHTNINGD_COIN_MVTS_H */
|
||||
|
@ -373,7 +373,7 @@ static void json_mvt_id(struct json_stream *stream, enum mvt_type mvt_type,
|
||||
case CHANNEL_MVT:
|
||||
json_add_sha256(stream, "payment_hash", id->payment_hash);
|
||||
if (id->part_id)
|
||||
json_add_u64(stream, "part_id", id->part_id);
|
||||
json_add_u64(stream, "part_id", *id->part_id);
|
||||
return;
|
||||
}
|
||||
abort();
|
||||
|
@ -1477,12 +1477,11 @@ static void remove_htlc_in(struct channel *channel, struct htlc_in *hin)
|
||||
channel->msat_to_us_max = channel->our_msat;
|
||||
|
||||
/* Coins have definitively moved, log a movement */
|
||||
mvt = new_channel_coin_mvt(hin, &channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
hin->payment_hash, 0, hin->msat,
|
||||
hin->we_filled ? INVOICE : ROUTED,
|
||||
/* FIXME: variable unit ? */
|
||||
true, BTC);
|
||||
if (hin->we_filled)
|
||||
mvt = new_channel_mvt_invoice_hin(hin, hin, channel);
|
||||
else
|
||||
mvt = new_channel_mvt_routed_hin(hin, hin, channel);
|
||||
|
||||
notify_channel_mvt(channel->peer->ld, mvt);
|
||||
}
|
||||
|
||||
@ -1526,14 +1525,10 @@ static void remove_htlc_out(struct channel *channel, struct htlc_out *hout)
|
||||
channel->msat_to_us_min = channel->our_msat;
|
||||
|
||||
/* Coins have definitively moved, log a movement */
|
||||
mvt = new_channel_coin_mvt(hout, &channel->funding_txid,
|
||||
channel->funding_outnum,
|
||||
hout->payment_hash, hout->partid,
|
||||
hout->msat,
|
||||
/* routed payments flow through... */
|
||||
hout->am_origin ? INVOICE : ROUTED,
|
||||
/* FIXME: variable unit ? */
|
||||
false, BTC);
|
||||
if (hout->am_origin)
|
||||
mvt = new_channel_mvt_invoice_hout(hout, hout, channel);
|
||||
else
|
||||
mvt = new_channel_mvt_routed_hout(hout, hout, channel);
|
||||
|
||||
notify_channel_mvt(channel->peer->ld, mvt);
|
||||
}
|
||||
|
@ -397,17 +397,26 @@ struct chain_coin_mvt *new_chain_coin_mvt_sat(const tal_t *ctx UNNEEDED,
|
||||
bool is_credit UNNEEDED,
|
||||
enum mvt_unit_type unit UNNEEDED)
|
||||
{ fprintf(stderr, "new_chain_coin_mvt_sat called!\n"); abort(); }
|
||||
/* Generated stub for new_channel_coin_mvt */
|
||||
struct channel_coin_mvt *new_channel_coin_mvt(const tal_t *ctx UNNEEDED,
|
||||
struct bitcoin_txid *funding_txid UNNEEDED,
|
||||
u32 funding_outnum UNNEEDED,
|
||||
struct sha256 payment_hash UNNEEDED,
|
||||
u32 part_id UNNEEDED,
|
||||
struct amount_msat amount UNNEEDED,
|
||||
enum mvt_tag tag UNNEEDED,
|
||||
bool is_credit UNNEEDED,
|
||||
enum mvt_unit_type unit UNNEEDED)
|
||||
{ fprintf(stderr, "new_channel_coin_mvt called!\n"); abort(); }
|
||||
/* Generated stub for new_channel_mvt_invoice_hin */
|
||||
struct channel_coin_mvt *new_channel_mvt_invoice_hin(const tal_t *ctx UNNEEDED,
|
||||
struct htlc_in *hin UNNEEDED,
|
||||
struct channel *channel UNNEEDED)
|
||||
{ fprintf(stderr, "new_channel_mvt_invoice_hin called!\n"); abort(); }
|
||||
/* Generated stub for new_channel_mvt_invoice_hout */
|
||||
struct channel_coin_mvt *new_channel_mvt_invoice_hout(const tal_t *ctx UNNEEDED,
|
||||
struct htlc_out *hout UNNEEDED,
|
||||
struct channel *channel UNNEEDED)
|
||||
{ fprintf(stderr, "new_channel_mvt_invoice_hout called!\n"); abort(); }
|
||||
/* Generated stub for new_channel_mvt_routed_hin */
|
||||
struct channel_coin_mvt *new_channel_mvt_routed_hin(const tal_t *ctx UNNEEDED,
|
||||
struct htlc_in *hin UNNEEDED,
|
||||
struct channel *channel UNNEEDED)
|
||||
{ fprintf(stderr, "new_channel_mvt_routed_hin called!\n"); abort(); }
|
||||
/* Generated stub for new_channel_mvt_routed_hout */
|
||||
struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx UNNEEDED,
|
||||
struct htlc_out *hout UNNEEDED,
|
||||
struct channel *channel UNNEEDED)
|
||||
{ fprintf(stderr, "new_channel_mvt_routed_hout called!\n"); abort(); }
|
||||
/* Generated stub for notify_chain_mvt */
|
||||
void notify_chain_mvt(struct lightningd *ld UNNEEDED, const struct chain_coin_mvt *mvt UNNEEDED)
|
||||
{ fprintf(stderr, "notify_chain_mvt called!\n"); abort(); }
|
||||
|
Loading…
Reference in New Issue
Block a user