diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2022-03-21 02:39:36 +0100 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2022-03-21 02:39:36 +0100 |
commit | f5f15e6531bb7072a02cb976771a43803bd044f6 (patch) | |
tree | 80cc93a627533fe4768bd5aded76c77c3d37660d /src/exchangedb | |
parent | b560527ee3d5605310f3793dbcbf86a9b4844c91 (diff) | |
download | exchange-f5f15e6531bb7072a02cb976771a43803bd044f6.tar.xz |
first rough-cut implementation of POST /reserves//status
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index bb6f46f59..2856f3009 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -732,6 +732,17 @@ prepare_statements (struct PostgresClosure *pg) " WHERE res.reserve_pub=$1;", 1), /* Used in #postgres_select_withdrawals_above_serial_id() */ + + GNUNET_PQ_make_prepare ( + "get_reserve_balance", + "SELECT" + " current_balance_val" + ",current_balance_frac" + " FROM reserves" + " WHERE reserve_pub=$1;", + 1), + /* Fetch deposits with rowid '\geq' the given parameter */ + GNUNET_PQ_make_prepare ( "audit_get_reserves_out_incr", "SELECT" @@ -5534,6 +5545,37 @@ postgres_get_reserve_history (void *cls, /** + * Get the balance of the specified reserve. + * + * @param cls the `struct PostgresClosure` with the plugin-specific state + * @param reserve_pub public key of the reserve + * @param[out] balance set to the reserve balance + * @return transaction status + */ +static enum GNUNET_DB_QueryStatus +postgres_get_reserve_balance (void *cls, + const struct TALER_ReservePublicKeyP *reserve_pub, + struct TALER_Amount *balance) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (reserve_pub), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + TALER_PQ_RESULT_SPEC_AMOUNT ("current_balance", + balance), + GNUNET_PQ_result_spec_end + }; + + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "get_reserve_balance", + params, + rs); +} + + +/** * Check if we have the specified deposit already in the database. * * @param cls the `struct PostgresClosure` with the plugin-specific state @@ -12503,6 +12545,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) plugin->do_refund = &postgres_do_refund; plugin->do_recoup = &postgres_do_recoup; plugin->do_recoup_refresh = &postgres_do_recoup_refresh; + plugin->get_reserve_balance = &postgres_get_reserve_balance; plugin->get_reserve_history = &postgres_get_reserve_history; plugin->free_reserve_history = &common_free_reserve_history; plugin->count_known_coins = &postgres_count_known_coins; |