commit c4f0daff5420fd96dfbbdcb0c2b1ed4dcaab9d6e
parent 1d99aea32b64cc9c02c32bc79434e0a4ce118a12
Author: Christian Grothoff <grothoff@gnunet.org>
Date: Thu, 1 May 2025 14:21:27 +0200
fix variable naming, fix data type int/size_t confusion
Diffstat:
4 files changed, 106 insertions(+), 104 deletions(-)
diff --git a/src/exchange/taler-exchange-httpd_reveal-withdraw.c b/src/exchange/taler-exchange-httpd_reveal-withdraw.c
@@ -87,7 +87,8 @@ parse_withdraw_reveal_json (
GNUNET_JSON_spec_end ()
};
struct GNUNET_JSON_Specification spec[] = {
- TALER_JSON_spec_tuple_of (NULL, tuple),
+ TALER_JSON_spec_tuple_of (NULL,
+ tuple),
GNUNET_JSON_spec_end ()
};
@@ -103,18 +104,19 @@ parse_withdraw_reveal_json (
error = "disclosed_batch_seeds must be an array";
else if (num_entries == 0)
error = "disclosed_batch_seeds must not be empty";
- else if (num_entries != 2)
+ else if (num_entries != TALER_CNC_KAPPA - 1)
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,
- spec,
- &error,
- NULL)))
+ if ( (NULL != error) ||
+ (GNUNET_OK !=
+ GNUNET_JSON_parse (j_disclosed_batch_seeds,
+ spec,
+ &error,
+ NULL)) )
{
GNUNET_break_op (0);
*mhd_ret = TALER_MHD_reply_with_ec (connection,
@@ -179,6 +181,7 @@ find_original_withdraw (
}
}
/* after unsuccessful retries*/
+ GNUNET_break (0);
*result = TALER_MHD_reply_with_ec (connection,
TALER_EC_GENERIC_DB_FETCH_FAILED,
"get_withdraw");
@@ -197,7 +200,7 @@ find_original_withdraw (
* @param max_age The maximum age allowed
* @param[out] bch Hashcode to write
* @param[out] result On error, a HTTP-response will be queued and result set accordingly
- * @return GNUNET_OK on success, GNUNET_SYSERR otherwise, with an error message
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise, with an error message
* written to the client and @e result set.
*/
static enum GNUNET_GenericReturnValue
@@ -302,7 +305,7 @@ calculate_blinded_hash (
* @param wd Original withdraw request
* @param disclosed_batch_seeds The secrets of the disclosed coins, (TALER_CNC_KAPPA - 1)*num_coins many
* @param[out] result On error, a HTTP-response will be queued and result set accordingly
- * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
*/
static enum GNUNET_GenericReturnValue
verify_commitment_and_max_age (
@@ -318,8 +321,8 @@ verify_commitment_and_max_age (
struct TALER_Amount total_amount;
struct TALER_Amount total_fee;
struct TALER_AgeMask mask;
- struct TALER_PlanchetMasterSecretP secrets[TALER_CNC_KAPPA
- - 1][wd->num_coins];
+ struct TALER_PlanchetMasterSecretP secrets[
+ TALER_CNC_KAPPA - 1][wd->num_coins];
bool is_cs[wd->num_coins];
size_t cs_count = 0;
uint8_t secrets_idx = 0; /* first index into secrets */
@@ -533,9 +536,9 @@ reply_withdraw_reveal_success (
const struct TALER_EXCHANGEDB_Withdraw *commitment)
{
json_t *list = json_array ();
- GNUNET_assert (NULL != list);
- for (unsigned int i = 0; i < commitment->num_coins; i++)
+ GNUNET_assert (NULL != list);
+ for (size_t i = 0; i < commitment->num_coins; i++)
{
json_t *obj = GNUNET_JSON_PACK (
TALER_JSON_pack_blinded_denom_sig (NULL,
@@ -557,7 +560,7 @@ MHD_RESULT
TEH_handler_reveal_withdraw (
struct TEH_RequestContext *rc,
const json_t *root,
- const char *const args[2])
+ const char *const args[0])
{
MHD_RESULT result = MHD_NO;
enum GNUNET_GenericReturnValue ret = GNUNET_SYSERR;
@@ -571,6 +574,7 @@ TEH_handler_reveal_withdraw (
GNUNET_JSON_spec_end ()
};
+ (void) args;
/* Parse JSON body*/
ret = TALER_MHD_parse_json_data (rc->connection,
root,
@@ -581,8 +585,6 @@ TEH_handler_reveal_withdraw (
return (GNUNET_SYSERR == ret) ? MHD_NO : MHD_YES;
}
- (void) args;
-
do {
/* Extract denominations, blinded and disclosed coins */
if (GNUNET_OK !=
@@ -620,7 +622,7 @@ TEH_handler_reveal_withdraw (
GNUNET_JSON_parse_free (spec);
if (NULL != actx.withdraw.denom_sigs)
- for (unsigned int i = 0; i<actx.withdraw.num_coins; i++)
+ for (size_t i = 0; i<actx.withdraw.num_coins; i++)
TALER_blinded_denom_sig_free (&actx.withdraw.denom_sigs[i]);
GNUNET_free (actx.withdraw.denom_sigs);
GNUNET_free (actx.withdraw.denom_pub_hashes);
diff --git a/src/exchange/taler-exchange-httpd_reveal-withdraw.h b/src/exchange/taler-exchange-httpd_reveal-withdraw.h
@@ -51,6 +51,6 @@ MHD_RESULT
TEH_handler_reveal_withdraw (
struct TEH_RequestContext *rc,
const json_t *root,
- const char *const args[2]);
+ const char *const args[0]);
#endif
diff --git a/src/exchangedb/exchange_do_withdraw.sql b/src/exchangedb/exchange_do_withdraw.sql
@@ -30,23 +30,23 @@ CREATE FUNCTION exchange_do_withdraw(
IN in_blinding_seed BYTEA, -- possibly NULL (if no CS denominations)
IN in_cs_r_values BYTEA[], -- possibly NULL (if no CS denominations)
IN in_cs_r_choices INT8, -- possibly NULL (if no CS denominations)
- OUT reserve_found BOOLEAN,
- OUT balance_ok BOOLEAN,
- OUT reserve_balance taler_amount,
- OUT age_ok BOOLEAN,
- OUT required_age INT2, -- in years ϵ [0,1..)
- OUT reserve_birthday INT4,
- OUT idempotent BOOLEAN,
+ OUT out_reserve_found BOOLEAN,
+ OUT out_balance_ok BOOLEAN,
+ OUT out_reserve_balance taler_amount,
+ OUT out_age_ok BOOLEAN,
+ OUT out_required_age INT2, -- in years ϵ [0,1..)
+ OUT out_reserve_birthday INT4,
+ OUT out_idempotent BOOLEAN,
OUT out_noreveal_index INT2,
- OUT nonce_reuse BOOLEAN)
+ OUT out_nonce_reuse BOOLEAN)
LANGUAGE plpgsql
AS $$
DECLARE
- reserve RECORD;
- difference RECORD;
- balance taler_amount;
- not_before date;
- earliest_date date;
+ my_reserve RECORD;
+ my_difference RECORD;
+ my_balance taler_amount;
+ my_not_before DATE;
+ my_earliest_date DATE;
BEGIN
-- Shards: reserves by reserve_pub (SELECT)
-- reserves_out (INSERT, with CONFLICT detection) by wih
@@ -57,100 +57,100 @@ BEGIN
SELECT current_balance
,birthday
,gc_date
- INTO reserve
+ INTO my_reserve
FROM reserves
WHERE reserve_pub=in_reserve_pub;
+out_reserve_found = FOUND;
-IF NOT FOUND
+IF NOT out_reserve_found
THEN
- reserve_found=FALSE;
- age_ok = FALSE;
- required_age=-1;
- idempotent=FALSE;
- out_noreveal_index=-1;
- reserve_balance.val = 0;
- reserve_balance.frac = 0;
- balance_ok=FALSE;
- nonce_reuse=FALSE;
+ out_age_ok = FALSE;
+ out_required_age = -1;
+ out_idempotent = FALSE;
+ out_noreveal_index = -1;
+ out_reserve_balance.val = 0;
+ out_reserve_balance.frac = 0;
+ out_balance_ok = FALSE;
+ out_nonce_reuse = FALSE;
RETURN;
END IF;
-reserve_found = TRUE;
-reserve_balance = reserve.current_balance;
-reserve_birthday = reserve.birthday;
+out_reserve_balance = my_reserve.current_balance;
+out_reserve_birthday = my_reserve.birthday;
+
+-- FIXME-performance: probably better to INSERT and on-conflict check for idempotency...
-- Next, check for idempotency of the withdraw
-SELECT TRUE, noreveal_index
-INTO idempotent, out_noreveal_index
-FROM withdraw
+SELECT noreveal_index
+ INTO out_noreveal_index
+ FROM withdraw
WHERE reserve_pub = in_reserve_pub
- AND planchets_h = in_planchets_h;
+ AND planchets_h = in_planchets_h;
+out_idempotent = FOUND;
-IF idempotent
+IF out_idempotent
THEN
- -- idempotent, out_noreveal_index are set, report.
- balance_ok = TRUE;
- age_ok = TRUE;
- required_age = -1;
- nonce_reuse = FALSE;
-RETURN;
+ -- out_idempotent, out_noreveal_index are set, report.
+ out_balance_ok = TRUE;
+ out_age_ok = TRUE;
+ out_required_age = -1;
+ out_nonce_reuse = FALSE;
+ RETURN;
END IF;
-idempotent = FALSE;
out_noreveal_index = -1;
-- Check age requirements
-IF (reserve.birthday <> 0)
+IF (my_reserve.birthday <> 0)
THEN
- not_before=date '1970-01-01' + reserve.birthday;
- earliest_date = current_date - make_interval(in_maximum_age_committed);
+ my_not_before=date '1970-01-01' + my_reserve.birthday;
+ my_earliest_date = current_date - make_interval(in_maximum_age_committed);
--
- -- 1970-01-01 + birthday == not_before now
+ -- 1970-01-01 + birthday == my_not_before now
-- | | |
-- <.......not allowed......>[<.....allowed range......>]
-- | | |
-- ____*_____________________*_________*________________* timeline
-- |
- -- earliest_date ==
+ -- my_earliest_date ==
-- now - maximum_age_committed*year
--
- IF ((in_maximum_age_committed IS NULL) OR
- (earliest_date < not_before))
+ IF ( (in_maximum_age_committed IS NULL) OR
+ (my_earliest_date < my_not_before) )
THEN
- required_age = extract(year from age(current_date, not_before));
- age_ok = FALSE;
- balance_ok=TRUE; -- not really
- nonce_reuse = FALSE; -- not really
+ out_required_age = extract(year FROM age(current_date, my_not_before));
+ out_age_ok = FALSE;
+ out_balance_ok = TRUE; -- not really
+ out_nonce_reuse = FALSE; -- not really
RETURN;
END IF;
END IF;
-age_ok = TRUE;
-required_age=0;
+out_age_ok = TRUE;
+out_required_age = 0;
-- Check reserve balance is sufficient.
SELECT *
-INTO difference
-FROM amount_left_minus_right(reserve_balance
- ,in_amount_with_fee);
+ INTO my_difference
+ FROM amount_left_minus_right(out_reserve_balance
+ ,in_amount_with_fee);
-balance_ok = difference.ok;
-
-IF NOT balance_ok
+out_balance_ok = my_difference.ok;
+IF NOT out_balance_ok
THEN
- nonce_reuse = FALSE; -- not yet determined
+ out_nonce_reuse = FALSE; -- not yet determined
RETURN;
END IF;
-balance = difference.diff;
+my_balance = my_difference.diff;
-- Calculate new expiration dates.
-in_min_reserve_gc=GREATEST(in_min_reserve_gc,reserve.gc_date);
+in_min_reserve_gc=GREATEST(in_min_reserve_gc,my_reserve.gc_date);
-- Update reserve balance.
UPDATE reserves SET
gc_date=in_min_reserve_gc
- ,current_balance=balance
+ ,current_balance=my_balance
WHERE
reserve_pub=in_reserve_pub;
@@ -165,12 +165,12 @@ THEN
IF NOT FOUND
THEN
- nonce_reuse = TRUE;
- RETURN;
+ out_nonce_reuse = TRUE;
+ RETURN;
END IF;
END IF;
-nonce_reuse = FALSE;
+out_nonce_reuse = FALSE;
-- Write the data into the withdraw table
INSERT INTO withdraw
diff --git a/src/exchangedb/pg_do_withdraw.c b/src/exchangedb/pg_do_withdraw.c
@@ -71,34 +71,34 @@ TEH_PG_do_withdraw (
? GNUNET_PQ_query_param_null ()
: GNUNET_PQ_query_param_auto_from_type (&withdraw->blinding_seed),
(withdraw->no_blinding_seed)
- ? TALER_PQ_query_param_array_cs_r_pub (withdraw->num_cs_r_values,
+ ? GNUNET_PQ_query_param_null ()
+ : TALER_PQ_query_param_array_cs_r_pub (withdraw->num_cs_r_values,
withdraw->cs_r_values,
- pg->conn)
- : GNUNET_PQ_query_param_null (),
+ pg->conn),
(withdraw->no_blinding_seed)
- ? GNUNET_PQ_query_param_uint64 (&withdraw->cs_r_choices)
- : GNUNET_PQ_query_param_null (),
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_uint64 (&withdraw->cs_r_choices),
GNUNET_PQ_query_param_end
};
bool reserve_found;
struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("reserve_found",
+ GNUNET_PQ_result_spec_bool ("out_reserve_found",
&reserve_found),
- GNUNET_PQ_result_spec_bool ("balance_ok",
+ GNUNET_PQ_result_spec_bool ("out_balance_ok",
balance_ok),
- TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_balance",
+ TALER_PQ_RESULT_SPEC_AMOUNT ("out_reserve_balance",
reserve_balance),
- GNUNET_PQ_result_spec_bool ("age_ok",
+ GNUNET_PQ_result_spec_bool ("out_age_ok",
age_ok),
- GNUNET_PQ_result_spec_uint16 ("required_age",
+ GNUNET_PQ_result_spec_uint16 ("out_required_age",
required_age),
- GNUNET_PQ_result_spec_uint32 ("reserve_birthday",
+ GNUNET_PQ_result_spec_uint32 ("out_reserve_birthday",
reserve_birthday),
- GNUNET_PQ_result_spec_bool ("idempotent",
+ GNUNET_PQ_result_spec_bool ("out_idempotent",
idempotent),
GNUNET_PQ_result_spec_uint16 ("out_noreveal_index",
noreveal_index),
- GNUNET_PQ_result_spec_bool ("nonce_reuse",
+ GNUNET_PQ_result_spec_bool ("out_nonce_reuse",
nonce_reuse),
GNUNET_PQ_result_spec_end
};
@@ -113,15 +113,15 @@ TEH_PG_do_withdraw (
PREPARE (pg,
"call_withdraw",
"SELECT "
- " reserve_found"
- ",balance_ok"
- ",reserve_balance"
- ",age_ok"
- ",required_age"
- ",reserve_birthday"
- ",idempotent"
+ " out_reserve_found"
+ ",out_balance_ok"
+ ",out_reserve_balance"
+ ",out_age_ok"
+ ",out_required_age"
+ ",out_reserve_birthday"
+ ",out_idempotent"
",out_noreveal_index"
- ",nonce_reuse"
+ ",out_nonce_reuse"
" FROM exchange_do_withdraw"
" ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);");
qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,