summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <marcello.stanisci@inria.fr>2017-03-09 20:35:02 +0100
committerMarcello Stanisci <marcello.stanisci@inria.fr>2017-03-09 20:35:02 +0100
commit5a0697a3b79a01da9bdbe1a8fc864d510303b9bf (patch)
treeb6f28b41a8c2e7bd5504dc45f29b89cef9a49e7e
parent2af86bf65663939d8cb1d8c16ae36fbf7fba9b73 (diff)
downloadmerchant-5a0697a3b79a01da9bdbe1a8fc864d510303b9bf.tar.gz
merchant-5a0697a3b79a01da9bdbe1a8fc864d510303b9bf.tar.bz2
merchant-5a0697a3b79a01da9bdbe1a8fc864d510303b9bf.zip
Adding options to take exchange, merchant backend, and bank URIs
to the payments generator.
-rw-r--r--src/samples/generate_payments.c117
1 files changed, 56 insertions, 61 deletions
diff --git a/src/samples/generate_payments.c b/src/samples/generate_payments.c
index b81ccf60..5c398fde 100644
--- a/src/samples/generate_payments.c
+++ b/src/samples/generate_payments.c
@@ -26,11 +26,9 @@
#include <gnunet/gnunet_curl_lib.h>
#include <microhttpd.h>
-#define EXCHANGE_URI "http://localhost:8081/"
-
-#define MERCHANT_URI "http://localhost:8082"
-
-#define BANK_URI "http://localhost:8083/"
+char *exchange_uri;
+char *merchant_uri;
+char *bank_uri;
#define ORDER_MAX_SIZE 1000
@@ -834,7 +832,7 @@ interpreter_run (void *cls)
cmd->details.pay.ph
= TALER_MERCHANT_pay_wallet (ctx,
- MERCHANT_URI,
+ merchant_uri,
"default",
&ref->details.proposal.hash,
&total_amount,
@@ -845,7 +843,7 @@ interpreter_run (void *cls)
refund_deadline,
pay_deadline,
&h_wire,
- EXCHANGE_URI,
+ exchange_uri,
order_id,
1 /* num_coins */,
&pc /* coins */,
@@ -882,7 +880,7 @@ interpreter_run (void *cls)
}
cmd->details.proposal.po
= TALER_MERCHANT_order_put (ctx,
- MERCHANT_URI,
+ merchant_uri,
order,
&proposal_cb,
is);
@@ -1022,6 +1020,9 @@ interpreter_run (void *cls)
fail (is);
return;
}
+
+ json_object_set (sender_details, "bank_uri", json_string (bank_uri));
+
transfer_details = json_loads (cmd->details.admin_add_incoming.transfer_details,
JSON_REJECT_DUPLICATES,
NULL);
@@ -1313,21 +1314,21 @@ run (void *cls)
{ .oc = OC_ADMIN_ADD_INCOMING,
.label = "create-reserve-1",
.expected_response_code = MHD_HTTP_OK,
- .details.admin_add_incoming.sender_details = "{ \"type\":\"test\", \"bank_uri\":\"" BANK_URI "\", \"account_number\":62, \"uuid\":1 }",
+ .details.admin_add_incoming.sender_details = "{ \"type\":\"test\", \"account_number\":62, \"uuid\":1 }",
.details.admin_add_incoming.transfer_details = "{ \"uuid\": 1}",
.details.admin_add_incoming.amount = "EUR:5.01" },
/* Fill reserve with EUR:5.01, as withdraw fee is 1 ct per config */
{ .oc = OC_ADMIN_ADD_INCOMING,
.label = "create-reserve-2",
.expected_response_code = MHD_HTTP_OK,
- .details.admin_add_incoming.sender_details = "{ \"type\":\"test\", \"bank_uri\":\"" BANK_URI "\", \"account_number\":62, \"uuid\":1 }",
+ .details.admin_add_incoming.sender_details = "{ \"type\":\"test\", \"account_number\":62, \"uuid\":1 }",
.details.admin_add_incoming.transfer_details = "{ \"uuid\": 1}",
.details.admin_add_incoming.amount = "EUR:5.01" },
/* Fill reserve with EUR:5.01, as withdraw fee is 1 ct per config */
{ .oc = OC_ADMIN_ADD_INCOMING,
.label = "create-reserve-3",
.expected_response_code = MHD_HTTP_OK,
- .details.admin_add_incoming.sender_details = "{ \"type\":\"test\", \"bank_uri\":\"" BANK_URI "\", \"account_number\":62, \"uuid\":1 }",
+ .details.admin_add_incoming.sender_details = "{ \"type\":\"test\", \"account_number\":62, \"uuid\":1 }",
.details.admin_add_incoming.transfer_details = "{ \"uuid\": 1}",
.details.admin_add_incoming.amount = "EUR:5.01" },
/* Withdraw a 5 EUR coin, at fee of 1 ct */
@@ -1436,7 +1437,7 @@ run (void *cls)
GNUNET_assert (NULL != ctx);
rc = GNUNET_CURL_gnunet_rc_create (ctx);
exchange = TALER_EXCHANGE_connect (ctx,
- EXCHANGE_URI,
+ exchange_uri,
&cert_cb, is,
TALER_EXCHANGE_OPTION_END);
GNUNET_assert (NULL != exchange);
@@ -1450,61 +1451,33 @@ run (void *cls)
}
int
-main ()
+main (int argc,
+ char *argv[])
{
- struct GNUNET_OS_Process *proc;
struct GNUNET_OS_Process *exchanged;
struct GNUNET_OS_Process *merchantd;
unsigned int cnt;
struct GNUNET_SIGNAL_Context *shc_chld;
-
+ char *wget_cmd;
+
+ static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ { 'e', "exchange-uri", "EXCHANGE_URI",
+ "Indicates the exchange's URI.", GNUNET_YES,
+ &GNUNET_GETOPT_set_string, &exchange_uri},
+ { 'm', "merchant-uri", "MERCHANT_URI",
+ "Indicates the merchant backend's URI.", GNUNET_YES,
+ &GNUNET_GETOPT_set_string, &merchant_uri},
+ { 'b', "merchant-uri", "MERCHANT_URI",
+ "Indicates the bank's URI.", GNUNET_YES,
+ &GNUNET_GETOPT_set_string, &bank_uri},
+ GNUNET_GETOPT_OPTION_END
+ };
unsetenv ("XDG_DATA_HOME");
unsetenv ("XDG_CONFIG_HOME");
GNUNET_log_setup ("merchant-create-payments",
"DEBUG",
NULL);
- cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_load (cfg,
- "merchant_generate_payments.conf"));
-
-
- proc = GNUNET_OS_start_process (GNUNET_NO,
- GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- "taler-exchange-keyup",
- "taler-exchange-keyup",
- "-c", "merchant_generate_payments.conf",
- NULL);
- if (NULL == proc)
- {
- fprintf (stderr,
- "Failed to run taler-exchange-keyup. Check your PATH.\n");
- return 77;
- }
-
-
- GNUNET_OS_process_wait (proc);
- GNUNET_OS_process_destroy (proc);
-
- proc = GNUNET_OS_start_process (GNUNET_NO,
- GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- "taler-exchange-dbinit",
- "taler-exchange-dbinit",
- "-c", "merchant_generate_payments.conf",
- "-r",
- NULL);
- if (NULL == proc)
- {
- fprintf (stderr,
- "Failed to run taler-exchange-dbinit. Check your PATH.\n");
- return 77;
- }
- GNUNET_OS_process_wait (proc);
- GNUNET_OS_process_destroy (proc);
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"About to launch the exchange.\n");
@@ -1513,7 +1486,6 @@ main ()
NULL, NULL, NULL,
"taler-exchange-httpd",
"taler-exchange-httpd",
- "-c", "merchant_generate_payments.conf",
NULL);
if (NULL == exchanged)
{
@@ -1524,6 +1496,10 @@ main ()
fprintf (stderr,
"Waiting for taler-exchange-httpd to be ready\n");
+
+ GNUNET_asprintf (&wget_cmd,
+ "wget -q -t 1 -T 1 %skeys -o /dev/null -O /dev/null",
+ exchange_uri);
cnt = 0;
do
{
@@ -1541,15 +1517,16 @@ main ()
return 77;
}
}
- while (0 != system ("wget -q -t 1 -T 1 " EXCHANGE_URI "keys -o /dev/null -O /dev/null"));
+ while (0 != system (wget_cmd));
fprintf (stderr, "\n");
+ GNUNET_free (wget_cmd);
+
merchantd = GNUNET_OS_start_process (GNUNET_NO,
GNUNET_OS_INHERIT_STD_ALL,
NULL, NULL, NULL,
"taler-merchant-httpd",
"taler-merchant-httpd",
- "-c", "merchant_generate_payments.conf",
"-L", "DEBUG",
NULL);
if (NULL == merchantd)
@@ -1565,6 +1542,9 @@ main ()
/* give child time to start and bind against the socket */
fprintf (stderr,
"Waiting for taler-merchant-httpd to be ready\n");
+ GNUNET_asprintf (&wget_cmd,
+ "wget -q -t 1 -T 1 %s -o /dev/null -O /dev/null",
+ merchant_uri);
cnt = 0;
do
{
@@ -1586,16 +1566,31 @@ main ()
return 77;
}
}
- while (0 != system ("wget -q -t 1 -T 1 " MERCHANT_URI " -o /dev/null -O /dev/null"));
+ while (wget_cmd);
fprintf (stderr, "\n");
-
+ GNUNET_free (wget_cmd);
result = GNUNET_SYSERR;
sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO);
GNUNET_assert (NULL != sigpipe);
shc_chld = GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD,
&sighandler_child_death);
+ if (GNUNET_GETOPT_run ("merchant-payments-generator",
+ options, argc, argv) < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid command line options.");
+ return 77;
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Options: exchange_uri '%s', merchant_uri '%s' bank_uri '%s'.",
+ exchange_uri,
+ merchant_uri,
+ bank_uri);
+
GNUNET_SCHEDULER_run (&run, NULL);
+
GNUNET_SIGNAL_handler_uninstall (shc_chld);
shc_chld = NULL;
GNUNET_DISK_pipe_close (sigpipe);