mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-02 20:54:23 +01:00
bkpr: use tags not str for tag originations
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
BOOKKEEPER_PLUGIN_SRC := \
|
||||
plugins/bkpr/account.c \
|
||||
plugins/bkpr/account_entry.c \
|
||||
plugins/bkpr/bookkeeper.c \
|
||||
plugins/bkpr/channel_event.c \
|
||||
plugins/bkpr/db.c \
|
||||
@@ -14,6 +15,7 @@ BOOKKEEPER_DB_QUERIES := \
|
||||
BOOKKEEPER_SRC := $(BOOKKEEPER_PLUGIN_SRC) $(BOOKKEEPER_DB_QUERIES)
|
||||
BOOKKEEPER_HEADER := \
|
||||
plugins/bkpr/account.h \
|
||||
plugins/bkpr/account_entry.h \
|
||||
plugins/bkpr/chain_event.h \
|
||||
plugins/bkpr/channel_event.h \
|
||||
plugins/bkpr/db.h \
|
||||
|
||||
26
plugins/bkpr/account_entry.c
Normal file
26
plugins/bkpr/account_entry.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <ccan/tal/str/str.h>
|
||||
#include <plugins/bkpr/account_entry.h>
|
||||
#include <stddef.h>
|
||||
|
||||
static const char *tags[] = {
|
||||
"journal_entry",
|
||||
};
|
||||
|
||||
const char *account_entry_tag_str(enum account_entry_tag tag)
|
||||
{
|
||||
return tags[tag];
|
||||
}
|
||||
|
||||
bool account_entry_tag_find(char *str, enum account_entry_tag *tag)
|
||||
{
|
||||
for (size_t i = 0; i < NUM_ACCOUNT_ENTRY_TAGS; i++) {
|
||||
if (streq(str, tags[i])) {
|
||||
*tag = (enum account_entry_tag) i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
15
plugins/bkpr/account_entry.h
Normal file
15
plugins/bkpr/account_entry.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef LIGHTNING_PLUGINS_BKPR_ACCOUNT_ENTRY_H
|
||||
#define LIGHTNING_PLUGINS_BKPR_ACCOUNT_ENTRY_H
|
||||
#include "config.h"
|
||||
|
||||
#define NUM_ACCOUNT_ENTRY_TAGS (JOURNAL_ENTRY + 1)
|
||||
enum account_entry_tag {
|
||||
JOURNAL_ENTRY = 0,
|
||||
};
|
||||
|
||||
/* Convert an enum into a string */
|
||||
const char *account_entry_tag_str(enum account_entry_tag tag);
|
||||
|
||||
/* True if entry tag found, false otherwise */
|
||||
bool account_entry_tag_find(char *str, enum account_entry_tag *tag);
|
||||
#endif /* LIGHTNING_PLUGINS_BKPR_ACCOUNT_ENTRY_H */
|
||||
@@ -9,10 +9,11 @@
|
||||
#include <common/memleak.h>
|
||||
#include <common/type_to_string.h>
|
||||
#include <db/exec.h>
|
||||
#include <plugins/bkpr/db.h>
|
||||
#include <plugins/bkpr/account.h>
|
||||
#include <plugins/bkpr/account_entry.h>
|
||||
#include <plugins/bkpr/chain_event.h>
|
||||
#include <plugins/bkpr/channel_event.h>
|
||||
#include <plugins/bkpr/db.h>
|
||||
#include <plugins/bkpr/onchain_fee.h>
|
||||
#include <plugins/bkpr/recorder.h>
|
||||
#include <plugins/libplugin.h>
|
||||
@@ -285,7 +286,7 @@ static bool new_missed_channel_account(struct command *cmd,
|
||||
continue;
|
||||
|
||||
chain_ev = tal(cmd, struct chain_event);
|
||||
chain_ev->tag = "channel_open";
|
||||
chain_ev->tag = mvt_tag_str(CHANNEL_OPEN);
|
||||
chain_ev->credit = amt;
|
||||
chain_ev->debit = AMOUNT_MSAT(0);
|
||||
chain_ev->output_value = AMOUNT_MSAT(0);
|
||||
@@ -403,7 +404,8 @@ static void log_journal_entry(struct account *acct,
|
||||
return;
|
||||
|
||||
chan_ev = new_channel_event(tmpctx,
|
||||
tal_fmt(tmpctx, "journal_entry"),
|
||||
tal_fmt(tmpctx, "%s",
|
||||
account_entry_tag_str(JOURNAL_ENTRY)),
|
||||
credit_diff,
|
||||
debit_diff,
|
||||
AMOUNT_MSAT(0),
|
||||
@@ -693,7 +695,8 @@ static struct command_result *json_balance_snapshot(struct command *cmd,
|
||||
}
|
||||
|
||||
ev = new_channel_event(cmd,
|
||||
tal_fmt(tmpctx, "journal_entry"),
|
||||
tal_fmt(tmpctx, "%s",
|
||||
account_entry_tag_str(JOURNAL_ENTRY)),
|
||||
credit_diff,
|
||||
debit_diff,
|
||||
AMOUNT_MSAT(0),
|
||||
|
||||
Reference in New Issue
Block a user