gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: [pq] add support for array of st


From: gnunet
Subject: [taler-exchange] branch master updated: [pq] add support for array of struct GNUNET_HashCode
Date: Tue, 28 Nov 2023 15:39:22 +0100

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

oec pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new d15fd5ad [pq] add support for array of struct GNUNET_HashCode
     new 0dae8022 Merge branch 'master' of ssh://git.taler.net/exchange
d15fd5ad is described below

commit d15fd5add80707b30b874ecb207e2dcad29692cc
Author: Özgür Kesim <oec-taler@kesim.org>
AuthorDate: Tue Nov 28 15:38:07 2023 +0100

    [pq] add support for array of struct GNUNET_HashCode
---
 src/pq/pq_common.h        |  1 +
 src/pq/pq_query_helper.c  | 45 ++++++++++++++++++++++++++++++++-------
 src/pq/pq_result_helper.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++
 src/pq/test_pq.c          | 52 ++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 143 insertions(+), 9 deletions(-)

diff --git a/src/pq/pq_common.h b/src/pq/pq_common.h
index 6172c0bf..735528ae 100644
--- a/src/pq/pq_common.h
+++ b/src/pq/pq_common.h
@@ -44,6 +44,7 @@ enum TALER_PQ_ArrayType
   TALER_PQ_array_of_blinded_denom_sig,
   TALER_PQ_array_of_blinded_coin_hash,
   TALER_PQ_array_of_denom_hash,
+  TALER_PQ_array_of_hash_code,
   /**
    * Amounts *without* currency.
    */
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index f6684451..24bf054d 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 */
   {
@@ -1037,6 +1037,15 @@ qconv_array (
                          sizeof(struct TALER_DenominationHashP));
           break;
         }
+      case TALER_PQ_array_of_hash_code:
+        {
+          const struct GNUNET_HashCode *hashes = data;
+
+          GNUNET_memcpy (out,
+                         &hashes[i],
+                         sizeof(struct GNUNET_HashCode));
+          break;
+        }
       default:
         {
           GNUNET_assert (0);
@@ -1170,6 +1179,26 @@ TALER_PQ_query_param_array_denom_hash (
 }
 
 
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_array_hash_code (
+  size_t num,
+  const struct GNUNET_HashCode *hashes,
+  struct GNUNET_PQ_Context *db)
+{
+  Oid oid;
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_PQ_get_oid_by_name (db, "gnunet_hashcode", &oid));
+  return query_param_array_generic (num,
+                                    true,
+                                    hashes,
+                                    NULL,
+                                    sizeof(struct GNUNET_HashCode),
+                                    TALER_PQ_array_of_hash_code,
+                                    oid,
+                                    NULL);
+}
+
+
 struct GNUNET_PQ_QueryParam
 TALER_PQ_query_param_array_amount (
   size_t num,
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c
index 9bd3fdb4..915aad14 100644
--- a/src/pq/pq_result_helper.c
+++ b/src/pq/pq_result_helper.c
@@ -1249,6 +1249,30 @@ extract_array_generic (
       }
       return GNUNET_OK;
 
+    case TALER_PQ_array_of_hash_code:
+      if (NULL != dst_size)
+        *dst_size = sizeof(struct GNUNET_HashCode) * (header.dim);
+      out = GNUNET_new_array (header.dim,
+                              struct GNUNET_HashCode);
+      *((void **) dst) = out;
+      for (uint32_t i = 0; i < header.dim; i++)
+      {
+        uint32_t val;
+        size_t sz;
+
+        GNUNET_memcpy (&val,
+                       in,
+                       sizeof(val));
+        sz =  ntohl (val);
+        FAIL_IF (sz != sizeof(struct GNUNET_HashCode));
+        in += sizeof(uint32_t);
+        *(struct GNUNET_HashCode *) out =
+          *(struct GNUNET_HashCode *) in;
+        in += sz;
+        out += sz;
+      }
+      return GNUNET_OK;
+
     case TALER_PQ_array_of_blinded_coin_hash:
       if (NULL != dst_size)
         *dst_size = sizeof(struct TALER_BlindedCoinHashP) * (header.dim);
@@ -1504,4 +1528,34 @@ TALER_PQ_result_spec_array_amount (
 }
 
 
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_array_hash_code (
+  struct GNUNET_PQ_Context *db,
+  const char *name,
+  size_t *num,
+  struct GNUNET_HashCode **hashes)
+{
+  struct ArrayResultCls *info = GNUNET_new (struct ArrayResultCls);
+
+  info->num = num;
+  info->typ = TALER_PQ_array_of_hash_code;
+  info->db = db;
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_PQ_get_oid_by_name (db,
+                                            "gnunet_hashcode",
+                                            &info->oid));
+
+  struct GNUNET_PQ_ResultSpec res = {
+    .conv = extract_array_generic,
+    .cleaner = array_cleanup,
+    .dst = (void *) hashes,
+    .fname = name,
+    .cls = info,
+  };
+  return res;
+
+
+}
+
+
 /* end of pq_result_helper.c */
diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c
index 237c8a9e..0fd2bfdd 100644
--- a/src/pq/test_pq.c
+++ b/src/pq/test_pq.c
@@ -21,6 +21,7 @@
 #include "platform.h"
 #include "taler_util.h"
 #include "taler_pq_lib.h"
+#include <gnunet/gnunet_pq_lib.h>
 
 
 /**
@@ -39,14 +40,18 @@ postgres_prepare (struct GNUNET_PQ_Context *db)
                             ",json"
                             ",aamount"
                             ",tamountc"
+                            ",hash"
+                            ",hashes"
                             ") VALUES "
-                            "($1, $2, $3, $4);"),
+                            "($1, $2, $3, $4, $5, $6);"),
     GNUNET_PQ_make_prepare ("test_select",
                             "SELECT"
                             " tamount"
                             ",json"
                             ",aamount"
                             ",tamountc"
+                            ",hash"
+                            ",hashes"
                             " FROM test_pq;"),
     GNUNET_PQ_PREPARED_STATEMENT_END
   };
@@ -67,6 +72,20 @@ run_queries (struct GNUNET_PQ_Context *conn)
   struct TALER_Amount tamount;
   struct TALER_Amount aamount[3];
   struct TALER_Amount tamountc;
+  struct GNUNET_HashCode hc =
+  {{0xdeadbeef,0xdeadbeef,0xdeadbeef,0xdeadbeef,
+    0xdeadbeef,0xdeadbeef,0xdeadbeef,0xdeadbeef,
+    0xdeadbeef,0xdeadbeef,0xdeadbeef,0xdeadbeef,
+    0xdeadbeef,0xdeadbeef,0xdeadbeef,0xdeadbeef, }};
+  struct GNUNET_HashCode hcs[2] =
+  {{{0xc0feec0f,0xc0feec0f,0xc0feec0f,0xc0feec0f,
+     0xc0feec0f,0xc0feec0f,0xc0feec0f,0xc0feec0f,
+     0xc0feec0f,0xc0feec0f,0xc0feec0f,0xc0feec0f,
+     0xc0feec0f,0xc0feec0f,0xc0feec0f,0xc0feec0f,}},
+   {{0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,
+     0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,
+     0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,
+     0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,}}};
   json_t *json;
 
   GNUNET_assert (GNUNET_OK ==
@@ -100,6 +119,11 @@ run_queries (struct GNUNET_PQ_Context *conn)
                                          conn),
       TALER_PQ_query_param_amount_with_currency (conn,
                                                  &tamountc),
+      GNUNET_PQ_query_param_fixed_size (&hc,
+                                        sizeof (hc)),
+      TALER_PQ_query_param_array_hash_code (2,
+                                            hcs,
+                                            conn),
       GNUNET_PQ_query_param_end
     };
     PGresult *result;
@@ -122,7 +146,10 @@ run_queries (struct GNUNET_PQ_Context *conn)
     struct TALER_Amount tamount2;
     struct TALER_Amount tamountc2;
     struct TALER_Amount *pamount;
+    struct GNUNET_HashCode hc2;
+    struct GNUNET_HashCode *hcs2;
     size_t npamount;
+    size_t nhcs;
     json_t *json2;
     struct GNUNET_PQ_QueryParam params_select[] = {
       GNUNET_PQ_query_param_end
@@ -140,6 +167,12 @@ run_queries (struct GNUNET_PQ_Context *conn)
                                          &pamount),
       TALER_PQ_result_spec_amount_with_currency ("tamountc",
                                                  &tamountc2),
+      GNUNET_PQ_result_spec_auto_from_type ("hash",
+                                            &hc2),
+      TALER_PQ_result_spec_array_hash_code (conn,
+                                            "hashes",
+                                            &nhcs,
+                                            &hcs2),
       GNUNET_PQ_result_spec_end
     };
 
@@ -168,6 +201,13 @@ run_queries (struct GNUNET_PQ_Context *conn)
     GNUNET_break (0 ==
                   TALER_amount_cmp (&tamountc,
                                     &tamountc2));
+    GNUNET_break (0 == GNUNET_memcmp (&hc,&hc2));
+    for (size_t i = 0; i < 2; i++)
+    {
+      GNUNET_break (0 ==
+                    GNUNET_memcmp (&hcs[i],
+                                   &hcs2[i]));
+    }
     GNUNET_PQ_cleanup_result (results_select);
   }
   return 0;
@@ -179,6 +219,14 @@ main (int argc,
       const char *const argv[])
 {
   struct GNUNET_PQ_ExecuteStatement es[] = {
+    GNUNET_PQ_make_execute ("DO $$ "
+                            " BEGIN"
+                            " CREATE DOMAIN gnunet_hashcode AS BYTEA"
+                            "   CHECK(length(VALUE)=64);"
+                            " EXCEPTION"
+                            "   WHEN duplicate_object THEN null;"
+                            " END "
+                            "$$;"),
     GNUNET_PQ_make_execute ("DO $$ "
                             " BEGIN"
                             " CREATE TYPE taler_amount AS"
@@ -200,6 +248,8 @@ main (int argc,
                             ",json VARCHAR NOT NULL"
                             ",aamount taler_amount[]"
                             ",tamountc taler_amount_currency"
+                            ",hash gnunet_hashcode"
+                            ",hashes gnunet_hashcode[]"
                             ")"),
     GNUNET_PQ_EXECUTE_STATEMENT_END
   };

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