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: fix testcase, refun


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated: fix testcase, refund array is boxed in a refund_permissions field of the main object
Date: Sat, 02 Sep 2017 14:39:03 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 037be4b  fix testcase, refund array is boxed in a refund_permissions 
field of the main object
037be4b is described below

commit 037be4be58f2348ab39807eaf1f41bd6736d179b
Author: Christian Grothoff <address@hidden>
AuthorDate: Sat Sep 2 14:39:00 2017 +0200

    fix testcase, refund array is boxed in a refund_permissions field of the 
main object
---
 src/backend/taler-merchant-httpd_exchanges.c | 33 +++++++++++-
 src/backend/taler-merchant-httpd_pay.c       | 15 ++++--
 src/backend/taler-merchant-httpd_refund.c    | 34 +++++++-----
 src/backenddb/plugin_merchantdb_postgres.c   | 70 +++++++++++++------------
 src/lib/test_merchant_api.c                  | 77 +++++++++++++++-------------
 5 files changed, 139 insertions(+), 90 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_exchanges.c 
b/src/backend/taler-merchant-httpd_exchanges.c
index c4df9ea..f53e63e 100644
--- a/src/backend/taler-merchant-httpd_exchanges.c
+++ b/src/backend/taler-merchant-httpd_exchanges.c
@@ -314,7 +314,7 @@ process_wire_fees (void *cls,
   struct TALER_EXCHANGE_WireAggregateFees *af;
   const struct TALER_EXCHANGE_Keys *keys;
   const struct TALER_MasterPublicKeyP *master_pub;
-  
+
   keys = TALER_EXCHANGE_get_keys (exchange->conn);
   GNUNET_assert (NULL != keys);
   master_pub = &keys->master_pub;
@@ -348,7 +348,7 @@ process_wire_fees (void *cls,
   {
     struct GNUNET_HashCode h_wire_method;
     enum GNUNET_DB_QueryStatus qs;
-    
+
     af = GNUNET_new (struct TALER_EXCHANGE_WireAggregateFees);
     *af = *fees;
     GNUNET_CRYPTO_hash (wire_method,
@@ -360,6 +360,14 @@ process_wire_fees (void *cls,
                wire_method,
                GNUNET_STRINGS_absolute_time_to_string (af->start_date),
                TALER_amount2s (&af->wire_fee));
+    if (GNUNET_OK !=
+        db->start (db->cls))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 "Failed to start database transaction!\n");
+      GNUNET_free (af);
+      break;
+    }
     qs = db->store_wire_fee_by_exchange (db->cls,
                                         master_pub,
                                         &h_wire_method,
@@ -374,8 +382,29 @@ process_wire_fees (void *cls,
                  "Failed to persist exchange wire fees in merchant DB!\n");
       GNUNET_free (af);
       fees = fees->next;
+      db->rollback (db->cls);
       continue;
     }
+    if (0 == qs)
+    {
+      /* Entry was already in DB, fine, continue as if we succeeded */
+      db->rollback (db->cls);
+      fees = fees->next;
+    }
+    if (0 < qs)
+    {
+      /* Inserted into DB, make sure transaction completes */
+      qs = db->commit (db->cls);
+      if (0 > qs)
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "Failed to persist exchange wire fees in merchant DB!\n");
+        GNUNET_free (af);
+        fees = fees->next;
+        continue;
+      }
+    }
+
     af->next = NULL;
     if (NULL == endp)
       f->af = af;
diff --git a/src/backend/taler-merchant-httpd_pay.c 
b/src/backend/taler-merchant-httpd_pay.c
index 93e76d1..f32d448 100644
--- a/src/backend/taler-merchant-httpd_pay.c
+++ b/src/backend/taler-merchant-httpd_pay.c
@@ -497,8 +497,9 @@ deposit_cb (void *cls,
   }
   /* store result to DB */
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Storing successful payment for h_contract_terms '%s'\n",
-              GNUNET_h2s (&pc->h_contract_terms));
+              "Storing successful payment for h_contract_terms `%s' and 
merchant `%s'\n",
+              GNUNET_h2s (&pc->h_contract_terms),
+              TALER_B2S (&pc->mi->pubkey));
   for (unsigned int i=0;i<MAX_RETRIES;i++)
   {
     qs = db->store_deposit (db->cls,
@@ -1389,6 +1390,8 @@ handler_pay_json (struct MHD_Connection *connection,
     return ret;
   }
   /* Check if transaction is already known, if not store it. */
+  /* FIXME: What if transaction exists, with a failed payment at
+     a different exchange? */
   qs = db->find_transaction (db->cls,
                             &pc->h_contract_terms,
                             &pc->mi->pubkey,
@@ -1417,7 +1420,7 @@ handler_pay_json (struct MHD_Connection *connection,
     struct GNUNET_TIME_Absolute now;
 
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Dealing with new transaction '%s'\n",
+                "Dealing with new transaction `%s'\n",
                 GNUNET_h2s (&pc->h_contract_terms));
 
     now = GNUNET_TIME_absolute_get ();
@@ -1428,7 +1431,7 @@ handler_pay_json (struct MHD_Connection *connection,
 
       pd_str = GNUNET_STRINGS_absolute_time_to_string (pc->pay_deadline);
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  "Attempt to get coins for expired contract. Deadline: 
'%s'\n",
+                  "Attempt to pay coins for expired contract. Deadline: 
`%s'\n",
                  pd_str);
       return TMH_RESPONSE_reply_bad_request (connection,
                                             TALER_EC_PAY_OFFER_EXPIRED,
@@ -1483,6 +1486,10 @@ handler_pay_json (struct MHD_Connection *connection,
                                                "Merchant database error: 
failed to store transaction");
     }
   }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Found transaction data for proposal `%s' of merchant `%s'\n",
+              GNUNET_h2s (&pc->h_contract_terms),
+              TALER_B2S (&pc->mi->pubkey));
 
   MHD_suspend_connection (connection);
   pc->suspended = GNUNET_YES;
diff --git a/src/backend/taler-merchant-httpd_refund.c 
b/src/backend/taler-merchant-httpd_refund.c
index d45890a..fc9e7a2 100644
--- a/src/backend/taler-merchant-httpd_refund.c
+++ b/src/backend/taler-merchant-httpd_refund.c
@@ -127,7 +127,7 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh,
     GNUNET_JSON_spec_string ("reason", &reason),
     GNUNET_JSON_spec_string ("instance", &merchant),
     GNUNET_JSON_spec_end ()
-  }; 
+  };
   enum GNUNET_DB_QueryStatus qs;
 
   if (NULL == *connection_cls)
@@ -179,7 +179,7 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh,
                                          TALER_EC_REFUND_INSTANCE_UNKNOWN,
                                         "Unknown instance given");
   }
-  
+
   /* Convert order id to h_contract_terms */
   qs = db->find_contract_terms (db->cls,
                                &contract_terms,
@@ -198,7 +198,7 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh,
   }
   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Unknown order id given: %s\n",
                 order_id);
     return TMH_RESPONSE_reply_not_found (connection,
@@ -276,10 +276,10 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh,
     return TMH_RESPONSE_reply_internal_error (connection,
                                               TALER_EC_NONE,
                                               "Refund done, but failed to sign 
confirmation");
-  
+
   }
 
-  return TMH_RESPONSE_reply_json_pack (connection, 
+  return TMH_RESPONSE_reply_json_pack (connection,
                                        MHD_HTTP_OK,
                                        "{s:o}",
                                        "sig", GNUNET_JSON_from_data_auto 
(&sig));
@@ -310,6 +310,11 @@ process_refunds_cb (void *cls,
   struct GNUNET_CRYPTO_EddsaSignature sig;
   json_t *element;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Found refund of %s for coin %s with reason `%s' in database\n",
+              TALER_B2S (coin_pub),
+              TALER_amount2s (refund_amount),
+              reason);
   rr.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_REFUND);
   rr.purpose.size = htonl (sizeof (struct TALER_RefundRequestPS));
   rr.h_contract_terms = *prd->h_contract_terms;
@@ -354,10 +359,11 @@ process_refunds_cb (void *cls,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Could not append a response's element\n");
     prd->ec = TALER_EC_PARSER_OUT_OF_MEMORY;
-    return; 
+    return;
   }
 }
 
+
 /**
  * Return refund situation about a contract.
  *
@@ -411,8 +417,8 @@ MH_handler_refund_lookup (struct TMH_RequestHandler *rh,
                                           MHD_GET_ARGUMENT_KIND,
                                           "order_id");
   if (NULL == order_id)
-  { 
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Argument 'order_id' not given\n");
     return TMH_RESPONSE_reply_arg_missing (connection,
                                           TALER_EC_PARAMETER_MISSING,
@@ -438,7 +444,7 @@ MH_handler_refund_lookup (struct TMH_RequestHandler *rh,
 
   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Unknown order id given: %s\n",
                 order_id);
     return TMH_RESPONSE_reply_not_found (connection,
@@ -461,7 +467,7 @@ MH_handler_refund_lookup (struct TMH_RequestHandler *rh,
   prd.merchant = mi;
   prd.ec = TALER_EC_NONE;
   for (unsigned int i=0;i<MAX_RETRIES;i++)
-  {  
+  {
     qs = db->get_refunds_from_contract_terms_hash (db->cls,
                                                   &mi->pubkey,
                                                   &h_contract_terms,
@@ -472,8 +478,8 @@ MH_handler_refund_lookup (struct TMH_RequestHandler *rh,
   }
   if (0 > qs)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
-                "database hard error on order_id lookup: %s\n",
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Database hard error on order_id lookup: %s\n",
                 order_id);
     json_decref (prd.response);
     return TMH_RESPONSE_reply_internal_error (connection,
@@ -487,10 +493,10 @@ MH_handler_refund_lookup (struct TMH_RequestHandler *rh,
     /* NOTE: error already logged by the callback */
     return TMH_RESPONSE_reply_internal_error (connection,
                                               prd.ec,
-                                              "Could not generate a 
response"); 
+                                              "Could not generate a response");
   }
 
-  return TMH_RESPONSE_reply_json_pack (connection, 
+  return TMH_RESPONSE_reply_json_pack (connection,
                                        MHD_HTTP_OK,
                                        "{s:o}",
                                        "refund_permissions", prd.response);
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index cb47519..c5cfa06 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -60,12 +60,12 @@ postgres_drop_tables (void *cls)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_ExecuteStatement es[] = {
-    GNUNET_PQ_make_try_execute ("DROP TABLE merchant_transfers;"),
-    GNUNET_PQ_make_try_execute ("DROP TABLE merchant_deposits;"),
-    GNUNET_PQ_make_try_execute ("DROP TABLE merchant_transactions;"),
-    GNUNET_PQ_make_try_execute ("DROP TABLE merchant_proofs;"),
-    GNUNET_PQ_make_try_execute ("DROP TABLE merchant_contract_terms;"),
-    GNUNET_PQ_make_try_execute ("DROP TABLE merchant_refunds;"),
+    GNUNET_PQ_make_try_execute ("DROP TABLE IF EXISTS merchant_transfers 
CASCADE;"),
+    GNUNET_PQ_make_try_execute ("DROP TABLE IF EXISTS merchant_deposits 
CASCADE;"),
+    GNUNET_PQ_make_try_execute ("DROP TABLE IF EXISTS merchant_transactions 
CASCADE;"),
+    GNUNET_PQ_make_try_execute ("DROP TABLE IF EXISTS merchant_proofs 
CASCADE;"),
+    GNUNET_PQ_make_try_execute ("DROP TABLE IF EXISTS merchant_contract_terms 
CASCADE;"),
+    GNUNET_PQ_make_try_execute ("DROP TABLE IF EXISTS merchant_refunds 
CASCADE;"),
     GNUNET_PQ_EXECUTE_STATEMENT_END
   };
 
@@ -85,32 +85,21 @@ postgres_initialize (void *cls)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_ExecuteStatement es[] = {
+    /* Offers we made to customers */
     GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS 
merchant_contract_terms ("
                             "order_id VARCHAR NOT NULL"
-                            ",merchant_pub BYTEA NOT NULL"
+                            ",merchant_pub BYTEA NOT NULL CHECK 
(LENGTH(merchant_pub)=32)"
                             ",contract_terms BYTEA NOT NULL"
-                            ",h_contract_terms BYTEA NOT NULL"
+                            ",h_contract_terms BYTEA NOT NULL CHECK 
(LENGTH(h_contract_terms)=64)"
                             ",timestamp INT8 NOT NULL"
                             ",row_id BIGSERIAL UNIQUE"
-                            ",paid BYTEA NOT NULL "
+                            ",paid BYTEA NOT NULL " /* WHY is this a BYTEA!? 
Why does this EXIST!? */
                             ",PRIMARY KEY (order_id, merchant_pub)"
                            ",UNIQUE (h_contract_terms, merchant_pub)"
                             ");"),
-    GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS merchant_refunds ("
-                            " rtransaction_id BIGSERIAL UNIQUE"
-                            ",merchant_pub BYTEA NOT NULL CHECK 
(LENGTH(merchant_pub)=32)"
-                            ",h_contract_terms BYTEA NOT NULL"
-                            ",coin_pub BYTEA NOT NULL CHECK 
(LENGTH(coin_pub)=32)"
-                            ",reason VARCHAR NOT NULL"
-                            ",refund_amount_val INT8 NOT NULL"
-                            ",refund_amount_frac INT4 NOT NULL"
-                            ",refund_amount_curr VARCHAR(" 
TALER_CURRENCY_LEN_STR ") NOT NULL"
-                            ",refund_fee_val INT8 NOT NULL"
-                            ",refund_fee_frac INT4 NOT NULL"
-                            ",refund_fee_curr VARCHAR(" TALER_CURRENCY_LEN_STR 
") NOT NULL"
-                            ");"),
+    /* Contracts that were paid via some exchange (or attempted to be paid???) 
*/
     GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS merchant_transactions 
("
-                            " h_contract_terms BYTEA NOT NULL"
+                            " h_contract_terms BYTEA NOT NULL CHECK 
(LENGTH(h_contract_terms)=64)"
                             ",exchange_uri VARCHAR NOT NULL"
                             ",merchant_pub BYTEA NOT NULL CHECK 
(LENGTH(merchant_pub)=32)"
                             ",h_wire BYTEA NOT NULL CHECK (LENGTH(h_wire)=64)"
@@ -120,11 +109,12 @@ postgres_initialize (void *cls)
                             ",total_amount_frac INT4 NOT NULL"
                             ",total_amount_curr VARCHAR(" 
TALER_CURRENCY_LEN_STR ") NOT NULL"
                             ",PRIMARY KEY (h_contract_terms, merchant_pub)"
+                            ",FOREIGN KEY (h_contract_terms, merchant_pub) 
REFERENCES merchant_contract_terms (h_contract_terms, merchant_pub)"
                             ");"),
+    /* Table with the proofs for each coin we deposited at the exchange */
     GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS merchant_deposits ("
                             " h_contract_terms BYTEA NOT NULL"
                             ",merchant_pub BYTEA NOT NULL CHECK 
(LENGTH(merchant_pub)=32)"
-                            ",FOREIGN KEY (h_contract_terms, merchant_pub) 
REFERENCES merchant_transactions (h_contract_terms, merchant_pub)"
                             ",coin_pub BYTEA NOT NULL CHECK 
(LENGTH(coin_pub)=32)"
                             ",amount_with_fee_val INT8 NOT NULL"
                             ",amount_with_fee_frac INT4 NOT NULL"
@@ -138,6 +128,7 @@ postgres_initialize (void *cls)
                             ",signkey_pub BYTEA NOT NULL CHECK 
(LENGTH(signkey_pub)=32)"
                             ",exchange_proof BYTEA NOT NULL"
                             ",PRIMARY KEY (h_contract_terms, coin_pub)"
+                            ",FOREIGN KEY (h_contract_terms, merchant_pub) 
REFERENCES merchant_transactions (h_contract_terms, merchant_pub)"
                             ");"),
     GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS merchant_proofs ("
                             " exchange_uri VARCHAR NOT NULL"
@@ -174,6 +165,19 @@ postgres_initialize (void *cls)
                            ",exchange_sig BYTEA NOT NULL CHECK 
(length(exchange_sig)=64)"
                            ",PRIMARY KEY 
(exchange_pub,h_wire_method,start_date,end_date)"
                            ");"),
+    GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS merchant_refunds ("
+                            " rtransaction_id BIGSERIAL UNIQUE"
+                            ",merchant_pub BYTEA NOT NULL CHECK 
(LENGTH(merchant_pub)=32)"
+                            ",h_contract_terms BYTEA NOT NULL"
+                            ",coin_pub BYTEA NOT NULL CHECK 
(LENGTH(coin_pub)=32)"
+                            ",reason VARCHAR NOT NULL"
+                            ",refund_amount_val INT8 NOT NULL"
+                            ",refund_amount_frac INT4 NOT NULL"
+                            ",refund_amount_curr VARCHAR(" 
TALER_CURRENCY_LEN_STR ") NOT NULL"
+                            ",refund_fee_val INT8 NOT NULL"
+                            ",refund_fee_frac INT4 NOT NULL"
+                            ",refund_fee_curr VARCHAR(" TALER_CURRENCY_LEN_STR 
") NOT NULL"
+                            ");"),
     GNUNET_PQ_EXECUTE_STATEMENT_END
   };
   struct GNUNET_PQ_PreparedStatement ps[] = {
@@ -700,6 +704,7 @@ postgres_insert_contract_terms (void *cls,
                                             params);
 }
 
+
 /**
  * Mark contract terms as payed.  Needed by /history as only payed
  * contracts must be shown.  NOTE: we can't get the list of (payed)
@@ -715,12 +720,6 @@ postgres_mark_proposal_paid (void *cls,
 {
   unsigned int yes = GNUNET_YES;
   struct PostgresClosure *pg = cls;
-
-  TALER_LOG_DEBUG ("Marking proposal paid, h_contract_terms: '%s',"
-                   " merchant_pub: '%s'\n",
-                   GNUNET_h2s (h_contract_terms),
-                   TALER_B2S (merchant_pub));
-
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (&yes),
     GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
@@ -728,6 +727,10 @@ postgres_mark_proposal_paid (void *cls,
     GNUNET_PQ_query_param_end
   };
 
+  TALER_LOG_DEBUG ("Marking proposal paid, h_contract_terms: '%s',"
+                   " merchant_pub: '%s'\n",
+                   GNUNET_h2s (h_contract_terms),
+                   TALER_B2S (merchant_pub));
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
                                              "mark_proposal_paid",
                                              params);
@@ -820,11 +823,12 @@ postgres_store_deposit (void *cls,
   };
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "storing payment for h_contract_terms '%s'"
-              ", coin_pub: %s, amount_with_fee: %s, merchant_pub: %s\n",
+              "Storing payment for h_contract_terms `%s', coin_pub: `%s', 
amount_with_fee: %s\n",
               GNUNET_h2s (h_contract_terms),
               TALER_B2S (coin_pub),
-              TALER_amount_to_string (amount_with_fee),
+              TALER_amount_to_string (amount_with_fee));
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Merchant pub is `%s'\n",
               TALER_B2S (merchant_pub));
   check_connection (pg);
   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c
index fe7b7cd..10695b9 100644
--- a/src/lib/test_merchant_api.c
+++ b/src/lib/test_merchant_api.c
@@ -1182,7 +1182,7 @@ proposal_cb (void *cls,
     cmd->details.proposal.merchant_sig = *sig;
     cmd->details.proposal.hash = *hash;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Hashed proposal, '%s'\n",
+                "Hashed proposal is `%s'\n",
                 GNUNET_h2s (hash));
     break;
   default:
@@ -1277,7 +1277,9 @@ refund_lookup_cb (void *cls,
   struct TALER_Amount acc;
   const struct Command *increase;
   struct TALER_Amount refund_amount;
+  const json_t *arr;
 
+  cmd->details.refund_lookup.rlo = NULL;
   if (MHD_HTTP_OK != http_status)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1287,8 +1289,15 @@ refund_lookup_cb (void *cls,
   }
 
   map = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
-
-  json_array_foreach (obj, index, elem)
+  arr = json_object_get (obj,
+                         "refund_permissions");
+  if (NULL == arr)
+  {
+    GNUNET_break (0);
+    fail (is);
+    return;
+  }
+  json_array_foreach (arr, index, elem)
   {
     struct TALER_CoinSpendPublicKeyP coin_pub;
     struct TALER_Amount *irefund_amount
@@ -1307,7 +1316,6 @@ refund_lookup_cb (void *cls,
     GNUNET_CRYPTO_hash (&coin_pub,
                        sizeof (struct TALER_CoinSpendPublicKeyP),
                        &h_coin_pub);
-
     GNUNET_assert (GNUNET_OK ==
                   GNUNET_CONTAINER_multihashmap_put (map,
                                                      &h_coin_pub,
@@ -1315,16 +1323,16 @@ refund_lookup_cb (void *cls,
                                                      
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
   };
 
-  /* Retrieve coins used to pay, from OC_PAY command */
+  /* Retrieve coins used to pay, from #OC_PAY command */
   GNUNET_assert (NULL != (pay =
                          find_command (is,
                                        cmd->details.refund_lookup.pay_ref)));
   icoin_refs = GNUNET_strdup (pay->details.pay.coin_ref);
-  GNUNET_assert (NULL != (icoin_ref =
-                         strtok (icoin_refs, ";")));
   TALER_amount_get_zero ("EUR",
                         &acc);
-  do
+  for (icoin_ref = strtok (icoin_refs, ";");
+       NULL != icoin_ref;
+       icoin_ref = strtok (NULL, ";"))
   {
     GNUNET_assert (NULL != (icoin =
                            find_command (is,
@@ -1337,40 +1345,35 @@ refund_lookup_cb (void *cls,
     /* Can be NULL: not all coins are involved in refund */
     iamount = GNUNET_CONTAINER_multihashmap_get (map,
                                                 &h_icoin_pub);
-    if (NULL != iamount)
-      GNUNET_assert (GNUNET_OK ==
-                    TALER_amount_add (&acc,
-                                      &acc,
-                                      iamount));
-
-    icoin_ref = strtok (NULL, ";");
-    if (NULL == icoin_ref)
-      break;
-  } while (0);
+    if (NULL == iamount)
+      continue;
+    GNUNET_assert (GNUNET_OK ==
+                   TALER_amount_add (&acc,
+                                     &acc,
+                                     iamount));
+  }
 
-  /**
-   * Check if refund has been 100% covered
-   */
+  /* Check if refund has been 100% covered */
   GNUNET_assert (increase =
-    find_command (is, cmd->details.refund_lookup.increase_ref));
+                 find_command (is,
+                               cmd->details.refund_lookup.increase_ref));
   GNUNET_assert (GNUNET_OK ==
-    TALER_string_to_amount (increase->details.refund_increase.refund_amount,
-                            &refund_amount));
-
+                 TALER_string_to_amount 
(increase->details.refund_increase.refund_amount,
+                                         &refund_amount));
+  GNUNET_CONTAINER_multihashmap_iterate (map,
+                                         &hashmap_free,
+                                         NULL);
+  GNUNET_CONTAINER_multihashmap_destroy (map);
   if (0 != TALER_amount_cmp (&acc,
                              &refund_amount))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Incomplete refund: ex[ected '%s', got '%s'\n",
+                "Incomplete refund: expected '%s', got '%s'\n",
                 TALER_amount_to_string (&refund_amount),
                 TALER_amount_to_string (&acc));
     fail (is);
+    return;
   }
-
-  GNUNET_CONTAINER_multihashmap_iterate (map,
-                                         &hashmap_free,
-                                         NULL);
-  cmd->details.refund_lookup.rlo = NULL;
   next_command (is);
 }
 
@@ -2819,12 +2822,12 @@ main (int argc,
   unsetenv ("XDG_DATA_HOME");
   unsetenv ("XDG_CONFIG_HOME");
   GNUNET_log_setup ("test-merchant-api",
-                "DEBUG",
-                NULL);
+                    "DEBUG",
+                    NULL);
   cfg = GNUNET_CONFIGURATION_create ();
-  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load
-    (cfg,
-     "test_merchant_api.conf"));
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_CONFIGURATION_load (cfg,
+                                            "test_merchant_api.conf"));
   GNUNET_assert (GNUNET_OK ==
     GNUNET_CONFIGURATION_get_value_string (cfg,
                                            "merchant",
@@ -2942,7 +2945,7 @@ main (int argc,
     return 77;
   }
   /* give child time to start and bind against the socket */
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Waiting for taler-merchant-httpd to be ready\n");
   cnt = 0;
   do

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



reply via email to

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