Files
palladum-lightning/plugins/bkpr/incomestmt.h
Rusty Russell b70f4f6184 bkpr: convert all the local db sql queries into calls to sql plugin.
With some help (and hinderance!) from ChatGPT: the field names
differ slightly from our internal db.

The particilar wrinkle is that we have to restrict all queries to
limit them to entries we've seen already.  Our code expects this (we
used to only enter it into the db when we processed it), and it would
otherwise be confusing if a sql query returned inconsistent results
because an event occurred while bookkeeper was processing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-08-19 13:37:50 +09:30

63 lines
1.8 KiB
C

#ifndef LIGHTNING_PLUGINS_BKPR_INCOMESTMT_H
#define LIGHTNING_PLUGINS_BKPR_INCOMESTMT_H
#include "config.h"
#include <ccan/tal/tal.h>
#include <stdio.h>
struct income_event {
const char *acct_name;
const char *tag;
const char *desc;
struct amount_msat credit;
struct amount_msat debit;
/* Some CSVs require us to put fees on the
* same line as another entry */
struct amount_msat fees;
u64 timestamp;
struct bitcoin_outpoint *outpoint;
struct bitcoin_txid *txid;
struct sha256 *payment_id;
};
/* Each csv format has a header and a 'row print' function */
struct csv_fmt {
const char *fmt_name;
void (*emit_header)(FILE *);
void (*emit_entry)(const tal_t *, FILE *, struct income_event *);
};
/* List all the events that are income related (gain/loss) */
struct income_event **list_income_events_all(const tal_t *ctx,
const struct bkpr *bkpr,
struct command *cmd,
bool consolidate_fees);
/* List all the events that are income related (gain/loss),
* by a start and end date */
struct income_event **list_income_events(const tal_t *ctx,
const struct bkpr *bkpr,
struct command *cmd,
u64 start_time,
u64 end_time,
bool consolidate_fees);
/* Given an event and a json_stream, add a new event object to the stream */
void json_add_income_event(struct json_stream *str, struct income_event *ev);
char *csv_print_income_events(const tal_t *ctx,
const struct csv_fmt *csvfmt,
const char *filename,
struct income_event **evs);
const struct csv_fmt *csv_match_token(const char *buffer, const jsmntok_t *tok);
/* Returns concatenated string of all available fmts */
const char *csv_list_fmts(const tal_t *ctx);
/* Generic income statement filename generator */
const char *csv_filename(const tal_t *ctx, const struct csv_fmt *fmt);
#endif /* LIGHTNING_PLUGINS_BKPR_INCOMESTMT_H */