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: Improve KYC status


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated: Improve KYC status callback.
Date: Mon, 09 Jul 2018 21:16:30 +0200

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

marcello pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new 5e25d7d  Improve KYC status callback.
5e25d7d is described below

commit 5e25d7dbcfbfe1859862a719e4392f17cd356a9b
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon Jul 9 21:15:47 2018 +0200

    Improve KYC status callback.
    
    More parameters for this callback.
---
 src/exchangedb/plugin_exchangedb_postgres.c | 54 ++++++++++++++++++++++-------
 src/exchangedb/test_exchangedb.c            | 52 +++++++++++++++------------
 src/include/taler_exchangedb_plugin.h       | 33 ++++++++++++++++--
 3 files changed, 102 insertions(+), 37 deletions(-)

diff --git a/src/exchangedb/plugin_exchangedb_postgres.c 
b/src/exchangedb/plugin_exchangedb_postgres.c
index dbd2948..7cf78c1 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -432,9 +432,9 @@ postgres_create_tables (void *cls)
                            ");"),
 
     GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS kyc_merchants "
-                           "(payto_url VARCHAR UNIQUE NOT NULL"
-                           ",kyc_checked BOOLEAN NOT NULL"
-                           ",merchant_serial_id BIGSERIAL PRIMARY KEY"
+                           "(merchant_serial_id BIGSERIAL PRIMARY KEY"
+                           ",kyc_checked BOOLEAN NOT NULL DEFAULT FALSE"
+                           ",payto_url VARCHAR UNIQUE NOT NULL"
                            ");"),
 
     GNUNET_PQ_make_try_execute ("CREATE INDEX kyc_merchants_payto_url ON "
@@ -1293,7 +1293,7 @@ postgres_prepare (PGconn *db_conn)
      * Methods needed to implement KYC monitoring.
      *
      * 1 Sum money flow for a (unchecked) merchant.
-     * 2 Change KYC status for a merchant.
+     * 2 Change KYC status for a merchant. V
      * 3 Get KYC status for a merchant. V
      * 4 Put money flow event for a merchant.
      * 5 Delete money flow records for a fresh-checked merchant.
@@ -1302,8 +1302,9 @@ postgres_prepare (PGconn *db_conn)
      */
 
     GNUNET_PQ_make_prepare ("get_kyc_status",
-                            "SELECT"
-                            " (kyc_checked)"
+                            "SELECT "
+                            "(kyc_checked"
+                            ",merchant_serial_id)"
                             " FROM kyc_merchants"
                             " WHERE payto_url=$1",
                             1),
@@ -1330,6 +1331,16 @@ postgres_prepare (PGconn *db_conn)
                             " payto_url=$1",
                             1),
 
+    GNUNET_PQ_make_prepare ("insert_kyc_event",
+                            "INSERT INTO kyc_events "
+                            "(merchant_serial_id"
+                            ",amount_val"
+                            ",amount_frac"
+                            ",amount_curr"
+                            ",timestamp)"
+                            " VALUES ($1, $2, $3, $4, $5)",
+                            5),
+
     /* Used in #postgres_select_deposits_missing_wire */
     GNUNET_PQ_make_prepare ("deposits_get_overdue",
                            "SELECT"
@@ -6602,24 +6613,41 @@ static enum GNUNET_DB_QueryStatus
 postgres_get_kyc_status (void *cls,
                          struct TALER_EXCHANGEDB_Session *session,
                          const char *payto_url,
-                         uint8_t *status)
+                         TALER_EXCHANGEDB_KycStatusCallback ksc,
+                         void *ksc_cls)
 { 
+  uint8_t status;
+  uint64_t merchant_serial_id; 
+  enum GNUNET_DB_QueryStatus qs;
+
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_string (payto_url),
     GNUNET_PQ_query_param_end
   }; 
 
+
   struct GNUNET_PQ_ResultSpec rs[] = {
     GNUNET_PQ_result_spec_auto_from_type ("kyc_checked",
-                                          status),
+                                          &status),
+    GNUNET_PQ_result_spec_uint64 ("merchant_serial_id",
+                                  &merchant_serial_id),
+
     GNUNET_PQ_result_spec_end
   };
 
-  return GNUNET_PQ_eval_prepared_singleton_select
-    (session->conn,
-     "get_kyc_status",
-     params,
-     rs);
+  qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn,
+                                                 "get_kyc_status",
+                                                 params,
+                                                 rs);
+  if (0 >= qs)
+    return qs;
+
+  ksc (ksc_cls,
+       payto_url,
+       status,
+       merchant_serial_id);
+
+  return qs;
 }
 
 
diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c
index 535077f..8b3486b 100644
--- a/src/exchangedb/test_exchangedb.c
+++ b/src/exchangedb/test_exchangedb.c
@@ -345,6 +345,26 @@ never_called_cb (void *cls,
 
 
 /**
+ * Callback used to process data of a merchant under KYC monitoring.
+ *
+ * @param cls closure
+ * @param payto_url payto URL of this particular merchant (bank account)
+ * @param kyc_checked status of KYC check: if GNUNET_OK, the merchant was
+ *        checked at least once, never otherwise.
+ * @param merchant_serial_id serial ID identifying this merchant (bank
+ *        account) into the database system; it helps making more efficient
+ *        queries instead of the payto URL.
+ */
+static void
+kcs (void *cls,
+     const char *payto_url,
+     uint8_t kyc_checked,
+     uint64_t merchant_serial_id)
+{
+  GNUNET_break (0);
+}
+
+/**
  * Function called with information about a refresh order.
  * Checks that the response matches what we expect to see.
  *
@@ -2190,29 +2210,17 @@ run (void *cls)
           plugin->mark_kyc_merchant (NULL,
                                      session,
                                      "payto://mock"));
+  FAILIF (GNUNET_OK !=
+          plugin->get_kyc_status (NULL,
+                                  session,
+                                  "payto://mock",
+                                  &kcs,
+                                  NULL));
 
-  {
-    uint8_t kyc_checked;
-
-    FAILIF (GNUNET_OK !=
-            plugin->get_kyc_status (NULL,
-                                    session,
-                                    "payto://mock",
-                                    &kyc_checked));
-    FAILIF (GNUNET_NO == kyc_checked); 
-
-    FAILIF (GNUNET_OK !=
-            plugin->unmark_kyc_merchant (NULL,
-                                         session,
-                                         "payto://mock"));
-    FAILIF (GNUNET_OK !=
-            plugin->get_kyc_status (NULL,
-                                    session,
-                                    "payto://mock",
-                                    &kyc_checked));
-
-    FAILIF (GNUNET_YES == kyc_checked); 
-  }
+  FAILIF (GNUNET_OK !=
+          plugin->unmark_kyc_merchant (NULL,
+                                       session,
+                                       "payto://mock"));
 
   plugin->preflight (plugin->cls,
                      session);
diff --git a/src/include/taler_exchangedb_plugin.h 
b/src/include/taler_exchangedb_plugin.h
index 80814ef..3cecfb5 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -711,6 +711,24 @@ typedef int
                                     int done);
 
 
+
+/**
+ * Callback used to process data of a merchant under KYC monitoring.
+ *
+ * @param cls closure
+ * @param payto_url payto URL of this particular merchant (bank account)
+ * @param kyc_checked status of KYC check: if GNUNET_OK, the merchant was
+ *        checked at least once, never otherwise.
+ * @param merchant_serial_id serial ID identifying this merchant (bank
+ *        account) into the database system; it helps making more efficient
+ *        queries instead of the payto URL.
+ */
+typedef void
+(*TALER_EXCHANGEDB_KycStatusCallback)(void *cls,
+                                      const char *payto_url,
+                                      uint8_t kyc_checked,
+                                      uint64_t merchant_serial_id);
+
 /**
  * Function called with details about coins that were melted,
  * with the goal of auditing the refresh's execution.
@@ -2226,6 +2244,8 @@ struct TALER_EXCHANGEDB_Plugin
    * associates a flag to the merchant that indicates whether
    * a KYC check has been done or not on this merchant.
    *
+   * @param cls closure
+   * @param session db session
    * @param payto_url payto:// URL indentifying the merchant
    *        bank account.
    * @return database transaction status.
@@ -2238,6 +2258,8 @@ struct TALER_EXCHANGEDB_Plugin
   /**
    * Mark a merchant as KYC-checked.
    *
+   * @param cls closure
+   * @param session db session
    * @param payto_url payto:// URL indentifying the merchant
    *        to check.  Note, different banks may have different
    *        policies to check their customers.
@@ -2252,6 +2274,8 @@ struct TALER_EXCHANGEDB_Plugin
   /**
    * Mark a merchant as NOT KYC-checked.
    *
+   * @param cls closure
+   * @param session db session
    * @param payto_url payto:// URL indentifying the merchant
    *        to unmark.  Note, different banks may have different
    *        policies to check their customers.
@@ -2266,16 +2290,21 @@ struct TALER_EXCHANGEDB_Plugin
   /**
    * Retrieve KYC-check status related to a particular merchant.
    *
+   * @param cls closure
+   * @param session db session
    * @param payto_url URL identifying a merchant bank account,
    *        whose KYC is going to be retrieved.
-   * @param[out] status store the result.
+   * @param ksc callback to process all the row's columns.  As
+   *        expectable, it will only be called _if_ a row is found.
+   * @param ksc_cls closure for above callback.
    * @return transaction status.
    */
   enum GNUNET_DB_QueryStatus
   (*get_kyc_status) (void *cls,
                      struct TALER_EXCHANGEDB_Session *session,
                      const char *payto_url,
-                     uint8_t *status);
+                     TALER_EXCHANGEDB_KycStatusCallback ksc,
+                     void *ksc_cls);
 };
 
 #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]