Skip to content

Commit

Permalink
bkpr: Add an option to set the database to something else (postgres)
Browse files Browse the repository at this point in the history
`lightningd` has an option --wallet that lets you supply a database dsn
string to connect to a sqlite3/postgres database that's hosted/stored
elsewhere.

This adds the `--bookkeeper-db` option which does the same, except for
the bookkeeping data for a node!

Note that the default is to go in the `lightning-dir` in a database
called `accounts.sqlite3`
  • Loading branch information
niftynei committed Jul 11, 2022
1 parent 630d51b commit 47b4dd7
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion plugins/bkpr/bookkeeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/* The database that we store all the accounting data in */
static struct db *db ;

static char *db_dsn = "sqlite3://accounts.sqlite3";
static char *db_dsn;
static char *datadir;

static struct fee_sum *find_sum_for_txid(struct fee_sum **sums,
Expand Down Expand Up @@ -1771,7 +1771,14 @@ static const char *init(struct plugin *p, const char *b, const jsmntok_t *t)
"Unable to switch to 'bookkeeper-dir'=%s",
datadir);
}

/* No user suppled db_dsn, set one up here */
if (!db_dsn)
db_dsn = tal_fmt(NULL, "sqlite3://accounts.sqlite3");

plugin_log(p, LOG_DBG, "Setting up database at %s", db_dsn);
db = notleak(db_setup(p, p, db_dsn));
db_dsn = tal_free(db_dsn);

return NULL;
}
Expand All @@ -1782,6 +1789,8 @@ int main(int argc, char *argv[])

/* No datadir is default */
datadir = NULL;
db_dsn = NULL;

plugin_main(argv, init, PLUGIN_STATIC, true, NULL,
commands, ARRAY_SIZE(commands),
notifs, ARRAY_SIZE(notifs),
Expand All @@ -1791,6 +1800,11 @@ int main(int argc, char *argv[])
"string",
"Location for bookkeeper records.",
charp_option, &datadir),
plugin_option("bookkeeper-db",
"string",
"Location of the bookkeeper database",
charp_option, &db_dsn),
NULL);

return 0;
}

0 comments on commit 47b4dd7

Please sign in to comment.