Browse Source

db: add amount functions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
confirmed-only
Rusty Russell 6 years ago
parent
commit
1d1fcc41b8
  1. 28
      wallet/db.c
  2. 8
      wallet/db.h

28
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);
}

8
wallet/db.h

@ -8,6 +8,7 @@
#include <bitcoin/tx.h>
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
#include <common/amount.h>
#include <secp256k1_ecdh.h>
#include <sqlite3.h>
#include <stdbool.h>
@ -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 */

Loading…
Cancel
Save