core-lightning/lightningd/coin_mvts.c
lisa neigut 8537e77ac7 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
2020-05-12 15:46:58 +09:30

96 lines
2.5 KiB
C

#include <lightningd/coin_mvts.h>
#include <lightningd/notification.h>
static s64 update_count(struct lightningd *ld)
{
s64 count;
count = ++ld->coin_moves_count;
db_set_intvar(ld->wallet->db, "coin_moves_count", count);
return count;
}
void notify_channel_mvt(struct lightningd *ld, const struct channel_coin_mvt *mvt)
{
const struct coin_mvt *cm;
u32 timestamp;
s64 count;
timestamp = time_now().ts.tv_sec;
count = update_count(ld);
cm = finalize_channel_mvt(mvt, mvt, timestamp,
&ld->id, count);
notify_coin_mvt(ld, cm);
}
void notify_chain_mvt(struct lightningd *ld, const struct chain_coin_mvt *mvt)
{
const struct coin_mvt *cm;
u32 timestamp;
s64 count;
timestamp = time_now().ts.tv_sec;
count = update_count(ld);
cm = finalize_chain_mvt(mvt, mvt, timestamp,
&ld->id, count);
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;
db_begin_transaction(ld->wallet->db);
count = db_get_intvar(ld->wallet->db,
"coin_moves_count", -1);
db_commit_transaction(ld->wallet->db);
if (count == -1)
fatal("Something went wrong attempting to fetch"
"the latest `coin_moves_count` from the intvars "
"table");
ld->coin_moves_count = count;
}