diff options
Diffstat (limited to 'src/lib/exchange_api_reserves_get.c')
-rw-r--r-- | src/lib/exchange_api_reserves_get.c | 75 |
1 files changed, 34 insertions, 41 deletions
diff --git a/src/lib/exchange_api_reserves_get.c b/src/lib/exchange_api_reserves_get.c index 563deeaf6..7f919ef80 100644 --- a/src/lib/exchange_api_reserves_get.c +++ b/src/lib/exchange_api_reserves_get.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of TALER | 2 | This file is part of TALER |
3 | Copyright (C) 2014-2020 Taler Systems SA | 3 | Copyright (C) 2014-2021 Taler Systems SA |
4 | 4 | ||
5 | TALER is free software; you can redistribute it and/or modify it under the | 5 | TALER is free software; you can redistribute it and/or modify it under the |
6 | terms of the GNU General Public License as published by the Free Software | 6 | terms of the GNU General Public License as published by the Free Software |
@@ -234,33 +234,18 @@ handle_reserves_get_finished (void *cls, | |||
234 | } | 234 | } |
235 | 235 | ||
236 | 236 | ||
237 | /** | ||
238 | * Submit a request to obtain the transaction history of a reserve | ||
239 | * from the exchange. Note that while we return the full response to the | ||
240 | * caller for further processing, we do already verify that the | ||
241 | * response is well-formed (i.e. that signatures included in the | ||
242 | * response are all valid and add up to the balance). If the exchange's | ||
243 | * reply is not well-formed, we return an HTTP status code of zero to | ||
244 | * @a cb. | ||
245 | * | ||
246 | * @param exchange the exchange handle; the exchange must be ready to operate | ||
247 | * @param reserve_pub public key of the reserve to inspect | ||
248 | * @param cb the callback to call when a reply for this request is available | ||
249 | * @param cb_cls closure for the above callback | ||
250 | * @return a handle for this request; NULL if the inputs are invalid (i.e. | ||
251 | * signatures fail to verify). In this case, the callback is not called. | ||
252 | */ | ||
253 | struct TALER_EXCHANGE_ReservesGetHandle * | 237 | struct TALER_EXCHANGE_ReservesGetHandle * |
254 | TALER_EXCHANGE_reserves_get (struct TALER_EXCHANGE_Handle *exchange, | 238 | TALER_EXCHANGE_reserves_get ( |
255 | const struct | 239 | struct TALER_EXCHANGE_Handle *exchange, |
256 | TALER_ReservePublicKeyP *reserve_pub, | 240 | const struct TALER_ReservePublicKeyP *reserve_pub, |
257 | TALER_EXCHANGE_ReservesGetCallback cb, | 241 | struct GNUNET_TIME_Relative timeout, |
258 | void *cb_cls) | 242 | TALER_EXCHANGE_ReservesGetCallback cb, |
243 | void *cb_cls) | ||
259 | { | 244 | { |
260 | struct TALER_EXCHANGE_ReservesGetHandle *rgh; | 245 | struct TALER_EXCHANGE_ReservesGetHandle *rgh; |
261 | struct GNUNET_CURL_Context *ctx; | 246 | struct GNUNET_CURL_Context *ctx; |
262 | CURL *eh; | 247 | CURL *eh; |
263 | char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 16]; | 248 | char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 16 + 32]; |
264 | 249 | ||
265 | if (GNUNET_YES != | 250 | if (GNUNET_YES != |
266 | TEAH_handle_is_ready (exchange)) | 251 | TEAH_handle_is_ready (exchange)) |
@@ -271,17 +256,31 @@ TALER_EXCHANGE_reserves_get (struct TALER_EXCHANGE_Handle *exchange, | |||
271 | { | 256 | { |
272 | char pub_str[sizeof (struct TALER_ReservePublicKeyP) * 2]; | 257 | char pub_str[sizeof (struct TALER_ReservePublicKeyP) * 2]; |
273 | char *end; | 258 | char *end; |
259 | char timeout_str[32]; | ||
274 | 260 | ||
275 | end = GNUNET_STRINGS_data_to_string (reserve_pub, | 261 | end = GNUNET_STRINGS_data_to_string ( |
276 | sizeof (struct | 262 | reserve_pub, |
277 | TALER_ReservePublicKeyP), | 263 | sizeof (struct TALER_ReservePublicKeyP), |
278 | pub_str, | 264 | pub_str, |
279 | sizeof (pub_str)); | 265 | sizeof (pub_str)); |
280 | *end = '\0'; | 266 | *end = '\0'; |
281 | GNUNET_snprintf (arg_str, | 267 | GNUNET_snprintf (timeout_str, |
282 | sizeof (arg_str), | 268 | sizeof (timeout_str), |
283 | "/reserves/%s", | 269 | "%llu", |
284 | pub_str); | 270 | (unsigned long long) |
271 | (timeout.rel_value_us | ||
272 | / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us)); | ||
273 | if (GNUNET_TIME_relative_is_zero (timeout)) | ||
274 | GNUNET_snprintf (arg_str, | ||
275 | sizeof (arg_str), | ||
276 | "/reserves/%s", | ||
277 | pub_str); | ||
278 | else | ||
279 | GNUNET_snprintf (arg_str, | ||
280 | sizeof (arg_str), | ||
281 | "/reserves/%s?timeout_ms=%s", | ||
282 | pub_str, | ||
283 | timeout_str); | ||
285 | } | 284 | } |
286 | rgh = GNUNET_new (struct TALER_EXCHANGE_ReservesGetHandle); | 285 | rgh = GNUNET_new (struct TALER_EXCHANGE_ReservesGetHandle); |
287 | rgh->exchange = exchange; | 286 | rgh->exchange = exchange; |
@@ -312,15 +311,9 @@ TALER_EXCHANGE_reserves_get (struct TALER_EXCHANGE_Handle *exchange, | |||
312 | } | 311 | } |
313 | 312 | ||
314 | 313 | ||
315 | /** | ||
316 | * Cancel a reserve status request. This function cannot be used | ||
317 | * on a request handle if a response is already served for it. | ||
318 | * | ||
319 | * @param rgh the reserve status request handle | ||
320 | */ | ||
321 | void | 314 | void |
322 | TALER_EXCHANGE_reserves_get_cancel (struct | 315 | TALER_EXCHANGE_reserves_get_cancel ( |
323 | TALER_EXCHANGE_ReservesGetHandle *rgh) | 316 | struct TALER_EXCHANGE_ReservesGetHandle *rgh) |
324 | { | 317 | { |
325 | if (NULL != rgh->job) | 318 | if (NULL != rgh->job) |
326 | { | 319 | { |
@@ -332,4 +325,4 @@ TALER_EXCHANGE_reserves_get_cancel (struct | |||
332 | } | 325 | } |
333 | 326 | ||
334 | 327 | ||
335 | /* end of exchange_api_reserve.c */ | 328 | /* end of exchange_api_reserves_get.c */ |