diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2017-03-08 15:49:09 +0100 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2017-03-08 15:49:09 +0100 |
commit | 60dc48f7703b9643c711b42748da021d8a2a056d (patch) | |
tree | f1df44602bfbd0915571be78974d870f276576a2 | |
parent | 09c090cdb8afd5e68f13064cac80f31c55fc2c35 (diff) | |
download | merchant-60dc48f7703b9643c711b42748da021d8a2a056d.tar.gz merchant-60dc48f7703b9643c711b42748da021d8a2a056d.tar.bz2 merchant-60dc48f7703b9643c711b42748da021d8a2a056d.zip |
Returning total sum of wire transferred coins instead
of an array about each of them. Adjusting lib accordingly.
-rw-r--r-- | src/backend/taler-merchant-httpd_responses.c | 18 | ||||
-rw-r--r-- | src/include/taler_merchant_service.h | 4 | ||||
-rw-r--r-- | src/lib/merchant_api_track_transaction.c | 70 | ||||
-rw-r--r-- | src/lib/test_merchant_api.c | 76 |
4 files changed, 15 insertions, 153 deletions
diff --git a/src/backend/taler-merchant-httpd_responses.c b/src/backend/taler-merchant-httpd_responses.c index 9c7ef8a5..8cbdf6b0 100644 --- a/src/backend/taler-merchant-httpd_responses.c +++ b/src/backend/taler-merchant-httpd_responses.c @@ -411,33 +411,31 @@ TMH_RESPONSE_make_track_transaction_ok (unsigned int num_transfers, struct MHD_Response *ret; unsigned int i; json_t *j_transfers; + struct TALER_Amount sum; j_transfers = json_array (); for (i=0;i<num_transfers;i++) { const struct TALER_MERCHANT_TransactionWireTransfer *transfer = &transfers[i]; - json_t *j_coins; unsigned int j; - j_coins = json_array (); - for (j=0;j<transfer->num_coins;j++) + sum = transfer->coins[0].amount_with_fee; + for (j=1;j<transfer->num_coins;j++) { const struct TALER_MERCHANT_CoinWireTransfer *coin = &transfer->coins[j]; - GNUNET_assert (0 == - json_array_append_new (j_coins, - json_pack ("{s:o, s:o, s:o}", - "coin_pub", GNUNET_JSON_from_data_auto (&coin->coin_pub), - "amount_with_fee", TALER_JSON_from_amount (&coin->amount_with_fee), - "deposit_fee", TALER_JSON_from_amount (&coin->deposit_fee)))); + GNUNET_assert (GNUNET_SYSERR != TALER_amount_add (&sum, + &sum, + &coin->amount_with_fee)); } + GNUNET_assert (0 == json_array_append_new (j_transfers, json_pack ("{s:s, s:o, s:o, s:o}", "exchange", exchange_uri, "wtid", GNUNET_JSON_from_data_auto (&transfer->wtid), "execution_time", GNUNET_JSON_from_time_abs (transfer->execution_time), - "coins", j_coins))); + "amount", TALER_JSON_from_amount (&sum)))); } ret = TMH_RESPONSE_make_json (j_transfers); json_decref (j_transfers); diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h index b1b25206..68ffe7fc 100644 --- a/src/include/taler_merchant_service.h +++ b/src/include/taler_merchant_service.h @@ -493,9 +493,7 @@ typedef void (*TALER_MERCHANT_TrackTransactionCallback) (void *cls, unsigned int http_status, enum TALER_ErrorCode ec, - const json_t *json, - unsigned int num_transfers, - const struct TALER_MERCHANT_TransactionWireTransfer *transfers); + const json_t *json); /** diff --git a/src/lib/merchant_api_track_transaction.c b/src/lib/merchant_api_track_transaction.c index 787e28c8..abb1d297 100644 --- a/src/lib/merchant_api_track_transaction.c +++ b/src/lib/merchant_api_track_transaction.c @@ -94,73 +94,11 @@ static int parse_track_transaction_ok (struct TALER_MERCHANT_TrackTransactionHandle *tdo, const json_t *json) { - unsigned int num_transfers = json_array_size (json); - struct TALER_MERCHANT_TransactionWireTransfer transfers[num_transfers]; - unsigned int i; - - if (0 == num_transfers) - { - /* zero transfers is not a valid reply */ - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - for (i=0;i<num_transfers;i++) - { - struct TALER_MERCHANT_TransactionWireTransfer *transfer = &transfers[i]; - json_t *coins; - unsigned int j; - struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_fixed_auto ("wtid", - &transfer->wtid), - GNUNET_JSON_spec_absolute_time ("execution_time", - &transfer->execution_time), - GNUNET_JSON_spec_json ("coins", - &coins), - GNUNET_JSON_spec_end() - }; - - if (GNUNET_OK != - GNUNET_JSON_parse (json_array_get (json, i), - spec, - NULL, NULL)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - transfer->num_coins = json_array_size (coins); - transfer->coins = GNUNET_new_array (transfer->num_coins, - struct TALER_MERCHANT_CoinWireTransfer); - for (j=0;j<transfer->num_coins;j++) - { - struct TALER_MERCHANT_CoinWireTransfer *coin = &transfer->coins[j]; - struct GNUNET_JSON_Specification coin_spec[] = { - GNUNET_JSON_spec_fixed_auto ("coin_pub", &coin->coin_pub), - TALER_JSON_spec_amount ("amount_with_fee", &coin->amount_with_fee), - TALER_JSON_spec_amount ("deposit_fee", &coin->deposit_fee), - GNUNET_JSON_spec_end() - }; - if (GNUNET_OK != - GNUNET_JSON_parse (json_array_get (coins, j), - coin_spec, - NULL, NULL)) - { - GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); - free_transfers (i, - transfers); - return GNUNET_SYSERR; - } - } - GNUNET_JSON_parse_free (spec); - } tdo->cb (tdo->cb_cls, MHD_HTTP_OK, TALER_EC_NONE, - json, - num_transfers, - transfers); - free_transfers (num_transfers, - transfers); + json); + return GNUNET_OK; } @@ -219,9 +157,7 @@ handle_track_transaction_finished (void *cls, tdo->cb (tdo->cb_cls, response_code, TALER_JSON_get_error_code (json), - json, - 0, - NULL); + json); } diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c index ac8a24b2..6051a660 100644 --- a/src/lib/test_merchant_api.c +++ b/src/lib/test_merchant_api.c @@ -1343,9 +1343,7 @@ static void track_transaction_cb (void *cls, unsigned int http_status, enum TALER_ErrorCode ec, - const json_t *json, - unsigned int num_transfers, - const struct TALER_MERCHANT_TransactionWireTransfer *transfers) + const json_t *json) { struct InterpreterState *is = cls; struct Command *cmd = &is->commands[is->ip]; @@ -1361,76 +1359,8 @@ track_transaction_cb (void *cls, fail (is); return; } - /* Test result vs. expecations... */ - switch (http_status) - { - case MHD_HTTP_OK: - { - const struct Command *ref; - struct TALER_Amount ea; - struct TALER_Amount wire_fee; - struct TALER_Amount coin_contribution; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Successful /track/tracking\n"); - if (1 != num_transfers) - { - GNUNET_break (0); - json_dumpf (json, stderr, 0); - fail (is); - return; - } - ref = find_command (is, - cmd->details.track_transaction.expected_transfer_ref); - GNUNET_assert (NULL != ref); - if (0 != memcmp (&ref->details.check_bank_transfer.wtid, - &transfers[0].wtid, - sizeof (struct TALER_WireTransferIdentifierRawP))) - { - GNUNET_break (0); - json_dumpf (json, stderr, 0); - fail (is); - return; - } - /* NOTE: this assumes that the wire transfer corresponds to a - single coin involved in a pay/deposit. Thus, this invariant - may not always hold in the future depending on how the - testcases evolve. */ - if (1 != transfers[0].num_coins) - { - GNUNET_break (0); - json_dumpf (json, stderr, 0); - fail (is); - return; - } - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (ref->details.check_bank_transfer.amount, - &ea)); - GNUNET_assert (GNUNET_OK == - TALER_string_to_amount (cmd->details.track_transaction.wire_fee, - &wire_fee)); - GNUNET_assert (GNUNET_OK == - TALER_amount_subtract (&coin_contribution, - &transfers[0].coins[0].amount_with_fee, - &transfers[0].coins[0].deposit_fee)); - GNUNET_assert (GNUNET_OK == - TALER_amount_subtract (&coin_contribution, - &coin_contribution, - &wire_fee)); - if (0 != - TALER_amount_cmp (&ea, - &coin_contribution)) - { - GNUNET_break (0); - json_dumpf (json, stderr, 0); - fail (is); - return; - } - break; - } - default: - break; - } + if (MHD_HTTP_OK != http_status) + fail (is); next_command (is); } |