From 1d1fcc41b861cd97cf8f210d5e60e60027e8e7a0 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 20 Feb 2019 22:01:48 +1030 Subject: [PATCH] db: add amount functions. Signed-off-by: Rusty Russell --- wallet/db.c | 28 ++++++++++++++++++++++++++++ wallet/db.h | 8 ++++++++ 2 files changed, 36 insertions(+) diff --git a/wallet/db.c b/wallet/db.c index cf9d53ee5..897ea1fb7 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -943,3 +943,31 @@ bool sqlite3_bind_json_escaped(sqlite3_stmt *stmt, int col, int err = sqlite3_bind_text(stmt, col, esc->s, strlen(esc->s), SQLITE_TRANSIENT); return err == SQLITE_OK; } + +struct amount_msat sqlite3_column_amount_msat(sqlite3_stmt *stmt, int col) +{ + struct amount_msat msat; + + msat.millisatoshis = sqlite3_column_int64(stmt, col); + return msat; +} + +struct amount_sat sqlite3_column_amount_sat(sqlite3_stmt *stmt, int col) +{ + struct amount_sat sat; + + sat.satoshis = sqlite3_column_int64(stmt, col); + return sat; +} + +void sqlite3_bind_amount_msat(sqlite3_stmt *stmt, int col, + struct amount_msat msat) +{ + sqlite3_bind_int64(stmt, col, msat.millisatoshis); +} + +void sqlite3_bind_amount_sat(sqlite3_stmt *stmt, int col, + struct amount_sat sat) +{ + sqlite3_bind_int64(stmt, col, sat.satoshis); +} diff --git a/wallet/db.h b/wallet/db.h index 2ec3b692e..388394066 100644 --- a/wallet/db.h +++ b/wallet/db.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -170,4 +171,11 @@ struct json_escaped *sqlite3_column_json_escaped(const tal_t *ctx, sqlite3_stmt *stmt, int col); bool sqlite3_bind_json_escaped(sqlite3_stmt *stmt, int col, const struct json_escaped *esc); + +struct amount_msat sqlite3_column_amount_msat(sqlite3_stmt *stmt, int col); +struct amount_sat sqlite3_column_amount_sat(sqlite3_stmt *stmt, int col); +void sqlite3_bind_amount_msat(sqlite3_stmt *stmt, int col, + struct amount_msat msat); +void sqlite3_bind_amount_sat(sqlite3_stmt *stmt, int col, + struct amount_sat sat); #endif /* LIGHTNING_WALLET_DB_H */