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 new DB queries


From: gnunet
Subject: [taler-exchange] branch master updated: -work on new DB queries
Date: Fri, 30 Dec 2022 21:28:23 +0100

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 b1d97455 -work on new DB queries
b1d97455 is described below

commit b1d9745545ff528729b53312947ba768c336a1d8
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Dec 30 21:28:19 2022 +0100

    -work on new DB queries
---
 src/exchangedb/pg_lookup_signkey_revocation.c |   2 -
 src/exchangedb/pg_lookup_wire_transfer.c      |  13 +--
 src/exchangedb/pg_select_aml_history.c        | 130 ++++++++++++++++++++++++-
 src/exchangedb/pg_select_aml_process.c        | 132 +++++++++++++++++++++++++-
 src/exchangedb/pg_trigger_aml_process.c       |  26 ++++-
 5 files changed, 289 insertions(+), 14 deletions(-)

diff --git a/src/exchangedb/pg_lookup_signkey_revocation.c 
b/src/exchangedb/pg_lookup_signkey_revocation.c
index 374aa7d5..056ecddc 100644
--- a/src/exchangedb/pg_lookup_signkey_revocation.c
+++ b/src/exchangedb/pg_lookup_signkey_revocation.c
@@ -26,7 +26,6 @@
 #include "pg_helper.h"
 
 
-
 enum GNUNET_DB_QueryStatus
 TEH_PG_lookup_signkey_revocation (
   void *cls,
@@ -44,7 +43,6 @@ TEH_PG_lookup_signkey_revocation (
     GNUNET_PQ_result_spec_end
   };
 
-
   PREPARE (pg,
            "lookup_signkey_revocation",
            "SELECT "
diff --git a/src/exchangedb/pg_lookup_wire_transfer.c 
b/src/exchangedb/pg_lookup_wire_transfer.c
index d8d7278d..5d1ad25f 100644
--- a/src/exchangedb/pg_lookup_wire_transfer.c
+++ b/src/exchangedb/pg_lookup_wire_transfer.c
@@ -48,7 +48,7 @@ struct WireTransferResultContext
   /**
    * Set to #GNUNET_SYSERR on serious errors.
    */
-  int status;
+  enum GNUNET_GenericReturnValue status;
 };
 
 
@@ -141,13 +141,14 @@ TEH_PG_lookup_wire_transfer (
     GNUNET_PQ_query_param_auto_from_type (wtid),
     GNUNET_PQ_query_param_end
   };
-  struct WireTransferResultContext ctx;
+  struct WireTransferResultContext ctx = {
+    .cb = cb,
+    .cb_cls = cb_cls,
+    .pg = pg,
+    .status = GNUNET_OK
+  };
   enum GNUNET_DB_QueryStatus qs;
 
-  ctx.cb = cb;
-  ctx.cb_cls = cb_cls;
-  ctx.pg = pg;
-  ctx.status = GNUNET_OK;
   PREPARE (pg,
            "lookup_transactions",
            "SELECT"
diff --git a/src/exchangedb/pg_select_aml_history.c 
b/src/exchangedb/pg_select_aml_history.c
index 2e310878..9638df5c 100644
--- a/src/exchangedb/pg_select_aml_history.c
+++ b/src/exchangedb/pg_select_aml_history.c
@@ -25,6 +25,96 @@
 #include "pg_select_aml_history.h"
 #include "pg_helper.h"
 
+
+/**
+ * Closure for #handle_aml_result.
+ */
+struct AmlHistoryResultContext
+{
+  /**
+   * Function to call on each result.
+   */
+  TALER_EXCHANGEDB_AmlHistoryCallback cb;
+
+  /**
+   * Closure for @e cb.
+   */
+  void *cb_cls;
+
+  /**
+   * Plugin context.
+   */
+  struct PostgresClosure *pg;
+
+  /**
+   * Set to #GNUNET_SYSERR on serious errors.
+   */
+  enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.  Helper function
+ * for #TEH_PG_select_aml_history().
+ *
+ * @param cls closure of type `struct AmlHistoryResultContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_aml_result (void *cls,
+                   PGresult *result,
+                   unsigned int num_results)
+{
+  struct AmlHistoryResultContext *ctx = cls;
+  struct PostgresClosure *pg = ctx->pg;
+
+  for (unsigned int i = 0; i<num_results; i++)
+  {
+    struct TALER_Amount new_threshold;
+    uint32_t ns;
+    struct GNUNET_TIME_Absolute decision_time;
+    char *justification;
+    struct TALER_AmlOfficerPublicKeyP decider_pub;
+    struct TALER_AmlOfficerSignatureP decider_sig;
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      TALER_PQ_RESULT_SPEC_AMOUNT ("new_threshold",
+                                   &new_threshold),
+      GNUNET_PQ_result_spec_uint32 ("new_status",
+                                    &ns),
+      GNUNET_PQ_result_spec_absolute_time ("decision_time",
+                                           &decision_time),
+      GNUNET_PQ_result_spec_string ("justification",
+                                    &justification),
+      GNUNET_PQ_result_spec_auto_from_type ("decider_pub",
+                                            &decider_pub),
+      GNUNET_PQ_result_spec_auto_from_type ("decider_sig",
+                                            &decider_sig),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_PQ_extract_result (result,
+                                  rs,
+                                  i))
+    {
+      GNUNET_break (0);
+      ctx->status = GNUNET_SYSERR;
+      return;
+    }
+    ctx->cb (ctx->cb_cls,
+             &new_threshold,
+             (enum TALER_AmlDecisionState) ns,
+             decision_time,
+             justification,
+             &decider_pub,
+             &decider_sig);
+    GNUNET_PQ_cleanup_result (rs);
+  }
+}
+
+
 enum GNUNET_DB_QueryStatus
 TEH_PG_select_aml_history (
   void *cls,
@@ -32,6 +122,42 @@ TEH_PG_select_aml_history (
   TALER_EXCHANGEDB_AmlHistoryCallback cb,
   void *cb_cls)
 {
-  GNUNET_break (0); // FIXME: not implemeted!
-  return GNUNET_DB_STATUS_HARD_ERROR;
+  struct PostgresClosure *pg = cls;
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_auto_from_type (h_payto),
+    GNUNET_PQ_query_param_end
+  };
+  struct AmlHistoryResultContext ctx = {
+    .cb = cb,
+    .cb_cls = cb_cls,
+    .pg = pg,
+    .status = GNUNET_OK
+  };
+  enum GNUNET_DB_QueryStatus qs;
+
+  PREPARE (pg,
+           "lookup_aml_history",
+           "SELECT"
+           " aggregation_serial_id"
+           ",deposits.h_contract_terms"
+           ",payto_uri"
+           ",wire_targets.wire_target_h_payto"
+           ",kc.coin_pub"
+           ",deposits.merchant_pub"
+           ",wire_out.execution_date"
+           ",deposits.amount_with_fee_val"
+           ",deposits.amount_with_fee_frac"
+           ",denom.fee_deposit_val"
+           ",denom.fee_deposit_frac"
+           ",denom.denom_pub"
+           " FROM aml_history"
+           " WHERE h_payto=$1;");
+  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                             "lookup_aml_history",
+                                             params,
+                                             &handle_aml_result,
+                                             &ctx);
+  if (GNUNET_OK != ctx.status)
+    return GNUNET_DB_STATUS_HARD_ERROR;
+  return qs;
 }
diff --git a/src/exchangedb/pg_select_aml_process.c 
b/src/exchangedb/pg_select_aml_process.c
index 9b5dedb3..2105308f 100644
--- a/src/exchangedb/pg_select_aml_process.c
+++ b/src/exchangedb/pg_select_aml_process.c
@@ -26,6 +26,87 @@
 #include "pg_helper.h"
 
 
+/**
+ * Closure for #handle_aml_result.
+ */
+struct AmlProcessResultContext
+{
+  /**
+   * Function to call on each result.
+   */
+  TALER_EXCHANGEDB_AmlStatusCallback cb;
+
+  /**
+   * Closure for @e cb.
+   */
+  void *cb_cls;
+
+  /**
+   * Plugin context.
+   */
+  struct PostgresClosure *pg;
+
+  /**
+   * Set to #GNUNET_SYSERR on serious errors.
+   */
+  enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.  Helper function
+ * for #TEH_PG_select_aml_process().
+ *
+ * @param cls closure of type `struct AmlProcessResultContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_aml_result (void *cls,
+                   PGresult *result,
+                   unsigned int num_results)
+{
+  struct AmlProcessResultContext *ctx = cls;
+  struct PostgresClosure *pg = ctx->pg;
+
+  for (unsigned int i = 0; i<num_results; i++)
+  {
+    struct TALER_PaytoHashP h_payto;
+    struct TALER_Amount threshold;
+    uint64_t rowid;
+    uint32_t sv;
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_uint64 ("aml_status_serial_id",
+                                    &rowid),
+      GNUNET_PQ_result_spec_auto_from_type ("h_payto",
+                                            &h_payto),
+      TALER_PQ_RESULT_SPEC_AMOUNT ("threshold",
+                                   &threshold),
+      GNUNET_PQ_result_spec_uint32 ("status",
+                                    &sv),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_PQ_extract_result (result,
+                                  rs,
+                                  i))
+    {
+      GNUNET_break (0);
+      ctx->status = GNUNET_SYSERR;
+      return;
+    }
+    ctx->cb (ctx->cb_cls,
+             rowid,
+             &h_payto,
+             &threshold,
+             (enum TALER_AmlDecisionState) sv);
+    GNUNET_PQ_cleanup_result (rs);
+  }
+}
+
+
 enum GNUNET_DB_QueryStatus
 TEH_PG_select_aml_process (
   void *cls,
@@ -35,6 +116,53 @@ TEH_PG_select_aml_process (
   TALER_EXCHANGEDB_AmlStatusCallback cb,
   void *cb_cls)
 {
-  GNUNET_break (0); // FIXME: not implemeted!
-  return GNUNET_DB_STATUS_HARD_ERROR;
+  struct PostgresClosure *pg = cls;
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_uint32 (&decision),
+    GNUNET_PQ_query_param_uint64 (&row_off),
+    GNUNET_PQ_query_param_end
+  };
+  struct AmlProcessResultContext ctx = {
+    .cb = cb,
+    .cb_cls = cb_cls,
+    .pg = pg,
+    .status = GNUNET_OK
+  };
+  enum GNUNET_DB_QueryStatus qs;
+  const char *stmt = forward
+    ? "select_aml_process_inc"
+    : "select_aml_process_dec";
+
+  PREPARE (pg,
+           "select_aml_process_inc",
+           "SELECT"
+           " aml_status_serial_id"
+           ",h_payto"
+           ",threshold_var"
+           ",threshold_frac"
+           ",status"
+           " FROM aml_status"
+           " WHERE aml_status_serial_id > $2"
+           "   AND $1 = status & $1"
+           " ORDER BY aml_status_serial_id INC");
+  PREPARE (pg,
+           "select_aml_process_dec",
+           "SELECT"
+           " aml_status_serial_id"
+           ",h_payto"
+           ",threshold_var"
+           ",threshold_frac"
+           ",status"
+           " FROM aml_status"
+           " WHERE aml_status_serial_id < $2"
+           "   AND $1 = status & $1"
+           " ORDER BY aml_status_serial_id DESC");
+  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                             stmt,
+                                             params,
+                                             &handle_aml_result,
+                                             &ctx);
+  if (GNUNET_OK != ctx.status)
+    return GNUNET_DB_STATUS_HARD_ERROR;
+  return qs;
 }
diff --git a/src/exchangedb/pg_trigger_aml_process.c 
b/src/exchangedb/pg_trigger_aml_process.c
index 29ac2de1..4dfc8a50 100644
--- a/src/exchangedb/pg_trigger_aml_process.c
+++ b/src/exchangedb/pg_trigger_aml_process.c
@@ -32,6 +32,28 @@ TEH_PG_trigger_aml_process (
   const struct TALER_PaytoHashP *h_payto,
   const struct TALER_Amount *threshold_crossed)
 {
-  GNUNET_break (0); // FIXME: not implemeted!
-  return GNUNET_DB_STATUS_HARD_ERROR;
+  struct PostgresClosure *pg = cls;
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_auto_from_type (h_payto),
+    TALER_PQ_query_param_amount (threshold_crossed),
+    GNUNET_PQ_query_param_end
+  };
+
+  PREPARE (pg,
+           "trigger_aml_process",
+           "INSERT INTO aml_status"
+           "(h_payto"
+           ",threshold_val"
+           ",threshold_frac"
+           ",status)"
+           "VALUES"
+           "($1, $2, $3, 1)" // 1: decision needed
+           "ON CONFLICT DO"
+           " UPDATE SET"
+           "   threshold_val=$2"
+           "  ,threshold_frac=$3"
+           "  ,status=status | 1;"); // do not clear 'frozen' status
+  return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+                                             "trigger_aml_process",
+                                             params);
 }

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