replace GNUNET_asserts() with more proper error handling, fix indentation
This commit is contained in:
parent
1a537490eb
commit
c0c80d4a67
@ -29,6 +29,14 @@
|
||||
#include "taler_json_lib.h"
|
||||
#include "taler-exchange-httpd_keystate.h"
|
||||
|
||||
/**
|
||||
* Enable checking signatures before we hand them out
|
||||
* (even though we should have checked them before).
|
||||
* So technically these checks are redundant, but good
|
||||
* during testing.
|
||||
*/
|
||||
#define SANITY_CHECKS_ON 1
|
||||
|
||||
|
||||
/**
|
||||
* Add headers we want to return in every response.
|
||||
@ -473,7 +481,9 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
||||
GNUNET_break (0); /* out of memory!? */
|
||||
return NULL;
|
||||
}
|
||||
for (const struct TALER_EXCHANGEDB_TransactionList *pos = tl; NULL != pos; pos = pos->next)
|
||||
for (const struct TALER_EXCHANGEDB_TransactionList *pos = tl;
|
||||
NULL != pos;
|
||||
pos = pos->next)
|
||||
{
|
||||
switch (pos->type)
|
||||
{
|
||||
@ -494,6 +504,7 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
||||
&deposit->deposit_fee);
|
||||
dr.merchant = deposit->merchant_pub;
|
||||
dr.coin_pub = deposit->coin.coin_pub;
|
||||
#if SANITY_CHECKS_ON
|
||||
/* internal sanity check before we hand out a bogus sig... */
|
||||
if (GNUNET_OK !=
|
||||
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_DEPOSIT,
|
||||
@ -505,8 +516,8 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
||||
json_decref (history);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GNUNET_assert (0 ==
|
||||
#endif
|
||||
if (0 !=
|
||||
json_array_append_new (history,
|
||||
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o}",
|
||||
"type", "DEPOSIT",
|
||||
@ -517,7 +528,12 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
||||
"merchant_pub", GNUNET_JSON_from_data_auto (&deposit->merchant_pub),
|
||||
"h_contract_terms", GNUNET_JSON_from_data_auto (&deposit->h_contract_terms),
|
||||
"h_wire", GNUNET_JSON_from_data_auto (&deposit->h_wire),
|
||||
"coin_sig", GNUNET_JSON_from_data_auto (&deposit->csig))));
|
||||
"coin_sig", GNUNET_JSON_from_data_auto (&deposit->csig))))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
json_decref (history);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TALER_EXCHANGEDB_TT_REFRESH_MELT:
|
||||
@ -533,6 +549,7 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
||||
TALER_amount_hton (&ms.melt_fee,
|
||||
&melt->melt_fee);
|
||||
ms.coin_pub = melt->session.coin.coin_pub;
|
||||
#if SANITY_CHECKS_ON
|
||||
/* internal sanity check before we hand out a bogus sig... */
|
||||
if (GNUNET_OK !=
|
||||
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_MELT,
|
||||
@ -544,15 +561,20 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
||||
json_decref (history);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GNUNET_assert (0 ==
|
||||
#endif
|
||||
if (0 !=
|
||||
json_array_append_new (history,
|
||||
json_pack ("{s:s, s:o, s:o, s:o, s:o}",
|
||||
"type", "MELT",
|
||||
"amount", TALER_JSON_from_amount (&melt->session.amount_with_fee),
|
||||
"melt_fee", TALER_JSON_from_amount (&melt->melt_fee),
|
||||
"rc", GNUNET_JSON_from_data_auto (&melt->session.rc),
|
||||
"coin_sig", GNUNET_JSON_from_data_auto (&melt->session.coin_sig))));
|
||||
"coin_sig", GNUNET_JSON_from_data_auto (&melt->session.coin_sig))))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
json_decref (history);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TALER_EXCHANGEDB_TT_REFUND:
|
||||
@ -580,6 +602,7 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
||||
&refund->refund_amount);
|
||||
TALER_amount_hton (&rr.refund_fee,
|
||||
&refund->refund_fee);
|
||||
#if SANITY_CHECKS_ON
|
||||
/* internal sanity check before we hand out a bogus sig... */
|
||||
if (GNUNET_OK !=
|
||||
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_REFUND,
|
||||
@ -591,8 +614,8 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
||||
json_decref (history);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GNUNET_assert (0 ==
|
||||
#endif
|
||||
if (0 !=
|
||||
json_array_append_new (history,
|
||||
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:I, s:o}",
|
||||
"type", "REFUND",
|
||||
@ -601,7 +624,12 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
||||
"h_contract_terms", GNUNET_JSON_from_data_auto (&refund->h_contract_terms),
|
||||
"merchant_pub", GNUNET_JSON_from_data_auto (&refund->merchant_pub),
|
||||
"rtransaction_id", (json_int_t) refund->rtransaction_id,
|
||||
"merchant_sig", GNUNET_JSON_from_data_auto (&refund->merchant_sig))));
|
||||
"merchant_sig", GNUNET_JSON_from_data_auto (&refund->merchant_sig))))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
json_decref (history);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TALER_EXCHANGEDB_TT_PAYBACK:
|
||||
@ -627,7 +655,7 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
||||
json_decref (history);
|
||||
return NULL;
|
||||
}
|
||||
GNUNET_assert (0 ==
|
||||
if (0 !=
|
||||
json_array_append_new (history,
|
||||
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
|
||||
"type", "PAYBACK",
|
||||
@ -635,7 +663,12 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
||||
"exchange_sig", GNUNET_JSON_from_data_auto (&esig),
|
||||
"exchange_pub", GNUNET_JSON_from_data_auto (&epub),
|
||||
"reserve_pub", GNUNET_JSON_from_data_auto (&payback->reserve_pub),
|
||||
"timestamp", GNUNET_JSON_from_time_abs (payback->timestamp))));
|
||||
"timestamp", GNUNET_JSON_from_time_abs (payback->timestamp))))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
json_decref (history);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -717,7 +750,7 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
||||
return NULL;
|
||||
}
|
||||
ret |= 1;
|
||||
GNUNET_assert (0 ==
|
||||
if (0 !=
|
||||
json_array_append_new (json_history,
|
||||
json_pack ("{s:s, s:o, s:s, s:o, s:o}",
|
||||
"type", "DEPOSIT",
|
||||
@ -725,7 +758,12 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
||||
"sender_account_url", pos->details.bank->sender_account_details,
|
||||
"wire_reference", GNUNET_JSON_from_data (pos->details.bank->wire_reference,
|
||||
pos->details.bank->wire_reference_size),
|
||||
"amount", TALER_JSON_from_amount (&pos->details.bank->amount))));
|
||||
"amount", TALER_JSON_from_amount (&pos->details.bank->amount))))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
json_decref (json_history);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
case TALER_EXCHANGEDB_RO_WITHDRAW_COIN:
|
||||
{
|
||||
@ -749,7 +787,7 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
||||
}
|
||||
}
|
||||
ret |= 2;
|
||||
GNUNET_assert (0 ==
|
||||
if (0 !=
|
||||
json_array_append_new (json_history,
|
||||
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
|
||||
"type", "WITHDRAW",
|
||||
@ -757,7 +795,12 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
||||
"h_coin_envelope", GNUNET_JSON_from_data_auto (&pos->details.withdraw->h_coin_envelope),
|
||||
"h_denom_pub", GNUNET_JSON_from_data_auto (&pos->details.withdraw->denom_pub_hash),
|
||||
"withdraw_fee", TALER_JSON_from_amount (&pos->details.withdraw->withdraw_fee),
|
||||
"amount", TALER_JSON_from_amount (&value))));
|
||||
"amount", TALER_JSON_from_amount (&value))))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
json_decref (json_history);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TALER_EXCHANGEDB_RO_PAYBACK_COIN:
|
||||
@ -798,7 +841,7 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GNUNET_assert (0 ==
|
||||
if (0 !=
|
||||
json_array_append_new (json_history,
|
||||
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
|
||||
"type", "PAYBACK",
|
||||
@ -806,12 +849,16 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
||||
"exchange_sig", GNUNET_JSON_from_data_auto (&sig),
|
||||
"timestamp", GNUNET_JSON_from_time_abs (payback->timestamp),
|
||||
"amount", TALER_JSON_from_amount (&payback->value),
|
||||
"coin_pub", GNUNET_JSON_from_data_auto (&payback->coin.coin_pub))));
|
||||
"coin_pub", GNUNET_JSON_from_data_auto (&payback->coin.coin_pub))))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
json_decref (json_history);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK:
|
||||
{
|
||||
|
||||
struct TALER_ReserveCloseConfirmationPS rcc;
|
||||
struct TALER_ExchangePublicKeyP pub;
|
||||
struct TALER_ExchangeSignatureP sig;
|
||||
@ -829,6 +876,7 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
||||
&withdraw_total,
|
||||
&value))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
json_decref (json_history);
|
||||
return NULL;
|
||||
}
|
||||
@ -855,7 +903,7 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
||||
json_decref (json_history);
|
||||
return NULL;
|
||||
}
|
||||
GNUNET_assert (0 ==
|
||||
if (0 !=
|
||||
json_array_append_new (json_history,
|
||||
json_pack ("{s:s, s:s, s:o, s:o, s:o, s:o, s:o, s:o}",
|
||||
"type", "CLOSING",
|
||||
@ -865,7 +913,12 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
||||
"exchange_sig", GNUNET_JSON_from_data_auto (&sig),
|
||||
"timestamp", GNUNET_JSON_from_time_abs (pos->details.closing->execution_date),
|
||||
"amount", TALER_JSON_from_amount (&value),
|
||||
"closing_fee", TALER_JSON_from_amount (&pos->details.closing->closing_fee))));
|
||||
"closing_fee", TALER_JSON_from_amount (&pos->details.closing->closing_fee))))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
json_decref (json_history);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -918,5 +971,4 @@ TEH_RESPONSE_reply_transaction_unknown (struct MHD_Connection *connection,
|
||||
"code", (json_int_t) ec);
|
||||
}
|
||||
|
||||
|
||||
/* end of taler-exchange-httpd_responses.c */
|
||||
|
Loading…
Reference in New Issue
Block a user