aboutsummaryrefslogtreecommitdiff
path: root/src/exchange
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2022-07-01 15:42:48 +0200
committerChristian Grothoff <grothoff@gnunet.org>2022-07-01 15:42:48 +0200
commitcebf4f11b90350d25d0c9f71e0d5354e0fda25d8 (patch)
tree7bfe33d052b4e656e16dfcebee6724c8a0c2fc44 /src/exchange
parent182c618579919c45281e4a2554890b2f40d2a974 (diff)
-add test for batch deposits
Diffstat (limited to 'src/exchange')
-rw-r--r--src/exchange/taler-exchange-httpd.c27
-rw-r--r--src/exchange/taler-exchange-httpd_batch-deposit.c46
-rw-r--r--src/exchange/taler-exchange-httpd_batch-deposit.h8
3 files changed, 46 insertions, 35 deletions
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c
index 5f400bd8..79db4acd 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -30,6 +30,7 @@
#include <limits.h>
#include "taler_mhd_lib.h"
#include "taler-exchange-httpd_auditors.h"
+#include "taler-exchange-httpd_batch-deposit.h"
#include "taler-exchange-httpd_batch-withdraw.h"
#include "taler-exchange-httpd_contract.h"
#include "taler-exchange-httpd_csr.h"
@@ -67,18 +68,6 @@
#include <gnunet/gnunet_mhd_compat.h>
/**
- * Macro to enable P2P handlers. ON for debugging,
- * FIXME: set to OFF for 0.9.0 release as the feature is not stable!
- */
-#define WITH_P2P 1
-
-/**
- * Should the experimental batch withdraw be supported?
- * ON for testing disable for 0.9.0 release!
- */
-#define WITH_EXPERIMENTAL 1
-
-/**
* Backlog for listen operation on unix domain sockets.
*/
#define UNIX_BACKLOG 50
@@ -374,12 +363,10 @@ handle_post_reserves (struct TEH_RequestContext *rc,
.op = "withdraw",
.handler = &TEH_handler_withdraw
},
-#if WITH_EXPERIMENTAL
{
.op = "batch-withdraw",
.handler = &TEH_handler_batch_withdraw
},
-#endif
{
.op = "status",
.handler = &TEH_handler_reserves_status
@@ -388,12 +375,10 @@ handle_post_reserves (struct TEH_RequestContext *rc,
.op = "history",
.handler = &TEH_handler_reserves_history
},
-#if WITH_P2P
{
.op = "purse",
.handler = &TEH_handler_reserves_purse
},
-#endif
{
.op = NULL,
.handler = NULL
@@ -465,7 +450,6 @@ handle_post_purses (struct TEH_RequestContext *rc,
PurseOpHandler handler;
} h[] = {
-#if WITH_P2P
{
.op = "create",
.handler = &TEH_handler_purses_create
@@ -478,7 +462,6 @@ handle_post_purses (struct TEH_RequestContext *rc,
.op = "merge",
.handler = &TEH_handler_purses_merge
},
-#endif
{
.op = NULL,
.handler = NULL
@@ -1123,6 +1106,12 @@ handle_mhd_request (void *cls,
.method = MHD_HTTP_METHOD_GET,
.handler.get = &TEH_handler_wire
},
+ {
+ .url = "batch-deposit",
+ .method = MHD_HTTP_METHOD_POST,
+ .handler.post = &TEH_handler_batch_deposit,
+ .nargs = 0
+ },
/* request R, used in clause schnorr withdraw and refresh */
{
.url = "csr-melt",
@@ -1190,7 +1179,6 @@ handle_mhd_request (void *cls,
.handler.post = &handle_post_purses,
.nargs = 2 // ??
},
-#if WITH_P2P
/* Getting purse status */
{
.url = "purses",
@@ -1205,7 +1193,6 @@ handle_mhd_request (void *cls,
.handler.get = &TEH_handler_contracts_get,
.nargs = 1
},
-#endif
/* KYC endpoints */
{
.url = "kyc-check",
diff --git a/src/exchange/taler-exchange-httpd_batch-deposit.c b/src/exchange/taler-exchange-httpd_batch-deposit.c
index 3c590e71..31405027 100644
--- a/src/exchange/taler-exchange-httpd_batch-deposit.c
+++ b/src/exchange/taler-exchange-httpd_batch-deposit.c
@@ -151,13 +151,15 @@ reply_batch_deposit_success (
const struct BatchDepositContext *bdc)
{
json_t *arr;
+ struct TALER_ExchangePublicKeyP pub;
+again:
arr = json_array ();
GNUNET_assert (NULL != arr);
for (unsigned int i = 0; i<bdc->num_coins; i++)
{
const struct TALER_EXCHANGEDB_Deposit *deposit = &bdc->deposits[i];
- struct TALER_ExchangePublicKeyP pub;
+ struct TALER_ExchangePublicKeyP pubi;
struct TALER_ExchangeSignatureP sig;
enum TALER_ErrorCode ec;
struct TALER_Amount amount_without_fee;
@@ -178,30 +180,45 @@ reply_batch_deposit_success (
&amount_without_fee,
&deposit->coin.coin_pub,
&bdc->merchant_pub,
- &pub,
+ &pubi,
&sig)))
{
+ GNUNET_break (0);
return TALER_MHD_reply_with_ec (connection,
ec,
NULL);
}
+ if (0 == i)
+ pub = pubi;
+ if (0 !=
+ GNUNET_memcmp (&pub,
+ &pubi))
+ {
+ /* note: in the future, maybe have batch
+ sign API to avoid having to handle
+ key rollover... */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Exchange public key changed during batch deposit, trying again\n");
+ json_decref (arr);
+ goto again;
+ }
GNUNET_assert (
0 ==
json_array_append_new (arr,
GNUNET_JSON_PACK (
GNUNET_JSON_pack_data_auto (
"exchange_sig",
- &sig),
- GNUNET_JSON_pack_data_auto (
- "exchange_pub",
- &pub))));
+ &sig))));
}
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
GNUNET_JSON_pack_timestamp ("exchange_timestamp",
bdc->exchange_timestamp),
- GNUNET_JSON_pack_array_steal ("confirmations",
+ GNUNET_JSON_pack_data_auto (
+ "exchange_pub",
+ &pub),
+ GNUNET_JSON_pack_array_steal ("exchange_sigs",
arr));
}
@@ -476,12 +493,15 @@ parse_coin (struct MHD_Connection *connection,
MHD_RESULT
-TEH_handler_batch_deposit (struct MHD_Connection *connection,
- const json_t *root)
+TEH_handler_batch_deposit (struct TEH_RequestContext *rc,
+ const json_t *root,
+ const char *const args[])
{
+ struct MHD_Connection *connection = rc->connection;
struct BatchDepositContext dc;
json_t *coins;
bool no_refund_deadline = true;
+ bool no_extensions = true;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_string ("merchant_payto_uri",
&dc.payto_uri),
@@ -493,8 +513,10 @@ TEH_handler_batch_deposit (struct MHD_Connection *connection,
&dc.h_contract_terms),
GNUNET_JSON_spec_json ("coins",
&coins),
- GNUNET_JSON_spec_json ("extension_details",
- &dc.extension_details),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_json ("extension_details",
+ &dc.extension_details),
+ &no_extensions),
GNUNET_JSON_spec_timestamp ("timestamp",
&dc.timestamp),
GNUNET_JSON_spec_mark_optional (
@@ -505,7 +527,6 @@ TEH_handler_batch_deposit (struct MHD_Connection *connection,
&dc.wire_deadline),
GNUNET_JSON_spec_end ()
};
-
enum GNUNET_GenericReturnValue res;
res = TALER_MHD_parse_json_data (connection,
@@ -567,6 +588,7 @@ TEH_handler_batch_deposit (struct MHD_Connection *connection,
&dc.wire_salt,
&dc.h_wire);
/* FIXME-OEC: hash actual extension JSON object here */
+ // if (! no_extensions)
memset (&dc.h_extensions,
0,
sizeof (dc.h_extensions));
diff --git a/src/exchange/taler-exchange-httpd_batch-deposit.h b/src/exchange/taler-exchange-httpd_batch-deposit.h
index 359df7d5..187fb9f2 100644
--- a/src/exchange/taler-exchange-httpd_batch-deposit.h
+++ b/src/exchange/taler-exchange-httpd_batch-deposit.h
@@ -35,13 +35,15 @@
* out, this will ultimately lead to the "/batch-deposit" being executed, or
* rejected.
*
- * @param connection the MHD connection to handle
+ * @param rc request context
* @param root uploaded JSON data
+ * @param args arguments, empty in this case
* @return MHD result code
*/
MHD_RESULT
-TEH_handler_batch_deposit (struct MHD_Connection *connection,
- const json_t *root);
+TEH_handler_batch_deposit (struct TEH_RequestContext *rc,
+ const json_t *root,
+ const char *const args[]);
#endif