gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] branch master updated (72afe27 -> 598f45b)


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated (72afe27 -> 598f45b)
Date: Mon, 23 Oct 2017 17:46:44 +0200

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

grothoff pushed a change to branch master
in repository merchant.

    from 72afe27  add new functions for tipping (unimplemented) to merchantdb
     new d2c33c7  implement postgres_enable_tip_reserve (but SQL statemets are 
missing)
     new 598f45b  add SQL for postgres_enable_tip_reserve

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/backenddb/plugin_merchantdb_postgres.c | 146 ++++++++++++++++++++++++++++-
 1 file changed, 144 insertions(+), 2 deletions(-)

diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index be2201e..6e70326 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -179,6 +179,38 @@ postgres_initialize (void *cls)
                             ",refund_fee_frac INT4 NOT NULL"
                             ",refund_fee_curr VARCHAR(" TALER_CURRENCY_LEN_STR 
") NOT NULL"
                             ");"),
+    /* balances of the reserves available for tips */
+    GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS merchant_tip_reserves 
("
+                            " reserve_priv BYTEA NOT NULL CHECK 
(LENGTH(reserve_priv)=32)"
+                            ",expiration INT8 NOT NULL"
+                            ",balance_val INT8 NOT NULL"
+                            ",balance_frac INT4 NOT NULL"
+                            ",balance_curr VARCHAR(" TALER_CURRENCY_LEN_STR ") 
NOT NULL"
+                            ",PRIMARY KEY (reserve_priv)"
+                            ");"),
+    /* tips that have been authorized */
+    GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS merchant_tips ("
+                            " reserve_priv BYTEA NOT NULL CHECK 
(LENGTH(reserve_priv)=32)"
+                            ",tip_id BYTEA NOT NULL CHECK (LENGTH(tip_id)=64)"
+                            ",justification VARCHAR NOT NULL"
+                            ",timestamp INT8 NOT NULL"
+                            ",amount_val INT8 NOT NULL" /* overall tip amount 
*/
+                            ",amount_frac INT4 NOT NULL"
+                            ",amount_curr VARCHAR(" TALER_CURRENCY_LEN_STR ") 
NOT NULL"
+                            ",left_val INT8 NOT NULL" /* tip amount not yet 
picked up */
+                            ",left_frac INT4 NOT NULL"
+                            ",left_curr VARCHAR(" TALER_CURRENCY_LEN_STR ") 
NOT NULL"
+                            ",PRIMARY KEY (tip_id)"
+                            ");"),
+    /* tips that have been picked up */
+    GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS merchant_tip_pickups ("
+                            " tip_id BYTEA NOT NULL REFERENCES merchant_tips 
(tip_id) ON DELETE CASCADE"
+                            ",pickup_id BYTEA NOT NULL CHECK 
(LENGTH(pickup_id)=64)"
+                            ",amount_val INT8 NOT NULL"
+                            ",amount_frac INT4 NOT NULL"
+                            ",amount_curr VARCHAR(" TALER_CURRENCY_LEN_STR ") 
NOT NULL"
+                            ",PRIMARY KEY (pickup_id)"
+                            ");"),
     GNUNET_PQ_EXECUTE_STATEMENT_END
   };
   struct GNUNET_PQ_PreparedStatement ps[] = {
@@ -473,6 +505,33 @@ postgres_initialize (void *cls)
                             " WHERE wtid=$1"
                             "  AND exchange_uri=$2",
                             2),
+    GNUNET_PQ_make_prepare ("lookup_tip_reserve_balance",
+                            "SELECT"
+                            " expiration"
+                            ",balance_val"
+                            ",balance_frac"
+                            ",balance_curr"
+                            " FROM merchant_tip_reserves"
+                            " WHERE reserve_priv=$1",
+                            1),
+    GNUNET_PQ_make_prepare ("update_tip_reserve_balance",
+                            "UPDATE merchant_tip_reserves SET"
+                            " expiration=$2"
+                            ",balance_val=$3"
+                            ",balance_frac=$4"
+                            ",balance_curr=$5"
+                            " WHERE reserve_priv=$1",
+                            5),
+    GNUNET_PQ_make_prepare ("insert_tip_reserve_balance",
+                            "INSERT INTO merchant_tip_reserves"
+                            "(reserve_priv"
+                            ",expiration"
+                            ",balance_val"
+                            ",balance_frac"
+                            ",balance_curr)"
+                            " VALUES "
+                            "($1, $2, $3, $4, $5)",
+                            5),
     GNUNET_PQ_PREPARED_STATEMENT_END
   };
 
@@ -2487,8 +2546,91 @@ postgres_enable_tip_reserve (void *cls,
                              const struct TALER_Amount *credit,
                              struct GNUNET_TIME_Absolute expiration)
 {
-  GNUNET_break (0); // not implemented
-  return GNUNET_DB_STATUS_HARD_ERROR;
+  struct PostgresClosure *pg = cls;
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_auto_from_type (reserve_priv),
+    GNUNET_PQ_query_param_end
+  };
+
+  struct GNUNET_TIME_Absolute old_expiration;
+  struct TALER_Amount old_balance;
+  struct GNUNET_PQ_ResultSpec rs[] = {
+    GNUNET_PQ_result_spec_absolute_time ("expiration",
+                                        &old_expiration),
+    TALER_PQ_result_spec_amount ("balance",
+                                 &old_balance),
+    GNUNET_PQ_result_spec_end
+  };
+  enum GNUNET_DB_QueryStatus qs;
+  struct GNUNET_TIME_Absolute new_expiration;
+  struct TALER_Amount new_balance;
+
+  check_connection (pg);
+  if (GNUNET_OK !=
+      postgres_start (pg))
+  {
+    GNUNET_break (0);
+    return GNUNET_DB_STATUS_HARD_ERROR;
+  }
+  qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                "lookup_tip_reserve_balance",
+                                                params,
+                                                rs);
+  if (0 > qs)
+  {
+    postgres_rollback (pg);
+    return qs;
+  }
+  if ( (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) &&
+       (GNUNET_TIME_absolute_get_remaining (old_expiration).rel_value_us > 0) )
+  {
+    new_expiration = GNUNET_TIME_absolute_max (old_expiration,
+                                               expiration);
+    if (GNUNET_OK !=
+        TALER_amount_add (&new_balance,
+                          credit,
+                          &old_balance))
+    {
+      GNUNET_break (0);
+      postgres_rollback (pg);
+      return GNUNET_DB_STATUS_HARD_ERROR;
+    }
+  }
+  else
+  {
+    if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Old reserve balance of %s had expired at %s, not carrying 
it over!\n",
+                  TALER_amount2s (&old_balance),
+                  GNUNET_STRINGS_absolute_time_to_string (old_expiration));
+    }
+    new_expiration = expiration;
+    new_balance = *credit;
+  }
+
+  {
+    struct GNUNET_PQ_QueryParam params[] = {
+      GNUNET_PQ_query_param_auto_from_type (reserve_priv),
+      GNUNET_PQ_query_param_absolute_time (&new_expiration),
+      TALER_PQ_query_param_amount (&new_balance),
+      GNUNET_PQ_query_param_end
+    };
+    const char *stmt;
+
+    stmt = (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+      ? "update_tip_reserve_balance"
+      : "insert_tip_reserve_balance";
+    qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+                                             stmt,
+                                             params);
+    if (0 > qs)
+    {
+      postgres_rollback (pg);
+      return qs;
+    }
+  }
+  return postgres_commit (pg);
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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