merchant

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

commit 13885abcbe47c8abb52a8c7217d76e0a79d81aaa
parent bd78152f47c4f71291f3dd0671fe2601e4c6a760
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon,  6 Jul 2026 09:56:24 +0200

use new GNUNET_JSON_pack_conditional where appropriate

Diffstat:
Msrc/backend/taler-merchant-httpd_get-exchanges.c | 10++++------
Msrc/backend/taler-merchant-httpd_get-private-kyc.c | 24+++++++++---------------
Msrc/backend/taler-merchant-httpd_get-private-transfers.c | 22+++++++++-------------
Msrc/lib/merchant_api_patch-management-instances-INSTANCE.c | 40++++++++++++++++------------------------
Msrc/lib/merchant_api_post-management-instances.c | 41++++++++++++++++-------------------------
Msrc/testing/testing_api_cmd_post_using_templates.c | 10++++------
Msrc/util/base_terms_serialize.c | 20++++++++------------
Msrc/util/contract_choice_serialize.c | 10++++------
Msrc/util/order_choice_serialize.c | 10++++------
Msrc/util/product_sold_serialize.c | 32+++++++++++++-------------------
10 files changed, 87 insertions(+), 132 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_get-exchanges.c b/src/backend/taler-merchant-httpd_get-exchanges.c @@ -95,13 +95,11 @@ add_exchange ( GNUNET_JSON_pack_timestamp ("next_download", GNUNET_TIME_absolute_to_timestamp (next_download )), - GNUNET_TIME_absolute_is_zero (keys_expiration) - ? GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("dummy", - NULL)) - : GNUNET_JSON_pack_timestamp ("keys_expiration", + GNUNET_JSON_pack_conditional ( + ! GNUNET_TIME_absolute_is_zero (keys_expiration), + GNUNET_JSON_pack_timestamp ("keys_expiration", GNUNET_TIME_absolute_to_timestamp ( - keys_expiration)), + keys_expiration))), GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_object_steal ("debit_restrictions", debit_restrictions)), diff --git a/src/backend/taler-merchant-httpd_get-private-kyc.c b/src/backend/taler-merchant-httpd_get-private-kyc.c @@ -993,21 +993,15 @@ ekr_expand_response (struct ExchangeKycRequest *ekr) tos_accepted_early)), GNUNET_JSON_pack_uint64 ("exchange_http_status", ekr->last_http_status), - (TALER_EC_NONE == ekr->last_ec) - ? GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ( - "dummy", - NULL)) - : GNUNET_JSON_pack_uint64 ("exchange_code", - ekr->last_ec), - ekr->auth_ok - ? GNUNET_JSON_pack_data_auto ( - "access_token", - &ekr->access_token) - : GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ( - "dummy", - NULL)), + GNUNET_JSON_pack_conditional ( + TALER_EC_NONE != ekr->last_ec, + GNUNET_JSON_pack_uint64 ("exchange_code", + ekr->last_ec)), + GNUNET_JSON_pack_conditional ( + ekr->auth_ok, + GNUNET_JSON_pack_data_auto ( + "access_token", + &ekr->access_token)), GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_array_steal ( "limits", diff --git a/src/backend/taler-merchant-httpd_get-private-transfers.c b/src/backend/taler-merchant-httpd_get-private-transfers.c @@ -67,12 +67,10 @@ transfer_cb (void *cls, exchange_url), GNUNET_JSON_pack_uint64 ("transfer_serial_id", transfer_serial_id), - (0 == expected_transfer_serial_id) - ? GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("dummy", - NULL)) - : GNUNET_JSON_pack_uint64 ("expected_transfer_serial_id", - expected_transfer_serial_id), + GNUNET_JSON_pack_conditional ( + 0 != expected_transfer_serial_id, + GNUNET_JSON_pack_uint64 ("expected_transfer_serial_id", + expected_transfer_serial_id)), // FIXME: protocol breaking to remove... GNUNET_JSON_pack_bool ("verified", false), @@ -81,13 +79,11 @@ transfer_cb (void *cls, true), GNUNET_JSON_pack_bool ("expected", expected), - GNUNET_TIME_absolute_is_zero (execution_time) - ? GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("dummy", - NULL)) - : GNUNET_JSON_pack_timestamp ( - "execution_time", - GNUNET_TIME_absolute_to_timestamp (execution_time))); + GNUNET_JSON_pack_conditional ( + ! GNUNET_TIME_absolute_is_zero (execution_time), + GNUNET_JSON_pack_timestamp ( + "execution_time", + GNUNET_TIME_absolute_to_timestamp (execution_time)))); GNUNET_assert (0 == json_array_append_new (ja, r)); diff --git a/src/lib/merchant_api_patch-management-instances-INSTANCE.c b/src/lib/merchant_api_patch-management-instances-INSTANCE.c @@ -343,31 +343,23 @@ TALER_MERCHANT_patch_management_instances_start ( pmih->jurisdiction), GNUNET_JSON_pack_bool ("use_stefan", pmih->use_stefan), - GNUNET_JSON_pack_allow_null ( - pmih->have_default_wire_transfer_delay - ? GNUNET_JSON_pack_time_rel ("default_wire_transfer_delay", - pmih->default_wire_transfer_delay) - : GNUNET_JSON_pack_string ("default_wire_transfer_delay", - NULL)), - GNUNET_JSON_pack_allow_null ( - pmih->have_default_pay_delay - ? GNUNET_JSON_pack_time_rel ("default_pay_delay", - pmih->default_pay_delay) - : GNUNET_JSON_pack_string ("default_pay_delay", - NULL)), - GNUNET_JSON_pack_allow_null ( - pmih->have_default_refund_delay - ? GNUNET_JSON_pack_time_rel ("default_refund_delay", - pmih->default_refund_delay) - : GNUNET_JSON_pack_string ("default_refund_delay", - NULL)), - GNUNET_JSON_pack_allow_null ( - pmih->have_default_wire_transfer_rounding_interval - ? GNUNET_JSON_pack_time_rounder_interval ( + GNUNET_JSON_pack_conditional ( + pmih->have_default_wire_transfer_delay, + GNUNET_JSON_pack_time_rel ("default_wire_transfer_delay", + pmih->default_wire_transfer_delay)), + GNUNET_JSON_pack_conditional ( + pmih->have_default_pay_delay, + GNUNET_JSON_pack_time_rel ("default_pay_delay", + pmih->default_pay_delay)), + GNUNET_JSON_pack_conditional ( + pmih->have_default_refund_delay, + GNUNET_JSON_pack_time_rel ("default_refund_delay", + pmih->default_refund_delay)), + GNUNET_JSON_pack_conditional ( + pmih->have_default_wire_transfer_rounding_interval, + GNUNET_JSON_pack_time_rounder_interval ( "default_wire_transfer_rounding_interval", - pmih->default_wire_transfer_rounding_interval) - : GNUNET_JSON_pack_string ("default_wire_transfer_rounding_interval", - NULL)), + pmih->default_wire_transfer_rounding_interval)), GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_string ("email", pmih->email)), diff --git a/src/lib/merchant_api_post-management-instances.c b/src/lib/merchant_api_post-management-instances.c @@ -392,32 +392,23 @@ TALER_MERCHANT_post_management_instances_start ( pmih->jurisdiction), GNUNET_JSON_pack_bool ("use_stefan", pmih->use_stefan), - GNUNET_JSON_pack_allow_null ( - pmih->have_default_wire_transfer_delay - ? GNUNET_JSON_pack_time_rel ("default_wire_transfer_delay", - pmih->default_wire_transfer_delay) - : GNUNET_JSON_pack_string ("default_wire_transfer_delay", - NULL)), - GNUNET_JSON_pack_allow_null ( - pmih->have_default_pay_delay - ? GNUNET_JSON_pack_time_rel ("default_pay_delay", - pmih->default_pay_delay) - : GNUNET_JSON_pack_string ("default_pay_delay", - NULL)), - GNUNET_JSON_pack_allow_null ( - pmih->have_default_refund_delay - ? GNUNET_JSON_pack_time_rel ("default_refund_delay", - pmih->default_refund_delay) - : GNUNET_JSON_pack_string ("default_refund_delay", - NULL)), - GNUNET_JSON_pack_allow_null ( - pmih->have_default_wire_transfer_rounding_interval - ? GNUNET_JSON_pack_time_rounder_interval ( - "default_wire_transfer_rounding_interval", - pmih->default_wire_transfer_rounding_interval) - : GNUNET_JSON_pack_string ( + GNUNET_JSON_pack_conditional ( + pmih->have_default_wire_transfer_delay, + GNUNET_JSON_pack_time_rel ("default_wire_transfer_delay", + pmih->default_wire_transfer_delay)), + GNUNET_JSON_pack_conditional ( + pmih->have_default_pay_delay, + GNUNET_JSON_pack_time_rel ("default_pay_delay", + pmih->default_pay_delay)), + GNUNET_JSON_pack_conditional ( + pmih->have_default_refund_delay, + GNUNET_JSON_pack_time_rel ("default_refund_delay", + pmih->default_refund_delay)), + GNUNET_JSON_pack_conditional ( + pmih->have_default_wire_transfer_rounding_interval, + GNUNET_JSON_pack_time_rounder_interval ( "default_wire_transfer_rounding_interval", - NULL)), + pmih->default_wire_transfer_rounding_interval)), GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_string ("email", pmih->email)), diff --git a/src/testing/testing_api_cmd_post_using_templates.c b/src/testing/testing_api_cmd_post_using_templates.c @@ -574,12 +574,10 @@ make_order_json (const char *using_template_id, GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_string ( "using_template_id", using_template_id)), - NULL == amount - ? GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("amount", - NULL)) - : TALER_JSON_pack_amount ("amount", - &tamount), + GNUNET_JSON_pack_conditional ( + NULL != amount, + TALER_JSON_pack_amount ("amount", + &tamount)), GNUNET_JSON_pack_string ("fulfillment_url", "https://example.com"), GNUNET_JSON_pack_allow_null ( diff --git a/src/util/base_terms_serialize.c b/src/util/base_terms_serialize.c @@ -73,16 +73,12 @@ TALER_MERCHANT_base_terms_serialize ( GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_uint64 ("minimum_age", ct->minimum_age)), - (0 == ct->default_money_pot) - ? GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("dummy", - NULL)) - : GNUNET_JSON_pack_uint64 ("order_default_money_pot", - ct->default_money_pot), - GNUNET_TIME_absolute_is_never (ct->max_pickup_time.abs_time) - ? GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("dummy", - NULL)) - : GNUNET_JSON_pack_timestamp ("max_pickup_time", - ct->max_pickup_time)); + GNUNET_JSON_pack_conditional ( + 0 != ct->default_money_pot, + GNUNET_JSON_pack_uint64 ("order_default_money_pot", + ct->default_money_pot)), + GNUNET_JSON_pack_conditional ( + ! GNUNET_TIME_absolute_is_never (ct->max_pickup_time.abs_time), + GNUNET_JSON_pack_timestamp ("max_pickup_time", + ct->max_pickup_time))); } diff --git a/src/util/contract_choice_serialize.c b/src/util/contract_choice_serialize.c @@ -87,12 +87,10 @@ json_from_contract_output ( output->details.token.token_family_slug), GNUNET_JSON_pack_uint64 ("count", output->details.token.count), - GNUNET_TIME_absolute_is_zero (output->details.token.valid_at.abs_time) - ? GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("dummy", - NULL)) - : GNUNET_JSON_pack_timestamp ("valid_at", - output->details.token.valid_at), + GNUNET_JSON_pack_conditional ( + ! GNUNET_TIME_absolute_is_zero (output->details.token.valid_at.abs_time), + GNUNET_JSON_pack_timestamp ("valid_at", + output->details.token.valid_at)), GNUNET_JSON_pack_uint64 ("key_index", output->details.token.key_index)); case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_DONATION_RECEIPT: diff --git a/src/util/order_choice_serialize.c b/src/util/order_choice_serialize.c @@ -87,12 +87,10 @@ json_from_order_output ( output->details.token.token_family_slug), GNUNET_JSON_pack_uint64 ("count", output->details.token.count), - GNUNET_TIME_absolute_is_zero (output->details.token.valid_at.abs_time) - ? GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("dummy", - NULL)) - : GNUNET_JSON_pack_timestamp ("valid_at", - output->details.token.valid_at)); + GNUNET_JSON_pack_conditional ( + ! GNUNET_TIME_absolute_is_zero (output->details.token.valid_at.abs_time), + GNUNET_JSON_pack_timestamp ("valid_at", + output->details.token.valid_at))); case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_DONATION_RECEIPT: return GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("type", diff --git a/src/util/product_sold_serialize.c b/src/util/product_sold_serialize.c @@ -74,20 +74,16 @@ TALER_MERCHANT_product_sold_serialize ( GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_object_incref ("description_i18n", (json_t *) p->description_i18n)), - GNUNET_JSON_pack_allow_null ( - ( (0 != p->unit_quantity.integer) || - (0 != p->unit_quantity.fractional) ) - ? GNUNET_JSON_pack_string ("unit_quantity", - quantity_to_string (&p->unit_quantity)) - : GNUNET_JSON_pack_string ("dummy", - NULL) ), + GNUNET_JSON_pack_conditional ( + (0 != p->unit_quantity.integer) || + (0 != p->unit_quantity.fractional), + GNUNET_JSON_pack_string ("unit_quantity", + quantity_to_string (&p->unit_quantity))), /* Legacy */ - GNUNET_JSON_pack_allow_null ( - (0 == p->unit_quantity.fractional) - ? GNUNET_JSON_pack_uint64 ("quantity", - p->unit_quantity.integer) - : GNUNET_JSON_pack_string ("dummy", - NULL) ), + GNUNET_JSON_pack_conditional ( + 0 == p->unit_quantity.fractional, + GNUNET_JSON_pack_uint64 ("quantity", + p->unit_quantity.integer)), GNUNET_JSON_pack_bool ("prices_are_net", p->prices_are_net), GNUNET_JSON_pack_allow_null ( @@ -107,12 +103,10 @@ TALER_MERCHANT_product_sold_serialize ( GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_array_incref ("taxes", (json_t *) p->taxes)), - GNUNET_JSON_pack_allow_null ( - GNUNET_TIME_absolute_is_never (p->delivery_date.abs_time) - ? GNUNET_JSON_pack_string ("dummy", - NULL) - : GNUNET_JSON_pack_timestamp ("delivery_date", - p->delivery_date)), + GNUNET_JSON_pack_conditional ( + ! GNUNET_TIME_absolute_is_never (p->delivery_date.abs_time), + GNUNET_JSON_pack_timestamp ("delivery_date", + p->delivery_date)), GNUNET_JSON_pack_uint64 ("product_money_pot", p->product_money_pot)); }