Skip to content

Commit

Permalink
bkpr: add a 'listincome' event
Browse files Browse the repository at this point in the history
list the income/expense events for a node.
  • Loading branch information
niftynei authored and rustyrussell committed Jul 28, 2022
1 parent 595c52f commit 593f1e7
Show file tree
Hide file tree
Showing 4 changed files with 394 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugins/bkpr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ BOOKKEEPER_PLUGIN_SRC := \
plugins/bkpr/chain_event.c \
plugins/bkpr/channel_event.c \
plugins/bkpr/db.c \
plugins/bkpr/incomestmt.c \
plugins/bkpr/onchain_fee.c \
plugins/bkpr/recorder.c

Expand All @@ -21,6 +22,7 @@ BOOKKEEPER_HEADER := \
plugins/bkpr/chain_event.h \
plugins/bkpr/channel_event.h \
plugins/bkpr/db.h \
plugins/bkpr/incomestmt.h \
plugins/bkpr/onchain_fee.h \
plugins/bkpr/recorder.h

Expand All @@ -39,6 +41,7 @@ plugins/bookkeeper: bitcoin/chainparams.o common/coin_mvt.o $(BOOKKEEPER_OBJS) $
BOOKKEEPER_SQL_FILES := \
$(DB_SQL_FILES) \
plugins/bkpr/db.c \
plugins/bkpr/incomestmt.c \
plugins/bkpr/recorder.c

plugins/bkpr/statements_gettextgen.po: $(BOOKKEEPER_SQL_FILES) $(FORCE)
Expand Down
34 changes: 34 additions & 0 deletions plugins/bkpr/bookkeeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <plugins/bkpr/chain_event.h>
#include <plugins/bkpr/channel_event.h>
#include <plugins/bkpr/db.h>
#include <plugins/bkpr/incomestmt.h>
#include <plugins/bkpr/onchain_fee.h>
#include <plugins/bkpr/recorder.h>
#include <plugins/libplugin.h>
Expand All @@ -37,6 +38,32 @@ static struct fee_sum *find_sum_for_txid(struct fee_sum **sums,
return NULL;
}

static struct command_result *json_list_income(struct command *cmd,
const char *buf,
const jsmntok_t *params)
{
struct json_stream *res;
struct income_event **evs;

if (!param(cmd, buf, params,
NULL))
return command_param_failed();

/* Ok, go find me some income events! */
db_begin_transaction(db);
evs = list_income_events_all(cmd, db);
db_commit_transaction(db);

res = jsonrpc_stream_success(cmd);

json_array_start(res, "income_events");
for (size_t i = 0; i < tal_count(evs); i++)
json_add_income_event(res, evs[i]);

json_array_end(res);
return command_finished(cmd, res);
}

static struct command_result *json_inspect(struct command *cmd,
const char *buf,
const jsmntok_t *params)
Expand Down Expand Up @@ -1261,6 +1288,13 @@ static const struct plugin_command commands[] = {
"Prints out the on-chain footprint of a given {account}.",
json_inspect
},
{
"listincome",
"bookkeeping",
"List all income impacting events",
"List all events for this node that impacted income",
json_list_income
},
};

static const char *init(struct plugin *p, const char *b, const jsmntok_t *t)
Expand Down
Loading

0 comments on commit 593f1e7

Please sign in to comment.