gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: simplify amount logic


From: gnunet
Subject: [taler-exchange] branch master updated: simplify amount logic
Date: Thu, 16 Jan 2020 08:49:28 +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 7c6853d8 simplify amount logic
7c6853d8 is described below

commit 7c6853d830336a377410fb15411a0350f184f092
Author: Christian Grothoff <address@hidden>
AuthorDate: Thu Jan 16 08:49:26 2020 +0100

    simplify amount logic
---
 doc/prebuilt           |   2 +-
 src/json/json_helper.c | 107 +++++--------------------------------------------
 2 files changed, 10 insertions(+), 99 deletions(-)

diff --git a/doc/prebuilt b/doc/prebuilt
index 934a6a18..ca53235c 160000
--- a/doc/prebuilt
+++ b/doc/prebuilt
@@ -1 +1 @@
-Subproject commit 934a6a18301e81c4fd1b3a8cda2dc13dca4741cc
+Subproject commit ca53235ccfa0458ebf11c204888ca370e20ec3f5
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index 0f67e9d8..536eece9 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -78,65 +78,20 @@ parse_amount (void *cls,
               struct GNUNET_JSON_Specification *spec)
 {
   struct TALER_Amount *r_amount = spec->ptr;
-  json_int_t value;
-  json_int_t fraction;
-  const char *currency;
 
   (void) cls;
-  if (json_is_string (root))
-  {
-    if (GNUNET_OK !=
-        TALER_string_to_amount (json_string_value (root), r_amount))
-    {
-      GNUNET_break_op (0);
-      return GNUNET_SYSERR;
-    }
-    return GNUNET_OK;
-  }
-
-  /* Also allow the legacy { value, fraction, currency} format.
-     This might be removed in the future. */
-
-  memset (r_amount,
-          0,
-          sizeof (struct TALER_Amount));
-  if (0 != json_unpack (root,
-                        "{s:I, s:I, s:s}",
-                        "value", &value,
-                        "fraction", &fraction,
-                        "currency", &currency))
-  {
-    char *json_enc;
-
-    if (NULL == (json_enc = json_dumps (root,
-                                        JSON_COMPACT | JSON_ENCODE_ANY)))
-    {
-      GNUNET_break (0);
-      return GNUNET_SYSERR;
-    }
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Malformed JSON amount: %s\n",
-                json_enc);
-    free (json_enc);
-    return GNUNET_SYSERR;
-  }
-  if ( (value < 0) ||
-       (fraction < 0) ||
-       (((uint64_t) value) > UINT64_MAX) ||
-       (fraction > UINT32_MAX) )
+  if (! json_is_string (root))
   {
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
-  if (strlen (currency) >= TALER_CURRENCY_LEN)
+  if (GNUNET_OK !=
+      TALER_string_to_amount (json_string_value (root),
+                              r_amount))
   {
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
-  r_amount->value = (uint64_t) value;
-  r_amount->fraction = (uint32_t) fraction;
-  strcpy (r_amount->currency, currency);
-  (void) TALER_amount_normalize (r_amount);
   return GNUNET_OK;
 }
 
@@ -178,64 +133,20 @@ parse_amount_nbo (void *cls,
                   struct GNUNET_JSON_Specification *spec)
 {
   struct TALER_AmountNBO *r_amount = spec->ptr;
-  struct TALER_Amount amount;
-  json_int_t value;
-  json_int_t fraction;
-  const char *currency;
 
   (void) cls;
-  if (json_is_string (root))
+  if (! json_is_string (root))
   {
-    if (GNUNET_OK !=
-        TALER_string_to_amount_nbo (json_string_value (root), r_amount))
-    {
-      GNUNET_break_op (0);
-      return GNUNET_SYSERR;
-    }
-    return GNUNET_OK;
-  }
-
-  memset (&amount,
-          0,
-          sizeof (struct TALER_Amount));
-  if (0 != json_unpack (root,
-                        "{s:I, s:I, s:s}",
-                        "value", &value,
-                        "fraction", &fraction,
-                        "currency", &currency))
-  {
-    char *json_enc;
-
-    if (NULL == (json_enc = json_dumps (root,
-                                        JSON_COMPACT | JSON_ENCODE_ANY)))
-    {
-      GNUNET_break (0);
-      return GNUNET_SYSERR;
-    }
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Malformed JSON amount: %s\n",
-                json_enc);
-    free (json_enc);
-    return GNUNET_SYSERR;
-  }
-  if ( (value < 0) ||
-       (fraction < 0) ||
-       (fraction > (json_int_t) UINT32_MAX) )
-  {
-    GNUNET_break_op (0);
+    GNUNET_break (0);
     return GNUNET_SYSERR;
   }
-  if (strlen (currency) >= TALER_CURRENCY_LEN)
+  if (GNUNET_OK !=
+      TALER_string_to_amount_nbo (json_string_value (root),
+                                  r_amount))
   {
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
-  amount.value = (uint64_t) value;
-  amount.fraction = (uint32_t) fraction;
-  strcpy (amount.currency, currency);
-  (void) TALER_amount_normalize (&amount);
-  TALER_amount_hton (r_amount,
-                     &amount);
   return GNUNET_OK;
 }
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]