diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-04-05 22:05:38 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-04-05 22:05:38 +0200 |
commit | bf8c5982a2e79f0b5198a0033dd41e9702d093f9 (patch) | |
tree | 93b62feb9b7e24ae3d4f73b1a5f883a8fc368bfe /src/lib/exchange_api_deposit.c | |
parent | 5059da7108fb2d65fc3844ffe695574c532f8dff (diff) | |
download | exchange-bf8c5982a2e79f0b5198a0033dd41e9702d093f9.tar.xz |
make exchange API more uniform in how information is returned
Diffstat (limited to 'src/lib/exchange_api_deposit.c')
-rw-r--r-- | src/lib/exchange_api_deposit.c | 87 |
1 files changed, 47 insertions, 40 deletions
diff --git a/src/lib/exchange_api_deposit.c b/src/lib/exchange_api_deposit.c index 54dad7473..e01a3c580 100644 --- a/src/lib/exchange_api_deposit.c +++ b/src/lib/exchange_api_deposit.c @@ -156,25 +156,24 @@ auditor_cb (void *cls, TALER_amount_ntoh (&amount_without_fee, &dh->depconf.amount_without_fee); aie = GNUNET_new (struct TEAH_AuditorInteractionEntry); - aie->dch = TALER_AUDITOR_deposit_confirmation (ah, - &dh->depconf.h_wire, - &dh->depconf.h_contract_terms, - GNUNET_TIME_absolute_ntoh ( - dh->depconf.timestamp), - GNUNET_TIME_absolute_ntoh ( - dh->depconf.refund_deadline), - &amount_without_fee, - &dh->depconf.coin_pub, - &dh->depconf.merchant, - &dh->exchange_pub, - &dh->exchange_sig, - &key_state->master_pub, - spk->valid_from, - spk->valid_until, - spk->valid_legal, - &spk->master_sig, - &TEAH_acc_confirmation_cb, - aie); + aie->dch = TALER_AUDITOR_deposit_confirmation ( + ah, + &dh->depconf.h_wire, + &dh->depconf.h_contract_terms, + GNUNET_TIME_absolute_ntoh (dh->depconf.timestamp), + GNUNET_TIME_absolute_ntoh (dh->depconf.refund_deadline), + &amount_without_fee, + &dh->depconf.coin_pub, + &dh->depconf.merchant, + &dh->exchange_pub, + &dh->exchange_sig, + &key_state->master_pub, + spk->valid_from, + spk->valid_until, + spk->valid_legal, + &spk->master_sig, + &TEAH_acc_confirmation_cb, + aie); return aie; } @@ -305,13 +304,16 @@ handle_deposit_finished (void *cls, struct TALER_ExchangeSignatureP *es = NULL; struct TALER_ExchangePublicKeyP *ep = NULL; const json_t *j = response; - enum TALER_ErrorCode ec; + struct TALER_EXCHANGE_HttpResponse hr = { + .reply = j, + .http_status = (unsigned int) response_code + }; dh->job = NULL; switch (response_code) { case 0: - ec = TALER_EC_INVALID_RESPONSE; + hr.ec = TALER_EC_INVALID_RESPONSE; break; case MHD_HTTP_OK: if (GNUNET_OK != @@ -321,66 +323,71 @@ handle_deposit_finished (void *cls, &exchange_pub)) { GNUNET_break_op (0); - response_code = 0; - ec = TALER_EC_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE; + hr.http_status = 0; + hr.ec = TALER_EC_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE; } else { es = &exchange_sig; ep = &exchange_pub; - ec = TALER_EC_NONE; } 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 */ - ec = TALER_JSON_get_error_code (j); + hr.ec = TALER_JSON_get_error_code (j); + hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_CONFLICT: /* Double spending; check signatures on transaction history */ - ec = TALER_JSON_get_error_code (j); if (GNUNET_OK != verify_deposit_signature_forbidden (dh, j)) { GNUNET_break_op (0); - response_code = 0; - ec = TALER_EC_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE; + hr.http_status = 0; + hr.ec = TALER_EC_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE; + } + else + { + hr.ec = TALER_JSON_get_error_code (j); + hr.hint = TALER_JSON_get_error_hint (j); } break; case MHD_HTTP_FORBIDDEN: - ec = TALER_JSON_get_error_code (j); + hr.ec = TALER_JSON_get_error_code (j); + 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: - ec = TALER_JSON_get_error_code (j); + hr.ec = TALER_JSON_get_error_code (j); + 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 */ + happen, we should pass the JSON reply to the application */ break; case MHD_HTTP_INTERNAL_SERVER_ERROR: - ec = TALER_JSON_get_error_code (j); + hr.ec = TALER_JSON_get_error_code (j); + 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 */ - ec = TALER_JSON_get_error_code (j); + hr.ec = TALER_JSON_get_error_code (j); + hr.hint = TALER_JSON_get_error_hint (j); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d\n", (unsigned int) response_code, - ec); - GNUNET_break (0); - response_code = 0; + hr.ec); + GNUNET_break_op (0); break; } dh->cb (dh->cb_cls, - response_code, - ec, + &hr, es, - ep, - j); + ep); TALER_EXCHANGE_deposit_cancel (dh); } |