gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] branch master updated: Rough logic for sum


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated: Rough logic for summing up all tracked wire transfers gotten from the exchange, grouping them by proposal's hash.
Date: Fri, 10 Mar 2017 20:53:26 +0100

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

marcello pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 7307067  Rough logic for summing up all tracked wire transfers gotten 
from the exchange, grouping them by proposal's hash.
7307067 is described below

commit 73070674f00f506f89f8a10fbf3b347f0b7c619a
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri Mar 10 20:51:34 2017 +0100

    Rough logic for summing up all tracked wire transfers gotten
    from the exchange, grouping them by proposal's hash.
---
 src/backend/taler-merchant-httpd_track-transfer.c | 90 ++++++++++++++++++++++-
 1 file changed, 87 insertions(+), 3 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_track-transfer.c 
b/src/backend/taler-merchant-httpd_track-transfer.c
index b273e99..7a4efa0 100644
--- a/src/backend/taler-merchant-httpd_track-transfer.c
+++ b/src/backend/taler-merchant-httpd_track-transfer.c
@@ -158,6 +158,26 @@ free_transfer_track_context (struct TrackTransferContext 
*rctx)
 }
 
 /**
+ * Callback that frees all the elements in the hashmap
+ *
+ * @param cls closure, NULL
+ * @param key current key
+ * @param value a `struct MerchantInstance`
+ * @return GNUNET_YES if the iteration should continue,
+ * GNUNET_NO otherwise.
+ */
+static int
+hashmap_free (void *cls,
+              const struct GNUNET_HashCode *key,
+              void *value)
+{
+  struct TALER_Amount *amount = value;
+  GNUNET_free (amount);
+  /*NOTE: how to find out when iteration should stop?*/
+  return GNUNET_YES;
+}
+
+/**
  * Transform /track/transfer result as gotten from the exchange
  * and transforms it in a format liked by the backoffice Web interface.
  *
@@ -167,10 +187,74 @@ free_transfer_track_context (struct TrackTransferContext 
*rctx)
 json_t *
 transform_response (const json_t *result)
 {
-  json_t *response;
+  json_t *response = NULL;
+  json_t *value;
+  json_t *deposits;
+  size_t index;
+  const char *key;
+  struct GNUNET_HashCode h_key;
+  struct GNUNET_CONTAINER_MultiHashMap *map;
+  struct TALER_Amount iter_amount;
+  struct TALER_Amount *current_amount;
+
+  /* TODO/FIXME Free the values in hashmap! */
+
+  struct GNUNET_JSON_Specification spec[] = {
+    TALER_JSON_spec_amount ("amount_with_fee", &iter_amount),
+    GNUNET_JSON_spec_string ("h_proposal_data", &key),
+    GNUNET_JSON_spec_end ()
+  };
+  
+  map = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
+
+  json_array_foreach (deposits, index, value)
+  {
+
+    if (GNUNET_OK != GNUNET_JSON_parse (value,
+                                        spec,
+                                        NULL,
+                                        NULL))
+    {
+      GNUNET_break_op (0); 
+      return NULL;
+    }
+
+    GNUNET_CRYPTO_hash (key,
+                        strlen (key),
+                        &h_key);
+
+    if (NULL != (current_amount = GNUNET_CONTAINER_multihashmap_get (map, 
(const struct GNUNET_HashCode *) &h_key)))
+    {
+      if (GNUNET_SYSERR == TALER_amount_add (current_amount,
+                                             current_amount,
+                                             &iter_amount))
+        goto cleanup;
+    
+    }
+    else
+    {
+      current_amount = GNUNET_malloc (sizeof (struct TALER_Amount));
+      memcpy (current_amount, &iter_amount, sizeof (struct TALER_Amount));
+      if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (map,
+                                                              (const struct 
GNUNET_HashCode *) &h_key,
+                                                              current_amount,
+                                                              
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+        goto cleanup;
+    }
+       
+  }
 
-  response = json_object ();
-  return response;
+  GNUNET_CONTAINER_multihashmap_destroy (map);
+  /*TODO fill up response */
+  goto cleanup;
+
+  cleanup:
+    GNUNET_CONTAINER_multihashmap_iterate (map,
+                                           &hashmap_free,
+                                           NULL);  
+    GNUNET_JSON_parse_free (spec);
+    GNUNET_CONTAINER_multihashmap_destroy (map);
+    return response;
 }
 
 /**

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



reply via email to

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