diff options
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-post-transfers.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-transfers.c | 168 |
1 files changed, 76 insertions, 92 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-transfers.c b/src/backend/taler-merchant-httpd_private-post-transfers.c index a9a0da75..1dd5d589 100644 --- a/src/backend/taler-merchant-httpd_private-post-transfers.c +++ b/src/backend/taler-merchant-httpd_private-post-transfers.c @@ -25,6 +25,7 @@ #include <taler/taler_json_lib.h> #include "taler-merchant-httpd_auditors.h" #include "taler-merchant-httpd_exchanges.h" +#include "taler-merchant-httpd_helper.h" #include "taler-merchant-httpd_private-post-transfers.h" @@ -320,44 +321,35 @@ check_transfer (void *cls, /* Build the `TrackTransferConflictDetails` */ ptc->response_code = MHD_HTTP_ACCEPTED; ptc->response - = TALER_MHD_make_json_pack ( - "{s:I, s:s, s:s, s:o, s:o," - " s:I, s:o, s:o, s:o, s:o," - " s:o, s:o, s:o, s:o, s:o }", - "code", - (json_int_t) - TALER_EC_MERCHANT_PRIVATE_POST_TRANSFERS_CONFLICTING_REPORTS, - "hint", - TALER_ErrorCode_get_hint ( + = TALER_MHD_MAKE_JSON_PACK ( + TALER_JSON_pack_ec ( TALER_EC_MERCHANT_PRIVATE_POST_TRANSFERS_CONFLICTING_REPORTS), - "exchange_url", - exchange_url, - "deposit_timestamp", - GNUNET_JSON_from_time_abs (deposit_timestamp), - "refund_deadline", - GNUNET_JSON_from_time_abs (refund_deadline), - /* first block of 5 */ - "conflict_offset", - (json_int_t) ptc->current_offset, - "coin_pub", - GNUNET_JSON_from_data_auto (&ttd->coin_pub), - "h_wire", - GNUNET_JSON_from_data_auto (h_wire), - "deposit_exchange_sig", - GNUNET_JSON_from_data_auto (exchange_sig), - "deposit_exchange_pub", - GNUNET_JSON_from_data_auto (exchange_pub), - /* first block of 5 */ - "h_contract_terms", - GNUNET_JSON_from_data_auto (&ttd->h_contract_terms), - "amount_with_fee", - TALER_JSON_from_amount (amount_with_fee), - "coin_value", - TALER_JSON_from_amount (&ttd->coin_value), - "coin_fee", - TALER_JSON_from_amount (&ttd->coin_fee), - "deposit_fee", - TALER_JSON_from_amount (deposit_fee)); + GNUNET_JSON_pack_string ("exchange_url", + exchange_url), + GNUNET_JSON_pack_time_abs ("deposit_timestamp", + deposit_timestamp), + GNUNET_JSON_pack_time_abs ("refund_deadline", + refund_deadline), + GNUNET_JSON_pack_uint64 ("conflict_offset", + ptc->current_offset), + GNUNET_JSON_pack_data_auto ("coin_pub", + &ttd->coin_pub), + GNUNET_JSON_pack_data_auto ("h_wire", + h_wire), + GNUNET_JSON_pack_data_auto ("deposit_exchange_sig", + exchange_sig), + GNUNET_JSON_pack_data_auto ("deposit_exchange_pub", + exchange_pub), + GNUNET_JSON_pack_data_auto ("h_contract_terms", + &ttd->h_contract_terms), + TALER_JSON_pack_amount ("amount_with_fee", + amount_with_fee), + TALER_JSON_pack_amount ("coin_value", + &ttd->coin_value), + TALER_JSON_pack_amount ("coin_fee", + &ttd->coin_fee), + TALER_JSON_pack_amount ("deposit_fee", + deposit_fee)); return; } ptc->check_transfer_result = GNUNET_OK; @@ -433,21 +425,25 @@ check_wire_fee (struct PostTransfersContext *ptc, /* Wire fee check failed, export proof to client */ ptc->response_code = MHD_HTTP_ACCEPTED; ptc->response = - TALER_MHD_make_json_pack ( - "{s:I, s:s, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o}", - "code", - (json_int_t) TALER_EC_MERCHANT_PRIVATE_POST_TRANSFERS_BAD_WIRE_FEE, - "hint", - TALER_ErrorCode_get_hint ( + TALER_MHD_MAKE_JSON_PACK ( + TALER_JSON_pack_ec ( TALER_EC_MERCHANT_PRIVATE_POST_TRANSFERS_BAD_WIRE_FEE), - "wire_fee", TALER_JSON_from_amount (wire_fee), - "execution_time", GNUNET_JSON_from_time_abs (execution_time), - "expected_wire_fee", TALER_JSON_from_amount (&expected_fee), - "expected_closing_fee", TALER_JSON_from_amount (&closing_fee), - "start_date", GNUNET_JSON_from_time_abs (start_date), - "end_date", GNUNET_JSON_from_time_abs (end_date), - "master_sig", GNUNET_JSON_from_data_auto (&master_sig), - "master_pub", GNUNET_JSON_from_data_auto (&ptc->master_pub)); + TALER_JSON_pack_amount ("wire_fee", + wire_fee), + GNUNET_JSON_pack_time_abs ("execution_time", + execution_time), + TALER_JSON_pack_amount ("expected_wire_fee", + &expected_fee), + TALER_JSON_pack_amount ("expected_closing_fee", + &closing_fee), + GNUNET_JSON_pack_time_abs ("start_date", + start_date), + GNUNET_JSON_pack_time_abs ("end_date", + end_date), + GNUNET_JSON_pack_data_auto ("master_sig", + &master_sig), + GNUNET_JSON_pack_data_auto ("master_pub", + &ptc->master_pub)); GNUNET_free (wire_method); return GNUNET_SYSERR; } @@ -482,24 +478,19 @@ wire_transfer_cb (void *cls, resume_transfer_with_response ( ptc, MHD_HTTP_BAD_GATEWAY, - TALER_MHD_make_json_pack ( - "{s:I, s:I, s:I}", - "code", - (json_int_t) TALER_EC_MERCHANT_PRIVATE_POST_TRANSFERS_EXCHANGE_UNKNOWN, - "exchange_code", (json_int_t) hr->ec, - "exchange_http_status", (json_int_t) hr->http_status)); + TALER_MHD_MAKE_JSON_PACK ( + TALER_JSON_pack_ec ( + TALER_EC_MERCHANT_PRIVATE_POST_TRANSFERS_EXCHANGE_UNKNOWN), + TMH_pack_exchange_reply (hr))); return; default: resume_transfer_with_response ( ptc, MHD_HTTP_BAD_GATEWAY, - TALER_MHD_make_json_pack ( - "{s:I, s:I, s:I, s:O}", - "code", - (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_UNEXPECTED_STATUS, - "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_GENERIC_EXCHANGE_UNEXPECTED_STATUS), + TMH_pack_exchange_reply (hr))); return; } TMH_db->preflight (TMH_db->cls); @@ -583,12 +574,8 @@ process_transfer_with_exchange (void *cls, resume_transfer_with_response ( ptc, 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_JSON_PACK ( + TALER_JSON_pack_ec (TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT))); return; } if (NULL == eh) @@ -598,16 +585,10 @@ process_transfer_with_exchange (void *cls, resume_transfer_with_response ( ptc, MHD_HTTP_BAD_GATEWAY, - TALER_MHD_make_json_pack ( - (NULL != hr->reply) - ? "{s:s, s:I, s:I, s:I, s:O}" - : "{s:s, s:I, s:I, s:I}", - "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; } @@ -827,13 +808,13 @@ hashmap_update_and_free (void *cls, 0 == json_array_append_new ( ja, - json_pack ("{s:s,s:o,s:o}", - "order_id", - entry->order_id, - "deposit_value", - TALER_JSON_from_amount (&entry->deposit_value), - "deposit_fee", - TALER_JSON_from_amount (&entry->deposit_fee)))); + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("order_id", + entry->order_id), + TALER_JSON_pack_amount ("deposit_value", + &entry->deposit_value), + TALER_JSON_pack_amount ("deposit_fee", + &entry->deposit_fee)))); } GNUNET_free (entry->order_id); GNUNET_free (entry); @@ -1340,14 +1321,17 @@ TMH_private_post_transfers (const struct TMH_RequestHandler *rh, &hashmap_update_and_free, deposit_sums); GNUNET_CONTAINER_multihashmap_destroy (map); - return TALER_MHD_reply_json_pack ( + return TALER_MHD_REPLY_JSON_PACK ( connection, MHD_HTTP_OK, - "{s:o,s:o,s:o,s:o}", - "total", TALER_JSON_from_amount (&total_amount), - "wire_fee", TALER_JSON_from_amount (&wire_fee), - "execution_time", GNUNET_JSON_from_time_abs (execution_time), - "deposit_sums", deposit_sums); + TALER_JSON_pack_amount ("total", + &total_amount), + TALER_JSON_pack_amount ("wire_fee", + &wire_fee), + GNUNET_JSON_pack_time_abs ("execution_time", + execution_time), + GNUNET_JSON_pack_array_steal ("deposit_sums", + deposit_sums)); } /* end of 'verified == true' (not an 'if'!) */ } /* end of 'switch (qs)' */ GNUNET_assert (0); |