diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2022-03-20 13:20:45 +0100 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2022-03-20 13:20:45 +0100 |
commit | 427417b8352c2036dc6f5c0ca6bd20c0b7edd225 (patch) | |
tree | 54b96b474e9af87586e12763333b04257849798a /src/lib/exchange_api_reserves_get.c | |
parent | dee45bf02284716d5dea18e94193d74e64f7e5bf (diff) |
towards support for new reserve history/status APIs
Diffstat (limited to 'src/lib/exchange_api_reserves_get.c')
-rw-r--r-- | src/lib/exchange_api_reserves_get.c | 100 |
1 files changed, 24 insertions, 76 deletions
diff --git a/src/lib/exchange_api_reserves_get.c b/src/lib/exchange_api_reserves_get.c index a25350e5b..4c2886e0b 100644 --- a/src/lib/exchange_api_reserves_get.c +++ b/src/lib/exchange_api_reserves_get.c @@ -83,19 +83,15 @@ static enum GNUNET_GenericReturnValue handle_reserves_get_ok (struct TALER_EXCHANGE_ReservesGetHandle *rgh, const json_t *j) { - json_t *history; - unsigned int len; - struct TALER_Amount balance; - struct TALER_Amount balance_from_history; + struct TALER_EXCHANGE_ReserveSummary rs = { + .hr.reply = j, + .hr.http_status = MHD_HTTP_OK + }; struct GNUNET_JSON_Specification spec[] = { TALER_JSON_spec_amount_any ("balance", - &balance), + &rs.details.ok.balance), GNUNET_JSON_spec_end () }; - struct TALER_EXCHANGE_HttpResponse hr = { - .reply = j, - .http_status = MHD_HTTP_OK - }; if (GNUNET_OK != GNUNET_JSON_parse (j, @@ -106,55 +102,9 @@ handle_reserves_get_ok (struct TALER_EXCHANGE_ReservesGetHandle *rgh, GNUNET_break_op (0); return GNUNET_SYSERR; } - history = json_object_get (j, - "history"); - if (NULL == history) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - len = json_array_size (history); - { - struct TALER_EXCHANGE_ReserveHistory *rhistory; - - rhistory = GNUNET_new_array (len, - struct TALER_EXCHANGE_ReserveHistory); - if (GNUNET_OK != - TALER_EXCHANGE_parse_reserve_history (rgh->exchange, - history, - &rgh->reserve_pub, - balance.currency, - &balance_from_history, - len, - rhistory)) - { - GNUNET_break_op (0); - TALER_EXCHANGE_free_reserve_history (rhistory, - len); - return GNUNET_SYSERR; - } - if (0 != - TALER_amount_cmp (&balance_from_history, - &balance)) - { - /* exchange cannot add up balances!? */ - GNUNET_break_op (0); - TALER_EXCHANGE_free_reserve_history (rhistory, - len); - return GNUNET_SYSERR; - } - if (NULL != rgh->cb) - { - rgh->cb (rgh->cb_cls, - &hr, - &balance, - len, - rhistory); - rgh->cb = NULL; - } - TALER_EXCHANGE_free_reserve_history (rhistory, - len); - } + rgh->cb (rgh->cb_cls, + &rs); + rgh->cb = NULL; return GNUNET_OK; } @@ -174,61 +124,59 @@ handle_reserves_get_finished (void *cls, { struct TALER_EXCHANGE_ReservesGetHandle *rgh = cls; const json_t *j = response; - struct TALER_EXCHANGE_HttpResponse hr = { - .reply = j, - .http_status = (unsigned int) response_code + struct TALER_EXCHANGE_ReserveSummary rs = { + .hr.reply = j, + .hr.http_status = (unsigned int) response_code }; rgh->job = NULL; switch (response_code) { case 0: - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + rs.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; case MHD_HTTP_OK: if (GNUNET_OK != handle_reserves_get_ok (rgh, j)) { - hr.http_status = 0; - hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + rs.hr.http_status = 0; + rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; } 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); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_NOT_FOUND: /* Nothing really to verify, this should never happen, we should pass the JSON reply to the application */ - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: /* Server had an internal issue; we should retry, but this API leaves this to the application */ - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); break; default: /* unexpected response code */ GNUNET_break_op (0); - hr.ec = TALER_JSON_get_error_code (j); - hr.hint = TALER_JSON_get_error_hint (j); + rs.hr.ec = TALER_JSON_get_error_code (j); + rs.hr.hint = TALER_JSON_get_error_hint (j); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for reserves get\n", (unsigned int) response_code, - (int) hr.ec); + (int) rs.hr.ec); break; } if (NULL != rgh->cb) { rgh->cb (rgh->cb_cls, - &hr, - NULL, - 0, NULL); + &rs); rgh->cb = NULL; } TALER_EXCHANGE_reserves_get_cancel (rgh); |