summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-08-01 19:59:40 +0200
committerChristian Grothoff <christian@grothoff.org>2021-08-01 19:59:44 +0200
commitbcf5863eb45523615540ac99ab81fd131bd2f413 (patch)
tree0086e76a9009289073c7b07338d072d6baac8e11 /src
parentc4d13313b9beff9b8b2948604ae0f6561721c33c (diff)
downloadmerchant-bcf5863eb45523615540ac99ab81fd131bd2f413.tar.gz
merchant-bcf5863eb45523615540ac99ab81fd131bd2f413.tar.bz2
merchant-bcf5863eb45523615540ac99ab81fd131bd2f413.zip
-more json_pack fixes
Diffstat (limited to 'src')
-rw-r--r--src/backend/taler-merchant-httpd_helper.h2
-rw-r--r--src/backend/taler-merchant-httpd_private-get-instances-ID.c91
-rw-r--r--src/backend/taler-merchant-httpd_private-get-instances.c34
-rw-r--r--src/backend/taler-merchant-httpd_private-get-orders-ID.c206
-rw-r--r--src/backend/taler-merchant-httpd_private-get-orders.c58
-rw-r--r--src/backend/taler-merchant-httpd_private-get-products-ID.c66
-rw-r--r--src/backend/taler-merchant-httpd_private-get-products.c15
-rw-r--r--src/backend/taler-merchant-httpd_private-get-reserves-ID.c53
-rw-r--r--src/backend/taler-merchant-httpd_private-get-reserves.c48
-rw-r--r--src/lib/merchant_api_merchant_get_order.c18
10 files changed, 286 insertions, 305 deletions
diff --git a/src/backend/taler-merchant-httpd_helper.h b/src/backend/taler-merchant-httpd_helper.h
index dd5da27a..536f4ce5 100644
--- a/src/backend/taler-merchant-httpd_helper.h
+++ b/src/backend/taler-merchant-httpd_helper.h
@@ -96,6 +96,8 @@ TMH_uuid_from_string (const char *uuids,
#define TMH_pack_exchange_reply(hr) \
GNUNET_JSON_pack_uint64 ("exchange_code", hr->ec), \
GNUNET_JSON_pack_uint64 ("exchange_http_status", hr->http_status), \
+ GNUNET_JSON_pack_uint64 ("exchange_ec", hr->ec), /* LEGACY */ \
+ GNUNET_JSON_pack_uint64 ("exchange_hc", hr->http_status), /* LEGACY */ \
GNUNET_JSON_pack_allow_null ( \
GNUNET_JSON_pack_object_incref ("exchange_reply", (json_t *) hr->reply))
diff --git a/src/backend/taler-merchant-httpd_private-get-instances-ID.c b/src/backend/taler-merchant-httpd_private-get-instances-ID.c
index 2e63995f..95a3e5ea 100644
--- a/src/backend/taler-merchant-httpd_private-get-instances-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-instances-ID.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2019, 2020 Taler Systems SA
+ (C) 2019-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
@@ -35,6 +35,7 @@ get_instances_ID (struct TMH_MerchantInstance *mi,
struct MHD_Connection *connection)
{
json_t *ja;
+ json_t *auth;
GNUNET_assert (NULL != mi);
ja = json_array ();
@@ -47,57 +48,51 @@ get_instances_ID (struct TMH_MerchantInstance *mi,
0 ==
json_array_append_new (
ja,
- json_pack (
- "{s:O, s:o, s:O, s:b}",
- "payto_uri",
- json_object_get (wm->j_wire,
- "payto_uri"),
- "h_wire",
- GNUNET_JSON_from_data_auto (&wm->h_wire),
- "salt",
- json_object_get (wm->j_wire,
- "salt"),
- "active",
- (wm->active) ? 1 : 0)));
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string (
+ "payto_uri",
+ json_string_value (json_object_get (wm->j_wire,
+ "payto_uri"))),
+ GNUNET_JSON_pack_data_auto ("h_wire",
+ &wm->h_wire),
+ GNUNET_JSON_pack_string (
+ "salt",
+ json_string_value (json_object_get (wm->j_wire,
+ "salt"))),
+ GNUNET_JSON_pack_bool ("active",
+ wm->active))));
}
- return TALER_MHD_reply_json_pack (
+ auth = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("method",
+ GNUNET_is_zero (mi->auth.auth_hash.bits)
+ ? "external"
+ : "token"));
+ return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
- "{s:o, s:s, s:o, s:O, s:O,"
- " s:o, s:o, s:I, s:o, s:o,"
- " s:{ s:s } }",
- "accounts",
- ja,
- "name",
- mi->settings.name,
- "merchant_pub",
- GNUNET_JSON_from_data_auto (
- &mi->merchant_pub),
- "address",
- mi->settings.address,
- "jurisdiction",
- mi->settings.jurisdiction,
- /* end of first group of 5 */
- "default_max_wire_fee",
- TALER_JSON_from_amount (
- &mi->settings.default_max_wire_fee),
- "default_max_deposit_fee",
- TALER_JSON_from_amount (
- &mi->settings.default_max_deposit_fee),
- "default_wire_fee_amortization",
- (json_int_t)
- mi->settings.default_wire_fee_amortization,
- "default_wire_transfer_delay",
- GNUNET_JSON_from_time_rel (
- mi->settings.default_wire_transfer_delay),
- "default_pay_delay",
- GNUNET_JSON_from_time_rel (
- mi->settings.default_pay_delay),
- /* end of second group of 5 */
- "auth",
- "method",
- GNUNET_is_zero (mi->auth.auth_hash.bits) ? "external" : "token");
+ GNUNET_JSON_pack_array_steal ("accounts",
+ ja),
+ GNUNET_JSON_pack_string ("name",
+ mi->settings.name),
+ GNUNET_JSON_pack_data_auto ("merchant_pub",
+ &mi->merchant_pub),
+ GNUNET_JSON_pack_object_incref ("address",
+ mi->settings.address),
+ GNUNET_JSON_pack_object_incref ("jurisdiction",
+ mi->settings.jurisdiction),
+ TALER_JSON_pack_amount ("default_max_wire_fee",
+ &mi->settings.default_max_wire_fee),
+ TALER_JSON_pack_amount ("default_max_deposit_fee",
+ &mi->settings.default_max_deposit_fee),
+ GNUNET_JSON_pack_uint64 ("default_wire_fee_amortization",
+ mi->settings.default_wire_fee_amortization),
+ GNUNET_JSON_pack_time_rel ("default_wire_transfer_delay",
+ mi->settings.default_wire_transfer_delay),
+ GNUNET_JSON_pack_time_rel ("default_pay_delay",
+ mi->settings.default_pay_delay),
+ GNUNET_JSON_pack_object_steal ("auth",
+ auth));
}
diff --git a/src/backend/taler-merchant-httpd_private-get-instances.c b/src/backend/taler-merchant-httpd_private-get-instances.c
index 542d0b44..f802fe66 100644
--- a/src/backend/taler-merchant-httpd_private-get-instances.c
+++ b/src/backend/taler-merchant-httpd_private-get-instances.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2019, 2020 Taler Systems SA
+ (C) 2019-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
@@ -71,18 +71,17 @@ add_instance (void *cls,
GNUNET_assert (0 ==
json_array_append_new (
ja,
- json_pack (
- "{s:s, s:s, s:o, s:o, s:b}",
- "name",
- mi->settings.name,
- "id",
- mi->settings.id,
- "merchant_pub",
- GNUNET_JSON_from_data_auto (&mi->merchant_pub),
- "payment_targets",
- pta,
- "deleted",
- mi->deleted)));
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("name",
+ mi->settings.name),
+ GNUNET_JSON_pack_string ("id",
+ mi->settings.id),
+ GNUNET_JSON_pack_data_auto ("merchant_pub",
+ &mi->merchant_pub),
+ GNUNET_JSON_pack_array_steal ("payment_targets",
+ pta),
+ GNUNET_JSON_pack_bool ("deleted",
+ mi->deleted))));
return GNUNET_OK;
}
@@ -108,10 +107,11 @@ TMH_private_get_instances (const struct TMH_RequestHandler *rh,
GNUNET_CONTAINER_multihashmap_iterate (TMH_by_id_map,
&add_instance,
ia);
- return TALER_MHD_reply_json_pack (connection,
- MHD_HTTP_OK,
- "{s:o}",
- "instances", ia);
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_steal ("instances",
+ ia));
}
diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.c b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
index abcf64e2..8f9dce35 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c
@@ -25,6 +25,7 @@
#include <taler/taler_json_lib.h>
#include "taler-merchant-httpd_mhd.h"
#include "taler-merchant-httpd_exchanges.h"
+#include "taler-merchant-httpd_helper.h"
#include "taler-merchant-httpd_private-get-orders.h"
@@ -337,28 +338,19 @@ gorc_report (struct GetOrderRequestContext *gorc,
GNUNET_assert (0 ==
json_array_append_new (
gorc->wire_reports,
- json_pack ("{s:I, s:s, s:I, s:I, s:o }",
- "code",
- (json_int_t) ec,
- "hint",
- TALER_ErrorCode_get_hint (ec),
- "exchange_ec",
- (json_int_t) exchange_hr->ec,
- "exchange_hc",
- (json_int_t) exchange_hr->http_status,
- "coin_pub",
- GNUNET_JSON_from_data_auto (coin_pub))));
+ GNUNET_JSON_PACK (
+ TALER_JSON_pack_ec (ec),
+ TMH_pack_exchange_reply (exchange_hr),
+ GNUNET_JSON_pack_data_auto ("coin_pub",
+ coin_pub))));
else
GNUNET_assert (0 ==
json_array_append_new (
gorc->wire_reports,
- json_pack ("{s:I, s:s, s:o }",
- "code",
- (json_int_t) ec,
- "hint",
- TALER_ErrorCode_get_hint (ec),
- "coin_pub",
- GNUNET_JSON_from_data_auto (coin_pub))));
+ GNUNET_JSON_PACK (
+ TALER_JSON_pack_ec (ec),
+ GNUNET_JSON_pack_data_auto ("coin_pub",
+ coin_pub))));
}
@@ -657,13 +649,13 @@ process_refunds_cb (void *cls,
GNUNET_assert (0 ==
json_array_append_new (
gorc->refund_details,
- json_pack ("{s:o, s:o, s:s}",
- "amount",
- TALER_JSON_from_amount (refund_amount),
- "timestamp",
- GNUNET_JSON_from_time_abs (timestamp),
- "reason",
- reason)));
+ GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("amount",
+ refund_amount),
+ GNUNET_JSON_pack_time_abs ("timestamp",
+ timestamp),
+ GNUNET_JSON_pack_string ("reason",
+ reason))));
/* For refunded coins, we are not charged deposit fees, so subtract those
again */
for (struct TransferQuery *tq = gorc->tq_head;
@@ -734,17 +726,17 @@ process_transfer_details (void *cls,
GNUNET_assert (0 ==
json_array_append_new (
wire_details,
- json_pack ("{s:o, s:s, s:o, s:o, s:b}",
- "wtid",
- GNUNET_JSON_from_data_auto (wtid),
- "exchange_url",
- exchange_url,
- "amount",
- TALER_JSON_from_amount (&wired),
- "execution_time",
- GNUNET_JSON_from_time_abs (execution_time_round),
- "confirmed",
- transfer_confirmed)));
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("wtid",
+ wtid),
+ GNUNET_JSON_pack_string ("exchange_url",
+ exchange_url),
+ TALER_JSON_pack_amount ("amount",
+ &wired),
+ GNUNET_JSON_pack_time_abs ("execution_time",
+ execution_time_round),
+ GNUNET_JSON_pack_bool ("confirmed",
+ transfer_confirmed))));
}
@@ -1044,27 +1036,25 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
TALER_EC_GENERIC_HTTP_HEADERS_MALFORMED,
"host");
}
- ret = TALER_MHD_reply_json_pack (connection,
- MHD_HTTP_OK,
- "{s:s, s:s, s:s, s:s, s:s"
- " s:o, s:s, s:o}",
- "taler_pay_uri",
- taler_pay_uri,
- "order_status_url",
- order_status_url,
- "order_status",
- "unpaid",
- "already_paid_order_id",
- already_paid_order_id,
- "already_paid_fulfillment_url",
- gorc->fulfillment_url,
- "total_amount",
- TALER_JSON_from_amount (
- &gorc->contract_amount),
- "summary",
- summary,
- "creation_time",
- GNUNET_JSON_from_time_abs (timestamp));
+ ret = TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_string ("taler_pay_uri",
+ taler_pay_uri),
+ GNUNET_JSON_pack_string ("order_status_url",
+ order_status_url),
+ GNUNET_JSON_pack_string ("order_status",
+ "unpaid"),
+ GNUNET_JSON_pack_string ("already_paid_order_id",
+ already_paid_order_id),
+ GNUNET_JSON_pack_string ("already_paid_fulfillment_url",
+ gorc->fulfillment_url),
+ TALER_JSON_pack_amount ("total_amount",
+ &gorc->contract_amount),
+ GNUNET_JSON_pack_string ("summary",
+ summary),
+ GNUNET_JSON_pack_time_abs ("creation_time",
+ timestamp));
GNUNET_free (taler_pay_uri);
GNUNET_free (already_paid_order_id);
return ret;
@@ -1094,13 +1084,13 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Order %s claimed but not paid yet\n",
hc->infix);
- return TALER_MHD_reply_json_pack (connection,
- MHD_HTTP_OK,
- "{s:O, s:s}",
- "contract_terms",
- gorc->contract_terms,
- "order_status",
- "claimed");
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_object_incref ("contract_terms",
+ gorc->contract_terms),
+ GNUNET_JSON_pack_string ("order_status",
+ "claimed"));
}
if (paid &&
(! wired) &&
@@ -1165,22 +1155,21 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
hc->instance->settings.id,
&claim_token,
NULL);
- ret = TALER_MHD_reply_json_pack (connection,
- MHD_HTTP_OK,
- "{s:s, s:s, s:s, s:o, s:s, s:o}",
- "taler_pay_uri",
- taler_pay_uri,
- "order_status_url",
- order_status_url,
- "order_status",
- "unpaid",
- "total_amount",
- TALER_JSON_from_amount (
- &gorc->contract_amount),
- "summary",
- summary,
- "creation_time",
- GNUNET_JSON_from_time_abs (timestamp));
+ ret = TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_string ("taler_pay_uri",
+ taler_pay_uri),
+ GNUNET_JSON_pack_string ("order_status_url",
+ order_status_url),
+ GNUNET_JSON_pack_string ("order_status",
+ "unpaid"),
+ TALER_JSON_pack_amount ("total_amount",
+ &gorc->contract_amount),
+ GNUNET_JSON_pack_string ("summary",
+ summary),
+ GNUNET_JSON_pack_time_abs ("creation_time",
+ timestamp));
GNUNET_free (taler_pay_uri);
GNUNET_free (order_status_url);
return ret;
@@ -1302,38 +1291,35 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh,
h_contract);
}
- ret = TALER_MHD_reply_json_pack (
+ ret = TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
- "{s:o, s:I, s:I, s:o, s:O,"
- " s:s, s:b, s:b, s:b, s:o,"
- " s:o, s:o, s:s}",
- "wire_reports",
- gorc->wire_reports,
- "exchange_ec",
- (json_int_t) gorc->exchange_ec,
- "exchange_hc",
- (json_int_t) gorc->exchange_hc,
- "deposit_total",
- TALER_JSON_from_amount (&gorc->deposits_total),
- "contract_terms",
- gorc->contract_terms,
- "order_status",
- "paid",
- "refunded",
- gorc->refunded,
- "wired",
- wired,
- "refund_pending",
- gorc->refund_pending,
- "refund_amount",
- TALER_JSON_from_amount (&gorc->refund_amount),
- "wire_details",
- gorc->wire_details,
- "refund_details",
- gorc->refund_details,
- "order_status_url",
- order_status_url);
+ GNUNET_JSON_pack_array_steal ("wire_reports",
+ gorc->wire_reports),
+ GNUNET_JSON_pack_uint64 ("exchange_code",
+ gorc->exchange_ec),
+ GNUNET_JSON_pack_uint64 ("exchange_http_status",
+ gorc->exchange_hc),
+ TALER_JSON_pack_amount ("deposit_total",
+ &gorc->deposits_total),
+ GNUNET_JSON_pack_object_incref ("contract_terms",
+ gorc->contract_terms),
+ GNUNET_JSON_pack_string ("order_status",
+ "paid"),
+ GNUNET_JSON_pack_bool ("refunded",
+ gorc->refunded),
+ GNUNET_JSON_pack_bool ("wired",
+ wired),
+ GNUNET_JSON_pack_bool ("refund_pending",
+ gorc->refund_pending),
+ TALER_JSON_pack_amount ("refund_amount",
+ &gorc->refund_amount),
+ GNUNET_JSON_pack_array_steal ("wire_details",
+ gorc->wire_details),
+ GNUNET_JSON_pack_array_steal ("refund_details",
+ gorc->refund_details),
+ GNUNET_JSON_pack_string ("order_status_url",
+ order_status_url));
GNUNET_free (order_status_url);
gorc->wire_details = NULL;
gorc->wire_reports = NULL;
diff --git a/src/backend/taler-merchant-httpd_private-get-orders.c b/src/backend/taler-merchant-httpd_private-get-orders.c
index 3504105c..5b1ab934 100644
--- a/src/backend/taler-merchant-httpd_private-get-orders.c
+++ b/src/backend/taler-merchant-httpd_private-get-orders.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2019, 2020 Taler Systems SA
+ (C) 2019-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
@@ -266,8 +266,10 @@ add_order (void *cls,
json_t *contract_terms;
struct GNUNET_HashCode h_contract_terms;
enum GNUNET_DB_QueryStatus qs;
+ const char *summary;
bool refundable = false;
bool paid;
+ struct TALER_Amount order_amount;
qs = TMH_db->lookup_order_status (TMH_db->cls,
po->instance_id,
@@ -317,7 +319,6 @@ add_order (void *cls,
}
{
- struct TALER_Amount order_amount;
struct GNUNET_TIME_Absolute rd;
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_amount ("amount",
@@ -325,6 +326,8 @@ add_order (void *cls,
&order_amount),
GNUNET_JSON_spec_absolute_time ("refund_deadline",
&rd),
+ GNUNET_JSON_spec_string ("summary",
+ &summary),
GNUNET_JSON_spec_end ()
};
@@ -368,24 +371,21 @@ add_order (void *cls,
GNUNET_assert (0 ==
json_array_append_new (
po->pa,
- json_pack (
- "{s:s, s:I, s:o, s:O, s:O, s:b, s:b}",
- "order_id",
- order_id,
- "row_id",
- (json_int_t) order_serial,
- "timestamp",
- GNUNET_JSON_from_time_abs (creation_time),
- "amount",
- json_object_get (contract_terms,
- "amount"),
- "summary",
- json_object_get (contract_terms,
- "summary"),
- "refundable",
- refundable,
- "paid",
- paid)));
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("order_id",
+ order_id),
+ GNUNET_JSON_pack_uint64 ("row_id",
+ order_serial),
+ GNUNET_JSON_pack_time_abs ("timestamp",
+ creation_time),
+ TALER_JSON_pack_amount ("amount",
+ &order_amount),
+ GNUNET_JSON_pack_string ("summary",
+ summary),
+ GNUNET_JSON_pack_bool ("refundable",
+ refundable),
+ GNUNET_JSON_pack_bool ("paid",
+ paid))));
json_decref (contract_terms);
}
@@ -487,10 +487,11 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh,
po->result,
NULL);
}
- return TALER_MHD_reply_json_pack (connection,
- MHD_HTTP_OK,
- "{s:O}",
- "orders", po->pa);
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_incref ("orders",
+ po->pa));
}
if (! (TALER_arg_to_yna (connection,
@@ -738,10 +739,11 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh,
}
return MHD_YES;
}
- return TALER_MHD_reply_json_pack (connection,
- MHD_HTTP_OK,
- "{s:O}",
- "orders", po->pa);
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_incref ("orders",
+ po->pa));
}
diff --git a/src/backend/taler-merchant-httpd_private-get-products-ID.c b/src/backend/taler-merchant-httpd_private-get-products-ID.c
index 48b04499..6af8236c 100644
--- a/src/backend/taler-merchant-httpd_private-get-products-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-products-ID.c
@@ -61,49 +61,39 @@ TMH_private_get_products_ID (const struct TMH_RequestHandler *rh,
hc->infix);
}
{
- json_t *reply;
MHD_RESULT ret;
- reply = json_pack (
- "{s:s, s:o, s:s, s:o, s:s,"
- " s:o, s:I, s:I, s:I, s:o}",
- "description",
- pd.description,
- "description_i18n",
- pd.description_i18n,
- "unit",
- pd.unit,
- "price",
- TALER_JSON_from_amount (&pd.price),
- "image",
- pd.image,
- /* end of first group of 5 */
- "taxes",
- pd.taxes,
- "total_stock",
- (INT64_MAX == pd.total_stock)
- ? (json_int_t) -1
- : (json_int_t) pd.total_stock,
- "total_sold",
- (json_int_t) pd.total_sold,
- "total_lost",
- (json_int_t) pd.total_lost,
- "address",
- pd.address);
- GNUNET_assert (NULL != reply);
+ ret = TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_string ("description",
+ pd.description),
+ GNUNET_JSON_pack_object_steal ("description_i18n",
+ pd.description_i18n),
+ GNUNET_JSON_pack_string ("unit",
+ pd.unit),
+ TALER_JSON_pack_amount ("price",
+ &pd.price),
+ GNUNET_JSON_pack_string ("image",
+ pd.image),
+ GNUNET_JSON_pack_array_steal ("taxes",
+ pd.taxes),
+ GNUNET_JSON_pack_int64 ("total_stock",
+ (INT64_MAX == pd.total_stock)
+ ? -1LL
+ : pd.total_stock),
+ GNUNET_JSON_pack_uint64 ("total_sold",
+ pd.total_sold),
+ GNUNET_JSON_pack_uint64 ("total_lost",
+ pd.total_lost),
+ GNUNET_JSON_pack_object_steal ("address",
+ pd.address),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_time_abs ("next_restock",
+ (pd.next_restock))));
GNUNET_free (pd.description);
GNUNET_free (pd.image);
GNUNET_free (pd.unit);
- if (0 != pd.next_restock.abs_value_us)
- GNUNET_assert (0 ==
- json_object_set_new (
- reply,
- "next_restock",
- GNUNET_JSON_from_time_abs (pd.next_restock)));
- ret = TALER_MHD_reply_json (connection,
- reply,
- MHD_HTTP_OK);
- json_decref (reply);
return ret;
}
}
diff --git a/src/backend/taler-merchant-httpd_private-get-products.c b/src/backend/taler-merchant-httpd_private-get-products.c
index fb9b2192..6c683887 100644
--- a/src/backend/taler-merchant-httpd_private-get-products.c
+++ b/src/backend/taler-merchant-httpd_private-get-products.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2019, 2020 Taler Systems SA
+ (C) 2019, 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 published by the Free Software
@@ -37,10 +37,9 @@ add_product (void *cls,
GNUNET_assert (0 ==
json_array_append_new (
pa,
- json_pack (
- "{s:s}",
- "product_id",
- product_id)));
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("product_id",
+ product_id))));
}
@@ -75,10 +74,10 @@ TMH_private_get_products (const struct TMH_RequestHandler *rh,
TALER_EC_GENERIC_DB_FETCH_FAILED,
NULL);
}
- return TALER_MHD_reply_json_pack (connection,
+ return TALER_MHD_REPLY_JSON_PACK (connection,
MHD_HTTP_OK,
- "{s:o}",
- "products", pa);
+ GNUNET_JSON_pack_array_steal ("products",
+ pa));
}
diff --git a/src/backend/taler-merchant-httpd_private-get-reserves-ID.c b/src/backend/taler-merchant-httpd_private-get-reserves-ID.c
index 8ad6e8de..e0cee3a7 100644
--- a/src/backend/taler-merchant-httpd_private-get-reserves-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-reserves-ID.c
@@ -94,41 +94,50 @@ handle_reserve_details (void *cls,
{
tips_json = json_array ();
GNUNET_assert (NULL != tips_json);
-
for (unsigned int i = 0; i<tips_length; i++)
{
GNUNET_assert (0 ==
json_array_append_new (
tips_json,
- json_pack ("{s:o,s:o,s:s}",
- "tip_id",
- GNUNET_JSON_from_data_auto (
- &tips[i].tip_id),
- "total_amount",
- TALER_JSON_from_amount (
- &tips[i].total_amount),
- "reason",
- tips[i].reason)));
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("tip_id",
+ &tips[i].tip_id),
+ TALER_JSON_pack_amount ("total_amount",
+ &tips[i].total_amount),
+ GNUNET_JSON_pack_string ("reason",
+ tips[i].reason))));
}
}
else
{
tips_json = NULL;
}
- ctx->res = TALER_MHD_reply_json_pack (
+ ctx->res = TALER_MHD_REPLY_JSON_PACK (
ctx->connection,
MHD_HTTP_OK,
- "{s:o, s:o, s:o, s:o, s:o, s:o, s:o?, s:b, s:s?, s:s?}",
- "creation_time", GNUNET_JSON_from_time_abs (creation_time_round),
- "expiration_time", GNUNET_JSON_from_time_abs (expiration_time_round),
- "merchant_initial_amount", TALER_JSON_from_amount (merchant_initial_amount),
- "exchange_initial_amount", TALER_JSON_from_amount (exchange_initial_amount),
- "pickup_amount", TALER_JSON_from_amount (picked_up_amount),
- "committed_amount", TALER_JSON_from_amount (committed_amount),
- "tips", tips_json,
- "active", active,
- "exchange_url", exchange_url,
- "payto_uri", payto_uri);
+ GNUNET_JSON_pack_time_abs ("creation_time",
+ creation_time_round),
+ GNUNET_JSON_pack_time_abs ("expiration_time",
+ expiration_time_round),
+ TALER_JSON_pack_amount ("merchant_initial_amount",
+ merchant_initial_amount),
+ TALER_JSON_pack_amount ("exchange_initial_amount",
+ exchange_initial_amount),
+ TALER_JSON_pack_amount ("pickup_amount",
+ picked_up_amount),
+ TALER_JSON_pack_amount ("committed_amount",
+ committed_amount),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_array_steal ("tips",
+ tips_json)),
+ GNUNET_JSON_pack_bool ("active",
+ active),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("exchange_url",
+ exchange_url)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("payto_uri",
+ payto_uri)));
}
diff --git a/src/backend/taler-merchant-httpd_private-get-reserves.c b/src/backend/taler-merchant-httpd_private-get-reserves.c
index 8b12afbe..f231a292 100644
--- a/src/backend/taler-merchant-httpd_private-get-reserves.c
+++ b/src/backend/taler-merchant-httpd_private-get-reserves.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2019, 2020 Taler Systems SA
+ (C) 2019-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
@@ -58,26 +58,23 @@ add_reserve (void *cls,
GNUNET_assert (0 ==
json_array_append_new (
pa,
- json_pack (
- "{s:o,s:o,s:o,"
- " s:o,s:o,s:o,s:o,"
- " s:b}",
- "reserve_pub",
- GNUNET_JSON_from_data_auto (reserve_pub),
- "creation_time",
- GNUNET_JSON_from_time_abs (creation_time_round),
- "expiration_time",
- GNUNET_JSON_from_time_abs (expiration_time_round),
- "merchant_initial_amount",
- TALER_JSON_from_amount (merchant_initial_amount),
- "exchange_initial_amount",
- TALER_JSON_from_amount (exchange_initial_amount),
- "pickup_amount",
- TALER_JSON_from_amount (pickup_amount),
- "committed_amount",
- TALER_JSON_from_amount (committed_amount),
- "active",
- active)));
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("reserve_pub",
+ reserve_pub),
+ GNUNET_JSON_pack_time_abs ("creation_time",
+ creation_time_round),
+ GNUNET_JSON_pack_time_abs ("expiration_time",
+ expiration_time_round),
+ TALER_JSON_pack_amount ("merchant_initial_amount",
+ merchant_initial_amount),
+ TALER_JSON_pack_amount ("exchange_initial_amount",
+ exchange_initial_amount),
+ TALER_JSON_pack_amount ("pickup_amount",
+ pickup_amount),
+ TALER_JSON_pack_amount ("committed_amount",
+ committed_amount),
+ GNUNET_JSON_pack_bool ("active",
+ active))));
}
@@ -140,10 +137,11 @@ TMH_private_get_reserves (const struct TMH_RequestHandler *rh,
TALER_EC_GENERIC_DB_FETCH_FAILED,
"reserves");
}
- return TALER_MHD_reply_json_pack (connection,
- MHD_HTTP_OK,
- "{s:o}",
- "reserves", ra);
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_steal ("reserves",
+ ra));
}
diff --git a/src/lib/merchant_api_merchant_get_order.c b/src/lib/merchant_api_merchant_get_order.c
index f4dc8131..64116419 100644
--- a/src/lib/merchant_api_merchant_get_order.c
+++ b/src/lib/merchant_api_merchant_get_order.c
@@ -82,7 +82,7 @@ handle_unpaid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh,
};
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_amount_any ("total_amount",
- &osr.details.unpaid.contract_amount),
+ &osr.details.unpaid.contract_amount),
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_string ("already_paid_order_id",
&osr.details.unpaid.already_paid_order_id)),
@@ -183,13 +183,13 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh,
GNUNET_JSON_spec_bool ("wired",
&osr.details.paid.wired),
TALER_JSON_spec_amount_any ("deposit_total",
- &osr.details.paid.deposit_total),
- GNUNET_JSON_spec_uint32 ("exchange_ec",
+ &osr.details.paid.deposit_total),
+ GNUNET_JSON_spec_uint32 ("exchange_code",
&ec32),
- GNUNET_JSON_spec_uint32 ("exchange_hc",
+ GNUNET_JSON_spec_uint32 ("exchange_http_status",
&hc32),
TALER_JSON_spec_amount_any ("refund_amount",
- &osr.details.paid.refund_amount),
+ &osr.details.paid.refund_amount),
GNUNET_JSON_spec_json ("contract_terms",
(json_t **) &osr.details.paid.contract_terms),
GNUNET_JSON_spec_json ("wire_details",
@@ -251,7 +251,7 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh,
TALER_JSON_spec_absolute_time ("execution_time",
&wt->execution_time),
TALER_JSON_spec_amount_any ("amount",
- &wt->total_amount),
+ &wt->total_amount),
GNUNET_JSON_spec_bool ("confirmed",
&wt->confirmed),
GNUNET_JSON_spec_end ()
@@ -285,9 +285,9 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh,
&c32),
GNUNET_JSON_spec_string ("hint",
&wr->hint),
- GNUNET_JSON_spec_uint32 ("exchange_ec",
+ GNUNET_JSON_spec_uint32 ("exchange_code",
&eec32),
- GNUNET_JSON_spec_uint32 ("exchange_hc",
+ GNUNET_JSON_spec_uint32 ("exchange_http_status",
&ehs32),
GNUNET_JSON_spec_fixed_auto ("coin_pub",
&wr->coin_pub),
@@ -320,7 +320,7 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh,
i);
struct GNUNET_JSON_Specification ispec[] = {
TALER_JSON_spec_amount_any ("amount",
- &ro->refund_amount),
+ &ro->refund_amount),
GNUNET_JSON_spec_string ("reason",
&ro->reason),
TALER_JSON_spec_absolute_time ("timestamp",