From a0c66e79191ca4339ea91e74e3742ccd8bd515ab Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 19 Jun 2017 20:12:00 +0200 Subject: fix #5010 for /track/transfer --- src/exchangedb/plugin_exchangedb_postgres.c | 194 ++++++++++++++-------------- src/exchangedb/test_exchangedb.c | 8 +- 2 files changed, 101 insertions(+), 101 deletions(-) (limited to 'src/exchangedb') diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 7267ef66f..2f05c0233 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -4430,50 +4430,44 @@ postgres_get_coin_transactions (void *cls, /** - * Lookup the list of Taler transactions that were aggregated - * into a wire transfer by the respective @a wtid. - * - * @param cls closure - * @param session database connection - * @param wtid the raw wire transfer identifier we used - * @param cb function to call on each transaction found - * @param cb_cls closure for @a cb - * @return #GNUNET_OK on success, #GNUNET_SYSERR on database errors, - * #GNUNET_NO if we found no results + * Closure for #handle_wt_result. */ -static int -postgres_lookup_wire_transfer (void *cls, - struct TALER_EXCHANGEDB_Session *session, - const struct TALER_WireTransferIdentifierRawP *wtid, - TALER_EXCHANGEDB_WireTransferDataCallback cb, - void *cb_cls) +struct WireTransferResultContext { - PGresult *result; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (wtid), - GNUNET_PQ_query_param_end - }; - int nrows; + /** + * Function to call on each result. + */ + TALER_EXCHANGEDB_WireTransferDataCallback cb; - /* check if the melt record exists and get it */ - result = GNUNET_PQ_exec_prepared (session->conn, - "lookup_transactions", - params); - if (PGRES_TUPLES_OK != PQresultStatus (result)) - { - BREAK_DB_ERR (result, session->conn); - PQclear (result); - return GNUNET_SYSERR; - } - nrows = PQntuples (result); - if (0 == nrows) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "lookup_wire_transfer() returned 0 matching rows\n"); - PQclear (result); - return GNUNET_NO; - } - for (int i=0;istatus = GNUNET_SYSERR; + return; } t = json_object_get (wire, "type"); if (NULL == t) { GNUNET_break (0); - PQclear (result); - return GNUNET_SYSERR; + ctx->status = GNUNET_SYSERR; + return; } wire_method = json_string_value (t); if (NULL == wire_method) { GNUNET_break (0); - PQclear (result); - return GNUNET_SYSERR; + ctx->status = GNUNET_SYSERR; + return; } - cb (cb_cls, - rowid, - &merchant_pub, - wire_method, - &h_wire, - exec_time, - &h_contract_terms, - &coin_pub, - &amount_with_fee, - &deposit_fee); + ctx->cb (ctx->cb_cls, + rowid, + &merchant_pub, + wire_method, + &h_wire, + exec_time, + &h_contract_terms, + &coin_pub, + &amount_with_fee, + &deposit_fee); GNUNET_PQ_cleanup_result (rs); } - PQclear (result); - return GNUNET_OK; +} + + +/** + * Lookup the list of Taler transactions that were aggregated + * into a wire transfer by the respective @a wtid. + * + * @param cls closure + * @param session database connection + * @param wtid the raw wire transfer identifier we used + * @param cb function to call on each transaction found + * @param cb_cls closure for @a cb + * @return query status of the transaction + */ +static enum GNUNET_DB_QueryStatus +postgres_lookup_wire_transfer (void *cls, + struct TALER_EXCHANGEDB_Session *session, + const struct TALER_WireTransferIdentifierRawP *wtid, + TALER_EXCHANGEDB_WireTransferDataCallback cb, + void *cb_cls) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (wtid), + GNUNET_PQ_query_param_end + }; + struct WireTransferResultContext ctx; + enum GNUNET_DB_QueryStatus qs; + + ctx.cb = cb; + ctx.cb_cls = cb_cls; + ctx.status = GNUNET_OK; + /* check if the melt record exists and get it */ + qs = GNUNET_PQ_eval_prepared_multi_select (session->conn, + "lookup_transactions", + params, + &handle_wt_result, + &ctx); + if (GNUNET_OK != ctx.status) + return GNUNET_DB_STATUS_HARD_ERROR; + return qs; } @@ -4733,10 +4765,9 @@ postgres_insert_aggregation_tracking (void *cls, * @param[out] end_date when does the fee end being valid * @param[out] wire_fee how high is the wire transfer fee * @param[out] master_sig signature over the above by the exchange master key - * @return #GNUNET_OK on success, #GNUNET_NO if no fee is known - * #GNUNET_SYSERR on failure + * @return status of the transaction */ -static int +static enum GNUNET_DB_QueryStatus postgres_get_wire_fee (void *cls, struct TALER_EXCHANGEDB_Session *session, const char *type, @@ -4758,42 +4789,11 @@ postgres_get_wire_fee (void *cls, GNUNET_PQ_result_spec_auto_from_type ("master_sig", master_sig), GNUNET_PQ_result_spec_end }; - PGresult *result; - int nrows; - result = GNUNET_PQ_exec_prepared (session->conn, - "get_wire_fee", - params); - if (PGRES_TUPLES_OK != - PQresultStatus (result)) - { - BREAK_DB_ERR (result, session->conn); - PQclear (result); - return GNUNET_SYSERR; - } - nrows = PQntuples (result); - if (0 == nrows) - { - /* no matches found */ - PQclear (result); - return GNUNET_NO; - } - if (1 != nrows) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - 0)) - { - PQclear (result); - GNUNET_break (0); - return GNUNET_SYSERR; - } - PQclear (result); - return GNUNET_OK; + return GNUNET_PQ_eval_prepared_singleton_select (session->conn, + "get_wire_fee", + params, + rs); } diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index 380b037cd..5c33418e1 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -1185,7 +1185,7 @@ test_wire_fees (struct TALER_EXCHANGEDB_Session *session) } /* This must fail as 'end_date' is NOT in the half-open interval [start_date,end_date) */ - if (GNUNET_OK == + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != plugin->get_wire_fee (plugin->cls, session, "wire-method", @@ -1198,7 +1198,7 @@ test_wire_fees (struct TALER_EXCHANGEDB_Session *session) GNUNET_break (0); return GNUNET_SYSERR; } - if (GNUNET_OK != + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != plugin->get_wire_fee (plugin->cls, session, "wire-method", @@ -1302,7 +1302,7 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session, TALER_amount_subtract (&transfer_value_wt, &coin_value_wt, &coin_fee_wt)); - FAILIF (GNUNET_NO != + FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != plugin->lookup_wire_transfer (plugin->cls, session, &wire_out_wtid, @@ -1344,7 +1344,7 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session, plugin->commit (plugin->cls, session)); - FAILIF (GNUNET_OK != + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != plugin->lookup_wire_transfer (plugin->cls, session, &wire_out_wtid, -- cgit v1.2.3