summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-08-01 22:49:04 +0200
committerChristian Grothoff <christian@grothoff.org>2021-08-01 22:49:04 +0200
commit92b86cc5a7277de1a3b3ab55aaf37c83a649930e (patch)
treeeef73525a65c6fe6825559f050b8ea971ca8302a
parent4e18bf19dfed52aa448a0b0d8547c0be182ba36a (diff)
downloadmerchant-92b86cc5a7277de1a3b3ab55aaf37c83a649930e.tar.gz
merchant-92b86cc5a7277de1a3b3ab55aaf37c83a649930e.tar.bz2
merchant-92b86cc5a7277de1a3b3ab55aaf37c83a649930e.zip
finish implementing #6935
-rw-r--r--src/backend/taler-merchant-httpd_get-tips-ID.c42
-rw-r--r--src/backend/taler-merchant-httpd_post-orders-ID-abort.c98
-rw-r--r--src/backend/taler-merchant-httpd_post-orders-ID-claim.c9
-rw-r--r--src/backend/taler-merchant-httpd_post-orders-ID-refund.c111
-rw-r--r--src/backend/taler-merchant-httpd_post-tips-ID-pickup.c82
-rw-r--r--src/lib/merchant_api_lock_product.c19
-rw-r--r--src/lib/merchant_api_patch_instance.c45
-rw-r--r--src/lib/merchant_api_patch_order_forget.c11
-rw-r--r--src/lib/merchant_api_patch_product.c51
-rw-r--r--src/lib/merchant_api_post_instance_auth.c26
-rw-r--r--src/lib/merchant_api_post_instances.c71
-rw-r--r--src/lib/merchant_api_post_order_abort.c39
-rw-r--r--src/lib/merchant_api_post_order_claim.c24
-rw-r--r--src/lib/merchant_api_post_order_paid.c21
-rw-r--r--src/lib/merchant_api_post_order_pay.c57
-rw-r--r--src/lib/merchant_api_post_order_refund.c10
-rw-r--r--src/lib/merchant_api_post_orders.c33
-rw-r--r--src/lib/merchant_api_post_products.c52
-rw-r--r--src/lib/merchant_api_post_reserves.c12
-rw-r--r--src/lib/merchant_api_post_transfers.c25
-rw-r--r--src/lib/merchant_api_tip_authorize.c55
-rw-r--r--src/lib/merchant_api_tip_pickup2.c35
-rw-r--r--src/lib/merchant_api_wallet_post_order_refund.c13
23 files changed, 395 insertions, 546 deletions
diff --git a/src/backend/taler-merchant-httpd_get-tips-ID.c b/src/backend/taler-merchant-httpd_get-tips-ID.c
index 09640bde..5b0abd89 100644
--- a/src/backend/taler-merchant-httpd_get-tips-ID.c
+++ b/src/backend/taler-merchant-httpd_get-tips-ID.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2014-2020 Taler Systems SA
+ (C) 2014-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -244,15 +244,14 @@ TMH_get_tips_ID (const struct TMH_RequestHandler *rh,
else
{
json_t *context;
- context = json_pack ("{s:s, s:s, s:s}",
- "remaining_tip",
- TALER_amount2s (&remaining),
- "taler_tip_uri",
- uri,
- "taler_tip_qrcode_svg",
- qr);
- GNUNET_assert (NULL != context);
+ context = GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("remaining_tip",
+ &remaining),
+ GNUNET_JSON_pack_string ("taler_tip_uri",
+ uri),
+ GNUNET_JSON_pack_string ("taler_tip_qrcode_svg",
+ qr));
ret = TMH_return_from_template (connection,
( (0 == remaining.value) &&
(0 == remaining.fraction) )
@@ -273,19 +272,18 @@ TMH_get_tips_ID (const struct TMH_RequestHandler *rh,
}
else
{
- ret = TALER_MHD_reply_json_pack (connection,
- ( (0 == remaining.value) &&
- (0 == remaining.fraction) )
- ? MHD_HTTP_GONE
- : MHD_HTTP_OK,
- "{s:s, s:o, s:o}",
- "exchange_url",
- exchange_url,
- "tip_amount",
- TALER_JSON_from_amount (&remaining),
- "expiration",
- GNUNET_JSON_from_time_abs (
- expiration_round));
+ ret = TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ ( (0 == remaining.value) &&
+ (0 == remaining.fraction) )
+ ? MHD_HTTP_GONE
+ : MHD_HTTP_OK,
+ GNUNET_JSON_pack_string ("exchange_url",
+ exchange_url),
+ TALER_JSON_pack_amount ("tip_amount",
+ &remaining),
+ GNUNET_JSON_pack_time_abs ("expiration",
+ expiration_round));
}
GNUNET_free (exchange_url);
return ret;
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
index 759c3ba5..f0b2a0c2 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2014-2020 Taler Systems SA
+ (C) 2014-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
@@ -27,6 +27,7 @@
#include <taler/taler_json_lib.h>
#include <taler/taler_exchange_service.h>
#include "taler-merchant-httpd_exchanges.h"
+#include "taler-merchant-httpd_helper.h"
/**
@@ -366,49 +367,44 @@ generate_success_response (struct AbortContext *ac)
(0 == rdi->http_status) ||
(NULL == rdi->exchange_reply) )
hc = MHD_HTTP_BAD_GATEWAY;
- detail = (MHD_HTTP_OK != rdi->http_status)
- ? json_pack ("{s:s, s:I, s:I, s:O?}",
- "type",
- "failure",
- "exchange_status",
- (json_int_t) rdi->http_status,
- "exchange_code",
- (json_int_t)
- (NULL != rdi->exchange_reply)
- ? TALER_JSON_get_error_code (
- rdi->exchange_reply)
- : TALER_EC_GENERIC_INVALID_RESPONSE,
- "exchange_reply",
- rdi->exchange_reply)
- : json_pack ("{s:s, s:I, s:o, s:o}",
- "type",
- "success",
- "exchange_status",
- (json_int_t) rdi->http_status,
- "exchange_sig",
- GNUNET_JSON_from_data_auto (&rdi->exchange_sig),
- "exchange_pub",
- GNUNET_JSON_from_data_auto (&rdi->exchange_pub));
- if ( (NULL == detail) ||
- (0 != json_array_append_new (refunds,
- detail)) )
- {
- json_decref (refunds);
- GNUNET_break (0);
- resume_abort_with_error (ac,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE,
- "could not create JSON array");
- return;
- }
+ if (MHD_HTTP_OK != rdi->http_status)
+ detail = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "failure"),
+ GNUNET_JSON_pack_uint64 ("exchange_status",
+ rdi->http_status),
+ GNUNET_JSON_pack_uint64 ("exchange_code",
+ (NULL != rdi->exchange_reply)
+ ?
+ TALER_JSON_get_error_code (
+ rdi->exchange_reply)
+ :
+ TALER_EC_GENERIC_INVALID_RESPONSE),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("exchange_reply",
+ rdi->exchange_reply)));
+ else
+ detail = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "success"),
+ GNUNET_JSON_pack_uint64 ("exchange_status",
+ rdi->http_status),
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &rdi->exchange_sig),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
+ &rdi->exchange_pub));
+ GNUNET_assert (0 ==
+ json_array_append_new (refunds,
+ detail));
}
/* Resume and send back the response. */
- resume_abort_with_response (ac,
- hc,
- TALER_MHD_make_json_pack ("{s:o}",
- "refunds",
- refunds));
+ resume_abort_with_response (
+ ac,
+ hc,
+ TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_array_steal ("refunds",
+ refunds)));
}
@@ -534,13 +530,9 @@ process_abort_with_exchange (void *cls,
resume_abort_with_response (
ac,
MHD_HTTP_GATEWAY_TIMEOUT,
- TALER_MHD_make_json_pack (
- "{s:s, s:I}",
- "hint",
- TALER_ErrorCode_get_hint (
- TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT),
- "code",
- (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT));
+ TALER_MHD_make_error (
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT,
+ NULL));
return;
}
if (NULL == exchange_handle)
@@ -550,14 +542,10 @@ process_abort_with_exchange (void *cls,
resume_abort_with_response (
ac,
MHD_HTTP_BAD_GATEWAY,
- TALER_MHD_make_json_pack (
- "{s:s, s:I, s:I, s:I, s:O?}",
- "hint", TALER_ErrorCode_get_hint (
+ TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE),
- "code", (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE,
- "exchange_http_status", (json_int_t) hr->http_status,
- "exchange_code", (json_int_t) hr->ec,
- "exchange_reply", hr->reply));
+ TMH_pack_exchange_reply (hr)));
return;
}
/* Initiate refund operation for all coins of
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-claim.c b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c
index 8b3b80ea..537ea0e1 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-claim.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c
@@ -267,12 +267,13 @@ TMH_post_orders_ID_claim (const struct TMH_RequestHandler *rh,
GNUNET_CRYPTO_eddsa_sign (&hc->instance->merchant_priv.eddsa_priv,
&pdps,
&merchant_sig);
- return TALER_MHD_reply_json_pack (
+ return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
- "{ s:o, s:o }",
- "contract_terms", contract_terms,
- "sig", GNUNET_JSON_from_data_auto (&merchant_sig));
+ GNUNET_JSON_pack_object_steal ("contract_terms",
+ contract_terms),
+ GNUNET_JSON_pack_data_auto ("sig",
+ &merchant_sig));
}
}
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-refund.c b/src/backend/taler-merchant-httpd_post-orders-ID-refund.c
index 22c9f717..27622d63 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-refund.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-refund.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2020 Taler Systems SA
+ (C) 2020-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
@@ -738,60 +738,60 @@ TMH_post_orders_ID_refund (const struct TMH_RequestHandler *rh,
{
if (NULL == cr->exchange_reply)
{
- refund = json_pack ("{s:s,s:I,s:I,s:o,s:o,s:o}",
- "type",
- "failure",
- "exchange_status",
- (json_int_t) cr->exchange_status,
- "rtransaction_id",
- (json_int_t) cr->rtransaction_id,
- "coin_pub",
- GNUNET_JSON_from_data_auto (&cr->coin_pub),
- "refund_amount",
- TALER_JSON_from_amount (&cr->refund_amount),
- "execution_time",
- GNUNET_JSON_from_time_abs (cr->execution_time));
+ refund = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "failure"),
+ GNUNET_JSON_pack_uint64 ("exchange_status",
+ cr->exchange_status),
+ GNUNET_JSON_pack_uint64 ("rtransaction_id",
+ cr->rtransaction_id),
+ GNUNET_JSON_pack_data_auto ("coin_pub",
+ &cr->coin_pub),
+ TALER_JSON_pack_amount ("refund_amount",
+ &cr->refund_amount),
+ GNUNET_JSON_pack_time_abs ("execution_time",
+ cr->execution_time));
}
else
{
- refund = json_pack ("{s:s,s:I,s:I,s:O,s:I,s:o,s:o,s:o}",
- "type",
- "failure",
- "exchange_status",
- (json_int_t) cr->exchange_status,
- "exchange_code",
- (json_int_t) cr->exchange_code,
- "exchange_reply",
- cr->exchange_reply,
- "rtransaction_id",
- (json_int_t) cr->rtransaction_id,
- "coin_pub",
- GNUNET_JSON_from_data_auto (&cr->coin_pub),
- "refund_amount",
- TALER_JSON_from_amount (&cr->refund_amount),
- "execution_time",
- GNUNET_JSON_from_time_abs (cr->execution_time));
+ refund = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "failure"),
+ GNUNET_JSON_pack_uint64 ("exchange_status",
+ cr->exchange_status),
+ GNUNET_JSON_pack_uint64 ("exchange_code",
+ cr->exchange_code),
+ GNUNET_JSON_pack_object_incref ("exchange_reply",
+ cr->exchange_reply),
+ GNUNET_JSON_pack_uint64 ("rtransaction_id",
+ cr->rtransaction_id),
+ GNUNET_JSON_pack_data_auto ("coin_pub",
+ &cr->coin_pub),
+ TALER_JSON_pack_amount ("refund_amount",
+ &cr->refund_amount),
+ GNUNET_JSON_pack_time_abs ("execution_time",
+ cr->execution_time));
}
}
else
{
- refund = json_pack ("{s:s,s:I,s:o,s:o,s:I,s:o,s:o,s:o}",
- "type",
- "success",
- "exchange_status",
- (json_int_t) cr->exchange_status,
- "exchange_sig",
- GNUNET_JSON_from_data_auto (&cr->exchange_sig),
- "exchange_pub",
- GNUNET_JSON_from_data_auto (&cr->exchange_pub),
- "rtransaction_id",
- (json_int_t) cr->rtransaction_id,
- "coin_pub",
- GNUNET_JSON_from_data_auto (&cr->coin_pub),
- "refund_amount",
- TALER_JSON_from_amount (&cr->refund_amount),
- "execution_time",
- GNUNET_JSON_from_time_abs (cr->execution_time));
+ refund = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "success"),
+ GNUNET_JSON_pack_uint64 ("exchange_status",
+ cr->exchange_status),
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &cr->exchange_sig),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
+ &cr->exchange_pub),
+ GNUNET_JSON_pack_uint64 ("rtransaction_id",
+ cr->rtransaction_id),
+ GNUNET_JSON_pack_data_auto ("coin_pub",
+ &cr->coin_pub),
+ TALER_JSON_pack_amount ("refund_amount",
+ &cr->refund_amount),
+ GNUNET_JSON_pack_time_abs ("execution_time",
+ cr->execution_time));
}
GNUNET_assert (
0 ==
@@ -799,16 +799,15 @@ TMH_post_orders_ID_refund (const struct TMH_RequestHandler *rh,
refund));
}
- return TALER_MHD_reply_json_pack (
+ return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
- "{s:o, s:o, s:o}",
- "refund_amount",
- TALER_JSON_from_amount (&prd->refund_amount),
- "refunds",
- ra,
- "merchant_pub",
- GNUNET_JSON_from_data_auto (&hc->instance->merchant_pub));
+ TALER_JSON_pack_amount ("refund_amount",
+ &prd->refund_amount),
+ GNUNET_JSON_pack_array_steal ("refunds",
+ ra),
+ GNUNET_JSON_pack_data_auto ("merchant_pub",
+ &hc->instance->merchant_pub));
}
return MHD_YES;
diff --git a/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c
index 2bdef2bc..bd327b56 100644
--- a/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c
+++ b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2017-2020 Taler Systems SA
+ (C) 2017-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -25,6 +25,7 @@
#include <taler/taler_signatures.h>
#include "taler-merchant-httpd.h"
#include "taler-merchant-httpd_mhd.h"
+#include "taler-merchant-httpd_helper.h"
#include "taler-merchant-httpd_exchanges.h"
#include "taler-merchant-httpd_post-tips-ID-pickup.h"
@@ -292,12 +293,9 @@ withdraw_cb (void *cls,
stop_operations (pc);
pc->http_status = MHD_HTTP_BAD_GATEWAY;
pc->response =
- TALER_MHD_make_json_pack (
- "{s:I, s:I, s:I, s:O}",
- "code", (json_int_t) TALER_EC_MERCHANT_TIP_PICKUP_EXCHANGE_ERROR,
- "exchange_code", (json_int_t) hr->ec,
- "exchange_http_status", (json_int_t) hr->http_status,
- "exchange_reply", hr->reply);
+ TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (TALER_EC_MERCHANT_TIP_PICKUP_EXCHANGE_ERROR),
+ TMH_pack_exchange_reply (hr));
MHD_resume_connection (pc->connection);
TMH_trigger_daemon (); /* we resumed, kick MHD */
return;
@@ -359,13 +357,9 @@ do_withdraw (void *cls,
po);
GNUNET_free (po);
pc->http_status = MHD_HTTP_GATEWAY_TIMEOUT;
- pc->response = TALER_MHD_make_json_pack (
- "{s:s, s:I}",
- "hint",
- TALER_ErrorCode_get_hint (
- TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT),
- "code",
- (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT);
+ pc->response = TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT));
MHD_resume_connection (pc->connection);
TMH_trigger_daemon (); /* we resumed, kick MHD */
return;
@@ -379,14 +373,10 @@ do_withdraw (void *cls,
GNUNET_free (po);
pc->http_status = MHD_HTTP_BAD_GATEWAY;
pc->response =
- TALER_MHD_make_json_pack (
- "{s:s, s:I, s:I, s:I, s:O?}",
- "hint", TALER_ErrorCode_get_hint (
+ TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE),
- "code", (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE,
- "exchange_code", (json_int_t) hr->ec,
- "exchange_http_status", (json_int_t) hr->http_status,
- "exchange_reply", hr->reply);
+ TMH_pack_exchange_reply (hr));
MHD_resume_connection (pc->connection);
TMH_trigger_daemon (); /* we resumed, kick MHD */
return;
@@ -485,10 +475,8 @@ compute_total_requested (void *cls,
if (NULL == hr)
{
pc->http_status = MHD_HTTP_GATEWAY_TIMEOUT;
- pc->response = TALER_MHD_make_json_pack (
- "{s:I, s:s}",
- "code", (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT,
- "hint", TALER_ErrorCode_get_hint (
+ pc->response = TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT));
MHD_resume_connection (pc->connection);
TMH_trigger_daemon (); /* we resumed, kick MHD */
@@ -498,14 +486,10 @@ compute_total_requested (void *cls,
{
pc->http_status = MHD_HTTP_BAD_GATEWAY;
pc->response =
- TALER_MHD_make_json_pack (
- "{s:I, s:s, s:I, s:I, s:O}",
- "code", (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE,
- "hint", TALER_ErrorCode_get_hint (
+ TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE),
- "exchange_code", (json_int_t) hr->ec,
- "exchange_http_status", (json_int_t) hr->http_status,
- "exchange_reply", hr->reply);
+ TMH_pack_exchange_reply (hr));
MHD_resume_connection (pc->connection);
TMH_trigger_daemon (); /* we resumed, kick MHD */
return;
@@ -514,14 +498,10 @@ compute_total_requested (void *cls,
{
pc->http_status = MHD_HTTP_BAD_GATEWAY;
pc->response =
- TALER_MHD_make_json_pack (
- "{s:I, s:s, s:I, s:I, s:O}",
- "code", (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_KEYS_FAILURE,
- "hint", TALER_ErrorCode_get_hint (
+ TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
TALER_EC_MERCHANT_GENERIC_EXCHANGE_KEYS_FAILURE),
- "exchange_code", (json_int_t) hr->ec,
- "exchange_http_status", (json_int_t) hr->http_status,
- "exchange_reply", hr->reply);
+ TMH_pack_exchange_reply (hr));
MHD_resume_connection (pc->connection);
TMH_trigger_daemon (); /* we resumed, kick MHD */
return;
@@ -540,13 +520,10 @@ compute_total_requested (void *cls,
{
pc->http_status = MHD_HTTP_CONFLICT;
pc->response =
- TALER_MHD_make_json_pack (
- "{s:I, s:I, s:I, s:O}",
- "code",
- (json_int_t) TALER_EC_MERCHANT_TIP_PICKUP_DENOMINATION_UNKNOWN,
- "exchange_code", (json_int_t) hr->ec,
- "exchange_http_status", (json_int_t) hr->http_status,
- "exchange_reply", hr->reply);
+ TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
+ TALER_EC_MERCHANT_TIP_PICKUP_DENOMINATION_UNKNOWN),
+ TMH_pack_exchange_reply (hr));
MHD_resume_connection (pc->connection);
TMH_trigger_daemon (); /* we resumed, kick MHD */
return;
@@ -869,17 +846,16 @@ RETRY:
GNUNET_assert (0 ==
json_array_append_new (
blind_sigs,
- json_pack ("{s:o}",
- "blind_sig",
- GNUNET_JSON_from_rsa_signature (
- sigs[i]))));
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_rsa_signature ("blind_sig",
+ sigs[i]))));
GNUNET_CRYPTO_rsa_signature_free (sigs[i]);
}
- return TALER_MHD_reply_json_pack (
+ return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
- "{s:o}",
- "blind_sigs", blind_sigs);
+ GNUNET_JSON_pack_array_steal ("blind_sigs",
+ blind_sigs));
}
break;
case GNUNET_DB_STATUS_SOFT_ERROR:
diff --git a/src/lib/merchant_api_lock_product.c b/src/lib/merchant_api_lock_product.c
index e9593fdb..a3c345d5 100644
--- a/src/lib/merchant_api_lock_product.c
+++ b/src/lib/merchant_api_lock_product.c
@@ -168,18 +168,13 @@ TALER_MERCHANT_product_lock (
struct TALER_MERCHANT_ProductLockHandle *plh;
json_t *req_obj;
- req_obj = json_pack ("{s:o, s:o, s:I}",
- "lock_uuid",
- GNUNET_JSON_from_data_auto (uuid),
- "duration",
- GNUNET_JSON_from_time_rel (duration),
- "quantity",
- (json_int_t) quantity);
- if (NULL == req_obj)
- {
- GNUNET_break (0);
- return NULL;
- }
+ req_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("lock_uuid",
+ uuid),
+ GNUNET_JSON_pack_time_rel ("duration",
+ duration),
+ GNUNET_JSON_pack_uint64 ("quantity",
+ quantity));
plh = GNUNET_new (struct TALER_MERCHANT_ProductLockHandle);
plh->ctx = ctx;
plh->cb = cb;
diff --git a/src/lib/merchant_api_patch_instance.c b/src/lib/merchant_api_patch_instance.c
index 74256330..5515e5e1 100644
--- a/src/lib/merchant_api_patch_instance.c
+++ b/src/lib/merchant_api_patch_instance.c
@@ -189,32 +189,25 @@ TALER_MERCHANT_instance_patch (
return NULL;
}
}
- req_obj = json_pack ("{s:o, s:s, s:O, s:O"
- " s:o, s:I: s:o, s:o, s:o}",
- "payto_uris",
- jpayto_uris,
- "name",
- name,
- "address",
- address,
- "jurisdiction",
- jurisdiction,
- /* end of group of 4 */
- "default_max_wire_fee",
- TALER_JSON_from_amount (default_max_wire_fee),
- "default_wire_fee_amortization",
- (json_int_t) default_wire_fee_amortization,
- "default_max_deposit_fee",
- TALER_JSON_from_amount (default_max_deposit_fee),
- "default_wire_transfer_delay",
- GNUNET_JSON_from_time_rel (default_wire_transfer_delay),
- "default_pay_delay",
- GNUNET_JSON_from_time_rel (default_pay_delay));
- if (NULL == req_obj)
- {
- GNUNET_break (0);
- return NULL;
- }
+ req_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_array_steal ("payto_uris",
+ jpayto_uris),
+ GNUNET_JSON_pack_string ("name",
+ name),
+ GNUNET_JSON_pack_object_incref ("address",
+ (json_t *) address),
+ GNUNET_JSON_pack_object_incref ("jurisdiction",
+ (json_t *) jurisdiction),
+ TALER_JSON_pack_amount ("default_max_wire_fee",
+ default_max_wire_fee),
+ GNUNET_JSON_pack_uint64 ("default_wire_fee_amortization",
+ default_wire_fee_amortization),
+ TALER_JSON_pack_amount ("default_max_deposit_fee",
+ default_max_deposit_fee),
+ GNUNET_JSON_pack_time_rel ("default_wire_transfer_delay",
+ default_wire_transfer_delay),
+ GNUNET_JSON_pack_time_rel ("default_pay_delay",
+ default_pay_delay));
iph = GNUNET_new (struct TALER_MERCHANT_InstancePatchHandle);
iph->ctx = ctx;
iph->cb = cb;
diff --git a/src/lib/merchant_api_patch_order_forget.c b/src/lib/merchant_api_patch_order_forget.c
index 69563aaf..e6a36ad4 100644
--- a/src/lib/merchant_api_patch_order_forget.c
+++ b/src/lib/merchant_api_patch_order_forget.c
@@ -177,14 +177,9 @@ TALER_MERCHANT_order_forget (struct GNUNET_CURL_Context *ctx,
return NULL;
}
}
- req_obj = json_pack ("{s:o}",
- "fields",
- req_fields);
- if (NULL == req_obj)
- {
- GNUNET_break (0);
- return NULL;
- }
+ req_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_array_steal ("fields",
+ req_fields));
ofh = GNUNET_new (struct TALER_MERCHANT_OrderForgetHandle);
ofh->ctx = ctx;
ofh->cb = cb;
diff --git a/src/lib/merchant_api_patch_product.c b/src/lib/merchant_api_patch_product.c
index 5cd1747e..da0e41ed 100644
--- a/src/lib/merchant_api_patch_product.c
+++ b/src/lib/merchant_api_patch_product.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
+ Copyright (C) 2020, 2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
@@ -176,34 +176,27 @@ TALER_MERCHANT_product_patch (
json_t *req_obj;
(void) GNUNET_TIME_round_abs (&next_restock);
- req_obj = json_pack ("{s:s, s:O, s:s, s:o, s:s,"
- " s:O, s:I: s:I, s:O, s:o}",
- "description",
- description,
- "description_i18n",
- description_i18n,
- "unit",
- unit,
- "price",
- TALER_JSON_from_amount (price),
- "image",
- image,
- /* End of first group of 5 */
- "taxes",
- taxes,
- "total_stock",
- (json_int_t) total_stock,
- "total_lost",
- (json_int_t) total_lost,
- "address",
- address,
- "next_restock",
- GNUNET_JSON_from_time_abs (next_restock));
- if (NULL == req_obj)
- {
- GNUNET_break (0);
- return NULL;
- }
+ req_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("description",
+ description),
+ GNUNET_JSON_pack_object_incref ("description_i18n",
+ (json_t *) description_i18n),
+ GNUNET_JSON_pack_string ("unit",
+ unit),
+ TALER_JSON_pack_amount ("price",
+ price),
+ GNUNET_JSON_pack_string ("image",
+ image),
+ GNUNET_JSON_pack_array_incref ("taxes",
+ (json_t *) taxes),
+ GNUNET_JSON_pack_uint64 ("total_stock",
+ total_stock),
+ GNUNET_JSON_pack_uint64 ("total_lost",
+ total_lost),
+ GNUNET_JSON_pack_object_incref ("address",
+ (json_t *) address),
+ GNUNET_JSON_pack_time_abs ("next_restock",
+ next_restock));
pph = GNUNET_new (struct TALER_MERCHANT_ProductPatchHandle);
pph->ctx = ctx;
pph->cb = cb;
diff --git a/src/lib/merchant_api_post_instance_auth.c b/src/lib/merchant_api_post_instance_auth.c
index a659ffb5..bda209ee 100644
--- a/src/lib/merchant_api_post_instance_auth.c
+++ b/src/lib/merchant_api_post_instance_auth.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2018, 2020 Taler Systems SA
+ Copyright (C) 2014-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software
@@ -168,24 +168,17 @@ TALER_MERCHANT_instance_auth_post (
}
if (NULL == auth_token)
{
- req_obj = json_pack ("{s:s}",
- "method",
- "external");
+ req_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("method",
+ "external"));
}
else
{
- req_obj = json_pack ("{s:s, s:s}",
- "method",
- "token",
- "token",
- auth_token);
- }
- if (NULL == req_obj)
- {
- GNUNET_break (0);
- GNUNET_free (iaph->url);
- GNUNET_free (iaph);
- return NULL;
+ req_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("method",
+ "token"),
+ GNUNET_JSON_pack_string ("token",
+ auth_token));
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Requesting URL '%s'\n",
@@ -194,6 +187,7 @@ TALER_MERCHANT_instance_auth_post (
CURL *eh;
eh = curl_easy_init ();
+ GNUNET_assert (NULL != eh);
if (GNUNET_OK !=
TALER_curl_easy_post (&iaph->post_ctx,
eh,
diff --git a/src/lib/merchant_api_post_instances.c b/src/lib/merchant_api_post_instances.c
index 8aede243..6101e192 100644
--- a/src/lib/merchant_api_post_instances.c
+++ b/src/lib/merchant_api_post_instances.c
@@ -191,17 +191,17 @@ TALER_MERCHANT_instances_post (
RFC_8959_PREFIX);
return NULL;
}
- auth_obj = json_pack ("{s:s, s:s}",
- "method",
- "token",
- "token",
- auth_token);
+ auth_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("method",
+ "token"),
+ GNUNET_JSON_pack_string ("token",
+ auth_token));
}
else
{
- auth_obj = json_pack ("{s:s}",
- "method",
- "external");
+ auth_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("method",
+ "external"));
}
if (NULL == auth_obj)
{
@@ -227,38 +227,29 @@ TALER_MERCHANT_instances_post (
return NULL;
}
}
- req_obj = json_pack ("{s:o, s:s, s:s, s:O, s:O"
- ",s:o, s:I: s:o, s:o, s:o"
- ",s:o}",
- "payto_uris",
- jpayto_uris,
- "id",
- instance_id,
- "name",
- name,
- "address",
- address,
- "jurisdiction",
- jurisdiction,
- /* end of group of 5 */
- "default_max_wire_fee",
- TALER_JSON_from_amount (default_max_wire_fee),
- "default_wire_fee_amortization",
- (json_int_t) default_wire_fee_amortization,
- "default_max_deposit_fee",
- TALER_JSON_from_amount (default_max_deposit_fee),
- "default_wire_transfer_delay",
- GNUNET_JSON_from_time_rel (default_wire_transfer_delay),
- "default_pay_delay",
- GNUNET_JSON_from_time_rel (default_pay_delay),
- "auth",
- auth_obj);
- if (NULL == req_obj)
- {
- json_decref (auth_obj);
- GNUNET_break (0);
- return NULL;
- }
+ req_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_array_steal ("payto_uris",
+ jpayto_uris),
+ GNUNET_JSON_pack_string ("id",
+ instance_id),
+ GNUNET_JSON_pack_string ("name",
+ name),
+ GNUNET_JSON_pack_object_incref ("address",
+ (json_t *) address),
+ GNUNET_JSON_pack_object_incref ("jurisdiction",
+ (json_t *) jurisdiction),
+ TALER_JSON_pack_amount ("default_max_wire_fee",
+ default_max_wire_fee),
+ GNUNET_JSON_pack_uint64 ("default_wire_fee_amortization",
+ default_wire_fee_amortization),
+ TALER_JSON_pack_amount ("default_max_deposit_fee",
+ default_max_deposit_fee),
+ GNUNET_JSON_pack_time_rel ("default_wire_transfer_delay",
+ default_wire_transfer_delay),
+ GNUNET_JSON_pack_time_rel ("default_pay_delay",
+ default_pay_delay),
+ GNUNET_JSON_pack_object_steal ("auth",
+ auth_obj));
iph = GNUNET_new (struct TALER_MERCHANT_InstancesPostHandle);
iph->ctx = ctx;
iph->cb = cb;
diff --git a/src/lib/merchant_api_post_order_abort.c b/src/lib/merchant_api_post_order_abort.c
index f8cdaab4..47df8ec4 100644
--- a/src/lib/merchant_api_post_order_abort.c
+++ b/src/lib/merchant_api_post_order_abort.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015, 2016, 2017, 2020 Taler Systems SA
+ Copyright (C) 2014-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
@@ -348,34 +348,27 @@ TALER_MERCHANT_order_abort (struct GNUNET_CURL_Context *ctx,
json_t *j_coin;
/* create JSON for this coin */
- j_coin = json_pack (
- "{s:o, s:o,s:s}",
- "coin_pub",
- GNUNET_JSON_from_data_auto (&ac->coin_pub),
- "contribution",
- TALER_JSON_from_amount (&ac->amount_with_fee),
- "exchange_url",
- ac->exchange_url);
- if ( (NULL == j_coin) ||
- (0 !=
- json_array_append_new (j_coins,
- j_coin)) )
+ j_coin = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("coin_pub",
+ &ac->coin_pub),
+ TALER_JSON_pack_amount ("contribution",
+ &ac->amount_with_fee),
+ GNUNET_JSON_pack_string ("exchange_url",
+ ac->exchange_url));
+ if (0 !=
+ json_array_append_new (j_coins,
+ j_coin))
{
GNUNET_break (0);
json_decref (j_coins);
return NULL;
}
}
- abort_obj = json_pack ("{s:o,s:o}",
- "coins",
- j_coins, /* reference consumed! */
- "h_contract",
- GNUNET_JSON_from_data_auto (h_contract));
- if (NULL == abort_obj)
- {
- GNUNET_break (0);
- return NULL;
- }
+ abort_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_array_steal ("coins",
+ j_coins),
+ GNUNET_JSON_pack_data_auto ("h_contract",
+ h_contract));
oah = GNUNET_new (struct TALER_MERCHANT_OrderAbortHandle);
oah->h_contract_terms = *h_contract;
oah->merchant_pub = *merchant_pub;
diff --git a/src/lib/merchant_api_post_order_claim.c b/src/lib/merchant_api_post_order_claim.c
index 80c4949a..442185b5 100644
--- a/src/lib/merchant_api_post_order_claim.c
+++ b/src/lib/merchant_api_post_order_claim.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
+ Copyright (C) 2014-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
@@ -182,22 +182,12 @@ TALER_MERCHANT_order_claim (struct GNUNET_CURL_Context *ctx,
GNUNET_break (0);
return NULL;
}
- req_obj = json_pack ("{s:o}",
- "nonce",
- GNUNET_JSON_from_data_auto (nonce));
- if (NULL == req_obj)
- {
- GNUNET_break (0);
- return NULL;
- }
- if (NULL != claim_token)
- {
- GNUNET_assert (0 ==
- json_object_set_new (req_obj,
- "token",
- GNUNET_JSON_from_data_auto (
- claim_token)));
- }
+ req_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("nonce",
+ nonce),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_data_auto ("token",
+ claim_token)));
och = GNUNET_new (struct TALER_MERCHANT_OrderClaimHandle);
och->ctx = ctx;
och->cb = cb;
diff --git a/src/lib/merchant_api_post_order_paid.c b/src/lib/merchant_api_post_order_paid.c
index cdb4ae23..cb3a8379 100644
--- a/src/lib/merchant_api_post_order_paid.c
+++ b/src/lib/merchant_api_post_order_paid.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
+ Copyright (C) 2020-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
@@ -173,18 +173,13 @@ TALER_MERCHANT_order_paid (
struct TALER_MERCHANT_OrderPaidHandle *oph;
json_t *req_obj;
- req_obj = json_pack ("{s:o, s:o, s:s}",
- "sig",
- GNUNET_JSON_from_data_auto (merchant_sig),
- "h_contract",
- GNUNET_JSON_from_data_auto (h_contract_terms),
- "session_id",
- session_id);
- if (NULL == req_obj)
- {
- GNUNET_break (0);
- return NULL;
- }
+ req_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("sig",
+ merchant_sig),
+ GNUNET_JSON_pack_data_auto ("h_contract",
+ h_contract_terms),
+ GNUNET_JSON_pack_string ("session_id",
+ session_id));
oph = GNUNET_new (struct TALER_MERCHANT_OrderPaidHandle);
oph->ctx = ctx;
oph->paid_cb = paid_cb;
diff --git a/src/lib/merchant_api_post_order_pay.c b/src/lib/merchant_api_post_order_pay.c
index 8decd2b1..e5d8cb5e 100644
--- a/src/lib/merchant_api_post_order_pay.c
+++ b/src/lib/merchant_api_post_order_pay.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015, 2016, 2017, 2020 Taler Systems SA
+ Copyright (C) 2014-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
@@ -481,22 +481,19 @@ TALER_MERCHANT_order_pay_frontend (
GNUNET_CRYPTO_rsa_public_key_hash (pc->denom_pub.rsa_public_key,
&denom_hash);
/* create JSON for this coin */
- j_coin = json_pack (
- "{s:o, s:o," /* contribution/coin_pub */
- " s:s, s:o," /* exchange_url / denom_pub */
- " s:o, s:o}", /* ub_sig / coin_sig */
- "contribution",
- TALER_JSON_from_amount (&pc->amount_with_fee),
- "coin_pub",
- GNUNET_JSON_from_data_auto (&pc->coin_pub),
- "exchange_url",
- pc->exchange_url,
- "h_denom",
- GNUNET_JSON_from_data_auto (&denom_hash),
- "ub_sig",
- GNUNET_JSON_from_rsa_signature (pc->denom_sig.rsa_signature),
- "coin_sig",
- GNUNET_JSON_from_data_auto (&pc->coin_sig));
+ j_coin = GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("contribution",
+ &pc->amount_with_fee),
+ GNUNET_JSON_pack_data_auto ("coin_pub",
+ &pc->coin_pub),
+ GNUNET_JSON_pack_string ("exchange_url",
+ pc->exchange_url),
+ GNUNET_JSON_pack_data_auto ("h_denom",
+ &denom_hash),
+ TALER_JSON_pack_denomination_signature ("ub_sig",
+ &pc->denom_sig),
+ GNUNET_JSON_pack_data_auto ("coin_sig",
+ &pc->coin_sig));
if (0 !=
json_array_append_new (j_coins,
j_coin))
@@ -507,26 +504,12 @@ TALER_MERCHANT_order_pay_frontend (
}
}
- pay_obj = json_pack ("{ s:o }",
- "coins",
- j_coins);
- if (NULL == pay_obj)
- {
- GNUNET_break (0);
- return NULL;
- }
- if (NULL != session_id)
- {
- if (0 !=
- json_object_set_new (pay_obj,
- "session_id",
- json_string (session_id)))
- {
- GNUNET_break (0);
- json_decref (pay_obj);
- return NULL;
- }
- }
+ pay_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_array_steal ("coins",
+ j_coins),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("session_id",
+ session_id)));
oph = GNUNET_new (struct TALER_MERCHANT_OrderPayHandle);
oph->ctx = ctx;
diff --git a/src/lib/merchant_api_post_order_refund.c b/src/lib/merchant_api_post_order_refund.c
index 63ed2f2c..9829e187 100644
--- a/src/lib/merchant_api_post_order_refund.c
+++ b/src/lib/merchant_api_post_order_refund.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015, 2016, 2017, 2019, 2020 Taler Systems SA
+ Copyright (C) 2014-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software
@@ -215,9 +215,11 @@ TALER_MERCHANT_post_order_refund (struct GNUNET_CURL_Context *ctx,
GNUNET_free (orh);
return NULL;
}
- req = json_pack ("{s:o, s:s}",
- "refund", TALER_JSON_from_amount (refund),
- "reason", reason);
+ req = GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("refund",
+ refund),
+ GNUNET_JSON_pack_string ("reason",
+ reason));
GNUNET_assert (NULL != req);
eh = curl_easy_init ();
GNUNET_assert (NULL != eh);
diff --git a/src/lib/merchant_api_post_orders.c b/src/lib/merchant_api_post_orders.c
index a79b9904..ae804ddf 100644
--- a/src/lib/merchant_api_post_orders.c
+++ b/src/lib/merchant_api_post_orders.c
@@ -260,9 +260,12 @@ TALER_MERCHANT_orders_post2 (
po->url = TALER_url_join (backend_url,
"private/orders",
NULL);
- req = json_pack ("{s:O}",
- "order", (json_t *) order);
- GNUNET_assert (NULL != req);
+ req = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_object_incref ("order",
+ (json_t *) order),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("payment_target",
+ payment_target)));
if (0 != refund_delay.rel_value_us)
{
GNUNET_assert (0 ==
@@ -271,13 +274,6 @@ TALER_MERCHANT_orders_post2 (
GNUNET_JSON_from_time_rel (
refund_delay)));
}
- if (NULL != payment_target)
- {
- GNUNET_assert (0 ==
- json_object_set_new (req,
- "payment_target",
- json_string (payment_target)));
- }
if (0 != inventory_products_length)
{
json_t *ipa = json_array ();
@@ -287,11 +283,11 @@ TALER_MERCHANT_orders_post2 (
{
json_t *ip;
- ip = json_pack ("{s:s, s:I}",
- "product_id",
- inventory_products[i].product_id,
- "quantity",
- (json_int_t) inventory_products[i].quantity);
+ ip = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("product_id",
+ inventory_products[i].product_id),
+ GNUNET_JSON_pack_uint64 ("quantity",
+ inventory_products[i].quantity));
GNUNET_assert (NULL != ip);
GNUNET_assert (0 ==
json_array_append_new (ipa,
@@ -311,10 +307,9 @@ TALER_MERCHANT_orders_post2 (
{
json_t *u;
- u = json_pack ("{s:o}",
- "uuid",
- GNUNET_JSON_from_data_auto (&uuids[i]));
- GNUNET_assert (NULL != u);
+ u = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("uuid",
+ &uuids[i]));
GNUNET_assert (0 ==
json_array_append_new (ua,
u));
diff --git a/src/lib/merchant_api_post_products.c b/src/lib/merchant_api_post_products.c
index 5ef8b90e..c8aeb9c9 100644
--- a/src/lib/merchant_api_post_products.c
+++ b/src/lib/merchant_api_post_products.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
+ Copyright (C) 2020-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
@@ -177,34 +177,28 @@ TALER_MERCHANT_products_post (
json_t *req_obj;
(void) GNUNET_TIME_round_abs (&next_restock);
- req_obj = json_pack ("{s:s, s:s, s:O, s:s, s:o,"
- " s:s, s:O, s:I, s:O, s:o}",
- "product_id",
- product_id,
- "description",
- description,
- "description_i18n",
- description_i18n,
- "unit",
- unit,
- "price",
- TALER_JSON_from_amount (price),
- /* End of first group of 5 */
- "image",
- image,
- "taxes",
- taxes,
- "total_stock",
- (json_int_t) total_stock,
- "address",
- address,
- "next_restock",
- GNUNET_JSON_from_time_abs (next_restock));
- if (NULL == req_obj)
- {
- GNUNET_break (0);
- return NULL;
- }
+ req_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("product_id",
+ product_id),
+ GNUNET_JSON_pack_string ("description",
+ description),
+ GNUNET_JSON_pack_object_incref ("description_i18n",
+ (json_t *) description_i18n),
+ GNUNET_JSON_pack_string ("unit",
+ unit),
+ TALER_JSON_pack_amount ("price",
+ price),
+ GNUNET_JSON_pack_string ("image",
+ image),
+ GNUNET_JSON_pack_array_incref ("taxes",
+ (json_t *) taxes),
+ GNUNET_JSON_pack_uint64 ("total_stock",
+ total_stock),
+ GNUNET_JSON_pack_object_incref ("address",
+ (json_t *) address),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_time_abs ("next_restock",
+ next_restock)));
pph = GNUNET_new (struct TALER_MERCHANT_ProductsPostHandle);
pph->ctx = ctx;
pph->cb = cb;
diff --git a/src/lib/merchant_api_post_reserves.c b/src/lib/merchant_api_post_reserves.c
index 8a8dee2d..6957d480 100644
--- a/src/lib/merchant_api_post_reserves.c
+++ b/src/lib/merchant_api_post_reserves.c
@@ -197,11 +197,13 @@ TALER_MERCHANT_reserves_post (
GNUNET_free (prh);
return NULL;
}
- req = json_pack ("{s:o, s:s, s:s}",
- "initial_balance", TALER_JSON_from_amount (initial_balance),
- "wire_method", wire_method,
- "exchange_url", exchange_url);
- GNUNET_assert (NULL != req);
+ req = GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("initial_balance",
+ initial_balance),
+ GNUNET_JSON_pack_string ("wire_method",
+ wire_method),
+ GNUNET_JSON_pack_string ("exchange_url",
+ exchange_url));
eh = curl_easy_init ();
GNUNET_assert (NULL != eh);
if (GNUNET_OK != TALER_curl_easy_post (&prh->post_ctx,
diff --git a/src/lib/merchant_api_post_transfers.c b/src/lib/merchant_api_post_transfers.c
index 3e1a55d5..62984835 100644
--- a/src/lib/merchant_api_post_transfers.c
+++ b/src/lib/merchant_api_post_transfers.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015, 2016, 2020 Taler Systems SA
+ Copyright (C) 2014-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software
@@ -104,9 +104,9 @@ handle_post_transfers_finished (void *cls,
json_t *deposit_sums;
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_amount_any ("total",
- &total),
+ &total),
TALER_JSON_spec_amount_any ("wire_fee",
- &wire_fee),
+ &wire_fee),
TALER_JSON_spec_absolute_time ("execution_time",
&execution_time),
GNUNET_JSON_spec_json ("deposit_sums",
@@ -149,9 +149,9 @@ handle_post_transfers_finished (void *cls,
GNUNET_JSON_spec_string ("order_id",
&d->order_id),
TALER_JSON_spec_amount_any ("deposit_value",
- &d->deposit_value),
+ &d->deposit_value),
TALER_JSON_spec_amount_any ("deposit_fee",
- &d->deposit_fee),
+ &d->deposit_fee),
GNUNET_JSON_spec_end ()
};
@@ -300,12 +300,15 @@ TALER_MERCHANT_transfers_post (
GNUNET_free (pth);
return NULL;
}
- req = json_pack ("{s:o, s:o, s:s, s:s}",
- "credit_amount", TALER_JSON_from_amount (credit_amount),
- "wtid", GNUNET_JSON_from_data_auto (wtid),
- "payto_uri", payto_uri,
- "exchange_url", exchange_url);
- GNUNET_assert (NULL != req);
+ req = GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("credit_amount",
+ credit_amount),
+ GNUNET_JSON_pack_data_auto ("wtid",
+ wtid),
+ GNUNET_JSON_pack_string ("payto_uri",
+ payto_uri),
+ GNUNET_JSON_pack_string ("exchange_url",
+ exchange_url));
eh = curl_easy_init ();
GNUNET_assert (NULL != eh);
if (GNUNET_OK != TALER_curl_easy_post (&pth->post_ctx,
diff --git a/src/lib/merchant_api_tip_authorize.c b/src/lib/merchant_api_tip_authorize.c
index d45f61a9..0a9c3d86 100644
--- a/src/lib/merchant_api_tip_authorize.c
+++ b/src/lib/merchant_api_tip_authorize.c
@@ -256,26 +256,19 @@ TALER_MERCHANT_tip_authorize2 (
GNUNET_free (tao);
return NULL;
}
- te_obj = json_pack ("{"
- " s:o," /* amount */
- " s:s," /* justification */
- " s:s," /* next_url */
- "}",
- "amount", TALER_JSON_from_amount (amount),
- "justification", justification,
- "next_url", next_url);
- if (NULL == te_obj)
- {
- GNUNET_break (0);
- GNUNET_free (tao->url);
- GNUNET_free (tao);
- return NULL;
- }
-
+ te_obj = GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("amount",
+ amount),
+ GNUNET_JSON_pack_string ("justification",
+ justification),
+ GNUNET_JSON_pack_string ("next_url",
+ next_url));
eh = curl_easy_init ();
- if (GNUNET_OK != TALER_curl_easy_post (&tao->post_ctx,
- eh,
- te_obj))
+ GNUNET_assert (NULL != eh);
+ if (GNUNET_OK !=
+ TALER_curl_easy_post (&tao->post_ctx,
+ eh,
+ te_obj))
{
GNUNET_break (0);
json_decref (te_obj);
@@ -329,23 +322,15 @@ TALER_MERCHANT_tip_authorize (struct GNUNET_CURL_Context *ctx,
GNUNET_free (tao);
return NULL;
}
- te_obj = json_pack ("{"
- " s:o," /* amount */
- " s:s," /* justification */
- " s:s," /* next_url */
- "}",
- "amount", TALER_JSON_from_amount (amount),
- "justification", justification,
- "next_url", next_url);
- if (NULL == te_obj)
- {
- GNUNET_break (0);
- GNUNET_free (tao->url);
- GNUNET_free (tao);
- return NULL;
- }
-
+ te_obj = GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("amount",
+ amount),
+ GNUNET_JSON_pack_string ("justification",
+ justification),
+ GNUNET_JSON_pack_string ("next_url",
+ next_url));
eh = curl_easy_init ();
+ GNUNET_assert (NULL != eh);
if (GNUNET_OK != TALER_curl_easy_post (&tao->post_ctx,
eh,
te_obj))
diff --git a/src/lib/merchant_api_tip_pickup2.c b/src/lib/merchant_api_tip_pickup2.c
index 9b6c4eff..38ad77d8 100644
--- a/src/lib/merchant_api_tip_pickup2.c
+++ b/src/lib/merchant_api_tip_pickup2.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2017, 2020 Taler Systems SA
+ Copyright (C) 2014-2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software
@@ -254,22 +254,12 @@ TALER_MERCHANT_tip_pickup2 (struct GNUNET_CURL_Context *ctx,
const struct TALER_PlanchetDetail *planchet = &planchets[i];
json_t *p;
- p = json_pack ("{"
- " s:o," /* denom_pub_hash */
- " s:o," /* coin_ev */
- "}",
- "denom_pub_hash",
- GNUNET_JSON_from_data_auto (
- &planchet->denom_pub_hash),
- "coin_ev",
- GNUNET_JSON_from_data (planchet->coin_ev,
- planchet->coin_ev_size));
- if (NULL == p)
- {
- GNUNET_break (0);
- json_decref (pa);
- return NULL;
- }
+ p = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("denom_pub_hash",
+ &planchet->denom_pub_hash),
+ GNUNET_JSON_pack_data_varsize ("coin_ev",
+ planchet->coin_ev,
+ planchet->coin_ev_size));
if (0 !=
json_array_append_new (pa,
p))
@@ -279,14 +269,9 @@ TALER_MERCHANT_tip_pickup2 (struct GNUNET_CURL_Context *ctx,
return NULL;
}
}
- tp_obj = json_pack ("{s:o}",
- "planchets",
- pa);
- if (NULL == tp_obj)
- {
- GNUNET_break (0);
- return NULL;
- }
+ tp_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_array_steal ("planchets",
+ pa));
tpo = GNUNET_new (struct TALER_MERCHANT_TipPickup2Handle);
tpo->num_planchets = num_planchets;
tpo->ctx = ctx;
diff --git a/src/lib/merchant_api_wallet_post_order_refund.c b/src/lib/merchant_api_wallet_post_order_refund.c
index ff19b09e..e2438cba 100644
--- a/src/lib/merchant_api_wallet_post_order_refund.c
+++ b/src/lib/merchant_api_wallet_post_order_refund.c
@@ -135,7 +135,7 @@ handle_refund_finished (void *cls,
unsigned int refund_len;
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_amount_any ("refund_amount",
- &refund_amount),
+ &refund_amount),
GNUNET_JSON_spec_json ("refunds",
&refunds),
GNUNET_JSON_spec_fixed_auto ("merchant_pub",
@@ -215,7 +215,7 @@ handle_refund_finished (void *cls,
GNUNET_JSON_spec_fixed_auto ("coin_pub",
&rd->coin_pub),
TALER_JSON_spec_amount_any ("refund_amount",
- &rd->refund_amount),
+ &rd->refund_amount),
GNUNET_JSON_spec_end ()
};
@@ -242,7 +242,7 @@ handle_refund_finished (void *cls,
GNUNET_JSON_spec_uint64 ("rtransaction_id",
&rd->rtransaction_id),
TALER_JSON_spec_amount_any ("refund_amount",
- &rd->refund_amount),
+ &rd->refund_amount),
GNUNET_JSON_spec_end ()
};
@@ -378,10 +378,9 @@ TALER_MERCHANT_wallet_post_order_refund (
GNUNET_free (orh);
return NULL;
}
- req = json_pack ("{s:o}",
- "h_contract",
- GNUNET_JSON_from_data_auto (h_contract_terms));
- GNUNET_assert (NULL != req);
+ req = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("h_contract",
+ h_contract_terms));
eh = curl_easy_init ();
GNUNET_assert (NULL != eh);
if (GNUNET_OK !=