gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-exchange] 02/03: remove dead do_withdraw code


From: gnunet
Subject: [taler-exchange] 02/03: remove dead do_withdraw code
Date: Mon, 16 Oct 2023 08:49:57 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository exchange.

commit d06d8596260655f52a3e7db9e46d8220f8a5716a
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Sun Oct 15 23:43:31 2023 +0200

    remove dead do_withdraw code
---
 src/exchangedb/Makefile.am                  |   1 -
 src/exchangedb/exchange_do_withdraw.sql     | 213 ----------------------------
 src/exchangedb/perf_deposits_get_ready.c    |  36 +++--
 src/exchangedb/pg_do_withdraw.c             |  97 -------------
 src/exchangedb/pg_do_withdraw.h             |  59 --------
 src/exchangedb/plugin_exchangedb_postgres.c |   3 -
 src/exchangedb/procedures.sql.in            |   1 -
 src/exchangedb/test_exchangedb.c            |  39 +++--
 src/include/taler_exchangedb_plugin.h       |  32 -----
 9 files changed, 50 insertions(+), 431 deletions(-)

diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am
index 3a4120af..33a5722c 100644
--- a/src/exchangedb/Makefile.am
+++ b/src/exchangedb/Makefile.am
@@ -221,7 +221,6 @@ libtaler_plugin_exchangedb_postgres_la_SOURCES = \
   pg_do_batch_withdraw_insert.h pg_do_batch_withdraw_insert.c \
   pg_do_reserve_open.c pg_do_reserve_open.h \
   pg_do_purse_delete.c pg_do_purse_delete.h \
-  pg_do_withdraw.h pg_do_withdraw.c \
   pg_preflight.h pg_preflight.c \
   pg_iterate_active_signkeys.h pg_iterate_active_signkeys.c \
   pg_commit.h pg_commit.c \
diff --git a/src/exchangedb/exchange_do_withdraw.sql 
b/src/exchangedb/exchange_do_withdraw.sql
deleted file mode 100644
index c25267b7..00000000
--- a/src/exchangedb/exchange_do_withdraw.sql
+++ /dev/null
@@ -1,213 +0,0 @@
---
--- This file is part of TALER
--- 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 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 General Public License for more details.
---
--- You should have received a copy of the GNU General Public License along with
--- TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
---
-
-
-CREATE OR REPLACE FUNCTION exchange_do_withdraw(
-  IN cs_nonce BYTEA,
-  IN amount taler_amount,
-  IN h_denom_pub BYTEA,
-  IN rpub BYTEA,
-  IN reserve_sig BYTEA,
-  IN h_coin_envelope BYTEA,
-  IN denom_sig BYTEA,
-  IN now INT8,
-  IN min_reserve_gc INT8,
-  IN do_age_check BOOLEAN,
-  OUT reserve_found BOOLEAN,
-  OUT balance_ok BOOLEAN,
-  OUT nonce_ok BOOLEAN,
-  OUT age_ok BOOLEAN,
-  OUT allowed_maximum_age INT2, -- in years
-  OUT ruuid INT8)
-LANGUAGE plpgsql
-AS $$
-DECLARE
-  reserve RECORD;
-  denom_serial INT8;
-  balance taler_amount;
-  not_before date;
-BEGIN
--- Shards: reserves by reserve_pub (SELECT)
---         reserves_out (INSERT, with CONFLICT detection) by wih
---         reserves by reserve_pub (UPDATE)
---         reserves_in by reserve_pub (SELECT)
---         wire_targets by wire_target_h_payto
-
-SELECT denominations_serial
-  INTO denom_serial
-  FROM exchange.denominations
- WHERE denom_pub_hash=h_denom_pub;
-
-IF NOT FOUND
-THEN
-  -- denomination unknown, should be impossible!
-  reserve_found=FALSE;
-  balance_ok=FALSE;
-  age_ok=FALSE;
-  allowed_maximum_age=0;
-  ruuid=0;
-  ASSERT false, 'denomination unknown';
-  RETURN;
-END IF;
-
-
-SELECT *
-  INTO reserve
-  FROM exchange.reserves
- WHERE reserves.reserve_pub=rpub;
-
-IF NOT FOUND
-THEN
-  -- reserve unknown
-  reserve_found=FALSE;
-  balance_ok=FALSE;
-  nonce_ok=TRUE;
-  age_ok=FALSE;
-  allowed_maximum_age=0;
-  ruuid=2;
-  RETURN;
-END IF;
-
-balance = reserve.current_balance;
-ruuid = reserve.reserve_uuid;
-
--- Check if age requirements are present
-IF ((NOT do_age_check) OR (reserve.birthday = 0))
-THEN
-  age_ok = TRUE;
-  allowed_maximum_age = -1;
-ELSE
-  -- Age requirements are formally not met:  The exchange is setup to support
-  -- age restrictions (do_age_check == TRUE) and the reserve has a
-  -- birthday set (reserve_birthday != 0), but the client called the
-  -- batch-withdraw endpoint instead of the age-withdraw endpoint, which it
-  -- should have.
-  not_before=date '1970-01-01' + reserve.birthday;
-  allowed_maximum_age = extract(year from age(current_date, not_before));
-
-  reserve_found=TRUE;
-  nonce_ok=TRUE; -- we do not really know
-  balance_ok=TRUE;-- we do not really know
-  age_ok = FALSE;
-  RETURN;
-END IF;
-
--- We optimistically insert, and then on conflict declare
--- the query successful due to idempotency.
-INSERT INTO exchange.reserves_out
-  (h_blind_ev
-  ,denominations_serial
-  ,denom_sig
-  ,reserve_uuid
-  ,reserve_sig
-  ,execution_date
-  ,amount_with_fee)
-VALUES
-  (h_coin_envelope
-  ,denom_serial
-  ,denom_sig
-  ,ruuid
-  ,reserve_sig
-  ,now
-  ,amount)
-ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
-  -- idempotent query, all constraints must be satisfied
-  reserve_found=TRUE;
-  balance_ok=TRUE;
-  nonce_ok=TRUE;
-  RETURN;
-END IF;
-
--- Check reserve balance is sufficient.
-IF (balance.val > amount.val)
-THEN
-  IF (balance.frac >= amount.frac)
-  THEN
-    balance.val=balance.val - amount.val;
-    balance.frac=balance.frac - amount.frac;
-  ELSE
-    balance.val=balance.val - amount.val - 1;
-    balance.frac=balance.frac + 100000000 - amount.frac;
-  END IF;
-ELSE
-  IF (balance.val = amount.val) AND (balance.frac >= amount.frac)
-  THEN
-    balance.val=0;
-    balance.frac=balance.frac - amount.frac;
-  ELSE
-    reserve_found=TRUE;
-    nonce_ok=TRUE; -- we do not really know
-    balance_ok=FALSE;
-    RETURN;
-  END IF;
-END IF;
-
--- Calculate new expiration dates.
-min_reserve_gc=GREATEST(min_reserve_gc,reserve.gc_date);
-
--- Update reserve balance.
-UPDATE reserves SET
-  gc_date=min_reserve_gc
- ,current_balance=balance
-WHERE
-  reserves.reserve_pub=rpub;
-
-reserve_found=TRUE;
-balance_ok=TRUE;
-
-
-
--- Special actions needed for a CS withdraw?
-IF NOT NULL cs_nonce
-THEN
-  -- Cache CS signature to prevent replays in the future
-  -- (and check if cached signature exists at the same time).
-  INSERT INTO exchange.cs_nonce_locks
-    (nonce
-    ,max_denomination_serial
-    ,op_hash)
-  VALUES
-    (cs_nonce
-    ,denom_serial
-    ,h_coin_envelope)
-  ON CONFLICT DO NOTHING;
-
-  IF NOT FOUND
-  THEN
-    -- See if the existing entry is identical.
-    SELECT 1
-      FROM exchange.cs_nonce_locks
-     WHERE nonce=cs_nonce
-       AND op_hash=h_coin_envelope;
-    IF NOT FOUND
-    THEN
-      reserve_found=FALSE;
-      balance_ok=FALSE;
-      nonce_ok=FALSE;
-      RETURN;
-    END IF;
-  END IF;
-ELSE
-  nonce_ok=TRUE; -- no nonce, hence OK!
-END IF;
-
-END $$;
-
-COMMENT ON FUNCTION exchange_do_withdraw(BYTEA, taler_amount, BYTEA, BYTEA, 
BYTEA, BYTEA, BYTEA, INT8, INT8, BOOLEAN)
-  IS 'Checks whether the reserve has sufficient balance for a withdraw 
operation (or the request is repeated and was previously approved) and if the 
age requirements are formally met.  If so updates the database with the result';
diff --git a/src/exchangedb/perf_deposits_get_ready.c 
b/src/exchangedb/perf_deposits_get_ready.c
index 2effee73..f1566548 100644
--- a/src/exchangedb/perf_deposits_get_ready.c
+++ b/src/exchangedb/perf_deposits_get_ready.c
@@ -364,26 +364,38 @@ run (void *cls)
                                           &cbc.withdraw_fee));
     {
       bool found;
-      bool nonce_ok;
+      bool nonce_reuse;
       bool balance_ok;
       bool age_ok;
+      bool conflict;
+      bool denom_unknown;
+      struct TALER_Amount reserve_balance;
       uint16_t allowed_minimum_age;
       uint64_t ruuid;
       struct GNUNET_TIME_Timestamp now;
 
       now = GNUNET_TIME_timestamp_get ();
       FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
-              plugin->do_withdraw (plugin->cls,
-                                   NULL,
-                                   &cbc,
-                                   now,
-                                   false,
-                                   &found,
-                                   &balance_ok,
-                                   &nonce_ok,
-                                   &age_ok,
-                                   &allowed_minimum_age,
-                                   &ruuid));
+              plugin->do_batch_withdraw (plugin->cls,
+                                         now,
+                                         &reserve_pub,
+                                         &value,
+                                         true,
+                                         &found,
+                                         &balance_ok,
+                                         &reserve_balance,
+                                         &age_ok,
+                                         &allowed_minimum_age,
+                                         &ruuid));
+      FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+              plugin->do_batch_withdraw_insert (plugin->cls,
+                                                NULL,
+                                                &cbc,
+                                                now,
+                                                ruuid,
+                                                &denom_unknown,
+                                                &conflict,
+                                                &nonce_reuse));
     }
     {
       /* ENSURE_COIN_KNOWN */
diff --git a/src/exchangedb/pg_do_withdraw.c b/src/exchangedb/pg_do_withdraw.c
deleted file mode 100644
index cb511b10..00000000
--- a/src/exchangedb/pg_do_withdraw.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
-   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 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 General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along with
-   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/pg_do_withdraw.c
- * @brief Implementation of the do_withdraw function for Postgres
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_error_codes.h"
-#include "taler_dbevents.h"
-#include "taler_pq_lib.h"
-#include "pg_do_withdraw.h"
-#include "pg_helper.h"
-
-
-// FIXME: this function is currently only used in tests.
-// Replace by batch withdraw function in tests as well!
-enum GNUNET_DB_QueryStatus
-TEH_PG_do_withdraw (
-  void *cls,
-  const struct TALER_CsNonce *nonce,
-  const struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable,
-  struct GNUNET_TIME_Timestamp now,
-  bool do_age_check,
-  bool *found,
-  bool *balance_ok,
-  bool *nonce_ok,
-  bool *age_ok,
-  uint16_t *allowed_maximum_age,
-  uint64_t *ruuid)
-{
-  struct PostgresClosure *pg = cls;
-  struct GNUNET_TIME_Timestamp gc;
-  struct GNUNET_PQ_QueryParam params[] = {
-    NULL == nonce
-    ? GNUNET_PQ_query_param_null ()
-    : GNUNET_PQ_query_param_auto_from_type (nonce),
-    TALER_PQ_query_param_amount (pg->conn,
-                                 &collectable->amount_with_fee),
-    GNUNET_PQ_query_param_auto_from_type (&collectable->denom_pub_hash),
-    GNUNET_PQ_query_param_auto_from_type (&collectable->reserve_pub),
-    GNUNET_PQ_query_param_auto_from_type (&collectable->reserve_sig),
-    GNUNET_PQ_query_param_auto_from_type (&collectable->h_coin_envelope),
-    TALER_PQ_query_param_blinded_denom_sig (&collectable->sig),
-    GNUNET_PQ_query_param_timestamp (&now),
-    GNUNET_PQ_query_param_timestamp (&gc),
-    GNUNET_PQ_query_param_bool (do_age_check),
-    GNUNET_PQ_query_param_end
-  };
-  struct GNUNET_PQ_ResultSpec rs[] = {
-    GNUNET_PQ_result_spec_bool ("reserve_found",
-                                found),
-    GNUNET_PQ_result_spec_bool ("balance_ok",
-                                balance_ok),
-    GNUNET_PQ_result_spec_bool ("nonce_ok",
-                                nonce_ok),
-    GNUNET_PQ_result_spec_bool ("age_ok",
-                                age_ok),
-    GNUNET_PQ_result_spec_uint16 ("allowed_maximum_age",
-                                  allowed_maximum_age),
-    GNUNET_PQ_result_spec_uint64 ("ruuid",
-                                  ruuid),
-    GNUNET_PQ_result_spec_end
-  };
-
-  PREPARE (pg,
-           "call_withdraw",
-           "SELECT "
-           " reserve_found"
-           ",balance_ok"
-           ",nonce_ok"
-           ",age_ok"
-           ",allowed_maximum_age"
-           ",ruuid"
-           " FROM exchange_do_withdraw"
-           " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);");
-  gc = GNUNET_TIME_absolute_to_timestamp (
-    GNUNET_TIME_absolute_add (now.abs_time,
-                              pg->legal_reserve_expiration_time));
-  return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                   "call_withdraw",
-                                                   params,
-                                                   rs);
-}
diff --git a/src/exchangedb/pg_do_withdraw.h b/src/exchangedb/pg_do_withdraw.h
deleted file mode 100644
index e771b1ac..00000000
--- a/src/exchangedb/pg_do_withdraw.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
-   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 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 General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along with
-   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file exchangedb/pg_do_withdraw.h
- * @brief implementation of the do_withdraw function for Postgres
- * @author Christian Grothoff
- */
-#ifndef PG_DO_WITHDRAW_H
-#define PG_DO_WITHDRAW_H
-
-#include "taler_util.h"
-#include "taler_json_lib.h"
-#include "taler_exchangedb_plugin.h"
-
-/**
- * Perform withdraw operation, checking for sufficient balance
- * and possibly persisting the withdrawal details.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param nonce client-contributed input for CS denominations that must be 
checked for idempotency, or NULL for non-CS withdrawals
- * @param[in,out] collectable corresponding collectable coin (blind signature) 
if a coin is found; possibly updated if a (different) signature exists already
- * @param now current time (rounded)
- * @param do_age_check set to true if age requirements must be verified
- * @param[out] found set to true if the reserve was found
- * @param[out] balance_ok set to true if the balance was sufficient
- * @param[out] nonce_ok set to false if the nonce was reused
- * @param[out] age_ok set to true if age requirements are met
- * @param[out] allowed_maximum_age if @e age_ok is false, the maximum age (in 
years) that is allowed during age-withdraw
- * @param[out] ruuid set to the reserve's UUID (reserves table row)
- * @return query execution status
- */
-enum GNUNET_DB_QueryStatus
-TEH_PG_do_withdraw (
-  void *cls,
-  const struct TALER_CsNonce *nonce,
-  const struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable,
-  struct GNUNET_TIME_Timestamp now,
-  bool do_age_check,
-  bool *found,
-  bool *balance_ok,
-  bool *nonce_ok,
-  bool *age_ok,
-  uint16_t *allowed_maximum_age,
-  uint64_t *ruuid);
-
-#endif
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c 
b/src/exchangedb/plugin_exchangedb_postgres.c
index aacc2968..ea43c8ff 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -38,7 +38,6 @@
 #include "pg_get_link_data.h"
 #include "pg_helper.h"
 #include "pg_do_reserve_open.h"
-#include "pg_do_withdraw.h"
 #include "pg_get_coin_transactions.h"
 #include "pg_get_expired_reserves.h"
 #include "pg_get_purse_request.h"
@@ -413,8 +412,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
     = &TEH_PG_do_reserve_open;
   plugin->drop_tables
     = &TEH_PG_drop_tables;
-  plugin->do_withdraw
-    = &TEH_PG_do_withdraw;
   plugin->free_coin_transaction_list
     = &TEH_COMMON_free_coin_transaction_list;
   plugin->free_reserve_history
diff --git a/src/exchangedb/procedures.sql.in b/src/exchangedb/procedures.sql.in
index c697afe9..7afb01f0 100644
--- a/src/exchangedb/procedures.sql.in
+++ b/src/exchangedb/procedures.sql.in
@@ -19,7 +19,6 @@ BEGIN;
 SET search_path TO exchange;
 
 #include "exchange_do_amount_specific.sql"
-#include "exchange_do_withdraw.sql"
 #include "exchange_do_batch_withdraw.sql"
 #include "exchange_do_batch_withdraw_insert.sql"
 #include "exchange_do_age_withdraw.sql"
diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c
index eeaaffad..336c1460 100644
--- a/src/exchangedb/test_exchangedb.c
+++ b/src/exchangedb/test_exchangedb.c
@@ -1410,26 +1410,39 @@ run (void *cls)
 
   {
     bool found;
-    bool nonce_ok;
+    bool nonce_reuse;
     bool balance_ok;
     bool age_ok;
+    bool conflict;
+    bool denom_unknown;
     uint16_t maximum_age;
     uint64_t ruuid;
+    struct TALER_Amount reserve_balance;
 
     FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
-            plugin->do_withdraw (plugin->cls,
-                                 NULL,
-                                 &cbc,
-                                 now,
-                                 false,
-                                 &found,
-                                 &balance_ok,
-                                 &nonce_ok,
-                                 &age_ok,
-                                 &maximum_age,
-                                 &ruuid));
+            plugin->do_batch_withdraw (plugin->cls,
+                                       now,
+                                       &reserve_pub,
+                                       &value,
+                                       true,
+                                       &found,
+                                       &balance_ok,
+                                       &reserve_balance,
+                                       &age_ok,
+                                       &maximum_age,
+                                       &ruuid));
+    FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+            plugin->do_batch_withdraw_insert (plugin->cls,
+                                              NULL,
+                                              &cbc,
+                                              now,
+                                              ruuid,
+                                              &denom_unknown,
+                                              &conflict,
+                                              &nonce_reuse));
     GNUNET_assert (found);
-    GNUNET_assert (nonce_ok);
+    GNUNET_assert (! nonce_reuse);
+    GNUNET_assert (! denom_unknown);
     GNUNET_assert (balance_ok);
   }
 
diff --git a/src/include/taler_exchangedb_plugin.h 
b/src/include/taler_exchangedb_plugin.h
index 20dca495..252c27a7 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -3877,38 +3877,6 @@ struct TALER_EXCHANGEDB_Plugin
                        struct TALER_EXCHANGEDB_CollectableBlindcoin 
*collectable);
 
 
-  /**
-   * Perform withdraw operation, checking for sufficient balance
-   * and possibly persisting the withdrawal details.
-   *
-   * @param cls the `struct PostgresClosure` with the plugin-specific state
-   * @param nonce client-contributed input for CS denominations that must be 
checked for idempotency, or NULL for non-CS withdrawals
-   * @param collectable corresponding collectable coin (blind signature)
-   * @param now current time (rounded)
-   * @param do_age_check set to true if age requirements must be checked.
-   * @param[out] found set to true if the reserve was found
-   * @param[out] balance_ok set to true if the balance was sufficient
-   * @param[out] nonce_ok set to false if the nonce was reused
-   * @param[out] age_ok set to true if no age requirements were defined on the 
reserve or @e do_age_check was false
-   * @param[out] allowed_maximum_age when @e age_ok is false, set to the 
allowed maximum age for withdrawal from the reserve.  The client MUST then use 
the age-withdraw endpoint
-   * @param[out] ruuid set to the reserve's UUID (reserves table row)
-   * @return query execution status
-   */
-  enum GNUNET_DB_QueryStatus
-  (*do_withdraw)(
-    void *cls,
-    const struct TALER_CsNonce *nonce,
-    const struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable,
-    struct GNUNET_TIME_Timestamp now,
-    bool do_age_check,
-    bool *found,
-    bool *balance_ok,
-    bool *nonce_ok,
-    bool *age_ok,
-    uint16_t *allowed_maximum_age,
-    uint64_t *ruuid);
-
-
   /**
    * FIXME: merge do_batch_withdraw and do_batch_withdraw_insert into one API,
    * which takes as input (among others)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]