better error handling; use handle result

This commit is contained in:
Özgür Kesim 2023-07-04 11:57:27 +02:00
parent d3772a834f
commit 47620fa81b
Signed by: oec
GPG Key ID: 3D76A56D79EDD9D7

View File

@ -781,21 +781,25 @@ prepare_coins (
const struct TALER_EXCHANGE_AgeWithdrawCoinInput coin_inputs[ const struct TALER_EXCHANGE_AgeWithdrawCoinInput coin_inputs[
static num_coins]) static num_coins])
{ {
#define FAIL_IF(cond) \
if (GNUNET_OK != TALER_amount_set_zero ( do { \
awh->keys->currency, if ((cond)) \
&awh->amount_with_fee)) { \
{ GNUNET_break (! (cond)); \
GNUNET_break (0); goto ERROR; \
return GNUNET_SYSERR; } \
} } while(0)
awh->coin_data = GNUNET_new_array (awh->num_coins,
struct CoinData);
GNUNET_assert (0 < num_coins); GNUNET_assert (0 < num_coins);
awh->age_mask = coin_inputs[0].denom_pub->key.age_mask; awh->age_mask = coin_inputs[0].denom_pub->key.age_mask;
FAIL_IF (GNUNET_OK !=
TALER_amount_set_zero (awh->keys->currency,
&awh->amount_with_fee));
awh->coin_data = GNUNET_new_array (awh->num_coins,
struct CoinData);
for (size_t i = 0; i < num_coins; i++) for (size_t i = 0; i < num_coins; i++)
{ {
struct CoinData *cd = &awh->coin_data[i]; struct CoinData *cd = &awh->coin_data[i];
@ -803,12 +807,7 @@ prepare_coins (
cd->denom_pub = *input->denom_pub; cd->denom_pub = *input->denom_pub;
/* The mask must be the same for all coins */ /* The mask must be the same for all coins */
if (awh->age_mask.bits != input->denom_pub->key.age_mask.bits) FAIL_IF (awh->age_mask.bits != input->denom_pub->key.age_mask.bits);
{
GNUNET_break (0);
TALER_EXCHANGE_age_withdraw_cancel (awh);
return GNUNET_SYSERR;
}
TALER_denom_pub_deep_copy (&cd->denom_pub.key, TALER_denom_pub_deep_copy (&cd->denom_pub.key,
&input->denom_pub->key); &input->denom_pub->key);
@ -817,26 +816,15 @@ prepare_coins (
{ {
struct TALER_Amount coin_total; struct TALER_Amount coin_total;
if (0 > FAIL_IF (0 >
TALER_amount_add (&coin_total, TALER_amount_add (&coin_total,
&cd->denom_pub.fees.withdraw, &cd->denom_pub.fees.withdraw,
&cd->denom_pub.value)) &cd->denom_pub.value));
{
GNUNET_break (0);
TALER_EXCHANGE_age_withdraw_cancel (awh);
return GNUNET_SYSERR;
}
if (0 > FAIL_IF (0 >
TALER_amount_add (&awh->amount_with_fee, TALER_amount_add (&awh->amount_with_fee,
&awh->amount_with_fee, &awh->amount_with_fee,
&coin_total)) &coin_total));
{
/* Overflow here? Very strange, our CPU must be fried... */
GNUNET_break (0);
TALER_EXCHANGE_age_withdraw_cancel (awh);
return GNUNET_SYSERR;
}
} }
for (uint8_t k = 0; k < TALER_CNC_KAPPA; k++) for (uint8_t k = 0; k < TALER_CNC_KAPPA; k++)
@ -847,12 +835,13 @@ prepare_coins (
/* Derive the age restriction from the given secret and /* Derive the age restriction from the given secret and
* the maximum age */ * the maximum age */
GNUNET_assert (GNUNET_OK == FAIL_IF (GNUNET_OK !=
TALER_age_restriction_from_secret ( TALER_age_restriction_from_secret (
&can->secret, &can->secret,
&input->denom_pub->key.age_mask, &input->denom_pub->key.age_mask,
awh->max_age, awh->max_age,
&can->age_commitment_proof)); &can->age_commitment_proof));
TALER_age_commitment_hash (&can->age_commitment_proof.commitment, TALER_age_commitment_hash (&can->age_commitment_proof.commitment,
&can->h_age_commitment); &can->h_age_commitment);
@ -867,28 +856,18 @@ prepare_coins (
TALER_planchet_blinding_secret_create (&can->secret, TALER_planchet_blinding_secret_create (&can->secret,
&can->alg_values, &can->alg_values,
&can->blinding_key); &can->blinding_key);
if (GNUNET_OK != FAIL_IF (GNUNET_OK !=
TALER_planchet_prepare (&cd->denom_pub.key, TALER_planchet_prepare (&cd->denom_pub.key,
&can->alg_values, &can->alg_values,
&can->blinding_key, &can->blinding_key,
&can->coin_priv, &can->coin_priv,
&can->h_age_commitment, &can->h_age_commitment,
&can->h_coin_pub, &can->h_coin_pub,
&can->planchet_detail)) &can->planchet_detail));
{ FAIL_IF (GNUNET_OK !=
GNUNET_break (0); TALER_coin_ev_hash (&can->planchet_detail.blinded_planchet,
TALER_EXCHANGE_age_withdraw_cancel (awh); &can->planchet_detail.denom_pub_hash,
return GNUNET_SYSERR; &can->blinded_coin_h));
}
if (GNUNET_OK !=
TALER_coin_ev_hash (&can->planchet_detail.blinded_planchet,
&can->planchet_detail.denom_pub_hash,
&can->blinded_coin_h))
{
GNUNET_break (0);
TALER_EXCHANGE_age_withdraw_cancel (awh);
return GNUNET_SYSERR;
}
break; break;
} }
case TALER_DENOMINATION_CS: case TALER_DENOMINATION_CS:
@ -911,36 +890,33 @@ prepare_coins (
of the blinded_planchet here; the other part of the blinded_planchet here; the other part
will be done after the /csr-withdraw request! */ will be done after the /csr-withdraw request! */
can->planchet_detail.blinded_planchet.cipher = TALER_DENOMINATION_CS; can->planchet_detail.blinded_planchet.cipher = TALER_DENOMINATION_CS;
can->csr_withdraw_handle = NULL; can->csr_withdraw_handle =
TALER_EXCHANGE_csr_withdraw ( TALER_EXCHANGE_csr_withdraw (awh->curl_ctx,
awh->curl_ctx, awh->exchange_url,
awh->exchange_url, &cd->denom_pub,
&cd->denom_pub, &can->planchet_detail
&can->planchet_detail .blinded_planchet
.blinded_planchet .details
.details .cs_blinded_planchet
.cs_blinded_planchet .nonce,
.nonce, &csr_withdraw_done,
&csr_withdraw_done, &can);
&can); FAIL_IF (NULL == can->csr_withdraw_handle);
if (NULL == can->csr_withdraw_handle)
{
GNUNET_break (0);
TALER_EXCHANGE_age_withdraw_cancel (awh);
return GNUNET_SYSERR;
}
awh->csr_pending++; awh->csr_pending++;
break; break;
} }
default: default:
GNUNET_break (0); FAIL_IF (1);
TALER_EXCHANGE_age_withdraw_cancel (awh);
return GNUNET_SYSERR;
} }
} }
} }
return GNUNET_OK; return GNUNET_OK;
ERROR:
TALER_EXCHANGE_age_withdraw_cancel (awh);
return GNUNET_SYSERR;
#undef FAIL_IF
}; };
struct TALER_EXCHANGE_AgeWithdrawHandle * struct TALER_EXCHANGE_AgeWithdrawHandle *
@ -950,8 +926,8 @@ TALER_EXCHANGE_age_withdraw (
struct TALER_EXCHANGE_Keys *keys, struct TALER_EXCHANGE_Keys *keys,
const struct TALER_ReservePrivateKeyP *reserve_priv, const struct TALER_ReservePrivateKeyP *reserve_priv,
size_t num_coins, size_t num_coins,
const struct TALER_EXCHANGE_AgeWithdrawCoinInput coin_inputs[ const struct TALER_EXCHANGE_AgeWithdrawCoinInput coin_inputs[const static
const static num_coins], num_coins],
uint8_t max_age, uint8_t max_age,
TALER_EXCHANGE_AgeWithdrawCallback res_cb, TALER_EXCHANGE_AgeWithdrawCallback res_cb,
void *res_cb_cls) void *res_cb_cls)