diff options
Diffstat (limited to 'src/testing/testing_api_cmd_post_transfers.c')
-rw-r--r-- | src/testing/testing_api_cmd_post_transfers.c | 255 |
1 files changed, 51 insertions, 204 deletions
diff --git a/src/testing/testing_api_cmd_post_transfers.c b/src/testing/testing_api_cmd_post_transfers.c index dee1b183..c194bd1e 100644 --- a/src/testing/testing_api_cmd_post_transfers.c +++ b/src/testing/testing_api_cmd_post_transfers.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2020 Taler Systems SA + Copyright (C) 2020, 2023 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 @@ -70,6 +70,11 @@ struct PostTransfersState const char *payto_uri; /** + * Set to the hash of the @e payto_uri. + */ + struct TALER_PaytoHashP h_payto; + + /** * Authentication details to authenticate to the bank. */ struct TALER_BANK_AuthenticationData auth; @@ -85,11 +90,6 @@ struct PostTransfersState struct TALER_Amount credit_amount; /** - * The fee incurred on the wire transfer. - */ - struct TALER_Amount wire_fee; - - /** * Expected HTTP response code. */ unsigned int http_status; @@ -110,10 +110,6 @@ struct PostTransfersState */ unsigned int deposits_length; - /** - * When the exchange executed the transfer. - */ - struct GNUNET_TIME_Timestamp execution_time; }; @@ -121,185 +117,29 @@ struct PostTransfersState * Callback for a POST /transfers operation. * * @param cls closure for this function - * @param hr HTTP response details - * @param execution_time when did the transfer happen (according to the exchange), - * #GNUNET_TIME_UNIT_FOREVER_ABS if the transfer did not yet happen or if - * we have no data from the exchange about it - * @param total_amount total amount of the wire transfer, or NULL if the exchange did - * not provide any details - * @param wire_fee how much did the exchange charge in terms of wire fees, or NULL - * if the exchange did not provide any details - * @param details_length length of the @a details array - * @param details array with details about the combined transactions + * @param ptr response details */ static void transfers_cb (void *cls, - const struct TALER_MERCHANT_HttpResponse *hr, - struct GNUNET_TIME_Timestamp execution_time, - const struct TALER_Amount *total_amount, - const struct TALER_Amount *wire_fee, - unsigned int details_length, - const struct TALER_MERCHANT_TrackTransferDetail details[]) + const struct TALER_MERCHANT_PostTransfersResponse *ptr) { struct PostTransfersState *pts = cls; pts->pth = NULL; - if (pts->http_status != hr->http_status) + if (pts->http_status != ptr->hr.http_status) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u (%d) to command %s\n", - hr->http_status, - (int) hr->ec, + ptr->hr.http_status, + (int) ptr->hr.ec, TALER_TESTING_interpreter_get_current_label (pts->is)); + GNUNET_break (0); TALER_TESTING_interpreter_fail (pts->is); return; } - switch (hr->http_status) + switch (ptr->hr.http_status) { - case MHD_HTTP_OK: - { - pts->execution_time = execution_time; - pts->wire_fee = *wire_fee; - fprintf (stderr, - "FIXME"); - json_dumpf (hr->reply, - stderr, - 0); -#if FIXME_WRITE_PROPPER_CHECK_OF_RETURNED_DATA_HERE - /* this code is some legacy logic that is close to what we - need but needs to be updated to the current API */ - struct TALER_Amount total; - - if (0 > - TALER_amount_subtract (&total, - total_amount, - wire_fee)) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (pts->is); - return; - } - if (0 != - TALER_amount_cmp (&total, - &pts->credit_amount)) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (pts->is); - return; - } - TALER_amount_set_zero (total.currency, - &total); - for (unsigned int i = 0; i<details_length; i++) - { - const struct TALER_MERCHANT_TrackTransferDetail *tdd = &details[i]; - struct TALER_Amount sum; - struct TALER_Amount fees; - - TALER_amount_set_zero (tdd->deposit_value.currency, - &sum); - TALER_amount_set_zero (tdd->deposit_fee.currency, - &fees); - for (unsigned int j = 0; j<pts->deposits_length; j++) - { - const char *label = pts->deposits[j]; - const struct TALER_TESTING_Command *cmd; - const json_t *contract_terms; - const struct TALER_Amount *deposit_value; - const struct TALER_Amount *deposit_fee; - const char *order_id; - - cmd = TALER_TESTING_interpreter_lookup_command (pts->is, - label); - if (NULL == cmd) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (pts->is); - return; - } - if ( (GNUNET_OK != - TALER_TESTING_get_trait_contract_terms (cmd, - 0, - &contract_terms)) || - (GNUNET_OK != - TALER_TESTING_get_trait_amount_obj (cmd, - TALER_TESTING_CMD_DEPOSIT_TRAIT_IDX_DEPOSIT_VALUE, - &deposit_value)) || - (GNUNET_OK != - TALER_TESTING_get_trait_amount_obj (cmd, - TALER_TESTING_CMD_DEPOSIT_TRAIT_IDX_DEPOSIT_FEE, - &deposit_fee)) ) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (pts->is); - return; - } - order_id = json_string_value (json_object_get (contract_terms, - "order_id")); - if (NULL == order_id) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (pts->is); - return; - } - if (0 != strcmp (tdd->order_id, - order_id)) - continue; - if (0 > - TALER_amount_add (&sum, - &sum, - deposit_value)) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (pts->is); - return; - } - if (0 > - TALER_amount_add (&fees, - &fees, - deposit_fee)) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (pts->is); - return; - } - } - if (0 != - TALER_amount_cmp (&sum, - &tdd->deposit_value)) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (pts->is); - return; - } - if (0 != - TALER_amount_cmp (&fees, - &tdd->deposit_fee)) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (pts->is); - return; - } - GNUNET_assert (0 <= - TALER_amount_add (&total, - &total, - &tdd->deposit_value)); - GNUNET_assert (0 <= - TALER_amount_subtract (&total, - &total, - &tdd->deposit_fee)); - } - if (0 != - TALER_amount_cmp (&total, - &pts->credit_amount)) - { - GNUNET_break (0); - TALER_TESTING_interpreter_fail (pts->is); - return; - } -#endif - break; - } - case MHD_HTTP_ACCEPTED: + case MHD_HTTP_NO_CONTENT: break; case MHD_HTTP_UNAUTHORIZED: break; @@ -311,7 +151,7 @@ transfers_cb (void *cls, GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unhandled HTTP status %u for POST /transfers.\n", - hr->http_status); + ptr->hr.http_status); } TALER_TESTING_interpreter_next (pts->is); } @@ -336,14 +176,10 @@ post_transfers_traits (void *cls, struct PostTransfersState *pts = cls; struct TALER_TESTING_Trait traits[] = { TALER_TESTING_make_trait_wtid (&pts->wtid), - TALER_TESTING_make_trait_credit_payto_uri ( - (const char **) &pts->credit_account), + TALER_TESTING_make_trait_credit_payto_uri (pts->credit_account), + TALER_TESTING_make_trait_h_payto (&pts->h_payto), TALER_TESTING_make_trait_amount (&pts->credit_amount), - TALER_TESTING_make_trait_fee (&pts->wire_fee), - TALER_TESTING_make_trait_exchange_url ( - (const char **) &pts->exchange_url), - TALER_TESTING_make_trait_timestamp (0, - &pts->execution_time), + TALER_TESTING_make_trait_exchange_url (pts->exchange_url), TALER_TESTING_make_trait_bank_row (&pts->serial), TALER_TESTING_trait_end (), }; @@ -371,14 +207,15 @@ post_transfers_run2 (void *cls, struct PostTransfersState *pts = cls; pts->is = is; - pts->pth = TALER_MERCHANT_transfers_post (pts->is->ctx, - pts->merchant_url, - &pts->credit_amount, - &pts->wtid, - pts->credit_account, - pts->exchange_url, - &transfers_cb, - pts); + pts->pth = TALER_MERCHANT_transfers_post ( + TALER_TESTING_interpreter_get_context (pts->is), + pts->merchant_url, + &pts->credit_amount, + &pts->wtid, + pts->credit_account, + pts->exchange_url, + &transfers_cb, + pts); GNUNET_assert (NULL != pts->pth); } @@ -400,22 +237,22 @@ debit_cb ( pts->dhh = NULL; switch (reply->http_status) { + case MHD_HTTP_OK: + /* handled below */ + break; case MHD_HTTP_NO_CONTENT: GNUNET_break (0); TALER_TESTING_interpreter_fail (pts->is); return; - case MHD_HTTP_OK: - /* handled below */ - break; default: GNUNET_break (0); TALER_TESTING_interpreter_fail (pts->is); return; } - for (unsigned int i = 0; i<reply->details.success.details_length; i++) + for (unsigned int i = 0; i<reply->details.ok.details_length; i++) { const struct TALER_BANK_DebitDetails *details - = &reply->details.success.details[i]; + = &reply->details.ok.details[i]; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Bank reports transfer of %s to %s\n", @@ -434,17 +271,24 @@ debit_cb ( pts->payto_uri, pts->exchange_url, TALER_B2S (&pts->wtid)); - pts->pth = TALER_MERCHANT_transfers_post (pts->is->ctx, - pts->merchant_url, - &pts->credit_amount, - &pts->wtid, - pts->credit_account, - pts->exchange_url, - &transfers_cb, - pts); + pts->pth = TALER_MERCHANT_transfers_post ( + TALER_TESTING_interpreter_get_context (pts->is), + pts->merchant_url, + &pts->credit_amount, + &pts->wtid, + pts->credit_account, + pts->exchange_url, + &transfers_cb, + pts); GNUNET_assert (NULL != pts->pth); break; } + if (NULL == pts->pth) + { + GNUNET_break (0); + TALER_TESTING_interpreter_fail (pts->is); + return; + } } @@ -468,7 +312,8 @@ post_transfers_run (void *cls, "Looking for transfer of %s from %s at bank\n", TALER_amount2s (&pts->credit_amount), pts->payto_uri); - pts->dhh = TALER_BANK_debit_history (is->ctx, + pts->dhh = TALER_BANK_debit_history (TALER_TESTING_interpreter_get_context ( + is), &pts->auth, UINT64_MAX, -INT64_MAX, @@ -529,6 +374,8 @@ TALER_TESTING_cmd_merchant_post_transfer ( pts->merchant_url = merchant_url; pts->auth = *auth; pts->payto_uri = payto_uri; + TALER_payto_hash (payto_uri, + &pts->h_payto); GNUNET_assert (GNUNET_OK == TALER_string_to_amount (credit_amount, &pts->credit_amount)); |