gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: currency DD51 JSON generation


From: gnunet
Subject: [taler-exchange] branch master updated: currency DD51 JSON generation
Date: Sun, 08 Oct 2023 10:51:05 +0200

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 2bccd24e currency DD51 JSON generation
2bccd24e is described below

commit 2bccd24ecf7286ff35d464544358ffa414d39619
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Sun Oct 8 10:51:02 2023 +0200

    currency DD51 JSON generation
---
 src/include/taler_util.h | 18 ++++++++++++++++++
 src/util/config.c        | 47 ++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/src/include/taler_util.h b/src/include/taler_util.h
index 66951e12..4c3a1c9f 100644
--- a/src/include/taler_util.h
+++ b/src/include/taler_util.h
@@ -219,6 +219,12 @@ struct TALER_CurrencySpecification
    */
   char currency[TALER_CURRENCY_LEN];
 
+  /**
+   * Human-readable long name of the currency, e.g.
+   * "Japanese Yen".
+   */
+  char *name;
+
   /**
    * Character used to separate decimals.  String as
    * multi-byte sequences may be required (UTF-8!).
@@ -286,6 +292,18 @@ TALER_CONFIG_free_currencies (
   struct TALER_CurrencySpecification cspecs[static num_currencies]);
 
 
+/**
+ * Convert a currency specification to the
+ * respective JSON object.
+ *
+ * @param cspec currency specification
+ * @return JSON object encoding @a cspec for `/config`.
+ */
+json_t *
+TALER_CONFIG_currency_specs_to_json (const struct
+                                     TALER_CurrencySpecification *cspec);
+
+
 /**
  * Allow user to specify an amount on the command line.
  *
diff --git a/src/util/config.c b/src/util/config.c
index 125ea7b1..9e115624 100644
--- a/src/util/config.c
+++ b/src/util/config.c
@@ -21,7 +21,7 @@
  */
 #include "platform.h"
 #include "taler_util.h"
-
+#include <gnunet/gnunet_json_lib.h>
 
 enum GNUNET_GenericReturnValue
 TALER_config_get_amount (const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -241,12 +241,12 @@ parse_currencies_cb (void *cls,
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cpc->cfg,
                                              section,
-                                             "NAME",
+                                             "CODE",
                                              &str))
   {
     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
                                section,
-                               "NAME");
+                               "CODE");
     cpc->failure = true;
     return;
   }
@@ -254,8 +254,8 @@ parse_currencies_cb (void *cls,
   {
     GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
                                section,
-                               "NAME",
-                               "Name given is too long");
+                               "CODE",
+                               "Currency code name given is too long");
     cpc->failure = true;
     GNUNET_free (str);
     return;
@@ -278,6 +278,20 @@ parse_currencies_cb (void *cls,
   }
   cspec->decimal_separator = str;
 
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (cpc->cfg,
+                                             section,
+                                             "NAME",
+                                             &str))
+  {
+    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+                               section,
+                               "NAME");
+    cpc->failure = true;
+    return;
+  }
+  cspec->name = str;
+
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_number (cpc->cfg,
                                              section,
@@ -407,6 +421,28 @@ TALER_CONFIG_parse_currencies (const struct 
GNUNET_CONFIGURATION_Handle *cfg,
 }
 
 
+json_t *
+TALER_CONFIG_currency_specs_to_json (const struct
+                                     TALER_CurrencySpecification *cspec)
+{
+  return GNUNET_JSON_PACK (
+    GNUNET_JSON_pack_string ("decimal_separator",
+                             cspec->decimal_separator),
+    GNUNET_JSON_pack_string ("name",
+                             cspec->name),
+    GNUNET_JSON_pack_uint64 ("num_fractional_input_digits",
+                             cspec->num_fractional_input_digits),
+    GNUNET_JSON_pack_uint64 ("num_fractional_normal_digits",
+                             cspec->num_fractional_normal_digits),
+    GNUNET_JSON_pack_uint64 ("num_fractional_trailing_zero_digits",
+                             cspec->num_fractional_trailing_zero_digits),
+    GNUNET_JSON_pack_bool ("is_currency_name_leading",
+                           cspec->is_currency_name_leading),
+    GNUNET_JSON_pack_object_incref ("alt_unit_names",
+                                    cspec->map_alt_unit_names));
+}
+
+
 void
 TALER_CONFIG_free_currencies (
   unsigned int num_currencies,
@@ -417,6 +453,7 @@ TALER_CONFIG_free_currencies (
     struct TALER_CurrencySpecification *cspec = &cspecs[i];
 
     GNUNET_free (cspec->decimal_separator);
+    GNUNET_free (cspec->name);
     json_decref (cspec->map_alt_unit_names);
   }
   GNUNET_array_grow (cspecs,

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