mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
db: Add timestamp primitives so we can store them in the DB
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
f2ecf8e9c3
commit
fcf133cd0a
17
wallet/db.c
17
wallet/db.c
@@ -11,6 +11,7 @@
|
||||
#include <lightningd/plugin_hook.h>
|
||||
|
||||
#define DB_FILE "lightningd.sqlite3"
|
||||
#define NSEC_IN_SEC 1000000000
|
||||
|
||||
/* For testing, we want to catch fatal messages. */
|
||||
#ifndef db_fatal
|
||||
@@ -1155,3 +1156,19 @@ void migrate_pr2342_feerate_per_channel(struct lightningd *ld, struct db *db)
|
||||
ld->config.fee_base,
|
||||
ld->config.fee_per_satoshi);
|
||||
}
|
||||
|
||||
void sqlite3_bind_timeabs(sqlite3_stmt *stmt, int col, struct timeabs t)
|
||||
{
|
||||
u64 timestamp = t.ts.tv_nsec + (t.ts.tv_sec * NSEC_IN_SEC);
|
||||
sqlite3_bind_int64(stmt, col, timestamp);
|
||||
}
|
||||
|
||||
struct timeabs sqlite3_column_timeabs(sqlite3_stmt *stmt, int col)
|
||||
{
|
||||
struct timeabs t;
|
||||
u64 timestamp = sqlite3_column_int64(stmt, col);
|
||||
t.ts.tv_sec = timestamp / NSEC_IN_SEC;
|
||||
t.ts.tv_nsec = timestamp % NSEC_IN_SEC;
|
||||
return t;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user