diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-10-13 18:52:59 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-10-13 18:52:59 +0200 |
commit | acbadd5c6e98282c4c4d568942b4c36c825c3dad (patch) | |
tree | 80560e70be10ff5a77265ef1b5e54bdf3998be62 /src/lib | |
parent | 9e25e39b80657f2fa07be22d878b2d3d8c4b5b45 (diff) |
-modify C API to future-proof it for returning more details as required for KYC implementation
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/exchange_api_deposit.c | 61 | ||||
-rw-r--r-- | src/lib/exchange_api_deposits_get.c | 111 | ||||
-rw-r--r-- | src/lib/exchange_api_withdraw.c | 61 |
3 files changed, 110 insertions, 123 deletions
diff --git a/src/lib/exchange_api_deposit.c b/src/lib/exchange_api_deposit.c index b945f6b76..7f7095f40 100644 --- a/src/lib/exchange_api_deposit.c +++ b/src/lib/exchange_api_deposit.c @@ -324,19 +324,17 @@ handle_deposit_finished (void *cls, struct TALER_EXCHANGE_DepositHandle *dh = cls; struct TALER_ExchangeSignatureP exchange_sig; struct TALER_ExchangePublicKeyP exchange_pub; - struct TALER_ExchangeSignatureP *es = NULL; - struct TALER_ExchangePublicKeyP *ep = NULL; const json_t *j = response; - struct TALER_EXCHANGE_HttpResponse hr = { - .reply = j, - .http_status = (unsigned int) response_code + struct TALER_EXCHANGE_DepositResult dr = { + .hr.reply = j, + .hr.http_status = (unsigned int) response_code }; dh->job = NULL; switch (response_code) { case 0: - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + dr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; case MHD_HTTP_OK: if (GNUNET_OK != @@ -346,31 +344,35 @@ handle_deposit_finished (void *cls, &exchange_pub)) { GNUNET_break_op (0); - hr.http_status = 0; - hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE; + dr.hr.http_status = 0; + dr.hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE; } else { - es = &exchange_sig; - ep = &exchange_pub; + dr.details.success.exchange_sig = &exchange_sig; + dr.details.success.exchange_pub = &exchange_pub; + dr.details.success.deposit_timestamp + = GNUNET_TIME_absolute_ntoh (dh->depconf.exchange_timestamp); + dr.details.success.transaction_base_url; // FIXME + dr.details.success.payment_target_uuid; // FIXME } break; case MHD_HTTP_BAD_REQUEST: /* This should never happen, either us or the exchange is buggy (or API version conflict); just pass JSON reply to the application */ - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + dr.hr.ec = TALER_JSON_get_error_code (j); + dr.hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_FORBIDDEN: - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + dr.hr.ec = TALER_JSON_get_error_code (j); + dr.hr.hint = TALER_JSON_get_error_hint (j); /* Nothing really to verify, exchange says one of the signatures is invalid; as we checked them, this should never happen, we should pass the JSON reply to the application */ break; case MHD_HTTP_NOT_FOUND: - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + dr.hr.ec = TALER_JSON_get_error_code (j); + dr.hr.hint = TALER_JSON_get_error_hint (j); /* Nothing really to verify, this should never happen, we should pass the JSON reply to the application */ break; @@ -381,13 +383,13 @@ handle_deposit_finished (void *cls, j)) { GNUNET_break_op (0); - hr.http_status = 0; - hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE; + dr.hr.http_status = 0; + dr.hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE; } else { - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + dr.hr.ec = TALER_JSON_get_error_code (j); + dr.hr.hint = TALER_JSON_get_error_hint (j); } break; case MHD_HTTP_GONE: @@ -395,31 +397,28 @@ handle_deposit_finished (void *cls, /* Note: one might want to check /keys for revocation signature here, alas tricky in case our /keys is outdated => left to clients */ - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + dr.hr.ec = TALER_JSON_get_error_code (j); + dr.hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + dr.hr.ec = TALER_JSON_get_error_code (j); + dr.hr.hint = TALER_JSON_get_error_hint (j); /* Server had an internal issue; we should retry, but this API leaves this to the application */ break; default: /* unexpected response code */ - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + dr.hr.ec = TALER_JSON_get_error_code (j); + dr.hr.hint = TALER_JSON_get_error_hint (j); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for exchange deposit\n", (unsigned int) response_code, - hr.ec); + dr.hr.ec); GNUNET_break_op (0); break; } dh->cb (dh->cb_cls, - &hr, - GNUNET_TIME_absolute_ntoh (dh->depconf.exchange_timestamp), - es, - ep); + &dr); TALER_EXCHANGE_deposit_cancel (dh); } diff --git a/src/lib/exchange_api_deposits_get.c b/src/lib/exchange_api_deposits_get.c index efe9070f1..6c2aa1cb1 100644 --- a/src/lib/exchange_api_deposits_get.c +++ b/src/lib/exchange_api_deposits_get.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2020 Taler Systems SA + Copyright (C) 2014-2021 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 published by the Free Software @@ -88,7 +88,7 @@ struct TALER_EXCHANGE_DepositGetHandle * @param exchange_sig the exchange's signature * @return #GNUNET_OK if the signature is valid, #GNUNET_SYSERR if not */ -static int +static enum GNUNET_GenericReturnValue verify_deposit_wtid_signature_ok ( const struct TALER_EXCHANGE_DepositGetHandle *dwh, const json_t *json, @@ -133,26 +133,30 @@ handle_deposit_wtid_finished (void *cls, { struct TALER_EXCHANGE_DepositGetHandle *dwh = cls; const json_t *j = response; - struct TALER_EXCHANGE_HttpResponse hr = { - .reply = j, - .http_status = (unsigned int) response_code + struct TALER_EXCHANGE_GetDepositResponse dr = { + .hr.reply = j, + .hr.http_status = (unsigned int) response_code }; dwh->job = NULL; switch (response_code) { case 0: - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + dr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; case MHD_HTTP_OK: { - struct TALER_EXCHANGE_DepositData dd; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_fixed_auto ("wtid", &dwh->depconf.wtid), - TALER_JSON_spec_absolute_time ("execution_time", &dd.execution_time), - TALER_JSON_spec_amount_any ("coin_contribution", &dd.coin_contribution), - GNUNET_JSON_spec_fixed_auto ("exchange_sig", &dd.exchange_sig), - GNUNET_JSON_spec_fixed_auto ("exchange_pub", &dd.exchange_pub), + GNUNET_JSON_spec_fixed_auto ("wtid", + &dr.details.success.wtid), + TALER_JSON_spec_absolute_time ("execution_time", + &dr.details.success.execution_time), + TALER_JSON_spec_amount_any ("coin_contribution", + &dr.details.success.coin_contribution), + GNUNET_JSON_spec_fixed_auto ("exchange_sig", + &dr.details.success.exchange_sig), + GNUNET_JSON_spec_fixed_auto ("exchange_pub", + &dr.details.success.exchange_pub), GNUNET_JSON_spec_end () }; @@ -162,41 +166,37 @@ handle_deposit_wtid_finished (void *cls, NULL, NULL)) { GNUNET_break_op (0); - hr.http_status = 0; - hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + dr.hr.http_status = 0; + dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } dwh->depconf.execution_time = GNUNET_TIME_absolute_hton ( - dd.execution_time); + dr.details.success.execution_time); + dwh->depconf.wtid = dr.details.success.wtid; TALER_amount_hton (&dwh->depconf.coin_contribution, - &dd.coin_contribution); + &dr.details.success.coin_contribution); if (GNUNET_OK != verify_deposit_wtid_signature_ok (dwh, j, - &dd.exchange_pub, - &dd.exchange_sig)) + &dr.details.success.exchange_pub, + &dr.details.success.exchange_sig)) { GNUNET_break_op (0); - hr.http_status = 0; - hr.ec = TALER_EC_EXCHANGE_DEPOSITS_GET_INVALID_SIGNATURE_BY_EXCHANGE; - } - else - { - dd.wtid = dwh->depconf.wtid; - dwh->cb (dwh->cb_cls, - &hr, - &dd); - TALER_EXCHANGE_deposits_get_cancel (dwh); - return; + dr.hr.http_status = 0; + dr.hr.ec = TALER_EC_EXCHANGE_DEPOSITS_GET_INVALID_SIGNATURE_BY_EXCHANGE; + break; } + dwh->cb (dwh->cb_cls, + &dr); + TALER_EXCHANGE_deposits_get_cancel (dwh); + return; } - break; case MHD_HTTP_ACCEPTED: { /* Transaction known, but not executed yet */ - struct GNUNET_TIME_Absolute execution_time; struct GNUNET_JSON_Specification spec[] = { - TALER_JSON_spec_absolute_time ("execution_time", &execution_time), + TALER_JSON_spec_absolute_time ("execution_time", + &dr.details.accepted.execution_time), GNUNET_JSON_spec_end () }; @@ -206,63 +206,54 @@ handle_deposit_wtid_finished (void *cls, NULL, NULL)) { GNUNET_break_op (0); - hr.http_status = 0; - hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + dr.hr.http_status = 0; + dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; break; } - else - { - struct TALER_EXCHANGE_DepositData dd = { - .execution_time = execution_time - }; - - dwh->cb (dwh->cb_cls, - &hr, - &dd); - TALER_EXCHANGE_deposits_get_cancel (dwh); - return; - } + dr.details.accepted.payment_target_uuid; // FIXME + dwh->cb (dwh->cb_cls, + &dr); + TALER_EXCHANGE_deposits_get_cancel (dwh); + return; } - break; case MHD_HTTP_BAD_REQUEST: - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + dr.hr.ec = TALER_JSON_get_error_code (j); + dr.hr.hint = TALER_JSON_get_error_hint (j); /* This should never happen, either us or the exchange is buggy (or API version conflict); just pass JSON reply to the application */ break; case MHD_HTTP_FORBIDDEN: - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + dr.hr.ec = TALER_JSON_get_error_code (j); + dr.hr.hint = TALER_JSON_get_error_hint (j); /* Nothing really to verify, exchange says one of the signatures is invalid; as we checked them, this should never happen, we should pass the JSON reply to the application */ break; case MHD_HTTP_NOT_FOUND: - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + dr.hr.ec = TALER_JSON_get_error_code (j); + dr.hr.hint = TALER_JSON_get_error_hint (j); /* Exchange does not know about transaction; we should pass the reply to the application */ break; case MHD_HTTP_INTERNAL_SERVER_ERROR: - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + dr.hr.ec = TALER_JSON_get_error_code (j); + dr.hr.hint = TALER_JSON_get_error_hint (j); /* Server had an internal issue; we should retry, but this API leaves this to the application */ break; default: /* unexpected response code */ - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + dr.hr.ec = TALER_JSON_get_error_code (j); + dr.hr.hint = TALER_JSON_get_error_hint (j); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for exchange GET deposits\n", (unsigned int) response_code, - (int) hr.ec); + (int) dr.hr.ec); GNUNET_break_op (0); break; } dwh->cb (dwh->cb_cls, - &hr, - NULL); + &dr); TALER_EXCHANGE_deposits_get_cancel (dwh); } diff --git a/src/lib/exchange_api_withdraw.c b/src/lib/exchange_api_withdraw.c index b96adacd4..aa1468247 100644 --- a/src/lib/exchange_api_withdraw.c +++ b/src/lib/exchange_api_withdraw.c @@ -91,44 +91,41 @@ handle_reserve_withdraw_finished ( const struct GNUNET_CRYPTO_RsaSignature *blind_sig) { struct TALER_EXCHANGE_WithdrawHandle *wh = cls; + struct TALER_EXCHANGE_WithdrawResponse wr = { + .hr = *hr + }; wh->wh2 = NULL; - if (MHD_HTTP_OK != hr->http_status) + switch (hr->http_status) { - wh->cb (wh->cb_cls, - hr, - NULL); - } - else - { - struct TALER_FreshCoin fc; - - if (GNUNET_OK != - TALER_planchet_to_coin (&wh->pk.key, - blind_sig, - &wh->ps, - &wh->c_hash, - &fc)) + case MHD_HTTP_OK: { - struct TALER_EXCHANGE_HttpResponse hrx = { - .reply = hr->reply, - .http_status = 0, - .ec = TALER_EC_EXCHANGE_WITHDRAW_UNBLIND_FAILURE - }; - - wh->cb (wh->cb_cls, - &hrx, - NULL); + struct TALER_FreshCoin fc; + + if (GNUNET_OK != + TALER_planchet_to_coin (&wh->pk.key, + blind_sig, + &wh->ps, + &wh->c_hash, + &fc)) + { + wr.hr.http_status = 0; + wr.hr.ec = TALER_EC_EXCHANGE_WITHDRAW_UNBLIND_FAILURE; + break; + } + wr.details.success.sig = fc.sig; + break; } - else - { - wh->cb (wh->cb_cls, - hr, - &fc.sig); - GNUNET_CRYPTO_rsa_signature_free (fc.sig.rsa_signature); - } - + case MHD_HTTP_ACCEPTED: + wr.details.accepted.payment_target_uuid; // FIXME + break; + default: + break; } + wh->cb (wh->cb_cls, + &wr); + if (MHD_HTTP_OK == hr->http_status) + GNUNET_CRYPTO_rsa_signature_free (wr.details.success.sig.rsa_signature); TALER_EXCHANGE_withdraw_cancel (wh); } |