mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
bkpr: add timestamp filters to event lists
This commit is contained in:
parent
462fa20c17
commit
595c52f611
2 changed files with 76 additions and 4 deletions
|
@ -102,7 +102,10 @@ static struct channel_event *stmt2channel_event(const tal_t *ctx, struct db_stmt
|
|||
return e;
|
||||
}
|
||||
|
||||
struct chain_event **list_chain_events(const tal_t *ctx, struct db *db)
|
||||
struct chain_event **list_chain_events_timebox(const tal_t *ctx,
|
||||
struct db *db,
|
||||
u64 start_time,
|
||||
u64 end_time)
|
||||
{
|
||||
struct db_stmt *stmt;
|
||||
|
||||
|
@ -125,11 +128,20 @@ struct chain_event **list_chain_events(const tal_t *ctx, struct db *db)
|
|||
" FROM chain_events e"
|
||||
" LEFT OUTER JOIN accounts a"
|
||||
" ON e.account_id = a.id"
|
||||
" WHERE e.timestamp > ?"
|
||||
" AND e.timestamp <= ?"
|
||||
" ORDER BY e.timestamp, e.id;"));
|
||||
|
||||
db_bind_u64(stmt, 0, start_time);
|
||||
db_bind_u64(stmt, 1, end_time);
|
||||
return find_chain_events(ctx, take(stmt));
|
||||
}
|
||||
|
||||
struct chain_event **list_chain_events(const tal_t *ctx, struct db *db)
|
||||
{
|
||||
return list_chain_events_timebox(ctx, db, 0, SQLITE_MAX_UINT);
|
||||
}
|
||||
|
||||
struct chain_event **account_get_chain_events(const tal_t *ctx,
|
||||
struct db *db,
|
||||
struct account *acct)
|
||||
|
@ -701,7 +713,11 @@ char *account_get_balance(const tal_t *ctx,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct channel_event **list_channel_events(const tal_t *ctx, struct db *db)
|
||||
struct channel_event **list_channel_events_timebox(const tal_t *ctx,
|
||||
struct db *db,
|
||||
u64 start_time,
|
||||
u64 end_time)
|
||||
|
||||
{
|
||||
struct db_stmt *stmt;
|
||||
struct channel_event **results;
|
||||
|
@ -721,8 +737,12 @@ struct channel_event **list_channel_events(const tal_t *ctx, struct db *db)
|
|||
" FROM channel_events e"
|
||||
" LEFT OUTER JOIN accounts a"
|
||||
" ON a.id = e.account_id"
|
||||
" WHERE e.timestamp > ?"
|
||||
" AND e.timestamp <= ?"
|
||||
" ORDER BY e.timestamp, e.id;"));
|
||||
|
||||
db_bind_u64(stmt, 0, start_time);
|
||||
db_bind_u64(stmt, 1, end_time);
|
||||
db_query_prepared(stmt);
|
||||
|
||||
results = tal_arr(ctx, struct channel_event *, 0);
|
||||
|
@ -735,6 +755,12 @@ struct channel_event **list_channel_events(const tal_t *ctx, struct db *db)
|
|||
return results;
|
||||
}
|
||||
|
||||
struct channel_event **list_channel_events(const tal_t *ctx, struct db *db)
|
||||
{
|
||||
return list_channel_events_timebox(ctx, db, 0, SQLITE_MAX_UINT);
|
||||
}
|
||||
|
||||
|
||||
struct channel_event **account_get_channel_events(const tal_t *ctx,
|
||||
struct db *db,
|
||||
struct account *acct)
|
||||
|
@ -827,7 +853,8 @@ struct onchain_fee **account_get_chain_fees(const tal_t *ctx, struct db *db,
|
|||
return results;
|
||||
}
|
||||
|
||||
struct onchain_fee **list_chain_fees(const tal_t *ctx, struct db *db)
|
||||
struct onchain_fee **list_chain_fees_timebox(const tal_t *ctx, struct db *db,
|
||||
u64 start_time, u64 end_time)
|
||||
{
|
||||
struct db_stmt *stmt;
|
||||
struct onchain_fee **results;
|
||||
|
@ -844,11 +871,16 @@ struct onchain_fee **list_chain_fees(const tal_t *ctx, struct db *db)
|
|||
" FROM onchain_fees of"
|
||||
" LEFT OUTER JOIN accounts a"
|
||||
" ON a.id = of.account_id"
|
||||
" WHERE timestamp > ?"
|
||||
" AND timestamp <= ?"
|
||||
" ORDER BY "
|
||||
" of.timestamp"
|
||||
", of.account_id"
|
||||
", of.txid"
|
||||
", of.update_count"));
|
||||
|
||||
db_bind_u64(stmt, 0, start_time);
|
||||
db_bind_u64(stmt, 1, end_time);
|
||||
db_query_prepared(stmt);
|
||||
|
||||
results = tal_arr(ctx, struct onchain_fee *, 0);
|
||||
|
@ -861,6 +893,11 @@ struct onchain_fee **list_chain_fees(const tal_t *ctx, struct db *db)
|
|||
return results;
|
||||
}
|
||||
|
||||
struct onchain_fee **list_chain_fees(const tal_t *ctx, struct db *db)
|
||||
{
|
||||
return list_chain_fees_timebox(ctx, db, 0, SQLITE_MAX_UINT);
|
||||
}
|
||||
|
||||
static struct account *stmt2account(const tal_t *ctx, struct db_stmt *stmt)
|
||||
{
|
||||
struct account *a = tal(ctx, struct account);
|
||||
|
|
|
@ -14,6 +14,7 @@ struct onchain_fee;
|
|||
|
||||
#define EXTERNAL_ACCT "external"
|
||||
#define WALLET_ACCT WALLET
|
||||
#define SQLITE_MAX_UINT 0x7FFFFFFFFFFFFFFF
|
||||
|
||||
struct acct_balance {
|
||||
char *currency;
|
||||
|
@ -53,14 +54,38 @@ struct channel_event **account_get_channel_events(const tal_t *ctx,
|
|||
/* Get all channel events, ordered by timestamp */
|
||||
struct channel_event **list_channel_events(const tal_t *ctx, struct db *db);
|
||||
|
||||
/* Get all channel events, order by timestamp.
|
||||
*
|
||||
* @ctx - context to allocate from
|
||||
* @db - database to query
|
||||
* @start_time - UNIX timestamp to query after (exclusive)
|
||||
* @end_time - UNIX timestamp to query until (inclusive)
|
||||
*/
|
||||
struct channel_event **list_channel_events_timebox(const tal_t *ctx,
|
||||
struct db *db,
|
||||
u64 start_time,
|
||||
u64 end_time);
|
||||
|
||||
/* Get all chain events for this account */
|
||||
struct chain_event **account_get_chain_events(const tal_t *ctx,
|
||||
struct db *db,
|
||||
struct account *acct);
|
||||
|
||||
/* Get all chain events, ordered by timestamp */
|
||||
/* Get all chain events, order by timestamp. */
|
||||
struct chain_event **list_chain_events(const tal_t *ctx, struct db *db);
|
||||
|
||||
/* Get all chain events, order by timestamp.
|
||||
*
|
||||
* @ctx - context to allocate from
|
||||
* @db - database to query
|
||||
* @start_time - UNIX timestamp to query after (exclusive)
|
||||
* @end_time - UNIX timestamp to query until (inclusive)
|
||||
*/
|
||||
struct chain_event **list_chain_events_timebox(const tal_t *ctx,
|
||||
struct db *db,
|
||||
u64 start_time,
|
||||
u64 end_time);
|
||||
|
||||
/* Calculate the balances for an account
|
||||
*
|
||||
* @calc_sum - compute the total balance. error if negative
|
||||
|
@ -93,6 +118,16 @@ bool find_txo_chain(const tal_t *ctx,
|
|||
/* List all chain fees, for all accounts */
|
||||
struct onchain_fee **list_chain_fees(const tal_t *ctx, struct db *db);
|
||||
|
||||
/* Get all chain fees, order by timestamp.
|
||||
*
|
||||
* @ctx - context to allocate from
|
||||
* @db - database to query
|
||||
* @start_time - UNIX timestamp to query after (exclusive)
|
||||
* @end_time - UNIX timestamp to query until (inclusive)
|
||||
*/
|
||||
struct onchain_fee **list_chain_fees_timebox(const tal_t *ctx, struct db *db,
|
||||
u64 start_time, u64 end_time);
|
||||
|
||||
/* Returns a list of sums of the fees we've recorded for every txid
|
||||
* for the given account */
|
||||
struct fee_sum **find_account_onchain_fees(const tal_t *ctx,
|
||||
|
|
Loading…
Add table
Reference in a new issue