gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: -sql fixes


From: gnunet
Subject: [taler-exchange] branch master updated: -sql fixes
Date: Sun, 08 May 2022 22:36:50 +0200

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

grothoff pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new 06bfbd91 -sql fixes
06bfbd91 is described below

commit 06bfbd9150e61a1b076175b22b27be4c88e058f3
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun May 8 22:36:39 2022 +0200

    -sql fixes
---
 src/exchange/taler-exchange-httpd_purses_create.c  |  2 +-
 src/exchange/taler-exchange-httpd_purses_deposit.c |  2 +-
 src/exchangedb/exchange-0001-part.sql              | 21 ++++++++++++++-------
 src/exchangedb/plugin_exchangedb_postgres.c        |  7 +++++--
 4 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/exchange/taler-exchange-httpd_purses_create.c 
b/src/exchange/taler-exchange-httpd_purses_create.c
index a5702ffe..f8293981 100644
--- a/src/exchange/taler-exchange-httpd_purses_create.c
+++ b/src/exchange/taler-exchange-httpd_purses_create.c
@@ -233,8 +233,8 @@ create_transaction (void *cls,
                                          &pcc->h_contract_terms,
                                          pcc->min_age,
                                          
TALER_WAMF_MODE_MERGE_FULLY_PAID_PURSE,
-                                         &pcc->amount,
                                          &purse_fee,
+                                         &pcc->amount,
                                          &pcc->purse_sig,
                                          &in_conflict);
   if (qs < 0)
diff --git a/src/exchange/taler-exchange-httpd_purses_deposit.c 
b/src/exchange/taler-exchange-httpd_purses_deposit.c
index 07fcfb1a..8ac63c51 100644
--- a/src/exchange/taler-exchange-httpd_purses_deposit.c
+++ b/src/exchange/taler-exchange-httpd_purses_deposit.c
@@ -220,7 +220,7 @@ deposit_transaction (void *cls,
       *mhd_ret = TALER_MHD_reply_with_error (connection,
                                              MHD_HTTP_INTERNAL_SERVER_ERROR,
                                              TALER_EC_GENERIC_DB_STORE_FAILED,
-                                             "purse deposit deposit");
+                                             "do purse deposit");
       return qs;
     }
     if (! balance_ok)
diff --git a/src/exchangedb/exchange-0001-part.sql 
b/src/exchangedb/exchange-0001-part.sql
index a8aebfba..f5276d0b 100644
--- a/src/exchangedb/exchange-0001-part.sql
+++ b/src/exchangedb/exchange-0001-part.sql
@@ -2854,6 +2854,10 @@ DECLARE
   was_merged BOOLEAN;
 DECLARE
   psi INT8; -- partner's serial ID (set if merged)
+DECLARE
+  my_amount_val INT8; -- total in purse
+DECLARE
+  my_amount_frac INT4; -- total in purse
 DECLARE
   was_paid BOOLEAN;
 DECLARE
@@ -2881,8 +2885,7 @@ IF NOT FOUND
 THEN
   -- Idempotency check: check if coin_sig is the same,
   -- if so, success, otherwise conflict!
-  SELECT
-    1
+  PERFORM
   FROM purse_deposits
   WHERE coin_pub = in_coin_pub
     AND purse_pub = in_purse_pub
@@ -2961,7 +2964,11 @@ THEN
 END IF;
 
 SELECT
-  1
+    amount_with_fee_val
+   ,amount_with_fee_frac
+  INTO
+    my_amount_val
+   ,my_amount_frac
   FROM purse_requests
   WHERE (purse_pub=in_purse_pub)
     AND ( ( ( (amount_with_fee_val <= balance_val)
@@ -2983,15 +2990,15 @@ ELSE
   -- This is a local reserve, update balance immediately.
   UPDATE reserves
   SET
-    current_balance_frac=current_balance_frac+amount_frac
+    current_balance_frac=current_balance_frac+my_amount_frac
        - CASE
-         WHEN current_balance_frac + amount_frac >= 100000000
+         WHEN current_balance_frac + my_amount_frac >= 100000000
          THEN 100000000
          ELSE 0
          END,
-    current_balance_val=current_balance_val+amount_val
+    current_balance_val=current_balance_val+my_amount_val
        + CASE
-         WHEN current_balance_frac + amount_frac >= 100000000
+         WHEN current_balance_frac + my_amount_frac >= 100000000
          THEN 1
          ELSE 0
          END
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c 
b/src/exchangedb/plugin_exchangedb_postgres.c
index 83a64be8..aaf38ea4 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -3538,6 +3538,7 @@ prepare_statements (struct PostgresClosure *pg)
       "INSERT INTO purse_requests"
       "  (purse_pub"
       "  ,merge_pub"
+      "  ,purse_creation"
       "  ,purse_expiration"
       "  ,h_contract_terms"
       "  ,age_limit"
@@ -3549,9 +3550,9 @@ prepare_statements (struct PostgresClosure *pg)
       "  ,purse_fee_frac"
       "  ,purse_sig"
       "  ) VALUES "
-      "  ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)"
+      "  ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)"
       "  ON CONFLICT DO NOTHING;",
-      12),
+      13),
     /* Used in #postgres_select_purse */
     GNUNET_PQ_make_prepare (
       "select_purse",
@@ -13511,12 +13512,14 @@ postgres_insert_purse_request (
 {
   struct PostgresClosure *pg = cls;
   enum GNUNET_DB_QueryStatus qs;
+  struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get ();
   uint32_t flags32 = (uint32_t) flags;
   bool in_reserve_quota = (TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE
                            == (flags & TALER_WAMF_MERGE_MODE_MASK));
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (purse_pub),
     GNUNET_PQ_query_param_auto_from_type (merge_pub),
+    GNUNET_PQ_query_param_timestamp (&now),
     GNUNET_PQ_query_param_timestamp (&purse_expiration),
     GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
     GNUNET_PQ_query_param_uint32 (&age_limit),

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