gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-exchange] branch master updated (b3cbe010 -> 30903b9


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated (b3cbe010 -> 30903b93)
Date: Tue, 18 Jun 2019 13:20:45 +0200

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

grothoff pushed a change to branch master
in repository exchange.

    from b3cbe010 fix NPE
     new 6066ffcb dead code elimination
     new 30903b93 reduce code duplication

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/exchange/taler-exchange-aggregator.c           | 10 ++--
 src/exchange/taler-exchange-httpd_keystate.c       | 28 ------------
 src/exchange/taler-exchange-httpd_keystate.h       | 16 -------
 src/exchange/taler-exchange-httpd_payback.c        | 18 ++++----
 src/exchange/taler-exchange-httpd_refresh_reveal.c | 25 ++++++----
 src/exchange/taler-exchange-httpd_responses.c      | 32 ++-----------
 src/exchange/taler-exchange-httpd_responses.h      | 25 +++-------
 src/exchange/test_taler_exchange_aggregator.c      |  2 +-
 src/exchange/test_taler_exchange_wirewatch.c       |  2 +-
 src/lib/exchange_api_common.c                      |  2 +-
 src/lib/testing_api_cmd_refresh.c                  |  7 +--
 .../testing_auditor_api_cmd_deposit_confirmation.c | 18 +++++++-
 src/util/amount.c                                  | 53 ++++++++++++++--------
 13 files changed, 98 insertions(+), 140 deletions(-)

diff --git a/src/exchange/taler-exchange-aggregator.c 
b/src/exchange/taler-exchange-aggregator.c
index fda0ad50..9b1c7e3e 100644
--- a/src/exchange/taler-exchange-aggregator.c
+++ b/src/exchange/taler-exchange-aggregator.c
@@ -620,19 +620,19 @@ refund_by_coin_cb (void *cls,
                   const struct TALER_Amount *amount_with_fee,
                   const struct TALER_Amount *refund_fee)
 {
-  struct AggregationUnit *au = cls;
+  struct AggregationUnit *aux = cls;
 
   /* TODO: potential optimization: include these conditions
      in the SELECT! */
   if (0 != GNUNET_memcmp (merchant_pub,
-                          &au->merchant_pub))
+                          &aux->merchant_pub))
     return GNUNET_OK; /* different merchant */
   if (0 != GNUNET_memcmp (h_contract,
-                          au->h_contract))
+                          aux->h_contract))
     return GNUNET_OK; /* different contract */
   if (GNUNET_OK !=
-      TALER_amount_subtract (&au->total_amount,
-                            &au->total_amount,
+      TALER_amount_subtract (&aux->total_amount,
+                            &aux->total_amount,
                             amount_with_fee))
   {
     GNUNET_break (0);
diff --git a/src/exchange/taler-exchange-httpd_keystate.c 
b/src/exchange/taler-exchange-httpd_keystate.c
index 7d6bb08a..6134faf3 100644
--- a/src/exchange/taler-exchange-httpd_keystate.c
+++ b/src/exchange/taler-exchange-httpd_keystate.c
@@ -1846,34 +1846,6 @@ TEH_KS_acquire_ (struct GNUNET_TIME_Absolute now,
 
 
 /**
- * Look up the issue for a denom public key.
- *
- * @param key_state state to look in
- * @param denom_pub denomination public key
- * @param use purpose for which the key is being located
- * @return the denomination key issue,
- *         or NULL if denom_pub could not be found
- */
-struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *
-TEH_KS_denomination_key_lookup (const struct TEH_KS_StateHandle *key_state,
-                                const struct TALER_DenominationPublicKey 
*denom_pub,
-                               enum TEH_KS_DenominationKeyUse use)
-{
-  struct GNUNET_HashCode hc;
-
-  GNUNET_CRYPTO_rsa_public_key_hash (denom_pub->rsa_public_key,
-                                     &hc);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Looking for denom: '%s..'\n",
-              TALER_B2S (&hc));
-
-  return TEH_KS_denomination_key_lookup_by_hash (key_state,
-                                                 &hc,
-                                                 use);
-}
-
-
-/**
  * Look up the issue for a denom public key.  Note that the result
  * is only valid while the @a key_state is not released!
  *
diff --git a/src/exchange/taler-exchange-httpd_keystate.h 
b/src/exchange/taler-exchange-httpd_keystate.h
index c9b98230..e197e7ac 100644
--- a/src/exchange/taler-exchange-httpd_keystate.h
+++ b/src/exchange/taler-exchange-httpd_keystate.h
@@ -119,22 +119,6 @@ enum TEH_KS_DenominationKeyUse {
  * is only valid while the @a key_state is not released!
  *
  * @param key_state state to look in
- * @param denom_pub denomination public key
- * @param use purpose for which the key is being located
- * @return the denomination key issue,
- *         or NULL if denom_pub could not be found (or is not valid at this 
time for the given @a use)
- */
-struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *
-TEH_KS_denomination_key_lookup (const struct TEH_KS_StateHandle *key_state,
-                                const struct TALER_DenominationPublicKey 
*denom_pub,
-                                enum TEH_KS_DenominationKeyUse use);
-
-
-/**
- * Look up the issue for a denom public key.  Note that the result
- * is only valid while the @a key_state is not released!
- *
- * @param key_state state to look in
  * @param denom_pub_hash hash of denomination public key
  * @param use purpose for which the key is being located
  * @return the denomination key issue,
diff --git a/src/exchange/taler-exchange-httpd_payback.c 
b/src/exchange/taler-exchange-httpd_payback.c
index 06181519..643b9fba 100644
--- a/src/exchange/taler-exchange-httpd_payback.c
+++ b/src/exchange/taler-exchange-httpd_payback.c
@@ -315,7 +315,6 @@ verify_and_execute_payback (struct MHD_Connection 
*connection,
   struct GNUNET_HashCode c_hash;
   char *coin_ev;
   size_t coin_ev_size;
-  int mhd_ret;
 
   /* check denomination exists and is in payback mode */
   key_state = TEH_KS_acquire (GNUNET_TIME_absolute_get ());
@@ -414,14 +413,17 @@ verify_and_execute_payback (struct MHD_Connection 
*connection,
   pc.coin_sig = coin_sig;
   pc.coin_bks = coin_bks;
   pc.coin = coin;
-  if (GNUNET_OK !=
-      TEH_DB_run_transaction (connection,
-                              "run payback",
-                             &mhd_ret,
-                             &payback_transaction,
-                             &pc))
-    return mhd_ret;
+  {
+    int mhd_ret;
 
+    if (GNUNET_OK !=
+        TEH_DB_run_transaction (connection,
+                                "run payback",
+                                &mhd_ret,
+                                &payback_transaction,
+                                &pc))
+      return mhd_ret;
+  }
   return reply_payback_success (connection,
                                &coin->coin_pub,
                                &pc.reserve_pub,
diff --git a/src/exchange/taler-exchange-httpd_refresh_reveal.c 
b/src/exchange/taler-exchange-httpd_refresh_reveal.c
index 0aee1982..6fc8d1c5 100644
--- a/src/exchange/taler-exchange-httpd_refresh_reveal.c
+++ b/src/exchange/taler-exchange-httpd_refresh_reveal.c
@@ -57,8 +57,6 @@ reply_refresh_reveal_success (struct MHD_Connection 
*connection,
                              unsigned int num_newcoins,
                              const struct TALER_DenominationSignature *sigs)
 {
-  json_t *root;
-  json_t *obj;
   json_t *list;
   int ret;
 
@@ -67,6 +65,8 @@ reply_refresh_reveal_success (struct MHD_Connection 
*connection,
        newcoin_index < num_newcoins;
        newcoin_index++)
   {
+    json_t *obj;
+
     obj = json_object ();
     json_object_set_new (obj,
                         "ev_sig",
@@ -75,14 +75,19 @@ reply_refresh_reveal_success (struct MHD_Connection 
*connection,
                    json_array_append_new (list,
                                           obj));
   }
-  root = json_object ();
-  json_object_set_new (root,
-                       "ev_sigs",
-                       list);
-  ret = TEH_RESPONSE_reply_json (connection,
-                                 root,
-                                 MHD_HTTP_OK);
-  json_decref (root);
+
+  {
+    json_t *root;
+
+    root = json_object ();
+    json_object_set_new (root,
+                         "ev_sigs",
+                         list);
+    ret = TEH_RESPONSE_reply_json (connection,
+                                   root,
+                                   MHD_HTTP_OK);
+    json_decref (root);
+  }
   return ret;
 }
 
diff --git a/src/exchange/taler-exchange-httpd_responses.c 
b/src/exchange/taler-exchange-httpd_responses.c
index 234a0107..8b242096 100644
--- a/src/exchange/taler-exchange-httpd_responses.c
+++ b/src/exchange/taler-exchange-httpd_responses.c
@@ -319,41 +319,19 @@ TEH_RESPONSE_reply_signature_invalid (struct 
MHD_Connection *connection,
  */
 int
 TEH_RESPONSE_reply_arg_missing (struct MHD_Connection *connection,
-                               enum TALER_ErrorCode ec,
+                                enum TALER_ErrorCode ec,
                                 const char *param_name)
 {
   return TEH_RESPONSE_reply_json_pack (connection,
                                        MHD_HTTP_BAD_REQUEST,
                                        "{s:s, s:I, s:s}",
                                        "error", "missing parameter",
-                                      "code", (json_int_t) ec,
+                                       "code", (json_int_t) ec,
                                        "parameter", param_name);
 }
 
 
 /**
- * Send a response indicating permission denied.
- *
- * @param connection the MHD connection to use
- * @param ec error code uniquely identifying the error
- * @param hint hint about why access was denied
- * @return a MHD result code
- */
-int
-TEH_RESPONSE_reply_permission_denied (struct MHD_Connection *connection,
-                                     enum TALER_ErrorCode ec,
-                                      const char *hint)
-{
-  return TEH_RESPONSE_reply_json_pack (connection,
-                                       MHD_HTTP_FORBIDDEN,
-                                       "{s:s, s:I, s:s}",
-                                       "error", "permission denied",
-                                      "code", (json_int_t) ec,
-                                       "hint", hint);
-}
-
-
-/**
  * Send a response indicating an internal error.
  *
  * @param connection the MHD connection to use
@@ -363,14 +341,14 @@ TEH_RESPONSE_reply_permission_denied (struct 
MHD_Connection *connection,
  */
 int
 TEH_RESPONSE_reply_internal_error (struct MHD_Connection *connection,
-                                  enum TALER_ErrorCode ec,
+                                   enum TALER_ErrorCode ec,
                                    const char *hint)
 {
   return TEH_RESPONSE_reply_json_pack (connection,
                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
                                        "{s:s, s:I, s:s}",
                                        "error", "internal error",
-                                      "code", (json_int_t) ec,
+                                       "code", (json_int_t) ec,
                                        "hint", hint);
 }
 
@@ -385,7 +363,7 @@ TEH_RESPONSE_reply_internal_error (struct MHD_Connection 
*connection,
  */
 int
 TEH_RESPONSE_reply_external_error (struct MHD_Connection *connection,
-                                  enum TALER_ErrorCode ec,
+                                   enum TALER_ErrorCode ec,
                                    const char *hint)
 {
   return TEH_RESPONSE_reply_json_pack (connection,
diff --git a/src/exchange/taler-exchange-httpd_responses.h 
b/src/exchange/taler-exchange-httpd_responses.h
index 1e504fd6..9b127156 100644
--- a/src/exchange/taler-exchange-httpd_responses.h
+++ b/src/exchange/taler-exchange-httpd_responses.h
@@ -152,25 +152,11 @@ TEH_RESPONSE_reply_arg_unknown (struct MHD_Connection 
*connection,
  */
 int
 TEH_RESPONSE_reply_arg_missing (struct MHD_Connection *connection,
-                               enum TALER_ErrorCode ec,
+                                enum TALER_ErrorCode ec,
                                 const char *param_name);
 
 
 /**
- * Send a response indicating permission denied.
- *
- * @param connection the MHD connection to use
- * @param ec error code uniquely identifying the error
- * @param hint hint about why access was denied
- * @return a MHD result code
- */
-int
-TEH_RESPONSE_reply_permission_denied (struct MHD_Connection *connection,
-                                     enum TALER_ErrorCode ec,
-                                      const char *hint);
-
-
-/**
  * Send a response indicating an internal error.
  *
  * @param connection the MHD connection to use
@@ -180,7 +166,7 @@ TEH_RESPONSE_reply_permission_denied (struct MHD_Connection 
*connection,
  */
 int
 TEH_RESPONSE_reply_internal_error (struct MHD_Connection *connection,
-                                  enum TALER_ErrorCode ec,
+                                   enum TALER_ErrorCode ec,
                                    const char *hint);
 
 
@@ -194,7 +180,7 @@ TEH_RESPONSE_reply_internal_error (struct MHD_Connection 
*connection,
  */
 int
 TEH_RESPONSE_reply_external_error (struct MHD_Connection *connection,
-                                  enum TALER_ErrorCode ec,
+                                   enum TALER_ErrorCode ec,
                                    const char *hint);
 
 
@@ -208,7 +194,8 @@ TEH_RESPONSE_reply_external_error (struct MHD_Connection 
*connection,
  */
 int
 TEH_RESPONSE_reply_commit_error (struct MHD_Connection *connection,
-                                     enum TALER_ErrorCode ec);
+                                 enum TALER_ErrorCode ec);
+
 
 /**
  * Send a response indicating a failure to talk to the Exchange's
@@ -220,7 +207,7 @@ TEH_RESPONSE_reply_commit_error (struct MHD_Connection 
*connection,
  */
 int
 TEH_RESPONSE_reply_internal_db_error (struct MHD_Connection *connection,
-                                     enum TALER_ErrorCode ec);
+                                      enum TALER_ErrorCode ec);
 
 
 /**
diff --git a/src/exchange/test_taler_exchange_aggregator.c 
b/src/exchange/test_taler_exchange_aggregator.c
index c0d3d912..b02c976a 100644
--- a/src/exchange/test_taler_exchange_aggregator.c
+++ b/src/exchange/test_taler_exchange_aggregator.c
@@ -1277,7 +1277,7 @@ main (int argc,
   {
     fprintf (stderr,
              "Required port %u not available, skipping.\n",
-            8082);
+             (unsigned int) 8082);
     return 77;
   }
   cfg = GNUNET_CONFIGURATION_create ();
diff --git a/src/exchange/test_taler_exchange_wirewatch.c 
b/src/exchange/test_taler_exchange_wirewatch.c
index 8c1210da..4a23bdb5 100644
--- a/src/exchange/test_taler_exchange_wirewatch.c
+++ b/src/exchange/test_taler_exchange_wirewatch.c
@@ -815,7 +815,7 @@ main (int argc,
   {
     fprintf (stderr,
              "Required port %u not available, skipping.\n",
-            8082);
+             (unsigned int) 8082);
     return 77;
   }
   cfg = GNUNET_CONFIGURATION_create ();
diff --git a/src/lib/exchange_api_common.c b/src/lib/exchange_api_common.c
index a9c6e16c..72eb9ace 100644
--- a/src/lib/exchange_api_common.c
+++ b/src/lib/exchange_api_common.c
@@ -42,7 +42,6 @@ TALER_EXCHANGE_verify_coin_history (const char *currency,
                                     struct TALER_Amount *total)
 {
   size_t len;
-  int add;
   struct TALER_Amount rtotal;
 
   if (NULL == history)
@@ -64,6 +63,7 @@ TALER_EXCHANGE_verify_coin_history (const char *currency,
                                         &rtotal));
   for (size_t off=0;off<len;off++)
   {
+    int add;
     json_t *transaction;
     struct TALER_Amount amount;
     const char *type;
diff --git a/src/lib/testing_api_cmd_refresh.c 
b/src/lib/testing_api_cmd_refresh.c
index ec885581..d0b589b1 100644
--- a/src/lib/testing_api_cmd_refresh.c
+++ b/src/lib/testing_api_cmd_refresh.c
@@ -873,12 +873,10 @@ refresh_melt_run (void *cls,
 {
   struct RefreshMeltState *rms = cls;
   unsigned int num_fresh_coins;
-  const struct TALER_TESTING_Command *coin_command;
   /* FIXME:  this should be dynamic */
   const char *melt_fresh_amounts[] = {
     "EUR:1", "EUR:1", "EUR:1", "EUR:0.1",
     NULL};
-  const struct TALER_EXCHANGE_DenomPublicKey *fresh_pk;
 
   rms->is = is;
   rms->noreveal_index = UINT16_MAX;
@@ -895,8 +893,9 @@ refresh_melt_run (void *cls,
     struct TALER_Amount fresh_amount;
     const struct TALER_DenominationSignature *melt_sig;
     const struct TALER_EXCHANGE_DenomPublicKey *melt_denom_pub;
-
+    const struct TALER_TESTING_Command *coin_command;
     const struct MeltDetails *md = &rms->melted_coin;
+
     if (NULL == (coin_command
       = TALER_TESTING_interpreter_lookup_command
         (is, md->coin_reference)))
@@ -945,6 +944,8 @@ refresh_melt_run (void *cls,
 
     for (unsigned int i=0;i<num_fresh_coins;i++)
     {
+      const struct TALER_EXCHANGE_DenomPublicKey *fresh_pk;
+
       if (GNUNET_OK != TALER_string_to_amount
         (melt_fresh_amounts[i], &fresh_amount))
       {
diff --git a/src/lib/testing_auditor_api_cmd_deposit_confirmation.c 
b/src/lib/testing_auditor_api_cmd_deposit_confirmation.c
index 70fd01e1..95871ef1 100644
--- a/src/lib/testing_auditor_api_cmd_deposit_confirmation.c
+++ b/src/lib/testing_auditor_api_cmd_deposit_confirmation.c
@@ -263,7 +263,23 @@ deposit_confirmation_run (void *cls,
   GNUNET_assert (GNUNET_OK ==
                  TALER_string_to_amount (dcs->amount_without_fee,
                                          &amount_without_fee));
-
+  {
+    struct GNUNET_JSON_Specification spec[] = {
+      GNUNET_JSON_spec_absolute_time ("timestamp", &timestamp),
+      GNUNET_JSON_spec_absolute_time ("refund_deadline", &refund_deadline),
+      GNUNET_JSON_spec_end()
+    };
+
+    if (GNUNET_OK !=
+        GNUNET_JSON_parse (contract_terms,
+                           spec,
+                           NULL, NULL))
+    {
+      GNUNET_break (0);
+      TALER_TESTING_interpreter_fail (is);
+      return;
+    }
+  }
   dcs->dc = TALER_AUDITOR_deposit_confirmation
     (dcs->auditor,
      &h_wire,
diff --git a/src/util/amount.c b/src/util/amount.c
index b3e9b54e..ac6be27d 100644
--- a/src/util/amount.c
+++ b/src/util/amount.c
@@ -539,6 +539,29 @@ TALER_amount_normalize (struct TALER_Amount *amount)
 
 
 /**
+ * Convert the fraction of @a amount to a string
+ * in decimals.
+ *
+ * @param amount value to convert
+ * @param tail[out] where to write the reesult
+ */
+static void
+amount_to_tail (const struct TALER_Amount *amount,
+                char tail[TALER_AMOUNT_FRAC_LEN + 1])
+{
+  uint32_t n = amount->fraction;
+  unsigned int i;
+
+  for (i = 0; (i < TALER_AMOUNT_FRAC_LEN) && (0 != n); i++)
+  {
+    tail[i] = '0' + (n / (TALER_AMOUNT_FRAC_BASE / 10));
+    n = (n * 10) % (TALER_AMOUNT_FRAC_BASE);
+  }
+  tail[i] = '\0';
+}
+
+
+/**
  * Convert amount to string.
  *
  * @param amount amount to convert to string
@@ -548,9 +571,6 @@ char *
 TALER_amount_to_string (const struct TALER_Amount *amount)
 {
   char *result;
-  unsigned int i;
-  uint32_t n;
-  char tail[TALER_AMOUNT_FRAC_LEN + 1];
   struct TALER_Amount norm;
 
   if (GNUNET_YES != TALER_amount_is_valid (amount))
@@ -558,14 +578,12 @@ TALER_amount_to_string (const struct TALER_Amount *amount)
   norm = *amount;
   GNUNET_break (GNUNET_SYSERR !=
                 TALER_amount_normalize (&norm));
-  if (0 != (n = norm.fraction))
+  if (0 != norm.fraction)
   {
-    for (i = 0; (i < TALER_AMOUNT_FRAC_LEN) && (0 != n); i++)
-    {
-      tail[i] = '0' + (n / (TALER_AMOUNT_FRAC_BASE / 10));
-      n = (n * 10) % (TALER_AMOUNT_FRAC_BASE);
-    }
-    tail[i] = '\0';
+    char tail[TALER_AMOUNT_FRAC_LEN + 1];
+
+    amount_to_tail (&norm,
+                    tail);
     GNUNET_asprintf (&result,
                      "%s:%llu.%s",
                      norm.currency,
@@ -594,9 +612,6 @@ const char *
 TALER_amount2s (const struct TALER_Amount *amount)
 {
   static char result[TALER_AMOUNT_FRAC_LEN + TALER_CURRENCY_LEN + 3 + 12];
-  unsigned int i;
-  uint32_t n;
-  char tail[TALER_AMOUNT_FRAC_LEN + 1];
   struct TALER_Amount norm;
 
   if (GNUNET_YES != TALER_amount_is_valid (amount))
@@ -604,14 +619,12 @@ TALER_amount2s (const struct TALER_Amount *amount)
   norm = *amount;
   GNUNET_break (GNUNET_SYSERR !=
                 TALER_amount_normalize (&norm));
-  if (0 != (n = norm.fraction))
+  if (0 != norm.fraction)
   {
-    for (i = 0; (i < TALER_AMOUNT_FRAC_LEN) && (0 != n); i++)
-    {
-      tail[i] = '0' + (n / (TALER_AMOUNT_FRAC_BASE / 10));
-      n = (n * 10) % (TALER_AMOUNT_FRAC_BASE);
-    }
-    tail[i] = '\0';
+    char tail[TALER_AMOUNT_FRAC_LEN + 1];
+
+    amount_to_tail (&norm,
+                    tail);
     GNUNET_snprintf (result,
                      sizeof (result),
                      "%s:%llu.%s",

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



reply via email to

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