gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] 04/29: [age-withdraw] WIP: change schema to use new sup


From: gnunet
Subject: [taler-exchange] 04/29: [age-withdraw] WIP: change schema to use new support for array types, 11/n
Date: Mon, 03 Jul 2023 16:23:40 +0200

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

oec pushed a commit to branch master
in repository exchange.

commit a04425df340e9bef067cbf64809ced5597576dfc
Author: Özgür Kesim <oec-taler@kesim.org>
AuthorDate: Fri May 12 15:10:23 2023 +0200

    [age-withdraw] WIP: change schema to use new support for array types, 11/n
---
 src/exchange/taler-exchange-httpd_batch-withdraw.c |  5 +++
 src/exchangedb/0003-age_withdraw_commitments.sql   | 42 ++++++++++++++++------
 src/exchangedb/0003-age_withdraw_reveals.sql       | 37 +++----------------
 src/exchangedb/exchange_do_batch_withdraw.sql      |  6 ++++
 .../exchange_do_batch_withdraw_insert.sql          |  2 +-
 src/exchangedb/pg_do_batch_withdraw.c              |  2 ++
 6 files changed, 50 insertions(+), 44 deletions(-)

diff --git a/src/exchange/taler-exchange-httpd_batch-withdraw.c 
b/src/exchange/taler-exchange-httpd_batch-withdraw.c
index c3065e1d..d97a5f0a 100644
--- a/src/exchange/taler-exchange-httpd_batch-withdraw.c
+++ b/src/exchange/taler-exchange-httpd_batch-withdraw.c
@@ -466,10 +466,12 @@ batch_withdraw_transaction (void *cls,
     return qs;
   }
   wc->kyc.ok = true;
+
   qs = TEH_plugin->do_batch_withdraw (TEH_plugin->cls,
                                       wc->now,
                                       wc->reserve_pub,
                                       &wc->batch_total,
+                                      /* TODO[oec]: add parameter for maximum 
age and [out]parameter for required age */
                                       &found,
                                       &balance_ok,
                                       &ruuid);
@@ -493,6 +495,9 @@ batch_withdraw_transaction (void *cls,
                                            NULL);
     return GNUNET_DB_STATUS_HARD_ERROR;
   }
+
+  /* TODO[oec]: add error handling for age restriction requirements */
+
   if (! balance_ok)
   {
     TEH_plugin->rollback (TEH_plugin->cls);
diff --git a/src/exchangedb/0003-age_withdraw_commitments.sql 
b/src/exchangedb/0003-age_withdraw_commitments.sql
index d74a697c..2ee462ec 100644
--- a/src/exchangedb/0003-age_withdraw_commitments.sql
+++ b/src/exchangedb/0003-age_withdraw_commitments.sql
@@ -26,20 +26,22 @@ BEGIN
   PERFORM create_partitioned_table(
     'CREATE TABLE %I'
       '(age_withdraw_commitment_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
-      ',h_commitment BYTEA CHECK (LENGTH(h_commitment)=64)'
-      ',amount_with_fee_val INT8 NOT NULL'
-      ',amount_with_fee_frac INT4 NOT NULL'
-      ',max_age INT2 NOT NULL'
-      ',reserve_pub BYTEA CHECK (LENGTH(reserve_pub)=32)'
-      ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
-      ',noreveal_index INT4 NOT NULL'
+      ',h_commitment BYTEA NOT NULL CONSTRAINT h_commitment_length 
CHECK(LENGTH(h_commitment)=64)'
+      ',max_age SMALLINT NOT NULL CONSTRAINT max_age_positive 
CHECK(max_age>=0)'
+      ',reserve_pub BYTEA NOT NULL CONSTRAINT reserve_pub_length 
CHECK(LENGTH(reserve_pub)=32)'
+      ',reserve_sig BYTEA NOT NULL CONSTRAINT reserve_sig_length 
CHECK(LENGTH(reserve_sig)=64)'
+      ',num_coins SMALLINT NOT NULL CONSTRAINT num_coins_positive 
CHECK(num_coins>0)'
+      ',denominations_serials INT8[] NOT NULL CONSTRAINT 
denominations_serial_array_length 
CHECK(cardinality(denominations_serials)=num_coins)'
+      ',denom_sigs BYTEA[] NOT NULL CONSTRAINT denom_sigs_array_length 
CHECK(cardinality(denom_sigs)=num_coins)'
+      ',noreveal_index SMALLINT NOT NULL CONSTRAINT noreveal_index_positive 
CHECK(noreveal_index>=0)'
     ') %s ;'
     ,table_name
     ,'PARTITION BY HASH (reserve_pub)'
     ,partition_suffix
   );
   PERFORM comment_partitioned_table(
-     'Commitments made when withdrawing coins with age restriction and the 
gamma value chosen by the exchange.'
+     'Commitments made when withdrawing coins with age restriction and the 
gamma value chosen by the exchange. '
+     'It also contains the blindly signed coins and related denominations.'
     ,table_name
     ,partition_suffix
   );
@@ -68,11 +70,29 @@ BEGIN
     ,partition_suffix
   );
   PERFORM comment_partitioned_column(
-     'Signature of the reserve''s private key over the withdraw-age request'
+     'Signature of the reserve''s private key over the age-withdraw request'
     ,'reserve_sig'
     ,table_name
     ,partition_suffix
   );
+  PERFORM comment_partinioned_column(
+    'Number of coins to be withdrawn'
+    ,'num_coins'
+    ,table_name
+    ,partition_suffix
+  );
+  PERFORM comment_partitioned_column(
+     'Array of #num_coins of references to the denominations'
+    ,'denominations_serials'
+    ,table_name
+    ,partition_suffix
+  );
+  PERFORM comment_partitioned_column(
+     'Array of #num_coins signatures over the blinded envelopes'
+    ,'denom_sigs'
+    ,table_name
+    ,partition_suffix
+  );
 END
 $$;
 
@@ -122,13 +142,13 @@ END
 $$;
 
 
-INSERT INTO exchange_tables 
+INSERT INTO exchange_tables
   (name
   ,version
   ,action
   ,partitioned
   ,by_range)
-VALUES 
+VALUES
   ('age_withdraw_commitments', 'exchange-0003', 'create',   TRUE ,FALSE),
   ('age_withdraw_commitments', 'exchange-0003', 'constrain',TRUE ,FALSE),
   ('age_withdraw_commitments', 'exchange-0003', 'foreign',  TRUE ,FALSE);
diff --git a/src/exchangedb/0003-age_withdraw_reveals.sql 
b/src/exchangedb/0003-age_withdraw_reveals.sql
index 1c55fb19..2ab73f4b 100644
--- a/src/exchangedb/0003-age_withdraw_reveals.sql
+++ b/src/exchangedb/0003-age_withdraw_reveals.sql
@@ -27,14 +27,11 @@ BEGIN
     'CREATE TABLE %I'
       '(age_withdraw_revealed_coins_id BIGINT GENERATED BY DEFAULT AS 
IDENTITY' -- UNIQUE
       ',h_commitment BYTEA NOT NULL CHECK (LENGTH(h_commitment)=64)'
-      ',freshcoin_index INT4 NOT NULL'
-      ',denominations_serial INT8 NOT NULL'
-      ',coin_ev BYTEA NOT NULL'
+      ',coin_index INT4 NOT NULL'
       ',h_coin_ev BYTEA CHECK (LENGTH(h_coin_ev)=64)'
-      ',ev_sig BYTEA NOT NULL'
     ') %s ;'
     ,table_name
-    ,'PARTITION BY HASH (h_commitment)'
+    ,'PARTITION BY HASH (h_coin_ev)'
     ,partition_suffix
   );
   PERFORM comment_partitioned_table(
@@ -49,35 +46,17 @@ BEGIN
     ,partition_suffix
   );
   PERFORM comment_partitioned_column(
-     'Index of the coin in the withdraw-age request, which is implicitly a 
batch request'
-    ,'freshcoin_index'
+     'Index of the coin in the age-withdraw request, which is implicitly a 
batch request'
+    ,'coin_index'
     ,table_name
     ,partition_suffix
   );
   PERFORM comment_partitioned_column(
-     'Foreign key reference to the denominations'
-    ,'denominations_serial'
-    ,table_name
-    ,partition_suffix
-  );
-  PERFORM comment_partitioned_column(
-     'Envelope of the new coin to be signed'
-    ,'coin_ev'
-    ,table_name
-    ,partition_suffix
-  );
-  PERFORM comment_partitioned_column(
-     'Hash of the envelope of the new coin to be signed (for lookups)'
+     'Hash of the envelope of the new coin to be signed (for lookups).  The 
corresponding signatures are stores in age_withdraw_commitments.denom_sigs.'
     ,'h_coin_ev'
     ,table_name
     ,partition_suffix
   );
-  PERFORM comment_partitioned_column(
-     'Exchange signature over the envelope'
-    ,'ev_sig'
-    ,table_name
-    ,partition_suffix
-  );
 END
 $$;
 
@@ -118,12 +97,6 @@ BEGIN
     ' FOREIGN KEY (h_commitment)'
     ' REFERENCES age_withdraw_commitments (h_commitment) ON DELETE CASCADE;'
   );
-  EXECUTE FORMAT (
-    'ALTER TABLE ' || table_name ||
-    ' ADD CONSTRAINT ' || table_name || '_foreign_denominations_serial'
-    ' FOREIGN KEY (denominations_serial) '
-    ' REFERENCES denominations (denominations_serial) ON DELETE CASCADE;'
-  );
 END
 $$;
 
diff --git a/src/exchangedb/exchange_do_batch_withdraw.sql 
b/src/exchangedb/exchange_do_batch_withdraw.sql
index fedb7e91..64777bb3 100644
--- a/src/exchangedb/exchange_do_batch_withdraw.sql
+++ b/src/exchangedb/exchange_do_batch_withdraw.sql
@@ -20,6 +20,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch_withdraw(
   IN rpub BYTEA,
   IN now INT8,
   IN min_reserve_gc INT8,
+-- TODO[oec]: add [IN] parameter for maximum age and [OUT] parameter for 
required age
   OUT reserve_found BOOLEAN,
   OUT balance_ok BOOLEAN,
   OUT ruuid INT8)
@@ -38,11 +39,13 @@ BEGIN
 --         reserves_in by reserve_pub (SELECT)
 --         wire_targets by wire_target_h_payto
 
+
 SELECT
    current_balance_val
   ,current_balance_frac
   ,gc_date
   ,reserve_uuid
+-- TODO[oec]: get age requirements
  INTO
    reserve_val
   ,reserve_frac
@@ -60,6 +63,8 @@ THEN
   RETURN;
 END IF;
 
+-- TODO[oec]: check age requirements
+
 -- Check reserve balance is sufficient.
 IF (reserve_val > amount_val)
 THEN
@@ -99,6 +104,7 @@ balance_ok=TRUE;
 
 END $$;
 
+-- TODO[oec]: Update comment re: age requirements are implemented
 COMMENT ON FUNCTION exchange_do_batch_withdraw(INT8, INT4, BYTEA, INT8, INT8)
   IS 'Checks whether the reserve has sufficient balance for a withdraw 
operation (or the request is repeated and was previously approved) and if so 
updates the database with the result. Excludes storing the planchets.';
 
diff --git a/src/exchangedb/exchange_do_batch_withdraw_insert.sql 
b/src/exchangedb/exchange_do_batch_withdraw_insert.sql
index 98db840f..27378674 100644
--- a/src/exchangedb/exchange_do_batch_withdraw_insert.sql
+++ b/src/exchangedb/exchange_do_batch_withdraw_insert.sql
@@ -15,7 +15,7 @@
 --
 
 
-
+-- TODO[oec]: add min. age requirements handling
 
 CREATE OR REPLACE FUNCTION exchange_do_batch_withdraw_insert(
   IN cs_nonce BYTEA,
diff --git a/src/exchangedb/pg_do_batch_withdraw.c 
b/src/exchangedb/pg_do_batch_withdraw.c
index 3dee20d2..d93caa15 100644
--- a/src/exchangedb/pg_do_batch_withdraw.c
+++ b/src/exchangedb/pg_do_batch_withdraw.c
@@ -31,6 +31,7 @@ TEH_PG_do_batch_withdraw (
   void *cls,
   struct GNUNET_TIME_Timestamp now,
   const struct TALER_ReservePublicKeyP *reserve_pub,
+  /* TODO[oec]: add parameter for maximum age and [out]parameter for required 
age */
   const struct TALER_Amount *amount,
   bool *found,
   bool *balance_ok,
@@ -68,6 +69,7 @@ TEH_PG_do_batch_withdraw (
            " reserve_found"
            ",balance_ok"
            ",ruuid"
+           /* TODO[oec]: add parameter for maximum age and [out] parameter for 
required age */
            " FROM exchange_do_batch_withdraw"
            " ($1,$2,$3,$4,$5);");
   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,

-- 
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]