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: KYC db methods.


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated: KYC db methods.
Date: Mon, 09 Jul 2018 09:45:15 +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 c139736  KYC db methods.
c139736 is described below

commit c13973626bed030c03748e05e6e15c07a79b3421
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon Jul 9 09:44:16 2018 +0200

    KYC db methods.
    
    Add method to insert a merchant into the monitored
    entries, and associates a "FALSE" KYC status to it.
---
 src/exchangedb/plugin_exchangedb_postgres.c | 135 +++++++++-------------------
 src/exchangedb/test_exchangedb.c            |   5 ++
 src/include/taler_exchangedb_plugin.h       |  43 ++++-----
 3 files changed, 66 insertions(+), 117 deletions(-)

diff --git a/src/exchangedb/plugin_exchangedb_postgres.c 
b/src/exchangedb/plugin_exchangedb_postgres.c
index 23a5757..9102811 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -106,6 +106,7 @@ postgres_drop_tables (void *cls)
   struct PostgresClosure *pc = cls;
   struct GNUNET_PQ_ExecuteStatement es[] = {
     GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS kyc_events CASCADE;"),
+    GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS kyc_merchants CASCADE;"),
     GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS prewire CASCADE;"),
     GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS payback CASCADE;"),
     GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS aggregation_tracking 
CASCADE;"),
@@ -430,14 +431,26 @@ postgres_create_tables (void *cls)
                            ",buf BYTEA NOT NULL"
                            ");"),
 
+    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"
+                           ");"),
+
+    GNUNET_PQ_make_try_execute ("CREATE INDEX kyc_merchants_payto_url ON "
+                                "kyc_merchants (payto_url);"),
+
     GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS kyc_events "
-                           "(url TEXT NOT NULL"
-                           ",timestamp INT8 NOT NULL"
+                           "(merchant_serial_id BIGSERIAL NOT NULL REFERENCES 
kyc_merchants (merchant_serial_id) ON DELETE CASCADE"
                            ",amount_val INT8 NOT NULL"
                            ",amount_frac INT4 NOT NULL"
                            ",amount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT 
NULL"
+                           ",timestamp INT8 NOT NULL"
                            ");"),
 
+    GNUNET_PQ_make_try_execute ("CREATE INDEX kyc_events_timestamp ON "
+                                "kyc_events (timestamp);"),
+
     /* Index for wire_prepare_data_get and gc_prewire statement */
     GNUNET_PQ_make_try_execute("CREATE INDEX prepare_iteration_index "
                                "ON prewire(finished);"),
@@ -1275,31 +1288,22 @@ postgres_prepare (PGconn *db_conn)
                             " ORDER BY prewire_uuid ASC"
                             " LIMIT 1;",
                             0),
-    /* Used in #postgres_insert_kyc_event */
-    GNUNET_PQ_make_prepare ("kyc_event_insert",
-                            "INSERT INTO kyc_events "
-                            "(url"
-                            ",timestamp"
-                            ",amount_val"
-                            ",amount_frac"
-                            ",amount_curr"
-                            ") VALUES "
-                            "($1, $2, $3, $4);",
-                            4),
 
-    /* Used in #postgres_kyc_event_get_last */
-    GNUNET_PQ_make_prepare ("kyc_event_get_last",
-                            "SELECT "
-                            " url"
-                            ",timestamp"
-                            ",amount_val"
-                            ",amount_frac"
-                            ",amount_curr"
-                            " FROM kyc_events"
-                            " WHERE url=$1"
-                            " ORDER BY timestamp"
-                            " LIMIT 1"
-                            " OFFSET 0;",
+    /**
+     * Methods needed to implement KYC monitoring.
+     *
+     * 1 Sum money flow for a (unchecked) merchant.
+     * 2 Change KYC status for a merchant.
+     * 3 Get KYC status for a merchant.
+     * 4 Put money flow event for a merchant.
+     * 5 Delete money flow records for a fresh-checked merchant.
+     * 6 Put a merchant.
+     */
+
+    GNUNET_PQ_make_prepare ("insert_kyc_merchant",
+                            "INSERT INTO kyc_merchants "
+                            "(payto_url, kyc_checked) VALUES "
+                            "($1, FALSE)",
                             1),
 
     /* Used in #postgres_select_deposits_missing_wire */
@@ -6512,80 +6516,26 @@ postgres_select_deposits_missing_wire (void *cls,
 }
 
 /**
- * Save a amount threshold for a KYC check that
- * has been triggered for a certain merchant.
+ * Insert a merchant into the KYC monitor table.
  *
- * @param cls plugins' closure
- * @param url "payto" url identifying the merchant to be checked.
- * @param amount the threshold amount associated with the check.
- * @return transaction status code.
+ * @param payto_url payto:// URL indentifying the merchant
+ *        bank account.
+ * @return database transaction status.
  */
 static enum GNUNET_DB_QueryStatus
-postgres_insert_kyc_event (void *cls,
-                           struct TALER_EXCHANGEDB_Session *session,
-                           const char *url,
-                           const struct TALER_Amount *amount)
+postgres_insert_kyc_merchant (void *cls,
+                              struct TALER_EXCHANGEDB_Session *session,
+                              const char *payto_url)
 {
-
-  enum GNUNET_DB_QueryStatus qs;
-
   struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (url),
-    TALER_PQ_query_param_amount (amount),
+    GNUNET_PQ_query_param_string (payto_url),
     GNUNET_PQ_query_param_end
   };
-
-  qs = GNUNET_PQ_eval_prepared_non_select (session->conn,
-                                           "kyc_event_insert",
-                                          params);
-  return qs;
+  return GNUNET_PQ_eval_prepared_non_select (session->conn,
+                                             "insert_kyc_merchant",
+                                             params);
 }
 
-/**
- * Get the _last_ KYC event associated with a certain merchant.
- *
- * @param cls plugin closure
- * @param url the payto URL associated with the merchant whose
- *        KYC has to be returned.
- * @param kyc_cb callback invoked with the timeout of last KYC event
- * @param kyc_cb_cls closure for callback above
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_kyc_event_get_last (void *cls,
-                             struct TALER_EXCHANGEDB_Session *session,
-                             const char *url,
-                             TALER_EXCHANGEDB_KycCallback kyc_cb,
-                             void *kyc_cb_cls)
-{
-  enum GNUNET_DB_QueryStatus qs;
-  struct GNUNET_TIME_Absolute ts;
-
-  struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_string (url),
-    GNUNET_PQ_query_param_end
-  };
-
-  struct GNUNET_PQ_ResultSpec rs[] = {
-    TALER_PQ_result_spec_absolute_time
-      ("timestamp", &ts),
-    GNUNET_PQ_result_spec_end
-  };
-
-  qs = GNUNET_PQ_eval_prepared_singleton_select
-    (session->conn,
-     "kyc_event_get_last",
-     params,
-     rs);
-
-  kyc_cb (kyc_cb_cls,
-          ts);
-
-  if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
-    GNUNET_PQ_cleanup_result (rs); 
-
-  return qs;
-}
 
 /**
  * Initialize Postgres database subsystem.
@@ -6721,8 +6671,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
   plugin->select_deposits_missing_wire
     = &postgres_select_deposits_missing_wire;
 
-  plugin->insert_kyc_event = postgres_insert_kyc_event;
-  plugin->kyc_event_get_last = postgres_kyc_event_get_last;
+  plugin->insert_kyc_merchant = postgres_insert_kyc_merchant;
 
   return plugin;
 }
diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c
index 9191f60..3a8f9e0 100644
--- a/src/exchangedb/test_exchangedb.c
+++ b/src/exchangedb/test_exchangedb.c
@@ -2182,6 +2182,11 @@ run (void *cls)
   FAILIF (GNUNET_OK !=
           test_wire_fees (session));
 
+  FAILIF (GNUNET_OK !=
+          plugin->insert_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 243ba4f..6d85d1a 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -807,8 +807,17 @@ typedef void
                                     const struct TALER_TransferPublicKeyP *tp);
 
 
+/**
+ * Callback for handling a KYC timestamped event associated with
+ * a certain customer (= merchant).
+ *
+ * @param cls closure
+ * @param url "payto" URL associated with the customer
+ * @param timeout last time when the KYC was issued to the customer.
+ */
 typedef void
 (*TALER_EXCHANGEDB_KycCallback)(void *cls,
+                                const char *url,
                                 struct GNUNET_TIME_Absolute timeout);
 
 /**
@@ -2213,34 +2222,20 @@ struct TALER_EXCHANGEDB_Plugin
                                  void *cb_cls);
 
   /**
-   * Save a amount threshold for a KYC check that
-   * has been triggered for a certain merchant.
+   * Insert a merchant into the KYC monitor table, namely it
+   * associates a flag to the merchant that indicates whether
+   * a KYC check has been done or not on this merchant.
    *
-   * @param cls plugins' closure
-   * @param url "payto" url identifying the merchant to be checked.
-   * @param amount the threshold amount associated with the check.
-   * @return transaction status code.
+   * @param payto_url payto:// URL indentifying the merchant
+   *        bank account.
+   * @return database transaction status.
    */
   enum GNUNET_DB_QueryStatus
-  (*insert_kyc_event)(void *cls,
-                      struct TALER_EXCHANGEDB_Session *session,
-                      const char *url,
-                      const struct TALER_Amount *amount);
+  (*insert_kyc_merchant) (void *cls,
+                          struct TALER_EXCHANGEDB_Session *session,
+                          const char *payto_url);
+
 
-  /**
-   * Get the _last_ KYC event associated with a certain merchant.
-   *
-   * @param cls plugin closure
-   * @param url the payto URL associated with the merchant whose
-   *        KYC has to be returned.
-   * @return transaction status.
-   */
-  enum GNUNET_DB_QueryStatus
-  (*kyc_event_get_last) (void *cls,
-                         struct TALER_EXCHANGEDB_Session *session,
-                         const char *url,
-                         TALER_EXCHANGEDB_KycCallback kyc_cb,
-                         void *kyc_cb_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]