diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2017-03-13 14:20:38 +0100 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2017-03-13 14:20:38 +0100 |
commit | 561deba2ee2a742cfa0c0a809e14965b7465c37a (patch) | |
tree | 43ef3849ccf844116137b6ea1afced67ce13ef29 | |
parent | a093c87917fb1d56a4d7e6b73c0f9f241d145770 (diff) | |
download | merchant-561deba2ee2a742cfa0c0a809e14965b7465c37a.tar.gz merchant-561deba2ee2a742cfa0c0a809e14965b7465c37a.tar.bz2 merchant-561deba2ee2a742cfa0c0a809e14965b7465c37a.zip |
Fix track transfer's response + adjusting tests to it.
-rw-r--r-- | src/backend/taler-merchant-httpd_track-transfer.c | 25 | ||||
-rw-r--r-- | src/backenddb/test_merchantdb.c | 1 | ||||
-rw-r--r-- | src/include/taler_merchant_service.h | 28 | ||||
-rw-r--r-- | src/lib/merchant_api_track_transfer.c | 23 | ||||
-rw-r--r-- | src/lib/test_merchant_api.c | 90 |
5 files changed, 60 insertions, 107 deletions
diff --git a/src/backend/taler-merchant-httpd_track-transfer.c b/src/backend/taler-merchant-httpd_track-transfer.c index 1bf48efb..ecd51bd0 100644 --- a/src/backend/taler-merchant-httpd_track-transfer.c +++ b/src/backend/taler-merchant-httpd_track-transfer.c @@ -140,10 +140,6 @@ struct Entry { */ struct TALER_Amount deposit_fee; - /** - * Transaction ID. - */ - uint64_t transaction_id; }; /** @@ -219,12 +215,11 @@ build_deposits_response (void *cls, struct Entry *entry = value; /*FIXME put error check*/ - element = json_pack ("{s:s, s:o, s:o, s:I}", + element = json_pack ("{s:o, s:o, s:o}", "h_proposal_data", - GNUNET_JSON_from_data (key, sizeof (struct GNUNET_HashCode)), - "total_amount", TALER_JSON_from_amount (&entry->deposit_value), - "total_fee", TALER_JSON_from_amount (&entry->deposit_fee), - "transaction_id", entry->transaction_id); + GNUNET_JSON_from_data_auto (key), + "deposit_value", TALER_JSON_from_amount (&entry->deposit_value), + "deposit_fee", TALER_JSON_from_amount (&entry->deposit_fee)); /*FIXME put error check*/ json_array_append_new (response, element); @@ -252,7 +247,6 @@ transform_response (const json_t *result) struct GNUNET_CONTAINER_MultiHashMap *map; struct TALER_Amount iter_value; struct TALER_Amount iter_fee; - uint64_t transaction_id; struct Entry *current_entry; /* TODO/FIXME Free the values in hashmap! */ @@ -261,13 +255,16 @@ transform_response (const json_t *result) TALER_JSON_spec_amount ("deposit_value", &iter_value), TALER_JSON_spec_amount ("deposit_fee", &iter_fee), GNUNET_JSON_spec_string ("h_proposal_data", &key), - GNUNET_JSON_spec_uint64 ("transaction_id", &transaction_id), GNUNET_JSON_spec_end () }; map = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); deposits = json_object_get (result, "deposits"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Inspecting deposits: '%s'\n", + json_dumps (deposits, JSON_INDENT (1))); + json_array_foreach (deposits, index, value) { @@ -301,7 +298,6 @@ transform_response (const json_t *result) current_entry = GNUNET_malloc (sizeof (struct Entry)); memcpy (¤t_entry->deposit_value, &iter_value, sizeof (struct TALER_Amount)); memcpy (¤t_entry->deposit_fee, &iter_fee, sizeof (struct TALER_Amount)); - current_entry->transaction_id = transaction_id; if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (map, (const struct GNUNET_HashCode *) &h_key, @@ -317,6 +313,11 @@ transform_response (const json_t *result) GNUNET_CONTAINER_multihashmap_iterate (map, build_deposits_response, deposits_response); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Fresh built deposits array: '%s'.\n", + json_dumps (deposits_response, JSON_INDENT (1))); + result_mod = json_copy ((struct json_t *) result); json_object_del (result_mod, "deposits"); json_object_set (result_mod, "deposits", deposits_response); diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c index fe520394..a18b8079 100644 --- a/src/backenddb/test_merchantdb.c +++ b/src/backenddb/test_merchantdb.c @@ -21,6 +21,7 @@ #include "platform.h" #include <taler/taler_util.h> +#include <taler/taler_json_lib.h> #include "taler_merchantdb_lib.h" #include <jansson.h> diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h index 68ffe7fc..0ed9802d 100644 --- a/src/include/taler_merchant_service.h +++ b/src/include/taler_merchant_service.h @@ -359,6 +359,32 @@ TALER_MERCHANT_pay_cancel (struct TALER_MERCHANT_Pay *ph); struct TALER_MERCHANT_TrackTransferHandle; /** + * Information about the _total_ amount that was paid back + * by the exchange for a given h_proposal_data, by _one_ wire + * transfer. + */ +struct TALER_MERCHANT_TrackTransferDetails { + + /** + * Total amount paid back by the exchange. + */ + struct TALER_Amount deposit_value; + + /** + * Total amount of deposit fees. + */ + struct TALER_Amount deposit_fee; + + /** + * Proposal data's hashcode associated whit this + * payment. NOTE, this value is temporary, as the + * order ID is supposed to be returned here. + */ + struct GNUNET_HashCode h_proposal_data; + +}; + +/** * Callbacks of this type are used to work the result of submitting a /track/transfer request to a merchant * * @param cls closure @@ -382,7 +408,7 @@ typedef void const struct GNUNET_HashCode *h_wire, const struct TALER_Amount *total_amount, unsigned int details_length, - const struct TALER_TrackTransferDetails *details); + const struct TALER_MERCHANT_TrackTransferDetails *details); /** * Request backend to return deposits associated with a given wtid. diff --git a/src/lib/merchant_api_track_transfer.c b/src/lib/merchant_api_track_transfer.c index 10e69815..f9a8709f 100644 --- a/src/lib/merchant_api_track_transfer.c +++ b/src/lib/merchant_api_track_transfer.c @@ -85,7 +85,7 @@ static int check_track_transfer_response_ok (struct TALER_MERCHANT_TrackTransferHandle *wdh, const json_t *json) { - json_t *details_j; + json_t *deposits; struct GNUNET_HashCode h_wire; struct TALER_Amount total_amount; struct TALER_MerchantPublicKeyP merchant_pub; @@ -95,7 +95,7 @@ check_track_transfer_response_ok (struct TALER_MERCHANT_TrackTransferHandle *wdh TALER_JSON_spec_amount ("total", &total_amount), GNUNET_JSON_spec_fixed_auto ("merchant_pub", &merchant_pub), GNUNET_JSON_spec_fixed_auto ("H_wire", &h_wire), - GNUNET_JSON_spec_json ("deposits", &details_j), + GNUNET_JSON_spec_json ("deposits", &deposits), GNUNET_JSON_spec_fixed_auto ("exchange_pub", &exchange_pub), GNUNET_JSON_spec_end() }; @@ -108,25 +108,28 @@ check_track_transfer_response_ok (struct TALER_MERCHANT_TrackTransferHandle *wdh GNUNET_break_op (0); return GNUNET_SYSERR; } - num_details = json_array_size (details_j); + num_details = json_array_size (deposits); { - struct TALER_TrackTransferDetails details[num_details]; + struct TALER_MERCHANT_TrackTransferDetails details[num_details]; unsigned int i; for (i=0;i<num_details;i++) { - struct TALER_TrackTransferDetails *detail = &details[i]; - struct json_t *detail_j = json_array_get (details_j, i); + struct TALER_MERCHANT_TrackTransferDetails *detail = &details[i]; + json_t *deposit = json_array_get (deposits, i); struct GNUNET_JSON_Specification spec_detail[] = { GNUNET_JSON_spec_fixed_auto ("h_proposal_data", &detail->h_proposal_data), - GNUNET_JSON_spec_fixed_auto ("coin_pub", &detail->coin_pub), - TALER_JSON_spec_amount ("deposit_value", &detail->coin_value), - TALER_JSON_spec_amount ("deposit_fee", &detail->coin_fee), + TALER_JSON_spec_amount ("deposit_value", &detail->deposit_value), + TALER_JSON_spec_amount ("deposit_fee", &detail->deposit_fee), GNUNET_JSON_spec_end() }; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Extracting fields from: '%s'.\n", + json_dumps (deposit, JSON_INDENT (1))); + if (GNUNET_OK != - GNUNET_JSON_parse (detail_j, + GNUNET_JSON_parse (deposit, spec_detail, NULL, NULL)) { diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c index c2d728c6..e59d542e 100644 --- a/src/lib/test_merchant_api.c +++ b/src/lib/test_merchant_api.c @@ -1200,7 +1200,7 @@ track_transfer_cb (void *cls, const struct GNUNET_HashCode *h_wire, const struct TALER_Amount *total_amount, unsigned int details_length, - const struct TALER_TrackTransferDetails *details) + const struct TALER_MERCHANT_TrackTransferDetails *details) { struct InterpreterState *is = cls; struct Command *cmd = &is->commands[is->ip]; @@ -1218,90 +1218,12 @@ track_transfer_cb (void *cls, } switch (http_status) { - case MHD_HTTP_OK: - { - const struct Command *ref; - unsigned int i; - int found; - - /** - * Retrieve the deposit operation that is supposed - * to have been paid by the wtid used in this operation. - * After that, check if that operation is actually mentioned - * in the returned data. - */ - ref = find_command (is, - cmd->details.track_transfer.expected_pay_ref); - GNUNET_assert (NULL != ref); - found = GNUNET_NO; - - /** - * Iterating over the details makes little sense now, - * as each payment involves exatcly one coin. - */ - for (i=0;i<details_length;i++) - { - struct TALER_Amount amount_with_fee; - struct TALER_Amount amount_without_fee; - struct TALER_Amount deposit_fee; - const struct Command *cref; - const struct Command *proposal_ref; - struct TALER_CoinSpendPublicKeyP coin_pub; - - /* Extract */ - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (ref->details.pay.amount_without_fee, - &amount_without_fee)); - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (ref->details.pay.amount_with_fee, - &amount_with_fee)); - GNUNET_assert (GNUNET_OK == - TALER_amount_subtract (&deposit_fee, - &amount_with_fee, - &amount_without_fee)); - - /* Find coin ('s public key) associated with the retrieved - deposit. Yes, one deposit - one coin. */ - cref = find_command (is, - ref->details.pay.coin_ref); - proposal_ref = find_command (is, - ref->details.pay.contract_ref); - GNUNET_assert (NULL != cref); - GNUNET_assert (NULL != proposal_ref); - switch (cref->oc) - { - case OC_WITHDRAW_SIGN: - GNUNET_CRYPTO_eddsa_key_get_public - (&cref->details.reserve_withdraw.coin_priv.eddsa_priv, - &coin_pub.eddsa_pub); - break; - default: - GNUNET_assert (0); - } - - if ( (0 == memcmp (&details[i].h_proposal_data, - &proposal_ref->details.proposal.hash, - sizeof (struct GNUNET_HashCode))) && - (0 == TALER_amount_cmp (&details[i].coin_value, - &amount_with_fee)) && - (0 == TALER_amount_cmp (&details[i].coin_fee, - &deposit_fee)) && - (0 == memcmp (&details[i].coin_pub, - &coin_pub, - sizeof (struct TALER_CoinSpendPublicKeyP))) ) - found = GNUNET_YES; - } - if (GNUNET_NO == found) - { - GNUNET_break (0); - json_dumpf (json, stderr, 0); - fail (is); - return; - } + case MHD_HTTP_OK: break; - } - default: - break; + + default: + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Unhandled HTTP status.\n"); } next_command (is); } |