gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: add TALER_PQ_array_of_amount_cur


From: gnunet
Subject: [taler-exchange] branch master updated: add TALER_PQ_array_of_amount_currency
Date: Wed, 10 Jan 2024 14:20:52 +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 68ced6e3 add TALER_PQ_array_of_amount_currency
68ced6e3 is described below

commit 68ced6e31a9d247bf18f22754c0bd3619ca9f726
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Jan 10 14:20:44 2024 +0100

    add TALER_PQ_array_of_amount_currency
---
 contrib/gana               |   2 +-
 contrib/wallet-core        |   2 +-
 src/include/taler_pq_lib.h |  17 ++++-
 src/pq/pq_common.h         |   7 ++
 src/pq/pq_query_helper.c   | 157 +++++++++++++++++++++++++++++++++++++++------
 5 files changed, 161 insertions(+), 24 deletions(-)

diff --git a/contrib/gana b/contrib/gana
index 9eddc2cf..0ff4edfe 160000
--- a/contrib/gana
+++ b/contrib/gana
@@ -1 +1 @@
-Subproject commit 9eddc2cf7b65bb43d285c75ef22fd9bc9cc7020e
+Subproject commit 0ff4edfe76be77a59d4ebff5031feb50f3ba07d8
diff --git a/contrib/wallet-core b/contrib/wallet-core
index a675c940..496bfdc3 160000
--- a/contrib/wallet-core
+++ b/contrib/wallet-core
@@ -1 +1 @@
-Subproject commit a675c94085cfa90052c9ebacd2cebccfab2c4f18
+Subproject commit 496bfdc3aecbea61922bb2e0c281f5d35f934a3b
diff --git a/src/include/taler_pq_lib.h b/src/include/taler_pq_lib.h
index a529b430..cf9f7c02 100644
--- a/src/include/taler_pq_lib.h
+++ b/src/include/taler_pq_lib.h
@@ -177,8 +177,9 @@ TALER_PQ_query_param_array_hash_code (
   const struct GNUNET_HashCode *hashes,
   struct GNUNET_PQ_Context *db);
 
+
 /**
- * Generate query parameter for an array of mounts
+ * Generate query parameter for an array of amounts
  *
  * @param num of elements in @e amounts
  * @param amounts continuous array of amounts
@@ -191,6 +192,20 @@ TALER_PQ_query_param_array_amount (
   struct GNUNET_PQ_Context *db);
 
 
+/**
+ * Generate query parameter for an array of amounts
+ *
+ * @param num of elements in @e amounts
+ * @param amounts continuous array of amounts
+ * @param db context for db-connection, needed for OID-lookup
+ */
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_array_amount_with_currency (
+  size_t num,
+  const struct TALER_Amount *amounts,
+  struct GNUNET_PQ_Context *db);
+
+
 /**
  * Generate query parameter for a blind sign public key of variable size.
  *
diff --git a/src/pq/pq_common.h b/src/pq/pq_common.h
index 735528ae..1562646f 100644
--- a/src/pq/pq_common.h
+++ b/src/pq/pq_common.h
@@ -45,13 +45,20 @@ enum TALER_PQ_ArrayType
   TALER_PQ_array_of_blinded_coin_hash,
   TALER_PQ_array_of_denom_hash,
   TALER_PQ_array_of_hash_code,
+
   /**
    * Amounts *without* currency.
    */
   TALER_PQ_array_of_amount,
+
+  /**
+   * Amounts *with* currency.
+   */
+  TALER_PQ_array_of_amount_currency,
   TALER_PQ_array_of_MAX,       /* must be last */
 };
 
+
 /**
  * Memory representation of an taler amount record for Postgres.
  *
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index d8655db0..6fda302d 100644
--- a/src/pq/pq_query_helper.c
+++ b/src/pq/pq_query_helper.c
@@ -846,14 +846,14 @@ qconv_array (
   same_sized = (0 != meta->same_size);
 
 #define RETURN_UNLESS(cond) \
-        do { \
-          if (! (cond)) \
-          { \
-            GNUNET_break ((cond)); \
-            noerror = false; \
-            goto DONE; \
-          } \
-        } while (0)
+  do { \
+    if (! (cond)) \
+    { \
+      GNUNET_break ((cond)); \
+      noerror = false; \
+      goto DONE; \
+    } \
+  } while (0)
 
   /* Calculate sizes and check bounds */
   {
@@ -881,6 +881,44 @@ qconv_array (
     {
       switch (meta->typ)
       {
+      case TALER_PQ_array_of_amount_currency:
+        {
+          const struct TALER_Amount *amounts = data;
+          Oid oid_v;
+          Oid oid_f;
+          Oid oid_c;
+
+          /* hoist out of loop? */
+          GNUNET_assert (GNUNET_OK ==
+                         GNUNET_PQ_get_oid_by_name (meta->db,
+                                                    "int8",
+                                                    &oid_v));
+          GNUNET_assert (GNUNET_OK ==
+                         GNUNET_PQ_get_oid_by_name (meta->db,
+                                                    "int4",
+                                                    &oid_f));
+          GNUNET_assert (GNUNET_OK ==
+                         GNUNET_PQ_get_oid_by_name (meta->db,
+                                                    "VARCHAR(12)",
+                                                    &oid_c));
+          for (size_t i = 0; i<num; i++)
+          {
+            struct TALER_PQ_AmountCurrencyP am;
+            size_t len;
+
+            len = TALER_PQ_make_taler_pq_amount_currency_ (
+              &amounts[i],
+              oid_v,
+              oid_f,
+              oid_c,
+              &am);
+            buffer_lengths[i] = len;
+            y = total_size;
+            total_size += len;
+            RETURN_UNLESS (total_size >= y);
+          }
+          break;
+        }
       case TALER_PQ_array_of_blinded_denom_sig:
         {
           const struct TALER_BlindedDenominationSignature *denom_sigs = data;
@@ -963,6 +1001,7 @@ qconv_array (
           Oid oid_v;
           Oid oid_f;
 
+          /* hoist out of loop? */
           GNUNET_assert (GNUNET_OK ==
                          GNUNET_PQ_get_oid_by_name (meta->db,
                                                     "int8",
@@ -984,6 +1023,42 @@ qconv_array (
           }
           break;
         }
+      case TALER_PQ_array_of_amount_currency:
+        {
+          const struct TALER_Amount *amounts = data;
+          Oid oid_v;
+          Oid oid_f;
+          Oid oid_c;
+
+          /* hoist out of loop? */
+          GNUNET_assert (GNUNET_OK ==
+                         GNUNET_PQ_get_oid_by_name (meta->db,
+                                                    "int8",
+                                                    &oid_v));
+          GNUNET_assert (GNUNET_OK ==
+                         GNUNET_PQ_get_oid_by_name (meta->db,
+                                                    "int4",
+                                                    &oid_f));
+          GNUNET_assert (GNUNET_OK ==
+                         GNUNET_PQ_get_oid_by_name (meta->db,
+                                                    "VARCHAR(12)",
+                                                    &oid_c));
+          {
+            struct TALER_PQ_AmountCurrencyP am;
+            size_t len;
+
+            len = TALER_PQ_make_taler_pq_amount_currency_ (
+              &amounts[i],
+              oid_v,
+              oid_f,
+              oid_c,
+              &am);
+            GNUNET_memcpy (out,
+                           &am,
+                           len);
+          }
+          break;
+        }
       case TALER_PQ_array_of_blinded_denom_sig:
         {
           const struct TALER_BlindedDenominationSignature *denom_sigs = data;
@@ -1099,6 +1174,7 @@ query_param_array_generic (
   struct GNUNET_PQ_Context *db)
 {
   struct qconv_array_cls *meta = GNUNET_new (struct qconv_array_cls);
+
   meta->typ = typ;
   meta->oid = oid;
   meta->sizes = sizes;
@@ -1106,16 +1182,18 @@ query_param_array_generic (
   meta->continuous = continuous;
   meta->db = db;
 
-  struct GNUNET_PQ_QueryParam res = {
-    .conv = qconv_array,
-    .conv_cls = meta,
-    .conv_cls_cleanup = qconv_array_cls_cleanup,
-    .data = elements,
-    .size = num,
-    .num_params = 1,
-  };
+  {
+    struct GNUNET_PQ_QueryParam res = {
+      .conv = qconv_array,
+      .conv_cls = meta,
+      .conv_cls_cleanup = qconv_array_cls_cleanup,
+      .data = elements,
+      .size = num,
+      .num_params = 1,
+    };
 
-  return res;
+    return res;
+  }
 }
 
 
@@ -1126,8 +1204,11 @@ TALER_PQ_query_param_array_blinded_denom_sig (
   struct GNUNET_PQ_Context *db)
 {
   Oid oid;
+
   GNUNET_assert (GNUNET_OK ==
-                 GNUNET_PQ_get_oid_by_name (db, "bytea", &oid));
+                 GNUNET_PQ_get_oid_by_name (db,
+                                            "bytea",
+                                            &oid));
   return query_param_array_generic (num,
                                     true,
                                     denom_sigs,
@@ -1146,8 +1227,11 @@ TALER_PQ_query_param_array_blinded_coin_hash (
   struct GNUNET_PQ_Context *db)
 {
   Oid oid;
+
   GNUNET_assert (GNUNET_OK ==
-                 GNUNET_PQ_get_oid_by_name (db, "bytea", &oid));
+                 GNUNET_PQ_get_oid_by_name (db,
+                                            "bytea",
+                                            &oid));
   return query_param_array_generic (num,
                                     true,
                                     coin_hs,
@@ -1166,8 +1250,11 @@ TALER_PQ_query_param_array_denom_hash (
   struct GNUNET_PQ_Context *db)
 {
   Oid oid;
+
   GNUNET_assert (GNUNET_OK ==
-                 GNUNET_PQ_get_oid_by_name (db, "bytea", &oid));
+                 GNUNET_PQ_get_oid_by_name (db,
+                                            "bytea",
+                                            &oid));
   return query_param_array_generic (num,
                                     true,
                                     denom_hs,
@@ -1206,8 +1293,11 @@ TALER_PQ_query_param_array_amount (
   struct GNUNET_PQ_Context *db)
 {
   Oid oid;
+
   GNUNET_assert (GNUNET_OK ==
-                 GNUNET_PQ_get_oid_by_name (db, "taler_amount", &oid));
+                 GNUNET_PQ_get_oid_by_name (db,
+                                            "taler_amount",
+                                            &oid));
   return query_param_array_generic (
     num,
     true,
@@ -1220,6 +1310,30 @@ TALER_PQ_query_param_array_amount (
 }
 
 
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_array_amount_with_currency (
+  size_t num,
+  const struct TALER_Amount *amounts,
+  struct GNUNET_PQ_Context *db)
+{
+  Oid oid;
+
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_PQ_get_oid_by_name (db,
+                                            "taler_amount_currency",
+                                            &oid));
+  return query_param_array_generic (
+    num,
+    true,
+    amounts,
+    NULL,
+    0, /* currency is technically variable length */
+    TALER_PQ_array_of_amount_currency,
+    oid,
+    db);
+}
+
+
 /**
  * Function called to convert input argument into SQL parameters.
  *
@@ -1300,6 +1414,7 @@ qconv_blind_sign_pub (void *cls,
   return 1;
 }
 
+
 /**
  * Generate query parameter for a blind sign public key of variable size.
  *

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