aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb/plugin_exchangedb_postgres.c
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2022-10-04 11:35:21 +0200
committerÖzgür Kesim <oec-taler@kesim.org>2022-10-04 11:35:21 +0200
commit77266e6c93f3368171a8b17288f279195f1931dc (patch)
tree6d3a00cc796feb3724c035b8c0be999717d9eaa3 /src/exchangedb/plugin_exchangedb_postgres.c
parent3fdf88f612719f062e5a19969f22204075941128 (diff)
parent856b8e26c2b83ebce31eb35c9fc9f23641187be9 (diff)
Merge branch 'master' into auction_brandt
Diffstat (limited to 'src/exchangedb/plugin_exchangedb_postgres.c')
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c150
1 files changed, 18 insertions, 132 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index e3da5216..d2e2eb5d 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -29,6 +29,12 @@
#include "taler_util.h"
#include "taler_json_lib.h"
#include "taler_exchangedb_plugin.h"
+#include "pg_helper.h"
+#include "pg_insert_close_request.h"
+#include "pg_insert_reserve_open_deposit.h"
+#include "pg_iterate_kyc_reference.h"
+#include "pg_iterate_reserve_close_info.h"
+#include "pg_select_reserve_close_info.h"
#include <poll.h>
#include <pthread.h>
#include <libpq-fe.h>
@@ -42,26 +48,6 @@
*/
#define AUTO_EXPLAIN 1
-/**
- * Wrapper macro to add the currency from the plugin's state
- * when fetching amounts from the database.
- *
- * @param field name of the database field to fetch amount from
- * @param[out] amountp pointer to amount to set
- */
-#define TALER_PQ_RESULT_SPEC_AMOUNT(field,amountp) TALER_PQ_result_spec_amount ( \
- field,pg->currency,amountp)
-
-/**
- * Wrapper macro to add the currency from the plugin's state
- * when fetching amounts from the database. NBO variant.
- *
- * @param field name of the database field to fetch amount from
- * @param[out] amountp pointer to amount to set
- */
-#define TALER_PQ_RESULT_SPEC_AMOUNT_NBO(field, \
- amountp) TALER_PQ_result_spec_amount_nbo ( \
- field,pg->currency,amountp)
/**
* Log a really unexpected PQ error with all the details we can get hold of.
@@ -82,69 +68,6 @@
/**
- * Type of the "cls" argument given to each of the functions in
- * our API.
- */
-struct PostgresClosure
-{
-
- /**
- * Our configuration.
- */
- const struct GNUNET_CONFIGURATION_Handle *cfg;
-
- /**
- * Directory with SQL statements to run to create tables.
- */
- char *sql_dir;
-
- /**
- * After how long should idle reserves be closed?
- */
- struct GNUNET_TIME_Relative idle_reserve_expiration_time;
-
- /**
- * After how long should reserves that have seen withdraw operations
- * be garbage collected?
- */
- struct GNUNET_TIME_Relative legal_reserve_expiration_time;
-
- /**
- * What delay should we introduce before ready transactions
- * are actually aggregated?
- */
- struct GNUNET_TIME_Relative aggregator_shift;
-
- /**
- * Which currency should we assume all amounts to be in?
- */
- char *currency;
-
- /**
- * Our base URL.
- */
- char *exchange_url;
-
- /**
- * Postgres connection handle.
- */
- struct GNUNET_PQ_Context *conn;
-
- /**
- * Name of the current transaction, for debugging.
- */
- const char *transaction_name;
-
- /**
- * Did we initialize the prepared statements
- * for this session?
- */
- bool init;
-
-};
-
-
-/**
* Drop all Taler tables. This should only be used by testcases.
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
@@ -4467,15 +4390,7 @@ prepare_statements (struct PostgresClosure *pg)
" FROM exchange_do_history_request"
" ($1, $2, $3, $4, $5)",
5),
- /* Used in #postgres_insert_close_request() */
- GNUNET_PQ_make_prepare (
- "call_account_close",
- "SELECT "
- " out_final_balance_val"
- ",out_final_balance_frac"
- " FROM exchange_do_close_request"
- " ($1, $2, $3)",
- 3),
+
/* Used in #postgres_insert_kyc_requirement_for_account() */
GNUNET_PQ_make_prepare (
"insert_legitimization_requirement",
@@ -4674,6 +4589,7 @@ internal_setup (struct PostgresClosure *pg,
NULL);
if (NULL == db_conn)
return GNUNET_SYSERR;
+ pg->prep_gen++;
pg->conn = db_conn;
}
if (NULL == pg->transaction_name)
@@ -16237,44 +16153,6 @@ postgres_insert_history_request (
/**
- * Function called to initiate closure of an account.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param reserve_pub public key of the account to close
- * @param reserve_sig signature affiming that the account is to be closed
- * @param request_timestamp time of the close request (client-side?)
- * @param[out] final_balance set to the final balance in the account that will be wired back to the origin account
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_close_request (
- void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_ReserveSignatureP *reserve_sig,
- struct GNUNET_TIME_Timestamp request_timestamp,
- struct TALER_Amount *final_balance)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_timestamp (&request_timestamp),
- GNUNET_PQ_query_param_auto_from_type (reserve_sig),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("out_final_balance",
- final_balance),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_account_close",
- params,
- rs);
-}
-
-
-/**
* Function called to persist a request to drain profits.
*
* @param cls the @e cls of this struct with the plugin-specific state
@@ -17389,8 +17267,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
= &postgres_select_purse_merge;
plugin->insert_history_request
= &postgres_insert_history_request;
- plugin->insert_close_request
- = &postgres_insert_close_request;
plugin->insert_drain_profit
= &postgres_insert_drain_profit;
plugin->profit_drains_get_pending
@@ -17419,6 +17295,16 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
= &postgres_select_aggregation_amounts_for_kyc_check;
plugin->select_merge_amounts_for_kyc_check
= &postgres_select_merge_amounts_for_kyc_check;
+ /* NEW style, sort alphabetically! */
+ plugin->insert_close_request
+ = &TEH_PG_insert_close_request;
+ plugin->iterate_reserve_close_info
+ = &TEH_PG_iterate_reserve_close_info;
+ plugin->iterate_kyc_reference
+ = &TEH_PG_iterate_kyc_reference;
+ plugin->select_reserve_close_info
+ = &TEH_PG_select_reserve_close_info;
+
return plugin;
}