gnunet-svn
[Top][All Lists]
Advanced

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

[taler-sync] branch master updated: finish syncdb implementation (untest


From: gnunet
Subject: [taler-sync] branch master updated: finish syncdb implementation (untested)
Date: Sun, 17 Nov 2019 17:52:25 +0100

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

grothoff pushed a commit to branch master
in repository sync.

The following commit(s) were added to refs/heads/master by this push:
     new 5feedd7  finish syncdb implementation (untested)
5feedd7 is described below

commit 5feedd7154afcd66d4d16923bdfe4ecbfd5cb700
Author: Christian Grothoff <address@hidden>
AuthorDate: Sun Nov 17 17:52:22 2019 +0100

    finish syncdb implementation (untested)
---
 src/include/sync_database_plugin.h  |   3 +-
 src/sync/sync-httpd_backup_post.c   |  22 +++++--
 src/syncdb/plugin_syncdb_postgres.c | 112 +++++++++++++++++++++++++++++++++++-
 3 files changed, 129 insertions(+), 8 deletions(-)

diff --git a/src/include/sync_database_plugin.h 
b/src/include/sync_database_plugin.h
index 15545bc..0321ce2 100644
--- a/src/include/sync_database_plugin.h
+++ b/src/include/sync_database_plugin.h
@@ -22,6 +22,7 @@
 #define SYNC_DATABASE_PLUGIN_H
 
 #include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_db_lib.h>
 #include "sync_service.h"
 #include <jansson.h>
 #include <taler/taler_util.h>
@@ -179,7 +180,7 @@ struct SYNC_DatabasePlugin
    * @param it_cls closure for @a it
    * @return transaction status
    */
-  enum SYNC_DB_QueryStatus
+  enum GNUNET_DB_QueryStatus
   (*lookup_pending_payments_by_account_TR)(void *cls,
                                            const struct
                                            SYNC_AccountPublicKeyP *account_pub,
diff --git a/src/sync/sync-httpd_backup_post.c 
b/src/sync/sync-httpd_backup_post.c
index 8cdb58a..58d517a 100644
--- a/src/sync/sync-httpd_backup_post.c
+++ b/src/sync/sync-httpd_backup_post.c
@@ -307,11 +307,25 @@ static int
 begin_payment (struct BackupContext *bc)
 {
   json_t *order;
+  enum GNUNET_DB_QueryStatus qs;
 
-  db->lookup_pending_payments_by_account_TR (db->cls,
-                                             &bc->account,
-                                             &ongoing_payment_cb,
-                                             bc);
+  qs = db->lookup_pending_payments_by_account_TR (db->cls,
+                                                  &bc->account,
+                                                  &ongoing_payment_cb,
+                                                  bc);
+  if (qs < 0)
+  {
+    struct MHD_Response *resp;
+    int ret;
+
+    resp = SH_RESPONSE_make_error (TALER_EC_SYNC_PAYMENT_CHECK_ORDER_DB_ERROR,
+                                   "Failed to check for existing orders in 
sync database");
+    ret = MHD_queue_response (bc->con,
+                              MHD_HTTP_INTERNAL_SERVER_ERROR,
+                              resp);
+    MHD_destroy_response (resp);
+    return ret;
+  }
   if (NULL != bc->existing_order_id)
   {
     // FIXME: this is incorrect, we should FIRST check
diff --git a/src/syncdb/plugin_syncdb_postgres.c 
b/src/syncdb/plugin_syncdb_postgres.c
index 2eea1d5..7cef697 100644
--- a/src/syncdb/plugin_syncdb_postgres.c
+++ b/src/syncdb/plugin_syncdb_postgres.c
@@ -48,6 +48,10 @@ struct PostgresClosure
    */
   const char *transaction_name;
 
+  /**
+   * Currency we accept payments in.
+   */
+  char *currency;
 };
 
 
@@ -300,6 +304,85 @@ postgres_store_payment (void *cls,
 }
 
 
+/**
+ * Closure for #payment_by_account_cb.
+ */
+struct PaymentIteratorContext
+{
+  /**
+   * Function to call on each result
+   */
+  SYNC_DB_PaymentPendingIterator it;
+
+  /**
+   * Closure for @e it.
+   */
+  void *it_cls;
+
+  /**
+   * Plugin context.
+   */
+  struct PostgresClosure *pg;
+
+  /**
+   * Query status to return.
+   */
+  enum GNUNET_DB_QueryStatus qs;
+
+};
+
+
+/**
+ * Helper function for #postgres_lookup_pending_payments_by_account().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PaymentIteratorContext *`
+ * @param result the postgres result
+ * @param num_result the number of results in @a result
+ */
+static void
+payment_by_account_cb (void *cls,
+                       PGresult *result,
+                       unsigned int num_results)
+{
+  struct PaymentIteratorContext *pic = cls;
+
+  for (unsigned int i = 0; i < num_results; i++)
+  {
+    struct GNUNET_TIME_Absolute timestamp;
+    char *order_id;
+    struct TALER_Amount amount;
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_absolute_time ("timestamp",
+                                           &timestamp),
+      GNUNET_PQ_result_spec_string ("order_id",
+                                    &order_id),
+      TALER_PQ_result_spec_amount ("amount",
+                                   pic->pg->currency,
+                                   &amount),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_PQ_extract_result (result,
+                                  rs,
+                                  i))
+    {
+      GNUNET_break (0);
+      pic->qs = GNUNET_DB_STATUS_HARD_ERROR;
+      return;
+    }
+    pic->qs = i + 1;
+    pic->it (pic->it_cls,
+             timestamp,
+             order_id,
+             &amount);
+    GNUNET_PQ_cleanup_result (rs);
+  }
+}
+
+
 /**
  * Lookup pending payments by account.
  *
@@ -309,14 +392,36 @@ postgres_store_payment (void *cls,
  * @param it_cls closure for @a it
  * @return transaction status
  */
-static enum SYNC_DB_QueryStatus
+static enum GNUNET_DB_QueryStatus
 postgres_lookup_pending_payments_by_account (void *cls,
                                              const struct
                                              SYNC_AccountPublicKeyP 
*account_pub,
                                              SYNC_DB_PaymentPendingIterator it,
                                              void *it_cls)
 {
-  // FIXME: use payments_select_by_account
+  struct PostgresClosure *pg = cls;
+  struct GNUNET_PQ_QueryParam params[] = {
+    GNUNET_PQ_query_param_auto_from_type (account_pub),
+    GNUNET_PQ_query_param_end
+  };
+  struct PaymentIteratorContext pic = {
+    .it = it,
+    .it_cls = it_cls,
+    .pg = pg
+  };
+  enum GNUNET_DB_QueryStatus qs;
+
+  check_connection (pg);
+  postgres_preflight (pg);
+  qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                             "payments_select_by_account",
+                                             params,
+                                             &payment_by_account_cb,
+                                             &pic);
+  if (qs > 0)
+    return pic.qs;
+  GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+  return qs;
 }
 
 
@@ -998,7 +1103,8 @@ libsync_plugin_db_postgres_init (void *cls)
                             0),
     GNUNET_PQ_make_prepare ("payments_select_by_account",
                             "SELECT"
-                            " order_id"
+                            " timestamp"
+                            ",order_id"
                             ",amount_val"
                             ",amount_frac"
                             "FROM"

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



reply via email to

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