From a118bd2c4951fa7b60737e3cca69e62266a1bcef Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 28 Jun 2020 11:04:48 +0200 Subject: deduplicate logic --- src/backenddb/plugin_merchantdb_postgres.c | 44 ++++++++++-------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 54d99d66..ae566021 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -1449,36 +1449,22 @@ postgres_lookup_contract_terms (void *cls, GNUNET_PQ_query_param_string (order_id), GNUNET_PQ_query_param_end }; - check_connection (pg); - if (NULL == contract_terms) - { - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("order_serial", - order_serial), - GNUNET_PQ_result_spec_end - }; - - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_contract_terms", - params, - rs); - } - else - { - struct GNUNET_PQ_ResultSpec rs[] = { - TALER_PQ_result_spec_json ("contract_terms", - contract_terms), - GNUNET_PQ_result_spec_uint64 ("order_serial", - order_serial), - GNUNET_PQ_result_spec_end - }; + struct GNUNET_PQ_ResultSpec rs[] = { + /* contract_terms must be first! */ + TALER_PQ_result_spec_json ("contract_terms", + contract_terms), + GNUNET_PQ_result_spec_uint64 ("order_serial", + order_serial), + GNUNET_PQ_result_spec_end + }; - *contract_terms = NULL; - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_contract_terms", - params, - rs); - } + check_connection (pg); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "lookup_contract_terms", + params, + (NULL != contract_terms) + ? rs + : &rs[1]); } -- cgit v1.2.3