Files
Rusty Russell fd657e8483 ]bkpr: save accounts in the datastore instead of database.
Note that the test where we remove the database causes the bookkeeper
plugin to assert, since we have removed part (but not all!) of its data
by removing the datastore.

Once the transition to the datastore is complete, this can be restored.

Note that we destroy the request before receiving a response, which causes
a message in the trace span which was confusing our test.

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

75 lines
1.9 KiB
C

#ifndef LIGHTNING_PLUGINS_BKPR_ACCOUNT_H
#define LIGHTNING_PLUGINS_BKPR_ACCOUNT_H
#include "config.h"
#include <ccan/short_types/short_types.h>
#include <common/coin_mvt.h>
struct node_id;
struct chain_event;
struct command;
struct account {
/* Unique name of account, typically channel id */
const char *name;
/* Peer we have this account with (NULL if not a channel) */
struct node_id *peer_id;
/* Is this our internal wallet account? */
bool is_wallet;
/* Is this an account we initiated open for? */
bool we_opened;
/* Was any portion of this account's funds leased? */
bool leased;
/* Block account was totally resolved at */
u64 onchain_resolved_block;
/* db_id of chain event that opened this account */
u64 *open_event_db_id;
/* db_id of chain event that closed this account */
u64 *closed_event_db_id;
/* Number of outputs to expect on close */
u32 closed_count;
};
struct bkpr;
/* Initialize the accounts subsystem */
struct accounts *init_accounts(const tal_t *ctx, struct command *init_cmd);
/* Get all accounts */
struct account **list_accounts(const tal_t *ctx, const struct bkpr *bkpr);
/* Given an account name, find that account record */
struct account *find_account(const struct bkpr *bkpr,
const char *name);
/* Create it if it's not found */
struct account *find_or_create_account(struct command *cmd,
struct bkpr *bkpr,
const char *name);
/* Some events update account information */
void maybe_update_account(struct command *cmd,
struct account *acct,
struct chain_event *e,
const enum mvt_tag *tags,
u32 closed_count,
struct node_id *peer_id);
/* Update the account with the highest blockheight that has a
* resolving tx in it.
*
* The point of this is to allow us to prune data, eventually */
void account_update_closeheight(struct command *cmd,
struct account *acct,
u64 close_height);
#endif /* LIGHTNING_PLUGINS_BKPR_ACCOUNT_H */