From f6a7d4a1edd9dce6781b2682568f90090cc7d602 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 15 Jun 2022 22:31:44 +0200 Subject: -more DB logic for taler-helper-auditor-reserves --- src/auditor/taler-helper-auditor-reserves.c | 2 +- src/exchangedb/plugin_exchangedb_postgres.c | 383 +++++++++++++++++++++++++++- src/include/taler_exchangedb_plugin.h | 2 +- 3 files changed, 377 insertions(+), 10 deletions(-) diff --git a/src/auditor/taler-helper-auditor-reserves.c b/src/auditor/taler-helper-auditor-reserves.c index 5ccd06a37..814ba11d0 100644 --- a/src/auditor/taler-helper-auditor-reserves.c +++ b/src/auditor/taler-helper-auditor-reserves.c @@ -1381,7 +1381,7 @@ handle_account_merged ( enum TALER_WalletAccountMergeFlags flags, const struct TALER_Amount *purse_fee, struct GNUNET_TIME_Timestamp merge_timestamp, - struct TALER_ReserveSignatureP *reserve_sig) + const struct TALER_ReserveSignatureP *reserve_sig) { GNUNET_break (0); // FIXME /* Debit purse fee */ diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index eab50e10e..523ccff48 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -1523,7 +1523,7 @@ prepare_statements (struct PostgresClosure *pg) 1), GNUNET_PQ_make_prepare ( - "audit_get_account_merges_incr", + "audit_get_account_merge_incr", "SELECT" " am.account_merge_request_serial_id" ",am.reserve_pub" @@ -1548,7 +1548,7 @@ prepare_statements (struct PostgresClosure *pg) 1), GNUNET_PQ_make_prepare ( - "audit_get_purse_merges_incr", + "audit_get_purse_merge_incr", "SELECT" " pm.purse_merge_request_serial_id" ",partner_base_url" @@ -10623,6 +10623,120 @@ postgres_select_purse_deposits_above_serial_id ( } +/** + * Closure for #account_merge_serial_helper_cb(). + */ +struct AccountMergeSerialContext +{ + + /** + * Callback to call. + */ + TALER_EXCHANGEDB_AccountMergeCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Plugin context. + */ + struct PostgresClosure *pg; + + /** + * Status code, set to #GNUNET_SYSERR on hard errors. + */ + enum GNUNET_GenericReturnValue status; +}; + + +/** + * Helper function to be called with the results of a SELECT statement + * that has returned @a num_results results. + * + * @param cls closure of type `struct AccountMergeSerialContext` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +account_merge_serial_helper_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct AccountMergeSerialContext *dsc = cls; + struct PostgresClosure *pg = dsc->pg; + + for (unsigned int i = 0; istatus = GNUNET_SYSERR; + return; + } + flags = (enum TALER_WalletAccountMergeFlags) flags32; + ret = dsc->cb (dsc->cb_cls, + rowid, + &reserve_pub, + &purse_pub, + &h_contract_terms, + purse_expiration, + &amount, + min_age, + flags, + &purse_fee, + merge_timestamp, + &reserve_sig); + GNUNET_PQ_cleanup_result (rs); + if (GNUNET_OK != ret) + break; + } +} + + /** * Select account merges above @a serial_id in monotonically increasing * order. @@ -10640,8 +10754,135 @@ postgres_select_account_merges_above_serial_id ( TALER_EXCHANGEDB_AccountMergeCallback cb, void *cb_cls) { - GNUNET_break (0); // FIXME: not implemented - return GNUNET_DB_STATUS_HARD_ERROR; + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&serial_id), + GNUNET_PQ_query_param_end + }; + struct AccountMergeSerialContext dsc = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg, + .status = GNUNET_OK + }; + enum GNUNET_DB_QueryStatus qs; + + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "audit_get_account_merge_incr", + params, + &account_merge_serial_helper_cb, + &dsc); + if (GNUNET_OK != dsc.status) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} + + +/** + * Closure for #purse_deposit_serial_helper_cb(). + */ +struct PurseMergeSerialContext +{ + + /** + * Callback to call. + */ + TALER_EXCHANGEDB_PurseMergeCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Plugin context. + */ + struct PostgresClosure *pg; + + /** + * Status code, set to #GNUNET_SYSERR on hard errors. + */ + enum GNUNET_GenericReturnValue status; +}; + + +/** + * Helper function to be called with the results of a SELECT statement + * that has returned @a num_results results. + * + * @param cls closure of type `struct PurseMergeSerialContext` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +purse_merges_serial_helper_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct PurseMergeSerialContext *dsc = cls; + struct PostgresClosure *pg = dsc->pg; + + for (unsigned int i = 0; istatus = GNUNET_SYSERR; + return; + } + ret = dsc->cb (dsc->cb_cls, + rowid, + partner_base_url, + &amount, + flags, + &merge_pub, + &reserve_pub, + &merge_sig, + &purse_pub, + merge_timestamp); + GNUNET_PQ_cleanup_result (rs); + if (GNUNET_OK != ret) + break; + } } @@ -10662,8 +10903,115 @@ postgres_select_purse_merges_above_serial_id ( TALER_EXCHANGEDB_PurseMergeCallback cb, void *cb_cls) { - GNUNET_break (0); // FIXME: not implemented - return GNUNET_DB_STATUS_HARD_ERROR; + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&serial_id), + GNUNET_PQ_query_param_end + }; + struct PurseMergeSerialContext dsc = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg, + .status = GNUNET_OK + }; + enum GNUNET_DB_QueryStatus qs; + + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "audit_get_purse_merge_incr", + params, + &purse_merges_serial_helper_cb, + &dsc); + if (GNUNET_OK != dsc.status) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; +} + + +/** + * Closure for #purse_deposit_serial_helper_cb(). + */ +struct HistoryRequestSerialContext +{ + + /** + * Callback to call. + */ + TALER_EXCHANGEDB_HistoryRequestCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + + /** + * Plugin context. + */ + struct PostgresClosure *pg; + + /** + * Status code, set to #GNUNET_SYSERR on hard errors. + */ + enum GNUNET_GenericReturnValue status; +}; + + +/** + * Helper function to be called with the results of a SELECT statement + * that has returned @a num_results results. + * + * @param cls closure of type `struct HistoryRequestSerialContext` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +history_request_serial_helper_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct HistoryRequestSerialContext *dsc = cls; + struct PostgresClosure *pg = dsc->pg; + + for (unsigned int i = 0; istatus = GNUNET_SYSERR; + return; + } + ret = dsc->cb (dsc->cb_cls, + rowid, + &history_fee, + ts, + &reserve_pub, + &reserve_sig); + GNUNET_PQ_cleanup_result (rs); + if (GNUNET_OK != ret) + break; + } } @@ -10684,8 +11032,27 @@ postgres_select_history_requests_above_serial_id ( TALER_EXCHANGEDB_HistoryRequestCallback cb, void *cb_cls) { - GNUNET_break (0); // FIXME: not implemented - return GNUNET_DB_STATUS_HARD_ERROR; + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&serial_id), + GNUNET_PQ_query_param_end + }; + struct HistoryRequestSerialContext dsc = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg, + .status = GNUNET_OK + }; + enum GNUNET_DB_QueryStatus qs; + + qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, + "audit_get_history_requests_incr", + params, + &history_request_serial_helper_cb, + &dsc); + if (GNUNET_OK != dsc.status) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; } diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index afd850ad5..5ef4e74ad 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -2023,7 +2023,7 @@ typedef enum GNUNET_GenericReturnValue enum TALER_WalletAccountMergeFlags flags, const struct TALER_Amount *purse_fee, struct GNUNET_TIME_Timestamp merge_timestamp, - struct TALER_ReserveSignatureP *reserve_sig); + const struct TALER_ReserveSignatureP *reserve_sig); /** -- cgit v1.2.3