add taler-exchange-httpd_reserves_purse.c to build

This commit is contained in:
Christian Grothoff 2022-04-21 21:04:33 +02:00
parent c3e67dfc6b
commit 582acc3cf3
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
12 changed files with 104 additions and 52 deletions

@ -1 +1 @@
Subproject commit 0e7707e441874b8aca9801b389d47003ac7a8f73
Subproject commit 1cfd50974f6e01dee0302b7918c18cc2b06edf71

View File

@ -112,6 +112,7 @@ taler_exchange_httpd_SOURCES = \
taler-exchange-httpd_refund.c taler-exchange-httpd_refund.h \
taler-exchange-httpd_reserves_get.c taler-exchange-httpd_reserves_get.h \
taler-exchange-httpd_reserves_history.c taler-exchange-httpd_reserves_history.h \
taler-exchange-httpd_reserves_purse.c taler-exchange-httpd_reserves_purse.h \
taler-exchange-httpd_reserves_status.c taler-exchange-httpd_reserves_status.h \
taler-exchange-httpd_responses.c taler-exchange-httpd_responses.h \
taler-exchange-httpd_terms.c taler-exchange-httpd_terms.h \

View File

@ -393,7 +393,7 @@ TEH_handler_deposit (struct MHD_Connection *connection,
TALER_LOG_WARNING ("Invalid coin passed for /deposit\n");
GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_UNAUTHORIZED,
MHD_HTTP_FORBIDDEN,
TALER_EC_EXCHANGE_DENOMINATION_SIGNATURE_INVALID,
NULL);
}
@ -427,7 +427,7 @@ TEH_handler_deposit (struct MHD_Connection *connection,
TALER_LOG_WARNING ("Invalid signature on /deposit request\n");
GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_UNAUTHORIZED,
MHD_HTTP_FORBIDDEN,
TALER_EC_EXCHANGE_DEPOSIT_COIN_SIGNATURE_INVALID,
NULL);
}

View File

@ -362,7 +362,7 @@ TEH_handler_kyc_check (
(unsigned long long) kyp->kyc.payment_target_uuid);
GNUNET_break_op (0);
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_UNAUTHORIZED,
MHD_HTTP_FORBIDDEN,
TALER_EC_EXCHANGE_KYC_CHECK_AUTHORIZATION_FAILED,
"h_payto");
}

View File

@ -37,7 +37,8 @@ enum TEH_MetricTypeRequest
TEH_MT_REQUEST_MELT = 3,
TEH_MT_REQUEST_PURSE_CREATE = 4,
TEH_MT_REQUEST_PURSE_MERGE = 5,
TEH_MT_REQUEST_COUNT = 6 /* MUST BE LAST! */
TEH_MT_REQUEST_RESERVE_PURSE = 6,
TEH_MT_REQUEST_COUNT = 7 /* MUST BE LAST! */
};
/**

View File

@ -500,7 +500,7 @@ parse_coin (struct MHD_Connection *connection,
GNUNET_JSON_parse_free (spec);
return (MHD_YES ==
TALER_MHD_reply_with_error (connection,
MHD_HTTP_UNAUTHORIZED,
MHD_HTTP_FORBIDDEN,
TALER_EC_EXCHANGE_PURSE_CREATE_COIN_SIGNATURE_INVALID,
TEH_base_url))
? GNUNET_NO : GNUNET_SYSERR;
@ -613,7 +613,7 @@ parse_coin (struct MHD_Connection *connection,
GNUNET_JSON_parse_free (spec);
return (MHD_YES ==
TALER_MHD_reply_with_error (connection,
MHD_HTTP_UNAUTHORIZED,
MHD_HTTP_FORBIDDEN,
TALER_EC_EXCHANGE_DENOMINATION_SIGNATURE_INVALID,
NULL))
? GNUNET_NO : GNUNET_SYSERR;
@ -816,7 +816,7 @@ TEH_handler_purses_create (
GNUNET_JSON_parse_free (spec);
GNUNET_free (pcc.coins);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_UNAUTHORIZED,
MHD_HTTP_FORBIDDEN,
TALER_EC_EXCHANGE_PURSE_CREATE_SIGNATURE_INVALID,
NULL);
}
@ -832,7 +832,7 @@ TEH_handler_purses_create (
GNUNET_JSON_parse_free (spec);
GNUNET_free (pcc.coins);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_UNAUTHORIZED,
MHD_HTTP_FORBIDDEN,
TALER_EC_EXCHANGE_PURSE_ECONTRACT_SIGNATURE_INVALID,
NULL);
}

View File

@ -38,9 +38,9 @@
* @return MHD result code
*/
MHD_RESULT
TEH_handler_purses_create (struct MHD_Connection *connection,
const struct
TALER_PurseContractPublicKeyP *purse_pub,
TEH_handler_purses_create (
struct MHD_Connection *connection,
const struct TALER_PurseContractPublicKeyP *purse_pub,
const json_t *root);

View File

@ -55,11 +55,21 @@ struct ReservePurseContext
*/
struct TALER_Amount amount;
/**
* Total amount already put into the purse.
*/
struct TALER_Amount deposit_total;
/**
* When should the purse expire.
*/
struct GNUNET_TIME_Timestamp purse_expiration;
/**
* Merge time.
*/
struct GNUNET_TIME_Timestamp merge_timestamp;
/**
* Our current time.
*/
@ -133,13 +143,13 @@ reply_purse_success (struct MHD_Connection *connection,
enum TALER_ErrorCode ec;
if (TALER_EC_NONE !=
(ec = TALER_exchange_online_purse_pursed_sign (
(ec = TALER_exchange_online_purse_created_sign (
&TEH_keys_exchange_sign_,
rpc->exchange_timestamp,
rpc->purse_expiration,
&rpc->amount,
&rpc->deposit_total,
rpc->purse_pub,
&rpc->purse_pub,
&rpc->merge_pub,
&rpc->h_contract_terms,
&pub,
@ -223,7 +233,7 @@ purse_transaction (void *cls,
TEH_plugin->rollback (TEH_plugin->cls);
qs = TEH_plugin->select_purse_request (TEH_plugin->cls,
rpc->purse_pub,
&rpc->purse_pub,
&merge_pub,
&purse_expiration,
&h_contract_terms,
@ -246,7 +256,7 @@ purse_transaction (void *cls,
connection,
MHD_HTTP_CONFLICT,
TALER_JSON_pack_ec (
TALER_EC_EXCHANGE_PURSE_PURSE_CONFLICTING_META_DATA),
TALER_EC_EXCHANGE_PURSE_CREATE_CONFLICTING_META_DATA),
TALER_JSON_pack_amount ("amount",
&target_amount),
GNUNET_JSON_pack_uint64 ("min_age",
@ -268,7 +278,7 @@ purse_transaction (void *cls,
/* 3) if present, persist contract */
in_conflict = true;
qs = TEH_plugin->insert_contract (TEH_plugin->cls,
rpc->purse_pub,
&rpc->purse_pub,
&rpc->contract_pub,
rpc->econtract_size,
rpc->econtract,
@ -294,7 +304,7 @@ purse_transaction (void *cls,
struct GNUNET_HashCode h_econtract;
qs = TEH_plugin->select_contract_by_purse (TEH_plugin->cls,
rpc->purse_pub,
&rpc->purse_pub,
&pub_ckey,
&econtract_sig,
&econtract_size,
@ -343,9 +353,6 @@ TEH_handler_reserves_purse (
.reserve_pub = reserve_pub,
.exchange_timestamp = GNUNET_TIME_timestamp_get ()
};
json_t *deposits;
json_t *deposit;
unsigned int idx;
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_amount ("purse_value",
TEH_currency,
@ -413,7 +420,7 @@ TEH_handler_reserves_purse (
GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_BAD_REQUEST,
TALER_EC_EXCHANGE_PURSE_PURSE_EXPIRATION_BEFORE_NOW,
TALER_EC_EXCHANGE_RESERVES_PURSE_EXPIRATION_BEFORE_NOW,
NULL);
}
if (GNUNET_TIME_absolute_is_never (rpc.purse_expiration.abs_time))
@ -422,7 +429,7 @@ TEH_handler_reserves_purse (
GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_BAD_REQUEST,
TALER_EC_EXCHANGE_PURSE_PURSE_EXPIRATION_IS_NEVER,
TALER_EC_EXCHANGE_RESERVES_PURSE_EXPIRATION_IS_NEVER,
NULL);
}
gf = TEH_keys_global_fee_by_time (TEH_keys_get_state (),
@ -444,19 +451,19 @@ TEH_handler_reserves_purse (
&rpc.merge_pub,
rpc.min_age,
&rpc.amount,
rpc.purse_pub,
&rpc.purse_pub,
&rpc.purse_sig))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
GNUNET_free (rpc.coins);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_UNAUTHORIZED,
return TALER_MHD_reply_with_error (
connection,
MHD_HTTP_FORBIDDEN,
TALER_EC_EXCHANGE_PURSE_CREATE_SIGNATURE_INVALID,
NULL);
}
if (GNUNET_OK !=
TALER_wallet_purse_merge_verify ("FIXME exchange_url",
TALER_wallet_purse_merge_verify (TEH_base_url,
rpc.merge_timestamp,
&rpc.purse_pub,
&rpc.merge_pub,
@ -464,10 +471,10 @@ TEH_handler_reserves_purse (
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
GNUNET_free (rpc.coins);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_UNAUTHORIZED,
TALER_EC_EXCHANGE_PURSE_MERGE_SIGNATURE_INVALID,
return TALER_MHD_reply_with_error (
connection,
MHD_HTTP_FORBIDDEN,
TALER_EC_EXCHANGE_RESERVES_PURSE_MERGE_SIGNATURE_INVALID,
NULL);
}
if (GNUNET_OK !=
@ -475,17 +482,17 @@ TEH_handler_reserves_purse (
&rpc.purse_pub,
rpc.purse_expiration,
&rpc.h_contract_terms,
&rpc.purse_value,
&rpc.amount,
rpc.min_age,
rpc.reserve_pub,
&rpc.reserve_sig))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
GNUNET_free (rpc.coins);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_UNAUTHORIZED,
TALER_EC_EXCHANGE_RESERVE_MERGE_SIGNATURE_INVALID,
return TALER_MHD_reply_with_error (
connection,
MHD_HTTP_FORBIDDEN,
TALER_EC_EXCHANGE_RESERVES_PURSE_MERGE_SIGNATURE_INVALID,
NULL);
}
if ( (NULL != rpc.econtract) &&
@ -493,14 +500,13 @@ TEH_handler_reserves_purse (
TALER_wallet_econtract_upload_verify (rpc.econtract,
rpc.econtract_size,
&rpc.contract_pub,
purse_pub,
&rpc.purse_pub,
&rpc.econtract_sig)) )
{
TALER_LOG_WARNING ("Invalid signature on /reserves/$PID/purse request\n");
GNUNET_JSON_parse_free (spec);
GNUNET_free (rpc.coins);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_UNAUTHORIZED,
MHD_HTTP_FORBIDDEN,
TALER_EC_EXCHANGE_PURSE_ECONTRACT_SIGNATURE_INVALID,
NULL);
}
@ -511,7 +517,6 @@ TEH_handler_reserves_purse (
{
GNUNET_break (0);
GNUNET_JSON_parse_free (spec);
GNUNET_free (rpc.coins);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_START_FAILED,
@ -525,13 +530,12 @@ TEH_handler_reserves_purse (
if (GNUNET_OK !=
TEH_DB_run_transaction (connection,
"execute purse purse",
TEH_MT_REQUEST_PURSE_PURSE,
TEH_MT_REQUEST_RESERVE_PURSE,
&mhd_ret,
&purse_transaction,
&rpc))
{
GNUNET_JSON_parse_free (spec);
GNUNET_free (rpc.coins);
return mhd_ret;
}
}

View File

@ -0,0 +1,46 @@
/*
This file is part of TALER
Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file taler-exchange-httpd_reserves_purse.h
* @brief Handle /reserves/$RID/purse requests
* @author Christian Grothoff
*/
#ifndef TALER_EXCHANGE_HTTPD_RESERVES_PURSE_H
#define TALER_EXCHANGE_HTTPD_RESERVES_PURSE_H
#include <gnunet/gnunet_util_lib.h>
#include <microhttpd.h>
#include "taler-exchange-httpd.h"
/**
* Handle a "/purses/$PURSE_PUB/create" request. Parses the JSON, and, if
* successful, passes the JSON data to #create_transaction() to further check
* the details of the operation specified. If everything checks out, this
* will ultimately lead to the "purses create" being executed, or rejected.
*
* @param connection the MHD connection to handle
* @param purse_pub public key of the purse
* @param root uploaded JSON data
* @return MHD result code
*/
MHD_RESULT
TEH_handler_reserves_purse (
struct MHD_Connection *connection,
const struct TALER_ReservePublicKeyP *reserve_pub,
const json_t *root);
#endif

View File

@ -178,7 +178,7 @@ handle_kyc_check_finished (void *cls,
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
break;
case MHD_HTTP_UNAUTHORIZED:
case MHD_HTTP_FORBIDDEN:
ks.ec = TALER_JSON_get_error_code (j);
break;
case MHD_HTTP_NOT_FOUND:

View File

@ -122,7 +122,7 @@ handle_kyc_wallet_finished (void *cls,
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
break;
case MHD_HTTP_UNAUTHORIZED:
case MHD_HTTP_FORBIDDEN:
ks.ec = TALER_JSON_get_error_code (j);
break;
case MHD_HTTP_NOT_FOUND:

View File

@ -427,7 +427,7 @@ TALER_EXCHANGE_purse_create_with_merge (
void
TALER_EXCHANGE_account_create_with_merge_cancel (
TALER_EXCHANGE_purse_create_with_merge_cancel (
struct TALER_EXCHANGE_PurseCreateMergeHandle *pcm)
{
if (NULL != pcm->job)