commit 834367660cd02772e71e379c4676ba63852f8103
parent 3404dbff00cc8ffb14b9f770d7ffcd690b5994d5
Author: Özgür Kesim <oec@codeblau.de>
Date: Mon, 31 Mar 2025 21:34:14 +0200
[wxchange+lib] code cleanup related to reveal-withdraw
Diffstat:
3 files changed, 42 insertions(+), 63 deletions(-)
diff --git a/src/exchange/taler-exchange-httpd_reveal-withdraw.c b/src/exchange/taler-exchange-httpd_reveal-withdraw.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2023 Taler Systems SA
+ Copyright (C) 2023,2025 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
@@ -35,7 +35,7 @@
/**
* State for an /reveal-withdraw operation.
*/
-struct AgeRevealContext
+struct WithdrawRevealContext
{
/**
@@ -72,11 +72,11 @@ static enum GNUNET_GenericReturnValue
parse_withdraw_reveal_json (
struct MHD_Connection *connection,
const json_t *j_disclosed_batch_seeds,
- struct AgeRevealContext *actx,
+ struct WithdrawRevealContext *actx,
MHD_RESULT *mhd_ret)
{
size_t num_entries;
- const char *error = NULL;
+ const char *error;
struct GNUNET_JSON_Specification tuple[] = {
GNUNET_JSON_spec_fixed (NULL,
&actx->disclosed_batch_seeds.tuple[0],
@@ -107,6 +107,8 @@ parse_withdraw_reveal_json (
error =
"disclosed_batch_seeds must be an array of size "
TALER_CNC_KAPPA_MINUS_ONE_STR;
+ else
+ error = NULL;
if ((NULL != error) ||
(GNUNET_OK != GNUNET_JSON_parse (j_disclosed_batch_seeds,
@@ -121,9 +123,7 @@ parse_withdraw_reveal_json (
return GNUNET_SYSERR;
}
-
return GNUNET_OK;
-
}
@@ -518,7 +518,7 @@ TEH_handler_reveal_withdraw (
{
MHD_RESULT result = MHD_NO;
enum GNUNET_GenericReturnValue ret = GNUNET_SYSERR;
- struct AgeRevealContext actx = {0};
+ struct WithdrawRevealContext actx = {0};
const json_t *j_disclosed_batch_seeds;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("withdraw_commitment_h",
@@ -586,4 +586,4 @@ TEH_handler_reveal_withdraw (
}
-/* end of taler-exchange-httpd_withdraw_reveal.c */
+/* end of taler-exchange-httpd_reveal_withdraw.c */
diff --git a/src/exchange/taler-exchange-httpd_reveal-withdraw.h b/src/exchange/taler-exchange-httpd_reveal-withdraw.h
@@ -18,8 +18,8 @@
* @brief Handle /reveal-withdraw/$ACH requests
* @author Özgür Kesim
*/
-#ifndef TALER_EXCHANGE_HTTPD_WITHDRAW_REVEAL_H
-#define TALER_EXCHANGE_HTTPD_WITHDRAW_REVEAL_H
+#ifndef TALER_EXCHANGE_HTTPD_REVEAL_WITHDRAW_H
+#define TALER_EXCHANGE_HTTPD_REVEAL_WITHDRAW_H
#include <microhttpd.h>
#include "taler-exchange-httpd.h"
diff --git a/src/lib/exchange_api_reveal_withdraw.c b/src/lib/exchange_api_reveal_withdraw.c
@@ -261,48 +261,37 @@ perform_protocol (
struct GNUNET_CURL_Context *curl_ctx,
struct TALER_EXCHANGE_RevealWithdrawHandle *wrh)
{
- CURL *curlh = NULL;
- json_t *j_request_body = NULL;
- json_t *j_array_of_secrets = NULL;
- json_t *j_secrets = NULL;
- json_t *j_sec = NULL;
-
-#define FAIL_IF(cond) \
- do { \
- if ((cond)) \
- { \
- GNUNET_break (! (cond)); \
- goto ERROR; \
- } \
- } while (0)
+ CURL *curlh;
+ json_t *j_array_of_secrets;
j_array_of_secrets = json_array ();
- FAIL_IF (NULL == j_array_of_secrets);
-
+ GNUNET_assert (NULL != j_array_of_secrets);
for (uint8_t k = 0; k < TALER_CNC_KAPPA - 1; k++)
{
- j_sec = GNUNET_JSON_from_data_auto (&wrh->seeds.tuple[k]);
- FAIL_IF (NULL == j_sec);
- FAIL_IF (0 < json_array_append_new (j_array_of_secrets,
- j_sec));
+ json_t *j_sec = GNUNET_JSON_from_data_auto (&wrh->seeds.tuple[k]);
+ GNUNET_assert (NULL != j_sec);
+ GNUNET_assert (0 == json_array_append_new (j_array_of_secrets,
+ j_sec));
+ }
+ {
+ json_t *j_request_body;
+
+ j_request_body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("withdraw_commitment_h",
+ wrh->h_commitment),
+ GNUNET_JSON_pack_array_steal ("disclosed_batch_seeds",
+ j_array_of_secrets));
+ GNUNET_assert (NULL != j_request_body);
+
+ curlh = TALER_EXCHANGE_curl_easy_get_ (wrh->request_url);
+ GNUNET_assert (NULL != curlh);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_curl_easy_post (&wrh->post_ctx,
+ curlh,
+ j_request_body));
+ json_decref (j_request_body);
}
-
- j_request_body = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("withdraw_commitment_h",
- wrh->h_commitment),
- GNUNET_JSON_pack_array_steal ("disclosed_batch_seeds",
- j_array_of_secrets));
- FAIL_IF (NULL == j_request_body);
-
- curlh = TALER_EXCHANGE_curl_easy_get_ (wrh->request_url);
- FAIL_IF (NULL == curlh);
- FAIL_IF (GNUNET_OK !=
- TALER_curl_easy_post (&wrh->post_ctx,
- curlh,
- j_request_body));
- json_decref (j_request_body);
- j_request_body = NULL;
wrh->job = GNUNET_CURL_job_add2 (
curl_ctx,
@@ -310,25 +299,15 @@ perform_protocol (
wrh->post_ctx.headers,
&handle_reveal_withdraw_finished,
wrh);
- FAIL_IF (NULL == wrh->job);
-
- /* No error, return */
- return;
+ if (NULL == wrh->job)
+ {
+ GNUNET_break (0);
+ if (NULL != curlh)
+ curl_easy_cleanup (curlh);
+ TALER_EXCHANGE_reveal_withdraw_cancel (wrh);
+ }
-ERROR:
- if (NULL != j_sec)
- json_decref (j_sec);
- if (NULL != j_secrets)
- json_decref (j_secrets);
- if (NULL != j_array_of_secrets)
- json_decref (j_array_of_secrets);
- if (NULL != j_request_body)
- json_decref (j_request_body);
- if (NULL != curlh)
- curl_easy_cleanup (curlh);
- TALER_EXCHANGE_reveal_withdraw_cancel (wrh);
return;
-#undef FAIL_IF
}