gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-exchange] branch master updated (109a4a5 -> 1d81c99)


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated (109a4a5 -> 1d81c99)
Date: Tue, 10 Jul 2018 15:39:54 +0200

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

marcello pushed a change to branch master
in repository exchange.

    from 109a4a5  KYC DB methods: store a wire transfer.
     new 61e737f  Put logic to sum KYC-monitored wire transfers.
     new 6801c69  Test last change.
     new 1d81c99  note

The 3 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/exchangedb/plugin_exchangedb_postgres.c | 100 +++++++++++++++++++++++++++-
 src/exchangedb/test_exchangedb.c            |  12 ++++
 src/include/taler_exchangedb_plugin.h       |  54 ++++++++++-----
 3 files changed, 146 insertions(+), 20 deletions(-)

diff --git a/src/exchangedb/plugin_exchangedb_postgres.c 
b/src/exchangedb/plugin_exchangedb_postgres.c
index fef35d5..a9ffbba 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -1292,15 +1292,27 @@ postgres_prepare (PGconn *db_conn)
     /**
      * Methods needed to implement KYC monitoring.
      *
-     * 1 Sum money flow for a (unchecked) merchant.
+     * 1 Sum money flow for a (unchecked) merchant. V
      * 2 Change KYC status for a merchant. V
      * 3 Get KYC status for a merchant. V
-     * 4 Put money flow event for a merchant.
+     * 4 Put money flow event for a merchant. V
      * 5 Delete money flow records for a fresh-checked merchant.
      * 6 Put a merchant. V
      * 7 Change KYC status flag for a merchant. V
      */
 
+    /* Assume a merchant _unchecked_ if their events
+     * are stored into the table queried below.  */
+    GNUNET_PQ_make_prepare ("get_kyc_events",
+                            "SELECT"
+                            " merchant_serial_id"
+                            ",amount_val"
+                            ",amount_frac"
+                            ",amount_curr"
+                            " FROM kyc_events"
+                            " WHERE merchant_serial_id=$1",
+                            1),
+
     GNUNET_PQ_make_prepare ("get_kyc_status",
                             "SELECT"
                             " kyc_checked"
@@ -1315,6 +1327,8 @@ postgres_prepare (PGconn *db_conn)
                             "($1, FALSE)",
                             1),
 
+
+    /* NOTE: NOT used yet, just _potentially_ needed.  */
     GNUNET_PQ_make_prepare ("unmark_kyc_merchant",
                             "UPDATE kyc_merchants"
                             " SET"
@@ -6634,6 +6648,87 @@ postgres_mark_kyc_merchant
                                              params);
 }
 
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_result the number of results in @a result
+ */
+static void
+sum_kyc_events (void *cls,
+                PGresult *result,
+                unsigned int num_results)
+{
+  struct TALER_Amount *tot = cls;
+  struct TALER_Amount tmp;
+
+  int ntuples = PQntuples (result);
+
+  struct GNUNET_PQ_ResultSpec rs[] = {
+    TALER_PQ_result_spec_amount ("amount", &tmp),
+    GNUNET_PQ_result_spec_end  
+  };
+
+  for (unsigned int i = 0; i < ntuples; i++)
+  {
+    GNUNET_assert
+      (GNUNET_OK == GNUNET_PQ_extract_result (result,
+                                              rs,
+                                              i));
+
+    if ((0 == tot->value) && (0 == tot->fraction))
+      *tot = tmp;
+    else
+      GNUNET_assert
+        (GNUNET_SYSERR != TALER_amount_add (tot,
+                                            tot,
+                                            &tmp));
+
+  }
+  
+}
+
+
+/**
+ * Calculate sum of money flow related to a particular merchant,
+ * used for KYC monitoring.
+ *
+ * @param cls closure
+ * @param session DB session
+ * @param merchant_serial_id serial id identifying the merchant
+ *        into the KYC monitoring system.
+ * @param amount[out] will store the amount of money received
+ *        by this merchant.
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_get_kyc_events (void *cls,
+                         struct TALER_EXCHANGEDB_Session *session,
+                         uint64_t merchant_serial_id,
+                         struct TALER_Amount *amount)
+{
+  enum GNUNET_DB_QueryStatus qs;
+
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_uint64 (&merchant_serial_id),
+    GNUNET_PQ_query_param_end
+  };
+
+  /* make sure sum object starts virgin.  */
+  memset (amount,
+          0,
+          sizeof (struct TALER_Amount));
+
+  qs = GNUNET_PQ_eval_prepared_multi_select (session->conn,
+                                             "get_kyc_events",
+                                             params,
+                                             sum_kyc_events,
+                                             amount);
+  return qs;
+}
+
 /**
  * Retrieve KYC-check status related to a particular merchant.
  *
@@ -6848,6 +6943,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
   plugin->unmark_kyc_merchant = postgres_unmark_kyc_merchant;
   plugin->get_kyc_status = postgres_get_kyc_status;
   plugin->insert_kyc_event = postgres_insert_kyc_event;
+  plugin->get_kyc_events = postgres_get_kyc_events;
 
   return plugin;
 }
diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c
index 5be7ecb..07372cf 100644
--- a/src/exchangedb/test_exchangedb.c
+++ b/src/exchangedb/test_exchangedb.c
@@ -364,20 +364,32 @@ kcs (void *cls,
 
   struct TALER_EXCHANGEDB_Session *session = cls;
   struct TALER_Amount amount;
+  struct TALER_Amount sum;
 
 
   TALER_amount_get_zero (CURRENCY,
                          &amount);
+  amount.value = 30;
   FAILIF
     (GNUNET_OK != plugin->insert_kyc_event (NULL,
                                             session,
                                             merchant_serial_id,
                                             &amount));
+  amount.value = 20;
+  amount.fraction = 70;
   FAILIF
     (GNUNET_OK != plugin->insert_kyc_event (NULL,
                                             session,
                                             merchant_serial_id,
                                             &amount));
+  FAILIF
+    (0 >= plugin->get_kyc_events (NULL,
+                                  session,
+                                  merchant_serial_id,
+                                  &sum));
+
+  FAILIF ((50 != sum.value) || (70 != sum.fraction));
+
   drop:
     return;
 }
diff --git a/src/include/taler_exchangedb_plugin.h 
b/src/include/taler_exchangedb_plugin.h
index cf2842e..c0fcdae 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -2251,9 +2251,9 @@ struct TALER_EXCHANGEDB_Plugin
    * @return database transaction status.
    */
   enum GNUNET_DB_QueryStatus
-  (*insert_kyc_merchant) (void *cls,
-                          struct TALER_EXCHANGEDB_Session *session,
-                          const char *payto_url);
+  (*insert_kyc_merchant)(void *cls,
+                         struct TALER_EXCHANGEDB_Session *session,
+                         const char *payto_url);
 
   /**
    * Mark a merchant as KYC-checked.
@@ -2266,9 +2266,9 @@ struct TALER_EXCHANGEDB_Plugin
    * @return database transaction status.
    */
   enum GNUNET_DB_QueryStatus
-  (*mark_kyc_merchant) (void *cls,
-                        struct TALER_EXCHANGEDB_Session *session,
-                        const char *payto_url);
+  (*mark_kyc_merchant)(void *cls,
+                       struct TALER_EXCHANGEDB_Session *session,
+                       const char *payto_url);
 
 
   /**
@@ -2282,9 +2282,9 @@ struct TALER_EXCHANGEDB_Plugin
    * @return database transaction status.
    */
   enum GNUNET_DB_QueryStatus
-  (*unmark_kyc_merchant) (void *cls,
-                          struct TALER_EXCHANGEDB_Session *session,
-                          const char *payto_url);
+  (*unmark_kyc_merchant)(void *cls,
+                         struct TALER_EXCHANGEDB_Session *session,
+                         const char *payto_url);
 
 
   /**
@@ -2300,11 +2300,11 @@ struct TALER_EXCHANGEDB_Plugin
    * @return transaction status.
    */
   enum GNUNET_DB_QueryStatus
-  (*get_kyc_status) (void *cls,
-                     struct TALER_EXCHANGEDB_Session *session,
-                     const char *payto_url,
-                     TALER_EXCHANGEDB_KycStatusCallback ksc,
-                     void *ksc_cls);
+  (*get_kyc_status)(void *cls,
+                    struct TALER_EXCHANGEDB_Session *session,
+                    const char *payto_url,
+                    TALER_EXCHANGEDB_KycStatusCallback ksc,
+                    void *ksc_cls);
 
   /**
    * Record timestamp where a particular merchant performed
@@ -2318,10 +2318,28 @@ struct TALER_EXCHANGEDB_Plugin
    * @return database transaction status.
    */
   enum GNUNET_DB_QueryStatus
-  (*insert_kyc_event) (void *cls,
-                       struct TALER_EXCHANGEDB_Session *session,
-                       uint64_t merchant_serial_id,
-                       struct TALER_Amount *amount);
+  (*insert_kyc_event)(void *cls,
+                      struct TALER_EXCHANGEDB_Session *session,
+                      uint64_t merchant_serial_id,
+                      struct TALER_Amount *amount);
+
+
+  /**
+   * Calculate sum of money flow related to a particular merchant,
+   * used for KYC monitoring.
+   *
+   * @param cls closure
+   * @param session DB session
+   * @param merchant_serial_id serial id identifying the merchant
+   *        into the KYC monitoring system.
+   * @param amount[out] will store the amount of money received
+   *        by this merchant.
+   */
+  enum GNUNET_DB_QueryStatus
+  (*get_kyc_events)(void *cls,
+                    struct TALER_EXCHANGEDB_Session *session,
+                    uint64_t merchant_serial_id,
+                    struct TALER_Amount *amount);
 };
 
 #endif /* _TALER_EXCHANGE_DB_H */

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



reply via email to

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