summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2018-06-12 10:27:46 +0200
committerMarcello Stanisci <stanisci.m@gmail.com>2018-06-12 10:27:46 +0200
commitf7be081ad266ee9ea11047033599d30b90fb5f32 (patch)
tree396118bfc2ff0eb1c8d6f33c7378a10b9a36c100
parentfcefedff112660cb33d407eb97bf139e52e9c2c7 (diff)
downloadmerchant-f7be081ad266ee9ea11047033599d30b90fb5f32.tar.gz
merchant-f7be081ad266ee9ea11047033599d30b90fb5f32.tar.bz2
merchant-f7be081ad266ee9ea11047033599d30b90fb5f32.zip
Dynamic currency at the generator.
Moving currency-dependant strings allocation above the run method.
-rw-r--r--src/merchant-tools/taler-merchant-generate-payments_new.c165
1 files changed, 88 insertions, 77 deletions
diff --git a/src/merchant-tools/taler-merchant-generate-payments_new.c b/src/merchant-tools/taler-merchant-generate-payments_new.c
index 986ddc73..b910d81f 100644
--- a/src/merchant-tools/taler-merchant-generate-payments_new.c
+++ b/src/merchant-tools/taler-merchant-generate-payments_new.c
@@ -127,58 +127,38 @@ static char *merchant_url;
static char *currency;
/**
- * Actual commands collection.
+ * 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.
*/
-static void
-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;
-
- GNUNET_asprintf (&CURRENCY_25_05,
- "%s:25.05",
- currency);
-
- GNUNET_asprintf (&CURRENCY_10,
- "%s:10",
+#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);
- 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);
-
- /* Orders. */
- char *order_worth_5;
- char *order_worth_10_2coins;
- char *order_worth_5_track;
- char *order_worth_5_unaggregated;
-
- GNUNET_asprintf
- (&order_worth_5,
+#define ALLOCATE_ORDERS(...) \
+ GNUNET_asprintf \
+ (&order_worth_5, \
"{\"max_fee\":\
{\"currency\":\"%s\",\
\"value\":0,\
@@ -192,14 +172,12 @@ run (void *cls,
\"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,
+ \"value\":\"{%s:5}\"} ] }", \
+ currency, \
+ currency, \
+ currency); \
+ GNUNET_asprintf \
+ (&order_worth_10_2coins, \
"{\"max_fee\":\
{\"currency\":\"%s\",\
\"value\":0,\
@@ -213,14 +191,12 @@ run (void *cls,
\"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,
+ \"value\":\"{%s:10}\"} ] }", \
+ currency, \
+ currency, \
+ currency); \
+ GNUNET_asprintf \
+ (&order_worth_5_track, \
"{\"max_fee\":\
{\"currency\":\"%s\",\
\"value\":0,\
@@ -234,15 +210,12 @@ run (void *cls,
\"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,
+ \"value\":\"{%s:5}\"} ] }", \
+ currency, \
+ currency, \
+ currency); \
+ GNUNET_asprintf \
+ (&order_worth_5_unaggregated, \
"{\"max_fee\":\
{\"currency\":\"%s\",\
\"value\":0,\
@@ -256,12 +229,50 @@ run (void *cls,
\"summary\": \"unaggregated deposit!\",\
\"fulfillment_url\": \"https://example.com/\",\
\"products\": [ {\"description\":\"unaggregated cream\",\
- \"value\":\"{%s:5}\"} ]\
- }",
- currency,
- currency,
+ \"value\":\"{%s:5}\"} ] }", \
+ currency, \
+ currency, \
currency);
+/**
+ * Actual commands collection.
+ */
+static void
+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