aboutsummaryrefslogtreecommitdiff
path: root/src/pq
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-01-10 14:20:44 +0100
committerChristian Grothoff <christian@grothoff.org>2024-01-10 14:20:50 +0100
commit68ced6e31a9d247bf18f22754c0bd3619ca9f726 (patch)
tree447650aba8d5f45189fcbf22012c154e70b0b9fa /src/pq
parente0cc5c9caf3953ee8409fad854ab894fd1a521e7 (diff)
add TALER_PQ_array_of_amount_currency
Diffstat (limited to 'src/pq')
-rw-r--r--src/pq/pq_common.h7
-rw-r--r--src/pq/pq_query_helper.c157
2 files changed, 143 insertions, 21 deletions
diff --git a/src/pq/pq_common.h b/src/pq/pq_common.h
index 735528ae1..1562646ff 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 d8655db08..6fda302d1 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.
*