summaryrefslogtreecommitdiff
path: root/src/lib/exchange_api_purse_create_with_deposit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/exchange_api_purse_create_with_deposit.c')
-rw-r--r--src/lib/exchange_api_purse_create_with_deposit.c166
1 files changed, 39 insertions, 127 deletions
diff --git a/src/lib/exchange_api_purse_create_with_deposit.c b/src/lib/exchange_api_purse_create_with_deposit.c
index ce0221aa6..fff898e57 100644
--- a/src/lib/exchange_api_purse_create_with_deposit.c
+++ b/src/lib/exchange_api_purse_create_with_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_PurseCreateDepositHandle
{
/**
- * 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.
@@ -83,6 +83,11 @@ struct TALER_EXCHANGE_PurseCreateDepositHandle
char *url;
/**
+ * The base URL of the exchange.
+ */
+ char *exchange_url;
+
+ /**
* Context for #TEH_curl_easy_post(). Keeps the data that must
* persist for Curl to make the upload.
*/
@@ -109,7 +114,7 @@ struct TALER_EXCHANGE_PurseCreateDepositHandle
struct TALER_Amount purse_value_after_fees;
/**
- * Our encryped contract (if we had any).
+ * Our encrypted contract (if we had any).
*/
struct TALER_EncryptedContract econtract;
@@ -170,10 +175,9 @@ handle_purse_create_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:
@@ -181,7 +185,6 @@ handle_purse_create_deposit_finished (void *cls,
break;
case MHD_HTTP_OK:
{
- const struct TALER_EXCHANGE_Keys *key_state;
struct GNUNET_TIME_Timestamp etime;
struct TALER_Amount total_deposited;
struct TALER_ExchangeSignatureP exchange_sig;
@@ -209,9 +212,8 @@ handle_purse_create_deposit_finished (void *cls,
dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
break;
}
- key_state = TALER_EXCHANGE_get_keys (pch->exchange);
if (GNUNET_OK !=
- TALER_EXCHANGE_test_signing_key (key_state,
+ TALER_EXCHANGE_test_signing_key (keys,
&exchange_pub))
{
GNUNET_break_op (0);
@@ -275,107 +277,12 @@ handle_purse_create_deposit_finished (void *cls,
}
break;
case TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS:
- {
- struct TALER_Amount left;
- struct TALER_CoinSpendPublicKeyP pcoin_pub;
- bool found = false;
-
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_amount_conflict_ (
- keys,
- j,
- &pcoin_pub,
- &left))
- {
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- for (unsigned int i = 0; i<pch->num_deposits; i++)
- {
- struct Deposit *deposit = &pch->deposits[i];
-
- if (0 != GNUNET_memcmp (&pcoin_pub,
- &deposit->coin_pub))
- continue;
- if (-1 !=
- TALER_amount_cmp (&left,
- &deposit->contribution))
- {
- /* Balance was sufficient after all; recoup MAY have still been possible */
- GNUNET_break_op (0);
- continue;
- }
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_signature_conflict_ (
- j,
- &deposit->coin_sig))
- {
- GNUNET_break_op (0);
- continue;
- }
- found = true;
- break;
- }
- if (! found)
- {
- /* conflict is for a different coin! */
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- 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_Amount left;
- struct TALER_CoinSpendPublicKeyP pcoin_pub;
- bool found = false;
-
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_amount_conflict_ (
- keys,
- j,
- &pcoin_pub,
- &left))
- {
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- for (unsigned int i = 0; i<pch->num_deposits; i++)
- {
- struct Deposit *deposit = &pch->deposits[i];
-
- if (0 !=
- GNUNET_memcmp (&pcoin_pub,
- &deposit->coin_pub))
- continue;
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_denomination_conflict_ (
- j,
- &deposit->h_denom_pub))
- {
- /* Eh, same denomination, hence no conflict */
- GNUNET_break_op (0);
- continue;
- }
- found = true;
- }
- if (! found)
- {
- /* conflict is for a different coin! */
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- /* meta data conflict is real! */
- break;
- }
+ // FIXME #7267: write check (add to exchange_api_common! */
+ break;
case TALER_EC_EXCHANGE_PURSE_DEPOSIT_CONFLICTING_META_DATA:
{
struct TALER_CoinSpendPublicKeyP coin_pub;
@@ -387,7 +294,7 @@ handle_purse_create_deposit_finished (void *cls,
if (GNUNET_OK !=
TALER_EXCHANGE_check_purse_coin_conflict_ (
&pch->purse_pub,
- pch->exchange->url,
+ pch->exchange_url,
j,
&h_denom_pub,
&phac,
@@ -496,28 +403,27 @@ handle_purse_create_deposit_finished (void *cls,
struct TALER_EXCHANGE_PurseCreateDepositHandle *
TALER_EXCHANGE_purse_create_with_deposit (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_PurseContractPrivateKeyP *purse_priv,
const struct TALER_PurseMergePrivateKeyP *merge_priv,
const struct TALER_ContractDiffiePrivateP *contract_priv,
const json_t *contract_terms,
unsigned int num_deposits,
- const struct TALER_EXCHANGE_PurseDeposit *deposits,
+ const struct TALER_EXCHANGE_PurseDeposit deposits[static num_deposits],
bool upload_contract,
TALER_EXCHANGE_PurseCreateDepositCallback cb,
void *cb_cls)
{
struct TALER_EXCHANGE_PurseCreateDepositHandle *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];
- char *url;
uint32_t min_age = 0;
pch = GNUNET_new (struct TALER_EXCHANGE_PurseCreateDepositHandle);
- pch->exchange = exchange;
pch->cb = cb;
pch->cb_cls = cb_cls;
{
@@ -542,8 +448,6 @@ TALER_EXCHANGE_purse_create_with_deposit (
return NULL;
}
}
- GNUNET_assert (GNUNET_YES ==
- TEAH_handle_is_ready (exchange));
if (GNUNET_OK !=
TALER_JSON_contract_hash (contract_terms,
&pch->h_contract_terms))
@@ -565,13 +469,14 @@ TALER_EXCHANGE_purse_create_with_deposit (
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/purses/%s/create",
+ "purses/%s/create",
pub_str);
}
GNUNET_CRYPTO_eddsa_key_get_public (&merge_priv->eddsa_priv,
&pch->merge_pub.eddsa_pub);
- 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);
@@ -583,8 +488,6 @@ TALER_EXCHANGE_purse_create_with_deposit (
struct Deposit);
deposit_arr = json_array ();
GNUNET_assert (NULL != deposit_arr);
- url = TEAH_path_to_url (exchange,
- "/");
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Signing with URL `%s'\n",
url);
@@ -609,8 +512,11 @@ TALER_EXCHANGE_purse_create_with_deposit (
&attest))
{
GNUNET_break (0);
+ GNUNET_array_grow (pch->deposits,
+ pch->num_deposits,
+ 0);
+ GNUNET_free (pch->url);
json_decref (deposit_arr);
- GNUNET_free (url);
GNUNET_free (pch);
return NULL;
}
@@ -648,7 +554,6 @@ TALER_EXCHANGE_purse_create_with_deposit (
json_array_append_new (deposit_arr,
jdeposit));
}
- GNUNET_free (url);
TALER_wallet_purse_create_sign (pch->purse_expiration,
&pch->h_contract_terms,
&pch->merge_pub,
@@ -705,7 +610,9 @@ TALER_EXCHANGE_purse_create_with_deposit (
curl_easy_cleanup (eh);
json_decref (create_obj);
GNUNET_free (pch->econtract.econtract);
- GNUNET_free (pch->deposits);
+ GNUNET_array_grow (pch->deposits,
+ pch->num_deposits,
+ 0);
GNUNET_free (pch->url);
GNUNET_free (pch);
return NULL;
@@ -714,7 +621,8 @@ TALER_EXCHANGE_purse_create_with_deposit (
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for purse create with deposit: `%s'\n",
pch->url);
- ctx = TEAH_handle_to_context (exchange);
+ pch->keys = TALER_EXCHANGE_keys_incref (keys);
+ pch->exchange_url = GNUNET_strdup (url);
pch->job = GNUNET_CURL_job_add2 (ctx,
eh,
pch->ctx.headers,
@@ -734,8 +642,12 @@ TALER_EXCHANGE_purse_create_with_deposit_cancel (
pch->job = NULL;
}
GNUNET_free (pch->econtract.econtract);
+ GNUNET_free (pch->exchange_url);
GNUNET_free (pch->url);
- GNUNET_free (pch->deposits);
+ GNUNET_array_grow (pch->deposits,
+ pch->num_deposits,
+ 0);
+ TALER_EXCHANGE_keys_decref (pch->keys);
TALER_curl_easy_post_finished (&pch->ctx);
GNUNET_free (pch);
}