introduce TALER_JSON_pack_ec

This commit is contained in:
Christian Grothoff 2021-08-01 15:36:38 +02:00
parent f1f0bf637b
commit d45774ccec
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
6 changed files with 20 additions and 33 deletions

View File

@ -69,11 +69,7 @@ reply_melt_insufficient_funds (
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_CONFLICT,
GNUNET_JSON_pack_string ("hint",
TALER_ErrorCode_get_hint (
TALER_EC_EXCHANGE_MELT_INSUFFICIENT_FUNDS)),
GNUNET_JSON_pack_uint64 ("code",
TALER_EC_EXCHANGE_MELT_INSUFFICIENT_FUNDS),
TALER_JSON_pack_ec (TALER_EC_EXCHANGE_MELT_INSUFFICIENT_FUNDS),
GNUNET_JSON_pack_data_auto ("coin_pub",
coin_pub),
TALER_JSON_pack_amount ("original_value",

View File

@ -387,11 +387,8 @@ refreshes_reveal_transaction (void *cls,
*mhd_ret = TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_CONFLICT,
GNUNET_JSON_pack_string ("hint",
TALER_ErrorCode_get_hint (
TALER_EC_EXCHANGE_REFRESHES_REVEAL_COMMITMENT_VIOLATION)),
GNUNET_JSON_pack_uint64 ("code",
TALER_EC_EXCHANGE_REFRESHES_REVEAL_COMMITMENT_VIOLATION),
TALER_JSON_pack_ec (
TALER_EC_EXCHANGE_REFRESHES_REVEAL_COMMITMENT_VIOLATION),
GNUNET_JSON_pack_data_auto ("rc_expected",
&rc_expected));
return GNUNET_DB_STATUS_HARD_ERROR;

View File

@ -233,11 +233,7 @@ refund_transaction (void *cls,
MHD_HTTP_PRECONDITION_FAILED,
TALER_JSON_pack_amount ("detail",
&ref->refund_amount),
GNUNET_JSON_pack_string ("hint",
TALER_ErrorCode_get_hint (
TALER_EC_EXCHANGE_REFUND_INCONSISTENT_AMOUNT)),
GNUNET_JSON_pack_uint64 ("code",
TALER_EC_EXCHANGE_REFUND_INCONSISTENT_AMOUNT),
TALER_JSON_pack_ec (TALER_EC_EXCHANGE_REFUND_INCONSISTENT_AMOUNT),
GNUNET_JSON_pack_array_steal ("history",
TEH_RESPONSE_compile_transaction_history (
&refund->coin.coin_pub,
@ -332,11 +328,8 @@ refund_transaction (void *cls,
MHD_HTTP_CONFLICT,
GNUNET_JSON_pack_string ("detail",
"total amount refunded exceeds total amount deposited for this coin"),
GNUNET_JSON_pack_string ("hint",
TALER_ErrorCode_get_hint (
TALER_EC_EXCHANGE_REFUND_CONFLICT_DEPOSIT_INSUFFICIENT)),
GNUNET_JSON_pack_uint64 ("code",
TALER_EC_EXCHANGE_REFUND_CONFLICT_DEPOSIT_INSUFFICIENT),
TALER_JSON_pack_ec (
TALER_EC_EXCHANGE_REFUND_CONFLICT_DEPOSIT_INSUFFICIENT),
GNUNET_JSON_pack_array_steal ("history",
TEH_RESPONSE_compile_transaction_history (
&refund->coin.coin_pub,

View File

@ -450,8 +450,7 @@ TEH_RESPONSE_reply_unknown_denom_pub_hash (
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_NOT_FOUND,
GNUNET_JSON_pack_uint64 ("code",
TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN),
TALER_JSON_pack_ec (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN),
GNUNET_JSON_pack_time_abs ("timestamp",
now),
GNUNET_JSON_pack_data_auto ("exchange_pub",
@ -501,8 +500,7 @@ TEH_RESPONSE_reply_expired_denom_pub_hash (
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_GONE,
GNUNET_JSON_pack_uint64 ("code",
ec),
TALER_JSON_pack_ec (ec),
GNUNET_JSON_pack_string ("oper",
oper),
GNUNET_JSON_pack_time_abs ("timestamp",
@ -550,10 +548,7 @@ TEH_RESPONSE_reply_coin_insufficient_funds (
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_CONFLICT,
GNUNET_JSON_pack_string ("hint",
TALER_ErrorCode_get_hint (ec)),
GNUNET_JSON_pack_uint64 ("code",
ec),
TALER_JSON_pack_ec (ec),
GNUNET_JSON_pack_array_steal ("history",
history));
}

View File

@ -81,11 +81,7 @@ reply_withdraw_insufficient_funds (
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_CONFLICT,
GNUNET_JSON_pack_string ("hint",
TALER_ErrorCode_get_hint (
TALER_EC_EXCHANGE_WITHDRAW_INSUFFICIENT_FUNDS)),
GNUNET_JSON_pack_uint64 ("code",
TALER_EC_EXCHANGE_WITHDRAW_INSUFFICIENT_FUNDS),
TALER_JSON_pack_ec (TALER_EC_EXCHANGE_WITHDRAW_INSUFFICIENT_FUNDS),
TALER_JSON_pack_amount ("balance",
&balance),
GNUNET_JSON_pack_array_steal ("history",

View File

@ -79,6 +79,16 @@ TALER_JSON_pack_time_abs_nbo (const char *name,
struct GNUNET_TIME_AbsoluteNBO at);
/**
* Put an error code into a JSON reply, including
* both the numeric value and the hint.
*
* @param ec error code to encode using canonical field names
*/
#define TALER_JSON_pack_ec(ec) \
GNUNET_JSON_pack_string ("hint", TALER_ErrorCode_get_hint (ec)), \
GNUNET_JSON_pack_uint64 ("code", ec)
/**
* Generate packer instruction for a JSON field of type
* absolute time creating a human-readable timestamp.