gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated (d200765 -> eee0f7d)


From: gnunet
Subject: [taler-anastasis] branch master updated (d200765 -> eee0f7d)
Date: Fri, 19 Jun 2020 09:44:00 +0200

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

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

    from d200765  json_unpack -> GNUNET_JSON_parse
     new 0ba0a03  fix currency, cost - assembler
     new eee0f7d  fixed cost calculation with different currencies

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/cli/anastasis-cli-assembler.c | 127 ++++++++++++++++++++++++++++----------
 1 file changed, 96 insertions(+), 31 deletions(-)

diff --git a/src/cli/anastasis-cli-assembler.c 
b/src/cli/anastasis-cli-assembler.c
index 1fcf69e..6953f7c 100644
--- a/src/cli/anastasis-cli-assembler.c
+++ b/src/cli/anastasis-cli-assembler.c
@@ -92,6 +92,11 @@ struct ConfigState
    */
   unsigned int http_status;
 
+  /**
+   * Challenge the ConfigState refers to.
+   */
+  struct ANASTASIS_ChallengeInformation *ci;
+
   /**
    * The /config GET operation handle.
    */
@@ -311,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);
         }
       }
@@ -486,8 +539,35 @@ config_cb (void *cls,
     return;
   }
 
-  cs->cost = *question_cost;
-  cs->currency = conf_currency;
+  cs->ci->cost = GNUNET_new (struct TALER_Amount);
+  GNUNET_memcpy (cs->ci->cost,
+                 question_cost,
+                 sizeof (*question_cost));
+  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__,
+              TALER_amount_to_string (cs->ci->cost));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "At %s:%d currency is %s\n", __FILE__, __LINE__,
+              cs->ci->currency);
+
+  unsigned int contains = 0;
+  for (unsigned int i = 0; i < challenges_length; i++)
+  {
+    if (0 == uuid_compare (challenges[i].uuid, cs->ci->uuid))
+    {
+      contains = 1;
+      break;
+    }
+  }
+  if (0 == contains)
+    GNUNET_array_append (challenges,
+                         challenges_length,
+                         *cs->ci);
 }
 
 
@@ -508,6 +588,7 @@ challenge_cb (void *cls,
   struct ConfigState *cs = GNUNET_new (struct ConfigState);
 
   cs->http_status = MHD_HTTP_OK;
+  cs->ci = ci;
   cs->co = ANASTASIS_get_config (ctx,
                                  ci->url,
                                  config_cb,
@@ -517,22 +598,6 @@ challenge_cb (void *cls,
     GNUNET_break (0);
     return;
   }
-  ci->cost = &cs->cost;
-  ci->currency = cs->currency;
-
-  unsigned int contains = 0;
-  for (unsigned int i = 0; i < challenges_length; i++)
-  {
-    if (0 == uuid_compare (challenges[i].uuid, ci->uuid))
-    {
-      contains = 1;
-      break;
-    }
-  }
-  if (0 == contains)
-    GNUNET_array_append (challenges,
-                         challenges_length,
-                         *ci);
 }
 
 

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