refactor: added reply_age_withdraw_success
This commit is contained in:
parent
7fc0086642
commit
2319c00ef6
@ -27,10 +27,51 @@
|
|||||||
#include "taler_json_lib.h"
|
#include "taler_json_lib.h"
|
||||||
#include "taler_kyclogic_lib.h"
|
#include "taler_kyclogic_lib.h"
|
||||||
#include "taler_mhd_lib.h"
|
#include "taler_mhd_lib.h"
|
||||||
#include "taler-exchange-httpd_withdraw.h"
|
#include "taler-exchange-httpd_age-withdraw.h"
|
||||||
#include "taler-exchange-httpd_responses.h"
|
#include "taler-exchange-httpd_responses.h"
|
||||||
#include "taler-exchange-httpd_keys.h"
|
#include "taler-exchange-httpd_keys.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a response to a "age-withdraw" request.
|
||||||
|
*
|
||||||
|
* @param connection the connection to send the response to
|
||||||
|
* @param ach value the client committed to
|
||||||
|
* @param noreveal_index which index will the client not have to reveal
|
||||||
|
* @return a MHD status code
|
||||||
|
*/
|
||||||
|
static MHD_RESULT
|
||||||
|
reply_age_withdraw_success (struct MHD_Connection *connection,
|
||||||
|
const struct TALER_AgeWithdrawCommitmentHashP *ach,
|
||||||
|
uint32_t noreveal_index)
|
||||||
|
{
|
||||||
|
struct TALER_ExchangePublicKeyP pub;
|
||||||
|
struct TALER_ExchangeSignatureP sig;
|
||||||
|
enum TALER_ErrorCode ec;
|
||||||
|
|
||||||
|
if (TALER_EC_NONE !=
|
||||||
|
(ec = TALER_exchange_online_age_withdraw_confirmation_sign (
|
||||||
|
&TEH_keys_exchange_sign_,
|
||||||
|
ach,
|
||||||
|
noreveal_index,
|
||||||
|
&pub,
|
||||||
|
&sig)))
|
||||||
|
{
|
||||||
|
return TALER_MHD_reply_with_ec (connection,
|
||||||
|
ec,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TALER_MHD_REPLY_JSON_PACK (
|
||||||
|
connection,
|
||||||
|
MHD_HTTP_OK,
|
||||||
|
GNUNET_JSON_pack_uint64 ("noreveal_index",
|
||||||
|
noreveal_index),
|
||||||
|
GNUNET_JSON_pack_data_auto ("exchange_sig",
|
||||||
|
&sig),
|
||||||
|
GNUNET_JSON_pack_data_auto ("exchange_pub",
|
||||||
|
&pub));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Context for #age_withdraw_transaction.
|
* Context for #age_withdraw_transaction.
|
||||||
@ -286,7 +327,7 @@ TEH_handler_age_withdraw (struct TEH_RequestContext *rc,
|
|||||||
struct GNUNET_JSON_Specification spec[] = {
|
struct GNUNET_JSON_Specification spec[] = {
|
||||||
GNUNET_JSON_spec_fixed_auto ("reserve_sig",
|
GNUNET_JSON_spec_fixed_auto ("reserve_sig",
|
||||||
&awc.commitment.reserve_sig),
|
&awc.commitment.reserve_sig),
|
||||||
GNUNET_JSON_spec_fixed_auto ("age_restricted_coins_commitment",
|
GNUNET_JSON_spec_fixed_auto ("h_commitment",
|
||||||
&awc.commitment.h_commitment),
|
&awc.commitment.h_commitment),
|
||||||
TALER_JSON_spec_amount ("amount",
|
TALER_JSON_spec_amount ("amount",
|
||||||
&awc.commitment.amount_with_fee);
|
&awc.commitment.amount_with_fee);
|
||||||
@ -300,6 +341,7 @@ TEH_handler_age_withdraw (struct TEH_RequestContext *rc,
|
|||||||
awc.commitment.reserve_pub = *reserve_pub;
|
awc.commitment.reserve_pub = *reserve_pub;
|
||||||
|
|
||||||
|
|
||||||
|
/* Parse the JSON body */
|
||||||
{
|
{
|
||||||
enum GNUNET_GenericReturnValue res;
|
enum GNUNET_GenericReturnValue res;
|
||||||
|
|
||||||
@ -310,6 +352,7 @@ TEH_handler_age_withdraw (struct TEH_RequestContext *rc,
|
|||||||
return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES;
|
return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If request was made before successfully, return the previous answer */
|
||||||
if (request_is_idempotent (rc,
|
if (request_is_idempotent (rc,
|
||||||
&awc,
|
&awc,
|
||||||
&mret))
|
&mret))
|
||||||
@ -318,6 +361,7 @@ TEH_handler_age_withdraw (struct TEH_RequestContext *rc,
|
|||||||
return mret;
|
return mret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Verify the signature of the request body with the reserve key */
|
||||||
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
|
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TALER_wallet_age_withdraw_verify (&awc.commitment.h_commitment,
|
TALER_wallet_age_withdraw_verify (&awc.commitment.h_commitment,
|
||||||
@ -348,7 +392,7 @@ TEH_handler_age_withdraw (struct TEH_RequestContext *rc,
|
|||||||
{
|
{
|
||||||
/* Even if #withdraw_transaction() failed, it may have created a signature
|
/* Even if #withdraw_transaction() failed, it may have created a signature
|
||||||
(or we might have done it optimistically above). */
|
(or we might have done it optimistically above). */
|
||||||
/*TODO:oec:which function to call here!? */
|
/* TODO:oec:which function to call here!? */
|
||||||
TALER_blinded_denom_sig_free (&awc.commitment.sig);
|
TALER_blinded_denom_sig_free (&awc.commitment.sig);
|
||||||
GNUNET_JSON_parse_free (spec);
|
GNUNET_JSON_parse_free (spec);
|
||||||
return mhd_ret;
|
return mhd_ret;
|
||||||
@ -362,23 +406,10 @@ TEH_handler_age_withdraw (struct TEH_RequestContext *rc,
|
|||||||
return TEH_RESPONSE_reply_kyc_required (rc->connection,
|
return TEH_RESPONSE_reply_kyc_required (rc->connection,
|
||||||
&awc.h_payto,
|
&awc.h_payto,
|
||||||
&awc.kyc);
|
&awc.kyc);
|
||||||
{
|
|
||||||
MHD_RESULT ret;
|
|
||||||
|
|
||||||
ret = TALER_MHD_REPLY_JSON_PACK (
|
return reply_age_withdraw_success (rc->connection,
|
||||||
rc->connection,
|
&awc.commitment.h_commitment,
|
||||||
MHD_HTTP_OK,
|
awc.commitment.noreveal_index);
|
||||||
/* TODO:oec: put in the right answer fields */
|
|
||||||
GNUNET_JSON_pack_uint64 ("noreveal_index",
|
|
||||||
&awc->commitment.noreveal_index),
|
|
||||||
GNUNET_JSON_pack_data_auto ("exchange_sig",
|
|
||||||
&awc->commitment.sig),
|
|
||||||
GNUNET_JSON_pack_data_auto ("exchange_pub",
|
|
||||||
/* TODO:oec: where does the pub come from? */
|
|
||||||
&pub));
|
|
||||||
TALER_blinded_denom_sig_free (&awc.commitment.sig);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user