summaryrefslogtreecommitdiff
path: root/src/lib/exchange_api_purse_deposit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/exchange_api_purse_deposit.c')
-rw-r--r--src/lib/exchange_api_purse_deposit.c164
1 files changed, 31 insertions, 133 deletions
diff --git a/src/lib/exchange_api_purse_deposit.c b/src/lib/exchange_api_purse_deposit.c
index 922251012..9c5fa4e78 100644
--- a/src/lib/exchange_api_purse_deposit.c
+++ b/src/lib/exchange_api_purse_deposit.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
@@ -73,9 +73,9 @@ struct TALER_EXCHANGE_PurseDepositHandle
{
/**
- * 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.
@@ -144,10 +144,9 @@ handle_purse_deposit_finished (void *cls,
.hr.reply = j,
.hr.http_status = (unsigned int) response_code
};
- const struct TALER_EXCHANGE_Keys *keys;
+ const struct TALER_EXCHANGE_Keys *keys = pch->keys;
pch->job = NULL;
- keys = TALER_EXCHANGE_get_keys (pch->exchange);
switch (response_code)
{
case 0:
@@ -164,17 +163,17 @@ handle_purse_deposit_finished (void *cls,
GNUNET_JSON_spec_fixed_auto ("exchange_pub",
&exchange_pub),
GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
- &dr.details.success.h_contract_terms),
+ &dr.details.ok.h_contract_terms),
GNUNET_JSON_spec_timestamp ("exchange_timestamp",
&etime),
GNUNET_JSON_spec_timestamp ("purse_expiration",
- &dr.details.success.purse_expiration),
+ &dr.details.ok.purse_expiration),
TALER_JSON_spec_amount ("total_deposited",
keys->currency,
- &dr.details.success.total_deposited),
+ &dr.details.ok.total_deposited),
TALER_JSON_spec_amount ("purse_value_after_fees",
keys->currency,
- &dr.details.success.purse_value_after_fees),
+ &dr.details.ok.purse_value_after_fees),
GNUNET_JSON_spec_end ()
};
@@ -200,11 +199,11 @@ handle_purse_deposit_finished (void *cls,
if (GNUNET_OK !=
TALER_exchange_online_purse_created_verify (
etime,
- dr.details.success.purse_expiration,
- &dr.details.success.purse_value_after_fees,
- &dr.details.success.total_deposited,
+ dr.details.ok.purse_expiration,
+ &dr.details.ok.purse_value_after_fees,
+ &dr.details.ok.total_deposited,
&pch->purse_pub,
- &dr.details.success.h_contract_terms,
+ &dr.details.ok.h_contract_terms,
&exchange_pub,
&exchange_sig))
{
@@ -298,114 +297,11 @@ handle_purse_deposit_finished (void *cls,
break;
}
case TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS:
- {
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_Amount remaining;
- bool found = false;
- const struct Coin *my_coin;
-
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_amount_conflict_ (
- keys,
- j,
- &coin_pub,
- &remaining))
- {
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- for (unsigned int i = 0; i<pch->num_deposits; i++)
- {
- if (0 == GNUNET_memcmp (&coin_pub,
- &pch->coins[i].coin_pub))
- {
- found = true;
- my_coin = &pch->coins[i];
- break;
- }
- }
- if (! found)
- {
- /* proof is about a coin we did not even deposit */
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- if (1 == TALER_amount_cmp (&remaining,
- &my_coin->contribution))
- {
- /* transaction should have still fit */
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_signature_conflict_ (
- j,
- &my_coin->coin_sig))
- {
- /* THIS transaction must not be in the conflicting history */
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- /* everything OK, proof of double-spending was provided */
- break;
- }
+ /* Nothing to check anymore here, proof needs to be
+ checked in the GET /coins/$COIN_PUB handler */
+ break;
case TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_DENOMINATION_KEY:
- {
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_Amount remaining;
- bool found = false;
- const struct Coin *my_coin;
-
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_amount_conflict_ (
- keys,
- j,
- &coin_pub,
- &remaining))
- {
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- for (unsigned int i = 0; i<pch->num_deposits; i++)
- {
- if (0 == GNUNET_memcmp (&coin_pub,
- &pch->coins[i].coin_pub))
- {
- found = true;
- my_coin = &pch->coins[i];
- break;
- }
- }
- if (! found)
- {
- /* proof is about a coin we did not even deposit */
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_denomination_conflict_ (
- j,
- &my_coin->h_denom_pub))
- {
- /* no conflicting denomination detected */
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- /* everything OK, proof of conflicting denomination was provided */
- break;
- }
+ break;
default:
GNUNET_break_op (0);
dr.hr.http_status = 0;
@@ -414,7 +310,7 @@ handle_purse_deposit_finished (void *cls,
} /* ec switch */
break;
case MHD_HTTP_GONE:
- /* could happen if denomination was revoked */
+ /* could happen if denomination was revoked or purse expired */
/* Note: one might want to check /keys for revocation
signature here, alas tricky in case our /keys
is outdated => left to clients */
@@ -447,32 +343,32 @@ handle_purse_deposit_finished (void *cls,
struct TALER_EXCHANGE_PurseDepositHandle *
TALER_EXCHANGE_purse_deposit (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const char *purse_exchange_url,
const struct TALER_PurseContractPublicKeyP *purse_pub,
uint8_t min_age,
unsigned int num_deposits,
- const struct TALER_EXCHANGE_PurseDeposit *deposits,
+ const struct TALER_EXCHANGE_PurseDeposit deposits[static num_deposits],
TALER_EXCHANGE_PurseDepositCallback cb,
void *cb_cls)
{
struct TALER_EXCHANGE_PurseDepositHandle *pch;
- struct GNUNET_CURL_Context *ctx;
json_t *create_obj;
json_t *deposit_arr;
CURL *eh;
char arg_str[sizeof (pch->purse_pub) * 2 + 32];
+ // FIXME: use purse_exchange_url for wad transfers (#7271)
+ (void) purse_exchange_url;
if (0 == num_deposits)
{
GNUNET_break (0);
return NULL;
}
- GNUNET_assert (GNUNET_YES ==
- TEAH_handle_is_ready (exchange));
pch = GNUNET_new (struct TALER_EXCHANGE_PurseDepositHandle);
pch->purse_pub = *purse_pub;
- pch->exchange = exchange;
pch->cb = cb;
pch->cb_cls = cb_cls;
{
@@ -487,11 +383,12 @@ TALER_EXCHANGE_purse_deposit (
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/purses/%s/deposit",
+ "purses/%s/deposit",
pub_str);
}
- pch->url = TEAH_path_to_url (exchange,
- arg_str);
+ pch->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == pch->url)
{
GNUNET_break (0);
@@ -500,8 +397,7 @@ TALER_EXCHANGE_purse_deposit (
}
deposit_arr = json_array ();
GNUNET_assert (NULL != deposit_arr);
- pch->base_url = TEAH_path_to_url (exchange,
- "/");
+ pch->base_url = GNUNET_strdup (url);
pch->num_deposits = num_deposits;
pch->coins = GNUNET_new_array (num_deposits,
struct Coin);
@@ -529,6 +425,7 @@ TALER_EXCHANGE_purse_deposit (
json_decref (deposit_arr);
GNUNET_free (pch->base_url);
GNUNET_free (pch->coins);
+ GNUNET_free (pch->url);
GNUNET_free (pch);
return NULL;
}
@@ -592,7 +489,7 @@ TALER_EXCHANGE_purse_deposit (
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for purse deposit: `%s'\n",
pch->url);
- ctx = TEAH_handle_to_context (exchange);
+ pch->keys = TALER_EXCHANGE_keys_incref (keys);
pch->job = GNUNET_CURL_job_add2 (ctx,
eh,
pch->ctx.headers,
@@ -614,6 +511,7 @@ TALER_EXCHANGE_purse_deposit_cancel (
GNUNET_free (pch->base_url);
GNUNET_free (pch->url);
GNUNET_free (pch->coins);
+ TALER_EXCHANGE_keys_decref (pch->keys);
TALER_curl_easy_post_finished (&pch->ctx);
GNUNET_free (pch);
}