gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 02/02: fixed cost calculation with different currencie


From: gnunet
Subject: [taler-anastasis] 02/02: fixed cost calculation with different currencies
Date: Fri, 19 Jun 2020 09:44:02 +0200

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

dennis-neufeld pushed a commit to branch master
in repository anastasis.

commit eee0f7df53736d519795923222b338dc809431b2
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Fri Jun 19 07:42:52 2020 +0000

    fixed cost calculation with different currencies
---
 src/cli/anastasis-cli-assembler.c | 79 ++++++++++++++++++++++++++++++++-------
 1 file changed, 65 insertions(+), 14 deletions(-)

diff --git a/src/cli/anastasis-cli-assembler.c 
b/src/cli/anastasis-cli-assembler.c
index 0dd02a3..6953f7c 100644
--- a/src/cli/anastasis-cli-assembler.c
+++ b/src/cli/anastasis-cli-assembler.c
@@ -316,38 +316,86 @@ read_keyboard_command (void *cls)
                      strlen ("policies")))
       && (characters == strlen ("policies")))
   {
-    // FIXME: Currency, maybe from config file?
-    char *currency = challenges[0].currency;
-    GNUNET_assert (NULL != currency);
-
     for (unsigned int i = 0; i < policies_length; i++)
     {
       // Calculate costs
-      struct TALER_Amount cost;
+      struct TALER_Amount *costs; // different cost for different currencies
+      char **currencies;
+      unsigned int costs_len = 0;
 
-      GNUNET_assert (GNUNET_OK == TALER_amount_get_zero (currency,
-                                                         &cost));
       for (unsigned int j = 0; j < policies[i].uuids_length; j++)
       {
         for (unsigned int k = 0; k < challenges_length; k++)
         {
           if (0 == uuid_compare (policies[i].escrow_uuids[j],
                                  challenges[k].uuid))
-            TALER_amount_add (&cost,
-                              &cost,
+          {
+            unsigned int new_currency = 1;
+            unsigned int index = 0;
+            for (unsigned int l = 0; l < costs_len; l++)
+            {
+              if (0 == strcmp (challenges[k].currency, currencies[l]))
+              {
+                index = l;
+                new_currency = 0;
+                break;
+              }
+            }
+            if (0 == costs_len)
+            {
+              costs = GNUNET_new_array (1, struct TALER_Amount);
+              currencies = GNUNET_new_array (1, char *);
+
+              GNUNET_assert (GNUNET_OK ==
+                             TALER_amount_get_zero (challenges[k].currency,
+                                                    &costs[0]));
+              currencies[0] = GNUNET_malloc (strlen (challenges[k].currency)
+                                             + 1);
+              GNUNET_strlcpy (currencies[0],
+                              challenges[k].currency,
+                              strlen (challenges[k].currency) + 1);
+              GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                          "At %s:%d cost is %s\n", __FILE__, __LINE__,
+                          TALER_amount_to_string (&costs[0]));
+              costs_len = 1;
+              new_currency = 0;
+            }
+            if (1 == new_currency)
+            {
+              struct TALER_Amount cost;
+              GNUNET_assert (GNUNET_OK ==
+                             TALER_amount_get_zero (challenges[k].currency,
+                                                    &cost));
+              GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                          "At %s:%d cost is %s\n", __FILE__, __LINE__,
+                          TALER_amount_to_string (&cost));
+              GNUNET_array_append (costs,
+                                   costs_len,
+                                   cost);
+              GNUNET_array_append (currencies,
+                                   costs_len,
+                                   challenges[k].currency);
+              index = costs_len - 1;
+            }
+
+            TALER_amount_add (&costs[index],
+                              &costs[index],
                               challenges[k].cost);
+          }
         }
       }
-      printf ("policy#%u: %s ",
-              i,
-              TALER_amount_to_string (&cost));
+      printf ("policy#%u: ", i);
+      for (unsigned int l = 0; l < costs_len; l++)
+      {
+        printf ("%s ", TALER_amount_to_string (&costs[l]));
+      }
       for (unsigned int j = 0; j < policies[i].uuids_length; j++)
       {
         for (unsigned int k = 0; k < challenges_length; k++)
         {
           if (0 == uuid_compare (policies[i].escrow_uuids[j],
                                  challenges[k].uuid))
-            if (1 != *challenges[k].solved)
+            if (1 != challenges[k].solved)
               printf ("truth#%u ", k);
         }
       }
@@ -495,7 +543,10 @@ config_cb (void *cls,
   GNUNET_memcpy (cs->ci->cost,
                  question_cost,
                  sizeof (*question_cost));
-  cs->ci->currency = conf_currency;
+  cs->ci->currency = GNUNET_malloc (strlen (conf_currency) + 1);
+  GNUNET_strlcpy (cs->ci->currency,
+                  conf_currency,
+                  strlen (conf_currency) + 1);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "At %s:%d cost is %s\n", __FILE__, __LINE__,

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