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 (c927661 -> f7be081)


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated (c927661 -> f7be081)
Date: Tue, 12 Jun 2018 10:28:45 +0200

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

marcello pushed a change to branch master
in repository merchant.

    from c927661  Authentication>Authorization
     new f9f7a59  fetch currency from configuration
     new fcefedf  Allocating strings beforehand
     new f7be081  Dynamic currency at the generator.

The 3 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:
 .../taler-merchant-generate-payments_new.c         | 283 +++++++++++++++------
 1 file changed, 202 insertions(+), 81 deletions(-)

diff --git a/src/merchant-tools/taler-merchant-generate-payments_new.c 
b/src/merchant-tools/taler-merchant-generate-payments_new.c
index e59433f..b910d81 100644
--- a/src/merchant-tools/taler-merchant-generate-payments_new.c
+++ b/src/merchant-tools/taler-merchant-generate-payments_new.c
@@ -44,6 +44,7 @@
 #define MISSING_BANK_URL 4
 #define FAILED_TO_LAUNCH_BANK 5
 #define BAD_CLI_ARG 6
+#define BAD_CONFIG_FILE 7
 
 /* Hard-coded params.  Note, the bank is expected to
  * have the Tor user with account number 3 and password 'x'.
@@ -90,8 +91,14 @@ static unsigned int payments_number = 1;
 static unsigned int tracks_number = 1;
 
 
+/**
+ * Usually set as ~/.config/taler.net
+ */
 static const char *default_config_file;
 
+/**
+ * Log level used during the run.
+ */
 static char *loglev;
 
 /**
@@ -115,6 +122,119 @@ static char *logfile;
 static char *merchant_url;
 
 /**
+ * Currency used.
+ */
+static char *currency;
+
+/**
+ * Convenience macros to allocate all the currency-dependant
+ * strings;  note that the argument list of the macro is ignored.
+ * It is kept as a way to make the macro more auto-descriptive
+ * where it is called.
+ */
+
+#define ALLOCATE_AMOUNTS(...) \
+  GNUNET_asprintf (&CURRENCY_25_05, \
+                   "%s:25.05", \
+                   currency); \
+  GNUNET_asprintf (&CURRENCY_10, \
+                   "%s:10", \
+                   currency); \
+  GNUNET_asprintf (&CURRENCY_9_98, \
+                   "%s:9.98", \
+                   currency); \
+  GNUNET_asprintf (&CURRENCY_5, \
+                   "%s:5", \
+                   currency); \
+  GNUNET_asprintf (&CURRENCY_4_99, \
+                   "%s:4.99", \
+                   currency); \
+  GNUNET_asprintf (&CURRENCY_0_02, \
+                   "%s:0.02", \
+                   currency); \
+  GNUNET_asprintf (&CURRENCY_0_01, \
+                   "%s:0.01", \
+                   currency);
+
+#define ALLOCATE_ORDERS(...) \
+  GNUNET_asprintf \
+    (&order_worth_5, \
+     "{\"max_fee\":\
+       {\"currency\":\"%s\",\
+        \"value\":0,\
+        \"fraction\":50000000},\
+       \"refund_deadline\":\"\\/Date(0)\\/\",\
+       \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
+       \"amount\":\
+         {\"currency\":\"%s\",\
+          \"value\":5,\
+          \"fraction\":0},\
+        \"summary\": \"merchant-lib testcase\",\
+        \"fulfillment_url\": \"https://example.com/\",\
+        \"products\": [ {\"description\":\"ice cream\",\
+                         \"value\":\"{%s:5}\"} ] }", \
+     currency, \
+     currency, \
+     currency); \
+  GNUNET_asprintf \
+    (&order_worth_10_2coins, \
+     "{\"max_fee\":\
+       {\"currency\":\"%s\",\
+        \"value\":0,\
+        \"fraction\":50000000},\
+       \"refund_deadline\":\"\\/Date(0)\\/\",\
+       \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
+       \"amount\":\
+         {\"currency\":\"%s\",\
+          \"value\":10,\
+          \"fraction\":0},\
+        \"summary\": \"2-coins untracked payment\",\
+        \"fulfillment_url\": \"https://example.com/\",\
+        \"products\": [ {\"description\":\"2-coins payment\",\
+                         \"value\":\"{%s:10}\"} ] }", \
+     currency, \
+     currency, \
+     currency); \
+  GNUNET_asprintf \
+    (&order_worth_5_track, \
+     "{\"max_fee\":\
+       {\"currency\":\"%s\",\
+        \"value\":0,\
+        \"fraction\":50000000},\
+       \"refund_deadline\":\"\\/Date(0)\\/\",\
+       \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
+       \"amount\":\
+         {\"currency\":\"%s\",\
+          \"value\":5,\
+          \"fraction\":0},\
+        \"summary\": \"ice track cream!\",\
+        \"fulfillment_url\": \"https://example.com/\",\
+        \"products\": [ {\"description\":\"ice track cream\",\
+                         \"value\":\"{%s:5}\"} ] }", \
+     currency, \
+     currency, \
+     currency); \
+  GNUNET_asprintf \
+    (&order_worth_5_unaggregated, \
+     "{\"max_fee\":\
+       {\"currency\":\"%s\",\
+        \"value\":0,\
+        \"fraction\":50000000},\
+       \"refund_deadline\":\"\\/Date(0)\\/\",\
+       \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
+       \"amount\":\
+         {\"currency\":\"%s\",\
+          \"value\":5,\
+          \"fraction\":0},\
+        \"summary\": \"unaggregated deposit!\",\
+        \"fulfillment_url\": \"https://example.com/\",\
+        \"products\": [ {\"description\":\"unaggregated cream\",\
+                         \"value\":\"{%s:5}\"} ] }", \
+     currency, \
+     currency, \
+     currency);
+
+/**
  * Actual commands collection.
  */
 static void
@@ -122,11 +242,42 @@ run (void *cls,
      struct TALER_TESTING_Interpreter *is)
 {
 
+  /* Currency strings.  */
+  char *CURRENCY_25_05;
+  char *CURRENCY_10;
+  char *CURRENCY_9_98;
+  char *CURRENCY_5;
+  char *CURRENCY_4_99;
+  char *CURRENCY_0_02;
+  char *CURRENCY_0_01;
+
+  ALLOCATE_AMOUNTS
+    (CURRENCY_25_05,
+     CURRENCY_10,
+     CURRENCY_9_98,
+     CURRENCY_5,
+     CURRENCY_4_99,
+     CURRENCY_0_02,
+     CURRENCY_0_01);
+
+
+  /* Orders.  */
+  char *order_worth_5;
+  char *order_worth_10_2coins;
+  char *order_worth_5_track;
+  char *order_worth_5_unaggregated;
+
+  ALLOCATE_ORDERS
+    (order_worth_5,
+     order_worth_10_2coins,
+     order_worth_5_track,
+     order_worth_5_unaggregated);
+
   struct TALER_TESTING_Command commands[] = {
 
     CMD_TRANSFER_TO_EXCHANGE
       ("create-reserve-1",
-       "USD:25.05"),
+       CURRENCY_25_05),
 
     TALER_TESTING_cmd_exec_wirewatch
       ("wirewatch-1",
@@ -136,14 +287,14 @@ run (void *cls,
       ("withdraw-coin-1",
        is->exchange, // picks port from config's [exchange].
        "create-reserve-1",
-       "USD:5",
+       CURRENCY_5,
        MHD_HTTP_OK),
 
     TALER_TESTING_cmd_withdraw_amount
       ("withdraw-coin-2",
        is->exchange,
        "create-reserve-1",
-       "USD:5",
+       CURRENCY_5,
        MHD_HTTP_OK),
 
     /* This coin will be spent but never aggregated,
@@ -152,7 +303,7 @@ run (void *cls,
       ("withdraw-coin-3",
        is->exchange,
        "create-reserve-1",
-       "USD:5",
+       CURRENCY_5,
        MHD_HTTP_OK),
 
     /* coin 4 & 5 will be deposited for the same
@@ -162,14 +313,14 @@ run (void *cls,
       ("withdraw-coin-4",
        is->exchange,
        "create-reserve-1",
-       "USD:5",
+       CURRENCY_5,
        MHD_HTTP_OK),
 
     TALER_TESTING_cmd_withdraw_amount
       ("withdraw-coin-5",
        is->exchange,
        "create-reserve-1",
-       "USD:5",
+       CURRENCY_5,
        MHD_HTTP_OK),
 
     TALER_TESTING_cmd_proposal
@@ -177,21 +328,8 @@ run (void *cls,
        merchant_url,
        is->ctx,
        MHD_HTTP_OK,
-       "{\"max_fee\":\
-          {\"currency\":\"USD\",\
-           \"value\":0,\
-           \"fraction\":50000000},\
-        \"refund_deadline\":\"\\/Date(0)\\/\",\
-        \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
-        \"amount\":\
-          {\"currency\":\"USD\",\
-           \"value\":5,\
-           \"fraction\":0},\
-        \"summary\": \"merchant-lib testcase\",\
-        \"fulfillment_url\": \"https://example.com/\",\
-        \"products\": [ {\"description\":\"ice cream\",\
-                         \"value\":\"{USD:5}\"} ] }",
-        NULL),
+       order_worth_5,
+       NULL),
 
     TALER_TESTING_cmd_pay
       ("deposit-simple",
@@ -200,9 +338,9 @@ run (void *cls,
        MHD_HTTP_OK,
        "create-proposal-1",
        "withdraw-coin-1",
-       "USD:5",
-       "USD:4.99",
-       "USD:0.01"),
+       CURRENCY_5,
+       CURRENCY_4_99,
+       CURRENCY_0_01),
 
     TALER_TESTING_cmd_rewind_ip
       ("rewind-payments",
@@ -218,21 +356,8 @@ run (void *cls,
        merchant_url,
        is->ctx,
        MHD_HTTP_OK,
-       "{\"max_fee\":\
-          {\"currency\":\"USD\",\
-           \"value\":0,\
-           \"fraction\":50000000},\
-        \"refund_deadline\":\"\\/Date(0)\\/\",\
-        \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
-        \"amount\":\
-          {\"currency\":\"USD\",\
-           \"value\":5,\
-           \"fraction\":0},\
-        \"summary\": \"merchant-lib testcase\",\
-        \"fulfillment_url\": \"https://example.com/\",\
-        \"products\": [ {\"description\":\"ice track cream\",\
-                         \"value\":\"{USD:5}\"} ] }",
-        NULL),
+       order_worth_5_track,
+       NULL),
 
     TALER_TESTING_cmd_pay
       ("deposit-simple-2",
@@ -241,9 +366,9 @@ run (void *cls,
        MHD_HTTP_OK,
        "create-proposal-2",
        "withdraw-coin-2",
-       "USD:5",
-       "USD:4.99",
-       "USD:0.01"),
+       CURRENCY_5,
+       CURRENCY_4_99,
+       CURRENCY_0_01),
 
     /* /track/transaction over deposit-simple-2 */
 
@@ -258,7 +383,7 @@ run (void *cls,
        MHD_HTTP_OK,
        "dummy", // "check bank" CMD, never used, to be deleted.
        "deposit-simple-2",
-       "USD:0.01"),
+       CURRENCY_0_01),
 
     TALER_TESTING_cmd_merchant_track_transfer
       ("track-transfer-1",
@@ -281,21 +406,8 @@ run (void *cls,
        merchant_url,
        is->ctx,
        MHD_HTTP_OK,
-       "{\"max_fee\":\
-          {\"currency\":\"USD\",\
-           \"value\":0,\
-           \"fraction\":50000000},\
-        \"refund_deadline\":\"\\/Date(0)\\/\",\
-        \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
-        \"amount\":\
-          {\"currency\":\"USD\",\
-           \"value\":10,\
-           \"fraction\":0},\
-        \"summary\": \"2-coins untracked payment\",\
-        \"fulfillment_url\": \"https://example.com/\",\
-        \"products\": [ {\"description\":\"2-coins payment\",\
-                         \"value\":\"{USD:10}\"} ] }",
-        NULL),
+       order_worth_10_2coins,
+       NULL),
 
     TALER_TESTING_cmd_pay ("deposit-4&5",
                            merchant_url,
@@ -304,9 +416,9 @@ run (void *cls,
                            "create-proposal-4&5",
                            "withdraw-coin-4;" \
                            "withdraw-coin-5",
-                           "EUR:10",
-                           "EUR:9.98", // no sense now
-                           "EUR:0.02"), // no sense now
+                           CURRENCY_10,
+                           CURRENCY_9_98, // no sense now
+                           CURRENCY_0_02), // no sense now
 
     TALER_TESTING_cmd_exec_aggregator
       ("aggregate-2",
@@ -318,21 +430,8 @@ run (void *cls,
        merchant_url,
        is->ctx,
        MHD_HTTP_OK,
-       "{\"max_fee\":\
-          {\"currency\":\"USD\",\
-           \"value\":0,\
-           \"fraction\":50000000},\
-        \"refund_deadline\":\"\\/Date(0)\\/\",\
-        \"pay_deadline\":\"\\/Date(99999999999)\\/\",\
-        \"amount\":\
-          {\"currency\":\"USD\",\
-           \"value\":5,\
-           \"fraction\":0},\
-        \"summary\": \"unaggregated deposit!\",\
-        \"fulfillment_url\": \"https://example.com/\",\
-        \"products\": [ {\"description\":\"unaggregated cream\",\
-                         \"value\":\"{USD:5}\"} ] }",
-        NULL),
+       order_worth_5_unaggregated,
+       NULL),
 
     TALER_TESTING_cmd_pay
       ("deposit-simple-3",
@@ -341,9 +440,9 @@ run (void *cls,
        MHD_HTTP_OK,
        "create-proposal-3",
        "withdraw-coin-3",
-       "USD:5",
-       "USD:4.99",
-       "USD:0.01"),
+       CURRENCY_5,
+       CURRENCY_4_99,
+       CURRENCY_0_01),
 
     TALER_TESTING_cmd_merchant_track_transaction
       ("track-transaction-2",
@@ -352,8 +451,7 @@ run (void *cls,
        MHD_HTTP_ACCEPTED,
        "dummy", // "check bank" CMD, never used, to be deleted.
        "deposit-simple-3",
-       "USD:0.01"),
-
+       CURRENCY_0_01),
 
     TALER_TESTING_cmd_rewind_ip
       ("rewind-tracks",
@@ -391,6 +489,7 @@ int
 main (int argc,
       char *const *argv)
 {
+  struct GNUNET_CONFIGURATION_Handle *cfg;
 
   default_config_file = GNUNET_OS_project_data_get
     ()->user_config_file;
@@ -475,6 +574,28 @@ main (int argc,
   if (NULL == cfg_filename)
     cfg_filename = (char *) default_config_file;
 
+  cfg = GNUNET_CONFIGURATION_create ();
+  if (GNUNET_OK != GNUNET_CONFIGURATION_load
+      (cfg,
+       cfg_filename))
+  {
+    TALER_LOG_ERROR ("Could not parse configuration\n");
+    return BAD_CONFIG_FILE;
+  }
+  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string
+      (cfg,
+       "taler",
+       "currency",
+       &currency))
+  {
+    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+                               "taler",
+                               "currency");
+    GNUNET_CONFIGURATION_destroy (cfg);
+    return BAD_CONFIG_FILE;
+  }
+  GNUNET_CONFIGURATION_destroy (cfg);
+
   if (NULL == merchant_url)
   {
     TALER_LOG_ERROR ("Option -m is mandatory!\n");

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



reply via email to

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