replace GNUNET_asserts() with more proper error handling, fix indentation

This commit is contained in:
Christian Grothoff 2019-07-22 13:02:07 +02:00
parent 1a537490eb
commit c0c80d4a67
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC

View File

@ -29,6 +29,14 @@
#include "taler_json_lib.h" #include "taler_json_lib.h"
#include "taler-exchange-httpd_keystate.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. * Add headers we want to return in every response.
@ -97,7 +105,7 @@ TEH_RESPONSE_can_compress (struct MHD_Connection *connection)
*/ */
int int
TEH_RESPONSE_body_compress (void **buf, TEH_RESPONSE_body_compress (void **buf,
size_t *buf_size) size_t *buf_size)
{ {
Bytef *cbuf; Bytef *cbuf;
uLongf cbuf_size; uLongf cbuf_size;
@ -251,14 +259,14 @@ TEH_RESPONSE_reply_json_pack (struct MHD_Connection *connection,
*/ */
int int
TEH_RESPONSE_reply_arg_invalid (struct MHD_Connection *connection, TEH_RESPONSE_reply_arg_invalid (struct MHD_Connection *connection,
enum TALER_ErrorCode ec, enum TALER_ErrorCode ec,
const char *param_name) const char *param_name)
{ {
return TEH_RESPONSE_reply_json_pack (connection, return TEH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_BAD_REQUEST, MHD_HTTP_BAD_REQUEST,
"{s:s, s:I, s:s}", "{s:s, s:I, s:s}",
"error", "invalid parameter", "error", "invalid parameter",
"code", (json_int_t) ec, "code", (json_int_t) ec,
"parameter", param_name); "parameter", param_name);
} }
@ -275,14 +283,14 @@ TEH_RESPONSE_reply_arg_invalid (struct MHD_Connection *connection,
*/ */
int int
TEH_RESPONSE_reply_arg_unknown (struct MHD_Connection *connection, TEH_RESPONSE_reply_arg_unknown (struct MHD_Connection *connection,
enum TALER_ErrorCode ec, enum TALER_ErrorCode ec,
const char *param_name) const char *param_name)
{ {
return TEH_RESPONSE_reply_json_pack (connection, return TEH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_NOT_FOUND, MHD_HTTP_NOT_FOUND,
"{s:s, s:I, s:s}", "{s:s, s:I, s:s}",
"error", "unknown entity referenced", "error", "unknown entity referenced",
"code", (json_int_t) ec, "code", (json_int_t) ec,
"parameter", param_name); "parameter", param_name);
} }
@ -297,14 +305,14 @@ TEH_RESPONSE_reply_arg_unknown (struct MHD_Connection *connection,
*/ */
int int
TEH_RESPONSE_reply_signature_invalid (struct MHD_Connection *connection, TEH_RESPONSE_reply_signature_invalid (struct MHD_Connection *connection,
enum TALER_ErrorCode ec, enum TALER_ErrorCode ec,
const char *param_name) const char *param_name)
{ {
return TEH_RESPONSE_reply_json_pack (connection, return TEH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_UNAUTHORIZED, MHD_HTTP_UNAUTHORIZED,
"{s:s, s:I, s:s}", "{s:s, s:I, s:s}",
"error", "invalid signature", "error", "invalid signature",
"code", (json_int_t) ec, "code", (json_int_t) ec,
"parameter", param_name); "parameter", param_name);
} }
@ -370,7 +378,7 @@ TEH_RESPONSE_reply_external_error (struct MHD_Connection *connection,
MHD_HTTP_BAD_REQUEST, MHD_HTTP_BAD_REQUEST,
"{s:s, s:I, s:s}", "{s:s, s:I, s:s}",
"error", "client error", "error", "client error",
"code", (json_int_t) ec, "code", (json_int_t) ec,
"hint", hint); "hint", hint);
} }
@ -391,7 +399,7 @@ TEH_RESPONSE_reply_commit_error (struct MHD_Connection *connection,
MHD_HTTP_INTERNAL_SERVER_ERROR, MHD_HTTP_INTERNAL_SERVER_ERROR,
"{s:s, s:I}", "{s:s, s:I}",
"error", "commit failure", "error", "commit failure",
"code", (json_int_t) ec); "code", (json_int_t) ec);
} }
@ -405,10 +413,10 @@ TEH_RESPONSE_reply_commit_error (struct MHD_Connection *connection,
*/ */
int int
TEH_RESPONSE_reply_internal_db_error (struct MHD_Connection *connection, TEH_RESPONSE_reply_internal_db_error (struct MHD_Connection *connection,
enum TALER_ErrorCode ec) enum TALER_ErrorCode ec)
{ {
return TEH_RESPONSE_reply_internal_error (connection, return TEH_RESPONSE_reply_internal_error (connection,
ec, ec,
"Failure in database interaction"); "Failure in database interaction");
} }
@ -452,7 +460,7 @@ TEH_RESPONSE_reply_invalid_json (struct MHD_Connection *connection)
MHD_HTTP_BAD_REQUEST, MHD_HTTP_BAD_REQUEST,
"{s:s, s:I}", "{s:s, s:I}",
"error", "invalid json", "error", "invalid json",
"code", (json_int_t) TALER_EC_JSON_INVALID); "code", (json_int_t) TALER_EC_JSON_INVALID);
} }
@ -473,7 +481,9 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
GNUNET_break (0); /* out of memory!? */ GNUNET_break (0); /* out of memory!? */
return NULL; 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) switch (pos->type)
{ {
@ -494,31 +504,37 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
&deposit->deposit_fee); &deposit->deposit_fee);
dr.merchant = deposit->merchant_pub; dr.merchant = deposit->merchant_pub;
dr.coin_pub = deposit->coin.coin_pub; dr.coin_pub = deposit->coin.coin_pub;
/* internal sanity check before we hand out a bogus sig... */ #if SANITY_CHECKS_ON
/* internal sanity check before we hand out a bogus sig... */
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_DEPOSIT, GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_DEPOSIT,
&dr.purpose, &dr.purpose,
&deposit->csig.eddsa_signature, &deposit->csig.eddsa_signature,
&deposit->coin.coin_pub.eddsa_pub)) &deposit->coin.coin_pub.eddsa_pub))
{ {
GNUNET_break (0); GNUNET_break (0);
json_decref (history); json_decref (history);
return NULL; return NULL;
} }
#endif
GNUNET_assert (0 == if (0 !=
json_array_append_new (history, 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}", json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o}",
"type", "DEPOSIT", "type", "DEPOSIT",
"amount", TALER_JSON_from_amount (&deposit->amount_with_fee), "amount", TALER_JSON_from_amount (&deposit->amount_with_fee),
"deposit_fee", TALER_JSON_from_amount (&deposit->deposit_fee), "deposit_fee", TALER_JSON_from_amount (&deposit->deposit_fee),
"timestamp", GNUNET_JSON_from_time_abs (deposit->timestamp), "timestamp", GNUNET_JSON_from_time_abs (deposit->timestamp),
"refund_deadline", GNUNET_JSON_from_time_abs (deposit->refund_deadline), "refund_deadline", GNUNET_JSON_from_time_abs (deposit->refund_deadline),
"merchant_pub", GNUNET_JSON_from_data_auto (&deposit->merchant_pub), "merchant_pub", GNUNET_JSON_from_data_auto (&deposit->merchant_pub),
"h_contract_terms", GNUNET_JSON_from_data_auto (&deposit->h_contract_terms), "h_contract_terms", GNUNET_JSON_from_data_auto (&deposit->h_contract_terms),
"h_wire", GNUNET_JSON_from_data_auto (&deposit->h_wire), "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))))
break; {
GNUNET_break (0);
json_decref (history);
return NULL;
}
break;
} }
case TALER_EXCHANGEDB_TT_REFRESH_MELT: case TALER_EXCHANGEDB_TT_REFRESH_MELT:
{ {
@ -533,42 +549,48 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
TALER_amount_hton (&ms.melt_fee, TALER_amount_hton (&ms.melt_fee,
&melt->melt_fee); &melt->melt_fee);
ms.coin_pub = melt->session.coin.coin_pub; ms.coin_pub = melt->session.coin.coin_pub;
/* internal sanity check before we hand out a bogus sig... */ #if SANITY_CHECKS_ON
/* internal sanity check before we hand out a bogus sig... */
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_MELT, GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_MELT,
&ms.purpose, &ms.purpose,
&melt->session.coin_sig.eddsa_signature, &melt->session.coin_sig.eddsa_signature,
&melt->session.coin.coin_pub.eddsa_pub)) &melt->session.coin.coin_pub.eddsa_pub))
{ {
GNUNET_break (0); GNUNET_break (0);
json_decref (history); json_decref (history);
return NULL; return NULL;
} }
#endif
GNUNET_assert (0 == if (0 !=
json_array_append_new (history, json_array_append_new (history,
json_pack ("{s:s, s:o, s:o, s:o, s:o}", json_pack ("{s:s, s:o, s:o, s:o, s:o}",
"type", "MELT", "type", "MELT",
"amount", TALER_JSON_from_amount (&melt->session.amount_with_fee), "amount", TALER_JSON_from_amount (&melt->session.amount_with_fee),
"melt_fee", TALER_JSON_from_amount (&melt->melt_fee), "melt_fee", TALER_JSON_from_amount (&melt->melt_fee),
"rc", GNUNET_JSON_from_data_auto (&melt->session.rc), "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; break;
case TALER_EXCHANGEDB_TT_REFUND: case TALER_EXCHANGEDB_TT_REFUND:
{ {
struct TALER_RefundRequestPS rr; struct TALER_RefundRequestPS rr;
const struct TALER_EXCHANGEDB_Refund *refund = pos->details.refund; const struct TALER_EXCHANGEDB_Refund *refund = pos->details.refund;
struct TALER_Amount value; struct TALER_Amount value;
if (GNUNET_OK != if (GNUNET_OK !=
TALER_amount_subtract (&value, TALER_amount_subtract (&value,
&refund->refund_amount, &refund->refund_amount,
&refund->refund_fee)) &refund->refund_fee))
{ {
GNUNET_break (0); GNUNET_break (0);
json_decref (history); json_decref (history);
return NULL; return NULL;
} }
rr.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_REFUND); rr.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_REFUND);
rr.purpose.size = htonl (sizeof (struct TALER_RefundRequestPS)); rr.purpose.size = htonl (sizeof (struct TALER_RefundRequestPS));
@ -580,28 +602,34 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
&refund->refund_amount); &refund->refund_amount);
TALER_amount_hton (&rr.refund_fee, TALER_amount_hton (&rr.refund_fee,
&refund->refund_fee); &refund->refund_fee);
/* internal sanity check before we hand out a bogus sig... */ #if SANITY_CHECKS_ON
/* internal sanity check before we hand out a bogus sig... */
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_REFUND, GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_REFUND,
&rr.purpose, &rr.purpose,
&refund->merchant_sig.eddsa_sig, &refund->merchant_sig.eddsa_sig,
&refund->merchant_pub.eddsa_pub)) &refund->merchant_pub.eddsa_pub))
{ {
GNUNET_break (0); GNUNET_break (0);
json_decref (history); json_decref (history);
return NULL; return NULL;
} }
#endif
GNUNET_assert (0 == if (0 !=
json_array_append_new (history, json_array_append_new (history,
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:I, s:o}", json_pack ("{s:s, s:o, s:o, s:o, s:o, s:I, s:o}",
"type", "REFUND", "type", "REFUND",
"amount", TALER_JSON_from_amount (&value), "amount", TALER_JSON_from_amount (&value),
"refund_fee", TALER_JSON_from_amount (&refund->refund_fee), "refund_fee", TALER_JSON_from_amount (&refund->refund_fee),
"h_contract_terms", GNUNET_JSON_from_data_auto (&refund->h_contract_terms), "h_contract_terms", GNUNET_JSON_from_data_auto (&refund->h_contract_terms),
"merchant_pub", GNUNET_JSON_from_data_auto (&refund->merchant_pub), "merchant_pub", GNUNET_JSON_from_data_auto (&refund->merchant_pub),
"rtransaction_id", (json_int_t) refund->rtransaction_id, "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; break;
case TALER_EXCHANGEDB_TT_PAYBACK: case TALER_EXCHANGEDB_TT_PAYBACK:
@ -619,23 +647,28 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
pc.coin_pub = payback->coin.coin_pub; pc.coin_pub = payback->coin.coin_pub;
pc.reserve_pub = payback->reserve_pub; pc.reserve_pub = payback->reserve_pub;
if (GNUNET_OK != if (GNUNET_OK !=
TEH_KS_sign (&pc.purpose, TEH_KS_sign (&pc.purpose,
&epub, &epub,
&esig)) &esig))
{ {
GNUNET_break (0); GNUNET_break (0);
json_decref (history); json_decref (history);
return NULL; return NULL;
} }
GNUNET_assert (0 == if (0 !=
json_array_append_new (history, json_array_append_new (history,
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}", json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
"type", "PAYBACK", "type", "PAYBACK",
"amount", TALER_JSON_from_amount (&payback->value), "amount", TALER_JSON_from_amount (&payback->value),
"exchange_sig", GNUNET_JSON_from_data_auto (&esig), "exchange_sig", GNUNET_JSON_from_data_auto (&esig),
"exchange_pub", GNUNET_JSON_from_data_auto (&epub), "exchange_pub", GNUNET_JSON_from_data_auto (&epub),
"reserve_pub", GNUNET_JSON_from_data_auto (&payback->reserve_pub), "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; break;
default: default:
@ -673,7 +706,7 @@ TEH_RESPONSE_reply_coin_insufficient_funds (struct MHD_Connection *connection,
MHD_HTTP_FORBIDDEN, MHD_HTTP_FORBIDDEN,
"{s:s, s:I, s:o}", "{s:s, s:I, s:o}",
"error", "insufficient funds", "error", "insufficient funds",
"code", (json_int_t) ec, "code", (json_int_t) ec,
"history", history); "history", history);
} }
@ -688,7 +721,7 @@ TEH_RESPONSE_reply_coin_insufficient_funds (struct MHD_Connection *connection,
*/ */
json_t * json_t *
TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHistory *rh, TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHistory *rh,
struct TALER_Amount *balance) struct TALER_Amount *balance)
{ {
struct TALER_Amount deposit_total; struct TALER_Amount deposit_total;
struct TALER_Amount withdraw_total; struct TALER_Amount withdraw_total;
@ -717,155 +750,175 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
return NULL; return NULL;
} }
ret |= 1; ret |= 1;
GNUNET_assert (0 == if (0 !=
json_array_append_new (json_history, json_array_append_new (json_history,
json_pack ("{s:s, s:o, s:s, s:o, s:o}", json_pack ("{s:s, s:o, s:s, s:o, s:o}",
"type", "DEPOSIT", "type", "DEPOSIT",
"timestamp", GNUNET_JSON_from_time_abs (pos->details.bank->execution_date), "timestamp", GNUNET_JSON_from_time_abs (pos->details.bank->execution_date),
"sender_account_url", pos->details.bank->sender_account_details, "sender_account_url", pos->details.bank->sender_account_details,
"wire_reference", GNUNET_JSON_from_data (pos->details.bank->wire_reference, "wire_reference", GNUNET_JSON_from_data (pos->details.bank->wire_reference,
pos->details.bank->wire_reference_size), 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; break;
case TALER_EXCHANGEDB_RO_WITHDRAW_COIN: case TALER_EXCHANGEDB_RO_WITHDRAW_COIN:
{ {
struct TALER_Amount value; struct TALER_Amount value;
value = pos->details.withdraw->amount_with_fee; value = pos->details.withdraw->amount_with_fee;
if (0 == (2 & ret)) if (0 == (2 & ret))
{ {
withdraw_total = value; withdraw_total = value;
} }
else else
{ {
if (GNUNET_OK != if (GNUNET_OK !=
TALER_amount_add (&withdraw_total, TALER_amount_add (&withdraw_total,
&withdraw_total, &withdraw_total,
&value)) &value))
{ {
GNUNET_break (0); GNUNET_break (0);
json_decref (json_history); json_decref (json_history);
return NULL; return NULL;
} }
} }
ret |= 2; ret |= 2;
GNUNET_assert (0 == if (0 !=
json_array_append_new (json_history, json_array_append_new (json_history,
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}", json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
"type", "WITHDRAW", "type", "WITHDRAW",
"reserve_sig", GNUNET_JSON_from_data_auto (&pos->details.withdraw->reserve_sig), "reserve_sig", GNUNET_JSON_from_data_auto (&pos->details.withdraw->reserve_sig),
"h_coin_envelope", GNUNET_JSON_from_data_auto (&pos->details.withdraw->h_coin_envelope), "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), "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), "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; break;
case TALER_EXCHANGEDB_RO_PAYBACK_COIN: case TALER_EXCHANGEDB_RO_PAYBACK_COIN:
{ {
const struct TALER_EXCHANGEDB_Payback *payback; const struct TALER_EXCHANGEDB_Payback *payback;
struct TALER_PaybackConfirmationPS pc; struct TALER_PaybackConfirmationPS pc;
struct TALER_ExchangePublicKeyP pub; struct TALER_ExchangePublicKeyP pub;
struct TALER_ExchangeSignatureP sig; struct TALER_ExchangeSignatureP sig;
payback = pos->details.payback; payback = pos->details.payback;
if (0 == (1 & ret)) if (0 == (1 & ret))
deposit_total = payback->value; deposit_total = payback->value;
else else
if (GNUNET_OK != if (GNUNET_OK !=
TALER_amount_add (&deposit_total, TALER_amount_add (&deposit_total,
&deposit_total, &deposit_total,
&payback->value)) &payback->value))
{ {
GNUNET_break (0); GNUNET_break (0);
json_decref (json_history); json_decref (json_history);
return NULL; return NULL;
} }
ret |= 1; ret |= 1;
pc.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_PAYBACK); pc.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_PAYBACK);
pc.purpose.size = htonl (sizeof (struct TALER_PaybackConfirmationPS)); pc.purpose.size = htonl (sizeof (struct TALER_PaybackConfirmationPS));
pc.timestamp = GNUNET_TIME_absolute_hton (payback->timestamp); pc.timestamp = GNUNET_TIME_absolute_hton (payback->timestamp);
TALER_amount_hton (&pc.payback_amount, TALER_amount_hton (&pc.payback_amount,
&payback->value); &payback->value);
pc.coin_pub = payback->coin.coin_pub; pc.coin_pub = payback->coin.coin_pub;
pc.reserve_pub = payback->reserve_pub; pc.reserve_pub = payback->reserve_pub;
if (GNUNET_OK != if (GNUNET_OK !=
TEH_KS_sign (&pc.purpose, TEH_KS_sign (&pc.purpose,
&pub, &pub,
&sig)) &sig))
{ {
GNUNET_break (0); GNUNET_break (0);
json_decref (json_history); json_decref (json_history);
return NULL; return NULL;
} }
GNUNET_assert (0 == if (0 !=
json_array_append_new (json_history, json_array_append_new (json_history,
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}", json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
"type", "PAYBACK", "type", "PAYBACK",
"exchange_pub", GNUNET_JSON_from_data_auto (&pub), "exchange_pub", GNUNET_JSON_from_data_auto (&pub),
"exchange_sig", GNUNET_JSON_from_data_auto (&sig), "exchange_sig", GNUNET_JSON_from_data_auto (&sig),
"timestamp", GNUNET_JSON_from_time_abs (payback->timestamp), "timestamp", GNUNET_JSON_from_time_abs (payback->timestamp),
"amount", TALER_JSON_from_amount (&payback->value), "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; break;
case TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK: case TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK:
{ {
struct TALER_ReserveCloseConfirmationPS rcc;
struct TALER_ExchangePublicKeyP pub;
struct TALER_ExchangeSignatureP sig;
struct TALER_Amount value;
struct TALER_ReserveCloseConfirmationPS rcc; value = pos->details.closing->amount;
struct TALER_ExchangePublicKeyP pub; if (0 == (2 & ret))
struct TALER_ExchangeSignatureP sig; {
struct TALER_Amount value; withdraw_total = value;
}
value = pos->details.closing->amount; else
if (0 == (2 & ret)) {
{ if (GNUNET_OK !=
withdraw_total = value; TALER_amount_add (&withdraw_total,
} &withdraw_total,
else &value))
{ {
if (GNUNET_OK != GNUNET_break (0);
TALER_amount_add (&withdraw_total, json_decref (json_history);
&withdraw_total, return NULL;
&value)) }
{ }
json_decref (json_history); ret |= 2;
return NULL;
}
}
ret |= 2;
rcc.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_RESERVE_CLOSED); rcc.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_RESERVE_CLOSED);
rcc.purpose.size = htonl (sizeof (struct TALER_ReserveCloseConfirmationPS)); rcc.purpose.size = htonl (sizeof (struct TALER_ReserveCloseConfirmationPS));
rcc.timestamp = GNUNET_TIME_absolute_hton (pos->details.closing->execution_date); rcc.timestamp = GNUNET_TIME_absolute_hton (pos->details.closing->execution_date);
TALER_amount_hton (&rcc.closing_amount, TALER_amount_hton (&rcc.closing_amount,
&value); &value);
TALER_amount_hton (&rcc.closing_fee, TALER_amount_hton (&rcc.closing_fee,
&pos->details.closing->closing_fee); &pos->details.closing->closing_fee);
rcc.reserve_pub = pos->details.closing->reserve_pub; rcc.reserve_pub = pos->details.closing->reserve_pub;
GNUNET_CRYPTO_hash (pos->details.closing->receiver_account_details, GNUNET_CRYPTO_hash (pos->details.closing->receiver_account_details,
strlen (pos->details.closing->receiver_account_details) + 1, strlen (pos->details.closing->receiver_account_details) + 1,
&rcc.h_wire); &rcc.h_wire);
rcc.wtid = pos->details.closing->wtid; rcc.wtid = pos->details.closing->wtid;
if (GNUNET_OK != if (GNUNET_OK !=
TEH_KS_sign (&rcc.purpose, TEH_KS_sign (&rcc.purpose,
&pub, &pub,
&sig)) &sig))
{ {
GNUNET_break (0); GNUNET_break (0);
json_decref (json_history); json_decref (json_history);
return NULL; return NULL;
} }
GNUNET_assert (0 == if (0 !=
json_array_append_new (json_history, json_array_append_new (json_history,
json_pack ("{s:s, s:s, s:o, s:o, s:o, s:o, s:o, s:o}", json_pack ("{s:s, s:s, s:o, s:o, s:o, s:o, s:o, s:o}",
"type", "CLOSING", "type", "CLOSING",
"receiver_account_details", pos->details.closing->receiver_account_details, "receiver_account_details", pos->details.closing->receiver_account_details,
"wtid", GNUNET_JSON_from_data_auto (&pos->details.closing->wtid), "wtid", GNUNET_JSON_from_data_auto (&pos->details.closing->wtid),
"exchange_pub", GNUNET_JSON_from_data_auto (&pub), "exchange_pub", GNUNET_JSON_from_data_auto (&pub),
"exchange_sig", GNUNET_JSON_from_data_auto (&sig), "exchange_sig", GNUNET_JSON_from_data_auto (&sig),
"timestamp", GNUNET_JSON_from_time_abs (pos->details.closing->execution_date), "timestamp", GNUNET_JSON_from_time_abs (pos->details.closing->execution_date),
"amount", TALER_JSON_from_amount (&value), "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; break;
} }
@ -909,14 +962,13 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
*/ */
int int
TEH_RESPONSE_reply_transaction_unknown (struct MHD_Connection *connection, TEH_RESPONSE_reply_transaction_unknown (struct MHD_Connection *connection,
enum TALER_ErrorCode ec) enum TALER_ErrorCode ec)
{ {
return TEH_RESPONSE_reply_json_pack (connection, return TEH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_NOT_FOUND, MHD_HTTP_NOT_FOUND,
"{s:s, s:I}", "{s:s, s:I}",
"error", "Deposit unknown", "error", "Deposit unknown",
"code", (json_int_t) ec); "code", (json_int_t) ec);
} }
/* end of taler-exchange-httpd_responses.c */ /* end of taler-exchange-httpd_responses.c */