gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 156/277: implement lookup tip details


From: gnunet
Subject: [taler-merchant] 156/277: implement lookup tip details
Date: Sun, 05 Jul 2020 20:51:09 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit e0991aa684c7a4e9895834286dfdf98007e8cfa6
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat May 30 12:48:57 2020 +0200

    implement lookup tip details
---
 .../taler-merchant-httpd_private-get-tips-ID.c     |   4 +-
 src/backenddb/plugin_merchantdb_postgres.c         | 167 +++++++++++++++++++--
 src/include/taler_merchantdb_plugin.h              |  17 +--
 3 files changed, 161 insertions(+), 27 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-get-tips-ID.c 
b/src/backend/taler-merchant-httpd_private-get-tips-ID.c
index 6276189..fc9ef06 100644
--- a/src/backend/taler-merchant-httpd_private-get-tips-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-tips-ID.c
@@ -125,13 +125,11 @@ TMH_private_get_tips_ID (const struct TMH_RequestHandler 
*rh,
     {
       json_array_append_new (
         pickups_json,
-        json_pack ("{s:o,s:o,s:o,s:I}",
+        json_pack ("{s:o,s:o,s:I}",
                    "pickup_id",
                    GNUNET_JSON_from_data_auto (&pickups[i].pickup_id),
                    "requested_amount",
                    TALER_JSON_from_amount (&pickups[i].requested_amount),
-                   "exchange_amount",
-                   TALER_JSON_from_amount (&pickups[i].exchange_amount),
                    "num_planchets",
                    (json_int_t) pickups[i].num_planchets));
     }
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index 756071a..a0490c5 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -4708,6 +4708,82 @@ postgres_lookup_tip (void *cls,
 }
 
 
+/**
+ * Closure for #lookup_pickup_details_cb().
+ */
+struct LookupTipDetailsContext
+{
+  /**
+   * Length of the @e sigs array
+   */
+  unsigned int *pickups_length;
+
+  /**
+   * Where to store the signatures.
+   */
+  struct TALER_MERCHANTDB_PickupDetails **pickups;
+
+  /**
+   * Database handle.
+   */
+  struct PostgresClosure *pg;
+
+  /**
+   * Transaction status.
+   */
+  enum GNUNET_DB_QueryStatus qs;
+
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results about pickups.
+ *
+ * @param[in,out] cls of type `struct LookupTipDetailsContext *`
+ * @param result the postgres result
+ * @param num_result the number of results in @a result
+ */
+static void
+lookup_pickup_details_cb (void *cls,
+                          PGresult *result,
+                          unsigned int num_results)
+{
+  struct LookupTipDetailsContext *ltdc = cls;
+  struct PostgresClosure *pg = ltdc->pg;
+
+  *ltdc->pickups_length = num_results;
+  *ltdc->pickups = GNUNET_new_array (num_results,
+                                     struct TALER_MERCHANTDB_PickupDetails);
+  for (unsigned int i = 0; i < num_results; i++)
+  {
+    struct TALER_MERCHANTDB_PickupDetails *pd = &((*ltdc->pickups)[i]);
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_auto_from_type ("pickup_id",
+                                            &pd->pickup_id),
+      TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+                                   &pd->requested_amount),
+      GNUNET_PQ_result_spec_uint32 ("num_planchets",
+                                    &pd->num_planchets),
+      GNUNET_PQ_result_spec_end
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_PQ_extract_result (result,
+                                  rs,
+                                  i))
+    {
+      GNUNET_break (0);
+      ltdc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+      GNUNET_array_grow (*ltdc->pickups,
+                         *ltdc->pickups_length,
+                         0);
+      return;
+    }
+  }
+}
+
+
 /**
  * Lookup tip details for tip @a tip_id.
  *
@@ -4723,17 +4799,11 @@ postgres_lookup_tip (void *cls,
  * @param[out] pickups_length set to the length of @e pickups
  * @param[out] pickups if @a fpu is true, set to details about the pickup 
operations
  * @return transaction status,
- *      #TALER_EC_TIP_AUTHORIZE_RESERVE_EXPIRED if the reserve is known but 
has expired
- *      #TALER_EC_TIP_AUTHORIZE_RESERVE_UNKNOWN if the reserve is not known
- *      #TALER_EC_TIP_AUTHORIZE_INSUFFICIENT_FUNDS if the reserve has 
insufficient funds left
- *      #TALER_EC_TIP_AUTHORIZE_DB_HARD_ERROR on hard DB errors
- *      #TALER_EC_TIP_AUTHORIZE_DB_SOFT_ERROR on soft DB errors (client should 
retry)
- *      #TALER_EC_NONE upon success
  */
-static enum TALER_ErrorCode
+static enum GNUNET_DB_QueryStatus
 postgres_lookup_tip_details (void *cls,
                              const char *instance_id,
-                             const struct GNUNET_HashCode tip_id,
+                             const struct GNUNET_HashCode *tip_id,
                              bool fpu,
                              struct TALER_Amount *total_authorized,
                              struct TALER_Amount *total_picked_up,
@@ -4743,7 +4813,66 @@ postgres_lookup_tip_details (void *cls,
                              unsigned int *pickups_length,
                              struct TALER_MERCHANTDB_PickupDetails **pickups)
 {
-  // FIXME!
+  struct PostgresClosure *pg = cls;
+  uint64_t tip_serial;
+  enum GNUNET_DB_QueryStatus qs;
+  {
+    struct GNUNET_PQ_QueryParam params[] = {
+      GNUNET_PQ_query_param_string (instance_id),
+      GNUNET_PQ_query_param_auto_from_type (tip_id),
+      GNUNET_PQ_query_param_end
+    };
+    struct GNUNET_PQ_ResultSpec rs[] = {
+      GNUNET_PQ_result_spec_uint64 ("tip_serial",
+                                    &tip_serial),
+      TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+                                   total_authorized),
+      TALER_PQ_RESULT_SPEC_AMOUNT ("picked_up",
+                                   total_picked_up),
+      GNUNET_PQ_result_spec_string ("justification",
+                                    justification),
+      GNUNET_PQ_result_spec_absolute_time ("expiration",
+                                           expiration),
+      GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+                                            reserve_pub),
+      GNUNET_PQ_result_spec_end
+    };
+
+    check_connection (pg);
+    qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+                                                   "lookup_tip_details",
+                                                   params,
+                                                   rs);
+    if (qs <= 0)
+      return qs;
+    if (! fpu)
+    {
+      *pickups_length = 0;
+      *pickups = NULL;
+      return qs;
+    }
+  }
+  {
+    struct GNUNET_PQ_QueryParam params[] = {
+      GNUNET_PQ_query_param_uint64 (&tip_serial),
+      GNUNET_PQ_query_param_end
+    };
+
+    struct LookupTipDetailsContext ltdc = {
+      .pickups_length = pickups_length,
+      .pickups = pickups,
+      .pg = pg
+    };
+
+    qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+                                               "lookup_pickup_details",
+                                               params,
+                                               &lookup_pickup_details_cb,
+                                               &ltdc);
+    if (qs <= 0)
+      return qs;
+    return ltdc.qs;
+  }
 }
 
 
@@ -7618,7 +7747,25 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
                             "       WHERE merchant_id=$1)",
                             2),
     /* for postgres_lookup_tip_details() */
-    // FIXME!
+    GNUNET_PQ_make_prepare ("lookup_tip_details",
+                            "SELECT"
+                            " tip_serial"
+                            ",amount_val"
+                            ",amount_frac"
+                            ",picked_up_val"
+                            ",picked_up_frac"
+                            ",justification"
+                            ",merchant_tips.expiration"
+                            ",exchange_url"
+                            ",reserve_pub"
+                            " FROM merchant_tips"
+                            " JOIN merchant_tip_reserves USING 
(reserve_serial)"
+                            " WHERE tip_id = $2"
+                            "   AND merchant_serial ="
+                            "     (SELECT merchant_serial"
+                            "        FROM merchant_instances"
+                            "       WHERE merchant_id=$1)",
+                            2),
     /* for postgres_lookup_tip_details() */
     // FIXME!
 
diff --git a/src/include/taler_merchantdb_plugin.h 
b/src/include/taler_merchantdb_plugin.h
index 3262c35..fe306b7 100644
--- a/src/include/taler_merchantdb_plugin.h
+++ b/src/include/taler_merchantdb_plugin.h
@@ -649,11 +649,6 @@ struct TALER_MERCHANTDB_PickupDetails
    */
   struct TALER_Amount requested_amount;
 
-  /**
-   * Total amount we successfully obtained from the exchange.
-   */
-  struct TALER_Amount exchange_amount;
-
   /**
    * Number of planchets involved in the request.
    */
@@ -1755,18 +1750,12 @@ struct TALER_MERCHANTDB_Plugin
    * @param[out] reserve_pub set to which reserve is debited
    * @param[out] pickups_length set to the length of @e pickups
    * @param[out] pickups if @a fpu is true, set to details about the pickup 
operations
-   * @return transaction status,
-   *      #TALER_EC_TIP_AUTHORIZE_RESERVE_EXPIRED if the reserve is known but 
has expired
-   *      #TALER_EC_TIP_AUTHORIZE_RESERVE_UNKNOWN if the reserve is not known
-   *      #TALER_EC_TIP_AUTHORIZE_INSUFFICIENT_FUNDS if the reserve has 
insufficient funds left
-   *      #TALER_EC_TIP_AUTHORIZE_DB_HARD_ERROR on hard DB errors
-   *      #TALER_EC_TIP_AUTHORIZE_DB_SOFT_ERROR on soft DB errors (client 
should retry)
-   *      #TALER_EC_NONE upon success
+   * @return transaction status
    */
-  enum TALER_ErrorCode
+  enum GNUNET_DB_QueryStatus
   (*lookup_tip_details)(void *cls,
                         const char *instance_id,
-                        const struct GNUNET_HashCode tip_id,
+                        const struct GNUNET_HashCode *tip_id,
                         bool fpu,
                         struct TALER_Amount *total_authorized,
                         struct TALER_Amount *total_picked_up,

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