gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: -work on DB logic


From: gnunet
Subject: [taler-exchange] branch master updated: -work on DB logic
Date: Mon, 03 Oct 2022 17:05:32 +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 2dbf8cef -work on DB logic
2dbf8cef is described below

commit 2dbf8cefe0a11252758227bf4a3a7881fa663edc
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Oct 3 17:05:29 2022 +0200

    -work on DB logic
---
 contrib/gana                                   |   2 +-
 src/exchangedb/Makefile.am                     |   5 +-
 src/exchangedb/pg_iterate_kyc_reference.c      |  95 ++++++++++++++++++++---
 src/exchangedb/pg_iterate_reserve_close_info.c | 103 ++++++++++++++++++++-----
 src/exchangedb/pg_select_reserve_close_info.c  |  25 +++---
 5 files changed, 184 insertions(+), 46 deletions(-)

diff --git a/contrib/gana b/contrib/gana
index 57d96e8e..d402af78 160000
--- a/contrib/gana
+++ b/contrib/gana
@@ -1 +1 @@
-Subproject commit 57d96e8e123df90c804a821874fc6cb88671ab75
+Subproject commit d402af78f6d360841db53baa46dddae13590ec33
diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am
index 3ea5a0d9..e446682b 100644
--- a/src/exchangedb/Makefile.am
+++ b/src/exchangedb/Makefile.am
@@ -70,7 +70,10 @@ endif
 libtaler_plugin_exchangedb_postgres_la_SOURCES = \
   plugin_exchangedb_postgres.c pg_helper.h \
   pg_insert_close_request.c pg_insert_close_request.h \
-  pg_insert_reserve_open_deposit.c pg_insert_reserve_open_deposit.h
+  pg_insert_reserve_open_deposit.c pg_insert_reserve_open_deposit.h \
+  pg_iterate_kyc_reference.c pg_iterate_kyc_reference.h \
+  pg_iterate_reserve_close_info.c pg_iterate_reserve_close_info.h \
+  pg_select_reserve_close_info.c pg_select_reserve_close_info.h 
 libtaler_plugin_exchangedb_postgres_la_LIBADD = \
   $(LTLIBINTL)
 libtaler_plugin_exchangedb_postgres_la_LDFLAGS = \
diff --git a/src/exchangedb/pg_iterate_kyc_reference.c 
b/src/exchangedb/pg_iterate_kyc_reference.c
index e24a22bf..4a94722c 100644
--- a/src/exchangedb/pg_iterate_kyc_reference.c
+++ b/src/exchangedb/pg_iterate_kyc_reference.c
@@ -26,6 +26,75 @@
 #include "pg_helper.h"
 
 
+/**
+ * Closure for #iterate_kyc_reference_cb()
+ */
+struct IteratorContext
+{
+  /**
+   * Function to call with the results.
+   */
+  TALER_EXCHANGEDB_LegitimizationProcessCallback cb;
+
+  /**
+   * Closure to pass to @e cb
+   */
+  void *cb_cls;
+
+  /**
+   * Plugin context.
+   */
+  struct PostgresClosure *pg;
+};
+
+
+/**
+ * Helper function for #TEH_PG_iterate_kyc_reference().
+ * Calls the callback with each denomination key.
+ *
+ * @param cls a `struct IteratorContext`
+ * @param result db results
+ * @param num_results number of results in @a result
+ */
+static void
+iterate_kyc_reference_cb (void *cls,
+                          PGresult *result,
+                          unsigned int num_results)
+{
+  struct IteratorContext *ic = cls;
+
+  for (unsigned int i = 0; i<num_results; i++)
+  {
+    char *kyc_provider_section_name;
+    char *provider_user_id;
+    char *legitimization_id;
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_string ("section_name",
+                                    &kyc_provider_section_name),
+      GNUNET_PQ_result_spec_string ("provider_user_id",
+                                    &provider_user_id),
+      GNUNET_PQ_result_spec_string ("legi_id",
+                                    &legitimization_id),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_PQ_extract_result (result,
+                                  rs,
+                                  i))
+    {
+      GNUNET_break (0);
+      return;
+    }
+    ic->cb (ic->cb_cls,
+            kyc_provider_section_name,
+            provider_user_id,
+            legitimization_id);
+    GNUNET_PQ_cleanup_result (rs);
+  }
+}
+
+
 enum GNUNET_DB_QueryStatus
 TEH_PG_iterate_kyc_reference (
   void *cls,
@@ -38,21 +107,23 @@ TEH_PG_iterate_kyc_reference (
     GNUNET_PQ_query_param_auto_from_type (h_payto),
     GNUNET_PQ_query_param_end
   };
-  // FIXME: everything from here is copy*paste
-  struct GNUNET_PQ_ResultSpec rs[] = {
-    GNUNET_PQ_result_spec_bool ("insufficient_funds",
-                                insufficient_funds),
-    GNUNET_PQ_result_spec_end
+  struct IteratorContext ic = {
+    .cb = lpc,
+    .cb_cls = lpc_cls,
+    .pg = pg
   };
 
   PREPARE (pg,
            "iterate_kyc_reference",
            "SELECT "
-           " insufficient_funds"
-           " FROM exchange_do_reserve_open_deposit"
-           " ($1,$2,$3,$4,$5,$6);");
-  return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                   "iterate_kyc_reference",
-                                                   params,
-                                                   rs);
+           " section_name"
+           ",provider_user_id"
+           ",legi_id"
+           " FROM FIXME"
+           " WHERE h_payto=$1;");
+  return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                               "iterate_kyc_reference",
+                                               params,
+                                               &iterate_kyc_reference_cb,
+                                               &ic);
 }
diff --git a/src/exchangedb/pg_iterate_reserve_close_info.c 
b/src/exchangedb/pg_iterate_reserve_close_info.c
index e9a5f664..c5ff6132 100644
--- a/src/exchangedb/pg_iterate_reserve_close_info.c
+++ b/src/exchangedb/pg_iterate_reserve_close_info.c
@@ -25,6 +25,70 @@
 #include "pg_insert_reserve_open_deposit.h"
 #include "pg_helper.h"
 
+/**
+ * Closure for #iterate_reserve_close_info_cb()
+ */
+struct IteratorContext
+{
+  /**
+   * Function to call with the results.
+   */
+  TALER_EXCHANGEDB_KycAmountCallback cb;
+
+  /**
+   * Closure to pass to @e cb
+   */
+  void *cb_cls;
+
+  /**
+   * Plugin context.
+   */
+  struct PostgresClosure *pg;
+};
+
+
+/**
+ * Helper function for #TEH_PG_iterate_reserve_close_info().
+ * Calls the callback with each denomination key.
+ *
+ * @param cls a `struct IteratorContext`
+ * @param result db results
+ * @param num_results number of results in @a result
+ */
+static void
+iterate_reserve_close_info_cb (void *cls,
+                               PGresult *result,
+                               unsigned int num_results)
+{
+  struct IteratorContext *ic = cls;
+  struct PostgresClosure *pg = ic->pg;
+
+  for (unsigned int i = 0; i<num_results; i++)
+  {
+    struct TALER_Amount amount;
+    struct GNUNET_TIME_Absolute ts;
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_absolute_time ("timestamp",
+                                           &ts),
+      TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+                                   &amount),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_PQ_extract_result (result,
+                                  rs,
+                                  i))
+    {
+      GNUNET_break (0);
+      return;
+    }
+    ic->cb (ic->cb_cls,
+            &amount,
+            ts);
+  }
+}
+
 
 enum GNUNET_DB_QueryStatus
 TEH_PG_iterate_reserve_close_info (
@@ -35,29 +99,30 @@ TEH_PG_iterate_reserve_close_info (
   void *kac_cls)
 {
   struct PostgresClosure *pg = cls;
-  // FIXME: everything from here is copy&paste
   struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_auto_from_type (&cpi->coin_pub),
-    GNUNET_PQ_query_param_uint64 (&known_coin_id),
-    GNUNET_PQ_query_param_auto_from_type (coin_sig),
-    GNUNET_PQ_query_param_auto_from_type (reserve_sig),
-    TALER_PQ_query_param_amount (coin_total),
+    GNUNET_PQ_query_param_auto_from_type (h_payto),
+    GNUNET_PQ_query_param_absolute_time (&time_limit),
     GNUNET_PQ_query_param_end
   };
-  struct GNUNET_PQ_ResultSpec rs[] = {
-    GNUNET_PQ_result_spec_bool ("insufficient_funds",
-                                insufficient_funds),
-    GNUNET_PQ_result_spec_end
+  struct IteratorContext ic = {
+    .cb = kac,
+    .cb_cls = kac_cls,
+    .pg = pg
   };
 
   PREPARE (pg,
-           "insert_reserve_open_deposit",
-           "SELECT "
-           " insufficient_funds"
-           " FROM exchange_do_reserve_open_deposit"
-           " ($1,$2,$3,$4,$5,$6);");
-  return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                   
"insert_reserve_open_deposit",
-                                                   params,
-                                                   rs);
+           "iterate_reserve_close_info",
+           "SELECT"
+           " amount_val"
+           ",amount_frac"
+           ",timestamp"
+           " FROM FIXME"
+           " WHERE h_payto=$1"
+           "   AND timestamp >= $2"
+           " ORDER BY timestamp DESC");
+  return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                               "iterate_reserve_close_info",
+                                               params,
+                                               &iterate_reserve_close_info_cb,
+                                               &ic);
 }
diff --git a/src/exchangedb/pg_select_reserve_close_info.c 
b/src/exchangedb/pg_select_reserve_close_info.c
index 472ec27c..a573f100 100644
--- a/src/exchangedb/pg_select_reserve_close_info.c
+++ b/src/exchangedb/pg_select_reserve_close_info.c
@@ -34,29 +34,28 @@ TEH_PG_select_reserve_close_info (
   char **payto_uri)
 {
   struct PostgresClosure *pg = cls;
-  // FIXME: everything from here is copy*paste!
   struct GNUNET_PQ_QueryParam params[] = {
-    GNUNET_PQ_query_param_auto_from_type (&cpi->coin_pub),
-    GNUNET_PQ_query_param_uint64 (&known_coin_id),
-    GNUNET_PQ_query_param_auto_from_type (coin_sig),
-    GNUNET_PQ_query_param_auto_from_type (reserve_sig),
-    TALER_PQ_query_param_amount (coin_total),
+    GNUNET_PQ_query_param_auto_from_type (reserve_pub),
     GNUNET_PQ_query_param_end
   };
   struct GNUNET_PQ_ResultSpec rs[] = {
-    GNUNET_PQ_result_spec_bool ("insufficient_funds",
-                                insufficient_funds),
+    TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+                                 balance),
+    GNUNET_PQ_result_spec_string ("payto_uri",
+                                  payto_uri),
     GNUNET_PQ_result_spec_end
   };
 
   PREPARE (pg,
-           "insert_reserve_open_deposit",
+           "select_reserve_close_info",
            "SELECT "
-           " insufficient_funds"
-           " FROM exchange_do_reserve_open_deposit"
-           " ($1,$2,$3,$4,$5,$6);");
+           " balance_frac"
+           ",balance_val"
+           ",payto_uri"
+           " FROM FIXME"
+           " WHERE reserve_pub=$1;");
   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
-                                                   
"insert_reserve_open_deposit",
+                                                   "select_reserve_close_info",
                                                    params,
                                                    rs);
 }

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