summaryrefslogtreecommitdiff
path: root/src/lib/exchange_api_purses_get.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/exchange_api_purses_get.c')
-rw-r--r--src/lib/exchange_api_purses_get.c76
1 files changed, 44 insertions, 32 deletions
diff --git a/src/lib/exchange_api_purses_get.c b/src/lib/exchange_api_purses_get.c
index 021954c2d..dc22c75ad 100644
--- a/src/lib/exchange_api_purses_get.c
+++ b/src/lib/exchange_api_purses_get.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ Copyright (C) 2022-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 published by the Free Software
@@ -39,9 +39,9 @@ struct TALER_EXCHANGE_PurseGetHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the exchange this request handle will use
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* The url for this request.
@@ -94,22 +94,29 @@ handle_purse_get_finished (void *cls,
break;
case MHD_HTTP_OK:
{
+ bool no_merge = false;
+ bool no_deposit = false;
struct TALER_ExchangePublicKeyP exchange_pub;
struct TALER_ExchangeSignatureP exchange_sig;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_timestamp ("merge_timestamp",
- &dr.details.success.merge_timestamp),
- GNUNET_JSON_spec_timestamp ("deposit_timestamp",
- &dr.details.success.deposit_timestamp),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_timestamp ("merge_timestamp",
+ &dr.details.ok.merge_timestamp),
+ &no_merge),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_timestamp ("deposit_timestamp",
+ &dr.details.ok.deposit_timestamp),
+ &no_deposit),
TALER_JSON_spec_amount_any ("balance",
- &dr.details.success.balance),
+ &dr.details.ok.balance),
+ GNUNET_JSON_spec_timestamp ("purse_expiration",
+ &dr.details.ok.purse_expiration),
GNUNET_JSON_spec_fixed_auto ("exchange_pub",
&exchange_pub),
GNUNET_JSON_spec_fixed_auto ("exchange_sig",
&exchange_sig),
GNUNET_JSON_spec_end ()
};
- const struct TALER_EXCHANGE_Keys *key_state;
if (GNUNET_OK !=
GNUNET_JSON_parse (j,
@@ -122,9 +129,8 @@ handle_purse_get_finished (void *cls,
break;
}
- key_state = TALER_EXCHANGE_get_keys (pgh->exchange);
if (GNUNET_OK !=
- TALER_EXCHANGE_test_signing_key (key_state,
+ TALER_EXCHANGE_test_signing_key (pgh->keys,
&exchange_pub))
{
GNUNET_break_op (0);
@@ -134,9 +140,9 @@ handle_purse_get_finished (void *cls,
}
if (GNUNET_OK !=
TALER_exchange_online_purse_status_verify (
- dr.details.success.merge_timestamp,
- dr.details.success.deposit_timestamp,
- &dr.details.success.balance,
+ dr.details.ok.merge_timestamp,
+ dr.details.ok.deposit_timestamp,
+ &dr.details.ok.balance,
&exchange_pub,
&exchange_sig))
{
@@ -199,7 +205,9 @@ handle_purse_get_finished (void *cls,
struct TALER_EXCHANGE_PurseGetHandle *
TALER_EXCHANGE_purse_get (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_PurseContractPublicKeyP *purse_pub,
struct GNUNET_TIME_Relative timeout,
bool wait_for_merge,
@@ -209,15 +217,11 @@ TALER_EXCHANGE_purse_get (
struct TALER_EXCHANGE_PurseGetHandle *pgh;
CURL *eh;
char arg_str[sizeof (*purse_pub) * 2 + 64];
+ unsigned int tms
+ = (unsigned int) timeout.rel_value_us
+ / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us;
- if (GNUNET_YES !=
- TEAH_handle_is_ready (exchange))
- {
- GNUNET_break (0);
- return NULL;
- }
pgh = GNUNET_new (struct TALER_EXCHANGE_PurseGetHandle);
- pgh->exchange = exchange;
pgh->cb = cb;
pgh->cb_cls = cb_cls;
{
@@ -232,26 +236,25 @@ TALER_EXCHANGE_purse_get (
*end = '\0';
GNUNET_snprintf (timeout_str,
sizeof (timeout_str),
- "%llu",
- (unsigned long long)
- (timeout.rel_value_us
- / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us));
- if (GNUNET_TIME_relative_is_zero (timeout))
+ "%u",
+ tms);
+ if (0 == tms)
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/purses/%s/%s",
+ "purses/%s/%s",
cpub_str,
wait_for_merge ? "merge" : "deposit");
else
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/purses/%s/%s?timeout_ms=%s",
+ "purses/%s/%s?timeout_ms=%s",
cpub_str,
wait_for_merge ? "merge" : "deposit",
timeout_str);
}
- pgh->url = TEAH_path_to_url (exchange,
- arg_str);
+ pgh->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == pgh->url)
{
GNUNET_free (pgh);
@@ -265,10 +268,18 @@ TALER_EXCHANGE_purse_get (
GNUNET_free (pgh);
return NULL;
}
- pgh->job = GNUNET_CURL_job_add (TEAH_handle_to_context (exchange),
+ if (0 != tms)
+ {
+ GNUNET_break (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_TIMEOUT_MS,
+ (long) (tms + 100L)));
+ }
+ pgh->job = GNUNET_CURL_job_add (ctx,
eh,
&handle_purse_get_finished,
pgh);
+ pgh->keys = TALER_EXCHANGE_keys_incref (keys);
return pgh;
}
@@ -283,6 +294,7 @@ TALER_EXCHANGE_purse_get_cancel (
pgh->job = NULL;
}
GNUNET_free (pgh->url);
+ TALER_EXCHANGE_keys_decref (pgh->keys);
GNUNET_free (pgh);
}