gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: no purse fee if purse is success


From: gnunet
Subject: [taler-exchange] branch master updated: no purse fee if purse is successfully merged
Date: Sun, 05 Jun 2022 21:00:56 +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 bdbd2a46 no purse fee if purse is successfully merged
bdbd2a46 is described below

commit bdbd2a464df579c014d71800cf72571dc73ed645
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Jun 5 21:00:41 2022 +0200

    no purse fee if purse is successfully merged
---
 src/auditor/auditor-basedb.conf               |  6 ++---
 src/exchange/taler-exchange-httpd_responses.c |  7 +-----
 src/exchangedb/exchange-0001-part.sql         | 36 +++++++++++++++++++--------
 src/exchangedb/plugin_exchangedb_postgres.c   |  2 +-
 src/lib/exchange_api_common.c                 | 28 ++++++++-------------
 src/testing/testing_api_cmd_purse_deposit.c   |  9 ++-----
 6 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/src/auditor/auditor-basedb.conf b/src/auditor/auditor-basedb.conf
index a67f2bf1..197e6d95 100644
--- a/src/auditor/auditor-basedb.conf
+++ b/src/auditor/auditor-basedb.conf
@@ -113,7 +113,7 @@ currency = TESTKUDOS
 [merchant-exchange-default]
 CURRENCY = TESTKUDOS
 EXCHANGE_BASE_URL = http://localhost:8081/
-MASTER_KEY = W2824S2YNKFZDR0P57Q005J23XGFWSE2GB24A1YS0157NE3F24NG
+MASTER_KEY = EQ73PAPVK53KV6QPBDXPD0DTAWR2TPTQQFFTT9AYSB73ZNYW0AD0
 
 [merchant-account-merchant]
 ACTIVE_default = YES
@@ -157,7 +157,7 @@ CONFIG = postgres:///auditor-basedb
 [exchange]
 LOOKAHEAD_SIGN = 32 weeks 1 day
 SIGNKEY_DURATION = 4 weeks
-MASTER_PUBLIC_KEY = W2824S2YNKFZDR0P57Q005J23XGFWSE2GB24A1YS0157NE3F24NG
+MASTER_PUBLIC_KEY = EQ73PAPVK53KV6QPBDXPD0DTAWR2TPTQQFFTT9AYSB73ZNYW0AD0
 SIGNKEY_LEGAL_DURATION = 4 weeks
 UNIXPATH = ${TALER_RUNTIME_DIR}/exchange.http
 
@@ -175,7 +175,7 @@ DATABASE = postgres:///auditor-basedb
 CONFIG = postgres:///auditor-basedb
 
 [auditor]
-PUBLIC_KEY = MSF4QDJMZTT9CC5EMHS480F652QAS40SEXEPAW0GGB9G9RB9B5T0
+PUBLIC_KEY = AAJ7CB4EV8MRZVCAR57B549SX1W7SPR50RFQ1ZV0GKZQMTJB4Z5G
 TINY_AMOUNT = TESTKUDOS:0.01
 BASE_URL = http://localhost:8083/
 
diff --git a/src/exchange/taler-exchange-httpd_responses.c 
b/src/exchange/taler-exchange-httpd_responses.c
index e5309f9e..429647e1 100644
--- a/src/exchange/taler-exchange-httpd_responses.c
+++ b/src/exchange/taler-exchange-httpd_responses.c
@@ -778,12 +778,7 @@ TEH_RESPONSE_compile_reserve_history (
       {
         const struct TALER_EXCHANGEDB_PurseMerge *merge =
           pos->details.merge;
-        struct TALER_Amount amount;
 
-        GNUNET_assert (0 <=
-                       TALER_amount_subtract (&amount,
-                                              &merge->amount_with_fee,
-                                              &merge->purse_fee));
         if (0 !=
             json_array_append_new (
               json_history,
@@ -807,7 +802,7 @@ TEH_RESPONSE_compile_reserve_history (
                 GNUNET_JSON_pack_timestamp ("purse_expiration",
                                             merge->purse_expiration),
                 TALER_JSON_pack_amount ("amount",
-                                        &amount),
+                                        &merge->amount_with_fee),
                 TALER_JSON_pack_amount ("purse_fee",
                                         &merge->purse_fee),
                 GNUNET_JSON_pack_bool ("merged",
diff --git a/src/exchangedb/exchange-0001-part.sql 
b/src/exchangedb/exchange-0001-part.sql
index c79fdf84..75f65ffb 100644
--- a/src/exchangedb/exchange-0001-part.sql
+++ b/src/exchangedb/exchange-0001-part.sql
@@ -1354,7 +1354,7 @@ CREATE OR REPLACE FUNCTION 
purse_requests_on_update_trigger()
   LANGUAGE plpgsql
   AS $$
 BEGIN
-  IF (NEW.finished)
+  IF (NEW.finished AND NOT OLD.finished)
   THEN
     -- If this purse counted against the reserve's
     -- quota of purses, decrement the reserve accounting.
@@ -3099,9 +3099,13 @@ CREATE OR REPLACE FUNCTION exchange_do_purse_merge(
 LANGUAGE plpgsql
 AS $$
 DECLARE
-  amount_val INT8;
+  my_amount_val INT8;
 DECLARE
-  amount_frac INT4;
+  my_amount_frac INT4;
+DECLARE
+  my_purse_fee_val INT8;
+DECLARE
+  my_purse_fee_frac INT4;
 DECLARE
   my_partner_serial_id INT8;
 DECLARE
@@ -3136,9 +3140,13 @@ out_no_partner=FALSE;
 -- Check purse is 'full'.
 SELECT amount_with_fee_val
       ,amount_with_fee_frac
+      ,purse_fee_val
+      ,purse_fee_frac
       ,finished
-  INTO amount_val
-      ,amount_frac
+  INTO my_amount_val
+      ,my_amount_frac
+      ,my_purse_fee_val
+      ,my_purse_fee_frac
       ,my_finished
   FROM purse_requests
   WHERE purse_pub=in_purse_pub
@@ -3246,18 +3254,26 @@ THEN
         ,partner_serial_id=my_partner_serial_id
    WHERE purse_pub=in_purse_pub;
 ELSE
-  -- This is a local reserve, update balance immediately.
+  -- This is a local reserve, update reserve balance immediately.
+
+  -- Refund the purse fee, by adding it to the purse value:
+  my_amount_val = my_amount_val + my_purse_fee_val;
+  my_amount_frac = my_amount_frac + my_purse_fee_frac;
+  -- normalize result
+  my_amount_val = my_amount_val + my_amount_frac / 100000000;
+  my_amount_frac = my_amount_frac % 100000000;
+
   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 4ff51ebc..0dbd804b 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -14149,7 +14149,7 @@ postgres_insert_purse_request (
   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
+  bool in_reserve_quota = (TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA
                            == (flags & TALER_WAMF_MERGE_MODE_MASK));
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (purse_pub),
diff --git a/src/lib/exchange_api_common.c b/src/lib/exchange_api_common.c
index 59f5bab8..79e5a31d 100644
--- a/src/lib/exchange_api_common.c
+++ b/src/lib/exchange_api_common.c
@@ -399,7 +399,6 @@ parse_merge (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
              const json_t *transaction)
 {
   uint32_t flags32;
-  struct TALER_Amount total;
   struct GNUNET_JSON_Specification merge_spec[] = {
     GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
                                  &rh->details.merge_details.h_contract_terms),
@@ -435,21 +434,13 @@ parse_merge (struct TALER_EXCHANGE_ReserveHistoryEntry 
*rh,
   }
   rh->details.merge_details.flags =
     (enum TALER_WalletAccountMergeFlags) flags32;
-  if (0 >
-      TALER_amount_add (&total,
-                        &rh->amount,
-                        &rh->details.merge_details.purse_fee))
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
   if (GNUNET_OK !=
       TALER_wallet_account_merge_verify (
         rh->details.merge_details.merge_timestamp,
         &rh->details.merge_details.purse_pub,
         rh->details.merge_details.purse_expiration,
         &rh->details.merge_details.h_contract_terms,
-        &total,
+        &rh->amount,
         &rh->details.merge_details.purse_fee,
         rh->details.merge_details.min_age,
         rh->details.merge_details.flags,
@@ -471,14 +462,17 @@ parse_merge (struct TALER_EXCHANGE_ReserveHistoryEntry 
*rh,
       return GNUNET_SYSERR;
     }
   }
-  if (0 >
-      TALER_amount_add (uc->total_out,
-                        uc->total_out,
-                        &rh->details.merge_details.purse_fee))
+  else
   {
-    /* overflow in history already!? inconceivable! Bad exchange! */
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
+    if (0 >
+        TALER_amount_add (uc->total_out,
+                          uc->total_out,
+                          &rh->details.merge_details.purse_fee))
+    {
+      /* overflow in history already!? inconceivable! Bad exchange! */
+      GNUNET_break_op (0);
+      return GNUNET_SYSERR;
+    }
   }
   return GNUNET_OK;
 }
diff --git a/src/testing/testing_api_cmd_purse_deposit.c 
b/src/testing/testing_api_cmd_purse_deposit.c
index 862163c6..57cc48cf 100644
--- a/src/testing/testing_api_cmd_purse_deposit.c
+++ b/src/testing/testing_api_cmd_purse_deposit.c
@@ -212,19 +212,14 @@ deposit_cb (void *cls,
         GNUNET_assert (NULL != gf);
 
         /* Note: change when flags below changes! */
+        ds->reserve_history.amount
+          = dr->details.success.purse_value_after_fees;
         if (true)
         {
-          /* If we paid a purse fee, we need to subtract the
-             purse fee from the reserve history amount */
-          TALER_amount_subtract (&ds->reserve_history.amount,
-                                 &dr->details.success.purse_value_after_fees,
-                                 &gf->fees.purse);
           ds->reserve_history.details.merge_details.purse_fee = gf->fees.purse;
         }
         else
         {
-          ds->reserve_history.amount
-            = dr->details.success.purse_value_after_fees;
           TALER_amount_set_zero (
             ds->reserve_history.amount.currency,
             &ds->reserve_history.details.merge_details.purse_fee);

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