merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 39232092eb3038d720d81e6b7891f6bdd7c048f0
parent 9f9d2470b6363fc1070fe3004154e65746cd9ea5
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu,  4 Mar 2021 11:19:04 +0100

fix #6782

Diffstat:
Msrc/backenddb/plugin_merchantdb_postgres.c | 133+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 86 insertions(+), 47 deletions(-)

diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c @@ -4301,37 +4301,6 @@ postgres_lookup_transfers (void *cls, { struct PostgresClosure *pg = cls; uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - struct GNUNET_PQ_QueryParam params_payto_et[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_absolute_time (&before), - GNUNET_PQ_query_param_absolute_time (&after), - GNUNET_PQ_query_param_uint64 (&offset), - GNUNET_PQ_query_param_uint64 (&plimit), - GNUNET_PQ_query_param_string (payto_uri), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_QueryParam params_et[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_absolute_time (&before), - GNUNET_PQ_query_param_absolute_time (&after), - GNUNET_PQ_query_param_uint64 (&offset), - GNUNET_PQ_query_param_uint64 (&plimit), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_QueryParam params_payto[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_uint64 (&offset), - GNUNET_PQ_query_param_uint64 (&plimit), - GNUNET_PQ_query_param_string (payto_uri), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_QueryParam params_none[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_uint64 (&offset), - GNUNET_PQ_query_param_uint64 (&plimit), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_QueryParam *params; struct LookupTransfersContext ltc = { .cb = cb, .cb_cls = cb_cls, @@ -4339,27 +4308,97 @@ postgres_lookup_transfers (void *cls, .verified = verified }; enum GNUNET_DB_QueryStatus qs; - char stmt[128]; bool by_time; by_time = ( (before.abs_value_us != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) || - (after.abs_value_us != GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us) ); + (after.abs_value_us != + GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us) ); check_connection (pg); - GNUNET_snprintf (stmt, - sizeof (stmt), - "lookup_transfers%s%s%s", - (by_time) ? "_time" : "", - (NULL != payto_uri) ? "_payto" : "", - (limit > 0) ? "_asc" : "_desc"); - params = (by_time) - ? ( (NULL != payto_uri) ? params_payto_et : params_et) - : ( (NULL != payto_uri) ? params_payto : params_none); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - stmt, - params, - &lookup_transfers_cb, - &ltc); + if (by_time) + { + if (NULL != payto_uri) + { + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (instance_id), + GNUNET_PQ_query_param_absolute_time (&before), + GNUNET_PQ_query_param_absolute_time (&after), + GNUNET_PQ_query_param_uint64 (&offset), + GNUNET_PQ_query_param_uint64 (&plimit), + GNUNET_PQ_query_param_string (payto_uri), + GNUNET_PQ_query_param_end + }; + + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + (limit > 0) + ? "lookup_transfers_time_payto_asc" + : "lookup_transfers_time_payto_desc", + params, + &lookup_transfers_cb, + &ltc); + } + else + { + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (instance_id), + GNUNET_PQ_query_param_absolute_time (&before), + GNUNET_PQ_query_param_absolute_time (&after), + GNUNET_PQ_query_param_uint64 (&offset), + GNUNET_PQ_query_param_uint64 (&plimit), + GNUNET_PQ_query_param_end + }; + + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + (limit > 0) + ? "lookup_transfers_time_asc" + : "lookup_transfers_time_desc", + params, + &lookup_transfers_cb, + &ltc); + } + } + else + { + if (NULL != payto_uri) + { + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (instance_id), + GNUNET_PQ_query_param_uint64 (&offset), + GNUNET_PQ_query_param_uint64 (&plimit), + GNUNET_PQ_query_param_string (payto_uri), + GNUNET_PQ_query_param_end + }; + + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + (limit > 0) + ? "lookup_transfers_payto_asc" + : "lookup_transfers_payto_desc", + params, + &lookup_transfers_cb, + &ltc); + } + else + { + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (instance_id), + GNUNET_PQ_query_param_uint64 (&offset), + GNUNET_PQ_query_param_uint64 (&plimit), + GNUNET_PQ_query_param_end + }; + + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + (limit > 0) + ? "lookup_transfers_asc" + : "lookup_transfers_desc", + params, + &lookup_transfers_cb, + &ltc); + } + } if (0 >= qs) return qs; return ltc.qs;