diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2022-04-11 16:48:30 +0200 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2022-04-11 16:48:30 +0200 |
commit | 7a1dcc52ca9a6d79be10076b06b9a3e6ea35d395 (patch) | |
tree | b16344053dbf177032286a5083cc938c480b8292 /src/exchange | |
parent | c8c100529711959a1c18a5591b450362e648a9f6 (diff) | |
download | exchange-7a1dcc52ca9a6d79be10076b06b9a3e6ea35d395.tar.gz exchange-7a1dcc52ca9a6d79be10076b06b9a3e6ea35d395.tar.bz2 exchange-7a1dcc52ca9a6d79be10076b06b9a3e6ea35d395.zip |
-towards new GET /contracts/$C_PUB hander
Diffstat (limited to 'src/exchange')
-rw-r--r-- | src/exchange/Makefile.am | 1 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd.c | 10 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_contract.c | 99 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_contract.h | 44 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_purses_create.c | 12 |
5 files changed, 159 insertions, 7 deletions
diff --git a/src/exchange/Makefile.am b/src/exchange/Makefile.am index 949a1dcba..3a929be06 100644 --- a/src/exchange/Makefile.am +++ b/src/exchange/Makefile.am @@ -79,6 +79,7 @@ taler_exchange_transfer_LDADD = \ taler_exchange_httpd_SOURCES = \ taler-exchange-httpd.c taler-exchange-httpd.h \ taler-exchange-httpd_auditors.c taler-exchange-httpd_auditors.h \ + taler-exchange-httpd_contract.c taler-exchange-httpd_contract.h \ taler-exchange-httpd_csr.c taler-exchange-httpd_csr \ taler-exchange-httpd_db.c taler-exchange-httpd_db.h \ taler-exchange-httpd_deposit.c taler-exchange-httpd_deposit.h \ diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c index 1f7f699c7..aa3a7c412 100644 --- a/src/exchange/taler-exchange-httpd.c +++ b/src/exchange/taler-exchange-httpd.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2021 Taler Systems SA + Copyright (C) 2014-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 @@ -30,6 +30,7 @@ #include <limits.h> #include "taler_mhd_lib.h" #include "taler-exchange-httpd_auditors.h" +#include "taler-exchange-httpd_contract.h" #include "taler-exchange-httpd_csr.h" #include "taler-exchange-httpd_deposit.h" #include "taler-exchange-httpd_deposits_get.h" @@ -1067,6 +1068,13 @@ handle_mhd_request (void *cls, .handler.get = &TEH_handler_deposits_get, .nargs = 4 }, + /* Getting purse contracts */ + { + .url = "contracts", + .method = MHD_HTTP_METHOD_GET, + .handler.get = &TEH_handler_contracts_get, + .nargs = 1 + }, /* KYC endpoints */ { .url = "kyc-check", diff --git a/src/exchange/taler-exchange-httpd_contract.c b/src/exchange/taler-exchange-httpd_contract.c new file mode 100644 index 000000000..defb7816d --- /dev/null +++ b/src/exchange/taler-exchange-httpd_contract.c @@ -0,0 +1,99 @@ +/* + 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_contract.c + * @brief Handle GET /contracts/$C_PUB requests + * @author Christian Grothoff + */ +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <jansson.h> +#include <microhttpd.h> +#include "taler_mhd_lib.h" +#include "taler-exchange-httpd_contract.h" +#include "taler-exchange-httpd_mhd.h" +#include "taler-exchange-httpd_responses.h" + + +MHD_RESULT +TEH_handler_contracts_get (struct TEH_RequestContext *rc, + const char *const args[1]) +{ + struct TALER_ContractDiffiePublicP contract_pub; + struct TALER_PurseContractPublicKeyP purse_pub; + void *econtract; + size_t econtract_size; + enum GNUNET_DB_QueryStatus qs; + struct TALER_PurseContractSignatureP econtract_sig; + MHD_RESULT res; + + if (GNUNET_OK != + GNUNET_STRINGS_string_to_data (args[0], + strlen (args[0]), + &contract_pub, + sizeof (contract_pub))) + { + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_EXCHANGE_CONTRACTS_INVALID_CONTRACT_PUB, + args[0]); + } + + qs = TEH_plugin->select_contract (TEH_plugin->cls, + &contract_pub, + &purse_pub, + &econtract_sig, + &econtract_size, + &econtract); + switch (qs) + { + case GNUNET_DB_STATUS_HARD_ERROR: + GNUNET_break (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "select_contract"); + case GNUNET_DB_STATUS_SOFT_ERROR: + GNUNET_break (0); + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "select_contract"); + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_EXCHANGE_CONTRACTS_UNKNOWN, + NULL); + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + break; /* handled below */ + } + res = TALER_MHD_REPLY_JSON_PACK ( + rc->connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_data_auto ("purse_pub", + &purse_pub), + GNUNET_JSON_pack_data_auto ("econtract_sig", + &econtract_sig), + GNUNET_JSON_pack_data_varsize ("econtract", + econtract, + econtract_size)); + GNUNET_free (econtract); + return res; +} + + +/* end of taler-exchange-httpd_contract.c */ diff --git a/src/exchange/taler-exchange-httpd_contract.h b/src/exchange/taler-exchange-httpd_contract.h new file mode 100644 index 000000000..dac6b81e3 --- /dev/null +++ b/src/exchange/taler-exchange-httpd_contract.h @@ -0,0 +1,44 @@ +/* + 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_contract.h + * @brief Handle /coins/$COIN_PUB/contract requests + * @author Florian Dold + * @author Benedikt Mueller + * @author Christian Grothoff + */ +#ifndef TALER_EXCHANGE_HTTPD_CONTRACT_H +#define TALER_EXCHANGE_HTTPD_CONTRACT_H + +#include <gnunet/gnunet_util_lib.h> +#include <microhttpd.h> +#include "taler-exchange-httpd.h" + + +/** + * Handle a GET "/contracts/$C_PUB" request. Returns the + * encrypted contract. + * + * @param rc request context + * @param args array of additional options (length: 1, first is the contract_pub) + * @return MHD result code + */ +MHD_RESULT +TEH_handler_contracts_get (struct TEH_RequestContext *rc, + const char *const args[1]); + + +#endif diff --git a/src/exchange/taler-exchange-httpd_purses_create.c b/src/exchange/taler-exchange-httpd_purses_create.c index 00bb1d1e7..4ea8b7d2d 100644 --- a/src/exchange/taler-exchange-httpd_purses_create.c +++ b/src/exchange/taler-exchange-httpd_purses_create.c @@ -404,12 +404,12 @@ create_transaction (void *cls, void *econtract; struct GNUNET_HashCode h_econtract; - qs = TEH_plugin->select_contract (TEH_plugin->cls, - pcc->purse_pub, - &pub_ckey, - &econtract_sig, - &econtract_size, - &econtract); + qs = TEH_plugin->select_contract_by_purse (TEH_plugin->cls, + pcc->purse_pub, + &pub_ckey, + &econtract_sig, + &econtract_size, + &econtract); if (qs <= 0) { if (GNUNET_DB_STATUS_SOFT_ERROR == qs) |