From 397c718809f2f53f3e0714ea6433083ea7379124 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 2 Mar 2017 06:26:12 +0100 Subject: implementing #4921: add base URL to wire transfers --- src/bank-lib/bank_api_admin.c | 12 +++--- src/bank-lib/fakebank.c | 34 ++++++++++++---- src/bank-lib/test_bank_api_with_fakebank.c | 4 +- src/bank-lib/test_bank_interpreter.c | 12 +++--- src/bank-lib/test_bank_interpreter.h | 7 +++- src/exchange-lib/test_exchange_api.c | 35 ++++++++++------ src/exchange-lib/test_exchange_api.conf | 4 ++ src/exchange/exchange.conf | 8 ++++ src/exchange/taler-exchange-aggregator.c | 20 +++++++++- .../test-taler-exchange-aggregator-postgres.conf | 34 +++++++++++++++- src/exchange/test_taler_exchange_aggregator.c | 46 ++++++++++++++++------ src/include/taler_bank_service.h | 6 ++- src/include/taler_fakebank_lib.h | 11 ++++-- src/include/taler_wire_plugin.h | 2 + src/wire/plugin_wire_sepa.c | 4 +- src/wire/plugin_wire_template.c | 2 + src/wire/plugin_wire_test.c | 40 +++++++++++++++---- 17 files changed, 222 insertions(+), 59 deletions(-) diff --git a/src/bank-lib/bank_api_admin.c b/src/bank-lib/bank_api_admin.c index 338ddce92..0b6386ad4 100644 --- a/src/bank-lib/bank_api_admin.c +++ b/src/bank-lib/bank_api_admin.c @@ -162,8 +162,9 @@ handle_admin_add_incoming_finished (void *cls, * to the operators of the bank. * * @param ctx curl context for the event loop - * @param bank_base_url URL of the bank - * @param reserve_pub public key of the reserve + * @param bank_base_url URL of the bank (used to execute this request) + * @param exchange_base_url base URL of the exchange (for tracking) + * @param wtid wire transfer identifier for the transfer * @param amount amount that was deposited * @param execution_date when did we receive the amount * @param debit_account_no account number to withdraw from (53 bits at most) @@ -177,6 +178,7 @@ handle_admin_add_incoming_finished (void *cls, struct TALER_BANK_AdminAddIncomingHandle * TALER_BANK_admin_add_incoming (struct GNUNET_CURL_Context *ctx, const char *bank_base_url, + const char *exchange_base_url, const struct TALER_WireTransferIdentifierRawP *wtid, const struct TALER_Amount *amount, uint64_t debit_account_no, @@ -188,9 +190,9 @@ TALER_BANK_admin_add_incoming (struct GNUNET_CURL_Context *ctx, json_t *admin_obj; CURL *eh; - admin_obj = json_pack ("{s:o, s:o," - " s:I, s:I}", - "wtid", GNUNET_JSON_from_data_auto (wtid), /* #4340 */ + admin_obj = json_pack ("{s:s, s:o, s:o, s:I, s:I}", + "exchange_url", exchange_base_url, + "wtid", GNUNET_JSON_from_data_auto (wtid), "amount", TALER_JSON_from_amount (amount), "debit_account", (json_int_t) debit_account_no, "credit_account", (json_int_t) credit_account_no); diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c index 83ea79770..d99332bdb 100644 --- a/src/bank-lib/fakebank.c +++ b/src/bank-lib/fakebank.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2016 Inria and GNUnet e.V. + (C) 2016, 2017 Inria and GNUnet e.V. TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -65,6 +65,11 @@ struct Transaction * Subject of the transfer. */ struct TALER_WireTransferIdentifierRawP wtid; + + /** + * Base URL of the exchange. + */ + char *exchange_base_url; }; @@ -105,6 +110,8 @@ struct TALER_FAKEBANK_Handle * @param want_amount transfer amount desired * @param want_debit account that should have been debited * @param want_debit account that should have been credited + * @param exchange_base_url expected base URL of the exchange + * i.e. "https://example.com/"; may include a port * @param[out] wtid set to the wire transfer identifier * @return #GNUNET_OK on success */ @@ -113,6 +120,7 @@ TALER_FAKEBANK_check (struct TALER_FAKEBANK_Handle *h, const struct TALER_Amount *want_amount, uint64_t want_debit, uint64_t want_credit, + const char *exchange_base_url, struct TALER_WireTransferIdentifierRawP *wtid) { struct Transaction *t; @@ -122,12 +130,15 @@ TALER_FAKEBANK_check (struct TALER_FAKEBANK_Handle *h, if ( (want_debit == t->debit_account) && (want_credit == t->credit_account) && (0 == TALER_amount_cmp (want_amount, - &t->amount)) ) + &t->amount)) && + (0 == strcasecmp (exchange_base_url, + t->exchange_base_url)) ) { GNUNET_CONTAINER_DLL_remove (h->transactions_head, h->transactions_tail, t); *wtid = t->wtid; + GNUNET_free (t->exchange_base_url); GNUNET_free (t); return GNUNET_OK; } @@ -140,10 +151,11 @@ TALER_FAKEBANK_check (struct TALER_FAKEBANK_Handle *h, s = TALER_amount_to_string (&t->amount); fprintf (stderr, - "%llu -> %llu (%s)\n", + "%llu -> %llu (%s) from %s\n", (unsigned long long) t->debit_account, (unsigned long long) t->credit_account, - s); + s, + t->exchange_base_url); GNUNET_free (s); } return GNUNET_SYSERR; @@ -174,10 +186,11 @@ TALER_FAKEBANK_check_empty (struct TALER_FAKEBANK_Handle *h) s = TALER_amount_to_string (&t->amount); fprintf (stderr, - "%llu -> %llu (%s)\n", + "%llu -> %llu (%s) from %s\n", (unsigned long long) t->debit_account, (unsigned long long) t->credit_account, - s); + s, + t->exchange_base_url); GNUNET_free (s); } return GNUNET_SYSERR; @@ -199,6 +212,7 @@ TALER_FAKEBANK_stop (struct TALER_FAKEBANK_Handle *h) GNUNET_CONTAINER_DLL_remove (h->transactions_head, h->transactions_tail, t); + GNUNET_free (t->exchange_base_url); GNUNET_free (t); } if (NULL != h->mhd_task) @@ -303,11 +317,13 @@ handle_mhd_request (void *cls, } t = GNUNET_new (struct Transaction); { + const char *base_url; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_fixed_auto ("wtid", &t->wtid), GNUNET_JSON_spec_uint64 ("debit_account", &t->debit_account), GNUNET_JSON_spec_uint64 ("credit_account", &t->credit_account), TALER_JSON_spec_amount ("amount", &t->amount), + GNUNET_JSON_spec_string ("exchange_url", &base_url), GNUNET_JSON_spec_end () }; if (GNUNET_OK != @@ -319,14 +335,16 @@ handle_mhd_request (void *cls, json_decref (json); return MHD_NO; } + t->exchange_base_url = GNUNET_strdup (base_url); GNUNET_CONTAINER_DLL_insert (h->transactions_head, h->transactions_tail, t); } GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Receiving incoming wire transfer: %llu->%llu\n", + "Receiving incoming wire transfer: %llu->%llu from %s\n", (unsigned long long) t->debit_account, - (unsigned long long) t->credit_account); + (unsigned long long) t->credit_account, + t->exchange_base_url); json_decref (json); resp = MHD_create_response_from_buffer (0, "", MHD_RESPMEM_PERSISTENT); ret = MHD_queue_response (connection, diff --git a/src/bank-lib/test_bank_api_with_fakebank.c b/src/bank-lib/test_bank_api_with_fakebank.c index 8e0ac6d15..3c726a749 100644 --- a/src/bank-lib/test_bank_api_with_fakebank.c +++ b/src/bank-lib/test_bank_api_with_fakebank.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2016 GNUnet e.V. + Copyright (C) 2016, 2017 GNUnet e.V. TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -45,6 +45,7 @@ run (void *cls) .details.admin_add_incoming.expected_response_code = MHD_HTTP_OK, .details.admin_add_incoming.credit_account_no = 1, .details.admin_add_incoming.debit_account_no = 2, + .details.admin_add_incoming.exchange_base_url = "https://exchange.net/", .details.admin_add_incoming.amount = "PUDOS:5.01" }, /* Add EUR:3.21 to account 3 */ { .oc = TBI_OC_ADMIN_ADD_INCOMING, @@ -52,6 +53,7 @@ run (void *cls) .details.admin_add_incoming.expected_response_code = MHD_HTTP_OK, .details.admin_add_incoming.credit_account_no = 3, .details.admin_add_incoming.debit_account_no = 2, + .details.admin_add_incoming.exchange_base_url = "https://exchange.org/", .details.admin_add_incoming.amount = "PUDOS:3.21" }, /* check transfers arrived at fakebank */ { .oc = TBI_OC_EXPECT_TRANSFER, diff --git a/src/bank-lib/test_bank_interpreter.c b/src/bank-lib/test_bank_interpreter.c index 03648786c..f088cfc40 100644 --- a/src/bank-lib/test_bank_interpreter.c +++ b/src/bank-lib/test_bank_interpreter.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2016 GNUnet e.V. + Copyright (C) 2016, 2017 GNUnet e.V. TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -222,6 +222,7 @@ interpreter_run (void *cls) cmd->details.admin_add_incoming.aih = TALER_BANK_admin_add_incoming (is->ctx, "http://localhost:8081", + cmd->details.admin_add_incoming.exchange_base_url, &cmd->details.admin_add_incoming.wtid, &amount, cmd->details.admin_add_incoming.debit_account_no, @@ -243,10 +244,11 @@ interpreter_run (void *cls) &amount)); if (GNUNET_OK != TALER_FAKEBANK_check (is->fakebank, - &amount, - ref->details.admin_add_incoming.debit_account_no, - ref->details.admin_add_incoming.credit_account_no, - &wtid)) + &amount, + ref->details.admin_add_incoming.debit_account_no, + ref->details.admin_add_incoming.credit_account_no, + ref->details.admin_add_incoming.exchange_base_url, + &wtid)) { GNUNET_break (0); fail (is); diff --git a/src/bank-lib/test_bank_interpreter.h b/src/bank-lib/test_bank_interpreter.h index 0093b0db3..1f2772ca7 100644 --- a/src/bank-lib/test_bank_interpreter.h +++ b/src/bank-lib/test_bank_interpreter.h @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2016 GNUnet e.V. + Copyright (C) 2016, 2017 GNUnet e.V. TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -99,6 +99,11 @@ struct TBI_Command */ uint64_t debit_account_no; + /** + * Exchange base URL to use. + */ + const char *exchange_base_url; + /** * Wire transfer identifier to use. Initialized to * a random value. diff --git a/src/exchange-lib/test_exchange_api.c b/src/exchange-lib/test_exchange_api.c index aa18f6527..2456d77a7 100644 --- a/src/exchange-lib/test_exchange_api.c +++ b/src/exchange-lib/test_exchange_api.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014, 2015, 2016 GNUnet e.V. and Inria + Copyright (C) 2014-2017 GNUnet e.V. and Inria TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -604,6 +604,11 @@ struct Command */ uint64_t account_credit; + /** + * Which exchange base URL is expected? + */ + const char *exchange_base_url; + /** * Set (!) to the wire transfer identifier observed. */ @@ -906,9 +911,10 @@ reserve_status_cb (void *cls, (0 == strcmp (cmd->details.reserve_status.reserve_reference, rel->details.admin_add_incoming.reserve_reference) ) ) ) { - if (GNUNET_OK != - compare_admin_add_incoming_history (&history[j], - rel)) + if ( (j >= history_length) || + (GNUNET_OK != + compare_admin_add_incoming_history (&history[j], + rel)) ) { GNUNET_break (0); fail (is); @@ -921,9 +927,10 @@ reserve_status_cb (void *cls, if (0 == strcmp (cmd->details.reserve_status.reserve_reference, rel->details.reserve_withdraw.reserve_reference)) { - if (GNUNET_OK != - compare_reserve_withdraw_history (&history[j], - rel)) + if ( (j >= history_length) || + (GNUNET_OK != + compare_reserve_withdraw_history (&history[j], + rel)) ) { GNUNET_break (0); fail (is); @@ -2280,10 +2287,11 @@ interpreter_run (void *cls) } if (GNUNET_OK != TALER_FAKEBANK_check (fakebank, - &amount, - cmd->details.check_bank_transfer.account_debit, - cmd->details.check_bank_transfer.account_credit, - &cmd->details.check_bank_transfer.wtid)) + &amount, + cmd->details.check_bank_transfer.account_debit, + cmd->details.check_bank_transfer.account_credit, + cmd->details.check_bank_transfer.exchange_base_url, + &cmd->details.check_bank_transfer.wtid)) { GNUNET_break (0); fail (is); @@ -2914,24 +2922,28 @@ run (void *cls) { .oc = OC_CHECK_BANK_TRANSFER, .label = "check_bank_transfer-499c", + .details.check_bank_transfer.exchange_base_url = "https://exchange.com/", .details.check_bank_transfer.amount = "EUR:4.99", .details.check_bank_transfer.account_debit = 2, .details.check_bank_transfer.account_credit = 42 }, { .oc = OC_CHECK_BANK_TRANSFER, .label = "check_bank_transfer-99c1", + .details.check_bank_transfer.exchange_base_url = "https://exchange.com/", .details.check_bank_transfer.amount = "EUR:0.99", .details.check_bank_transfer.account_debit = 2, .details.check_bank_transfer.account_credit = 42 }, { .oc = OC_CHECK_BANK_TRANSFER, .label = "check_bank_transfer-99c2", + .details.check_bank_transfer.exchange_base_url = "https://exchange.com/", .details.check_bank_transfer.amount = "EUR:0.99", .details.check_bank_transfer.account_debit = 2, .details.check_bank_transfer.account_credit = 42 }, { .oc = OC_CHECK_BANK_TRANSFER, .label = "check_bank_transfer-9c", + .details.check_bank_transfer.exchange_base_url = "https://exchange.com/", .details.check_bank_transfer.amount = "EUR:0.09", .details.check_bank_transfer.account_debit = 2, .details.check_bank_transfer.account_credit = 43 @@ -3017,6 +3029,7 @@ run (void *cls) /* Check that deposit did run */ { .oc = OC_CHECK_BANK_TRANSFER, .label = "check_bank_transfer-pre-refund", + .details.check_bank_transfer.exchange_base_url = "https://exchange.com/", .details.check_bank_transfer.amount = "EUR:4.98", .details.check_bank_transfer.account_debit = 2, .details.check_bank_transfer.account_credit = 42 diff --git a/src/exchange-lib/test_exchange_api.conf b/src/exchange-lib/test_exchange_api.conf index e815a0bbf..83be7c410 100644 --- a/src/exchange-lib/test_exchange_api.conf +++ b/src/exchange-lib/test_exchange_api.conf @@ -24,6 +24,10 @@ MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG # How to access our database DB = postgres +# Base URL of the exchange. Note that the test expects exactly this +# value in the wire transfers. +BASE_URL = "https://exchange.com/" + [exchangedb-postgres] DB_CONN_STR = "postgres:///talercheck" diff --git a/src/exchange/exchange.conf b/src/exchange/exchange.conf index 39151ea67..a226d4149 100644 --- a/src/exchange/exchange.conf +++ b/src/exchange/exchange.conf @@ -33,6 +33,14 @@ UNIXPATH_MODE = 660 # HTTP port the exchange listens to PORT = 8081 +# Base URL of the exchange (public-facing). Due to reverse proxies, +# this may or may not match our port or hostname at all and can thus +# not be determined automatically. Note that a globally reachable name +# is required, so 'localhost' will not work except for testing. +# Required for wire transfers as we need to include it in the wire +# transfers to enable tracking. +BASE_URL = http://localhost:8081/ + [exchange-admin] # Network configuration for the /admin HTTP server diff --git a/src/exchange/taler-exchange-aggregator.c b/src/exchange/taler-exchange-aggregator.c index d692fe396..96ec7627f 100644 --- a/src/exchange/taler-exchange-aggregator.c +++ b/src/exchange/taler-exchange-aggregator.c @@ -29,8 +29,6 @@ #include "taler_wire_lib.h" - - /** * Information we keep for each loaded wire plugin. */ @@ -168,6 +166,11 @@ struct AggregationUnit */ static char *exchange_currency_string; +/** + * What is the base URL of this exchange? + */ +static char *exchange_base_url; + /** * The exchange's configuration (global) */ @@ -763,6 +766,7 @@ run_aggregation (void *cls) au->ph = wp->wire_plugin->prepare_wire_transfer (wp->wire_plugin->cls, au->wire, &au->total_amount, + exchange_base_url, &au->wtid, &prepare_cb, au); @@ -1061,6 +1065,18 @@ run (void *cls, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) { + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (c, + "exchange", + "BASE_URL", + &exchange_base_url)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "exchange", + "BASE_URL"); + global_ret = 1; + return; + } cfg = GNUNET_CONFIGURATION_dup (c); if (GNUNET_OK != exchange_serve_process_config ()) { diff --git a/src/exchange/test-taler-exchange-aggregator-postgres.conf b/src/exchange/test-taler-exchange-aggregator-postgres.conf index 0822bab44..7bcadc157 100644 --- a/src/exchange/test-taler-exchange-aggregator-postgres.conf +++ b/src/exchange/test-taler-exchange-aggregator-postgres.conf @@ -1,8 +1,40 @@ +[PATHS] +# Persistant data storage for the testcase +TALER_TEST_HOME = test_taler_exchange_httpd_home/ + +[taler] +# Currency supported by the exchange (can only be one) +CURRENCY = EUR + [exchange] -#The DB plugin to use +# The DB plugin to use DB = postgres +# Wire format supported by the exchange +# We use 'test' for testing of the actual +# coin operations. +WIREFORMAT = test + +# HTTP port the exchange listens to +PORT = 8081 + +# Master public key used to sign the exchange's various keys +MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG + +# Expected base URL of the exchange. +BASE_URL = "https://exchange.taler.net/" + [exchangedb-postgres] #The connection string the plugin has to use for connecting to the database DB_CONN_STR = postgres:///talercheck + + + +[exchange-wire-outgoing-test] +# What is the main website of the bank? +BANK_URI = "http://localhost:8082/" + +# From which account at the 'bank' should outgoing +# wire transfers be made? +EXCHANGE_ACCOUNT_NUMBER = 3 diff --git a/src/exchange/test_taler_exchange_aggregator.c b/src/exchange/test_taler_exchange_aggregator.c index aa998712d..6bd0d709b 100644 --- a/src/exchange/test_taler_exchange_aggregator.c +++ b/src/exchange/test_taler_exchange_aggregator.c @@ -110,6 +110,11 @@ struct Command */ uint64_t credit_account; + /** + * Base URL of the exchange. + */ + const char *exchange_base_url; + /** * Subject of the transfer, set by the command. */ @@ -512,7 +517,7 @@ interpreter (void *cls) NULL, NULL, NULL, "taler-exchange-aggregator", "taler-exchange-aggregator", - "-c", "test_taler_exchange_httpd.conf", + "-c", config_filename, "-t", /* enable temporary tables */ NULL); if (NULL == aggregator_proc) @@ -556,10 +561,11 @@ interpreter (void *cls) } if (GNUNET_OK != TALER_FAKEBANK_check (fb, - &want_amount, - cmd->details.expect_transaction.debit_account, - cmd->details.expect_transaction.credit_account, - &cmd->details.expect_transaction.wtid)) + &want_amount, + cmd->details.expect_transaction.debit_account, + cmd->details.expect_transaction.credit_account, + cmd->details.expect_transaction.exchange_base_url, + &cmd->details.expect_transaction.wtid)) { fail (cmd); return; @@ -614,6 +620,7 @@ run_test () .label = "expect-deposit-1", .details.expect_transaction.debit_account = 3, .details.expect_transaction.credit_account = 4, + .details.expect_transaction.exchange_base_url = "https://exchange.taler.net/", .details.expect_transaction.amount = "EUR:0.9" }, @@ -660,6 +667,7 @@ run_test () .label = "expect-deposit-2", .details.expect_transaction.debit_account = 3, .details.expect_transaction.credit_account = 4, + .details.expect_transaction.exchange_base_url = "https://exchange.taler.net/", .details.expect_transaction.amount = "EUR:1.8" }, @@ -705,6 +713,7 @@ run_test () .label = "expect-deposit-3a", .details.expect_transaction.debit_account = 3, .details.expect_transaction.credit_account = 4, + .details.expect_transaction.exchange_base_url = "https://exchange.taler.net/", .details.expect_transaction.amount = "EUR:0.9" }, { @@ -712,6 +721,7 @@ run_test () .label = "expect-deposit-3b", .details.expect_transaction.debit_account = 3, .details.expect_transaction.credit_account = 4, + .details.expect_transaction.exchange_base_url = "https://exchange.taler.net/", .details.expect_transaction.amount = "EUR:0.9" }, { @@ -719,6 +729,7 @@ run_test () .label = "expect-deposit-3c", .details.expect_transaction.debit_account = 3, .details.expect_transaction.credit_account = 5, + .details.expect_transaction.exchange_base_url = "https://exchange.taler.net/", .details.expect_transaction.amount = "EUR:0.9" }, { @@ -767,6 +778,7 @@ run_test () .label = "expect-deposit-4", .details.expect_transaction.debit_account = 3, .details.expect_transaction.credit_account = 4, + .details.expect_transaction.exchange_base_url = "https://exchange.taler.net/", .details.expect_transaction.amount = "EUR:0.2" }, @@ -811,6 +823,7 @@ run_test () .label = "expect-deposit-5", .details.expect_transaction.debit_account = 3, .details.expect_transaction.credit_account = 4, + .details.expect_transaction.exchange_base_url = "https://exchange.taler.net/", .details.expect_transaction.amount = "EUR:0.2" }, @@ -893,6 +906,7 @@ run_test () .label = "expect-deposit-6", .details.expect_transaction.debit_account = 3, .details.expect_transaction.credit_account = 4, + .details.expect_transaction.exchange_base_url = "https://exchange.taler.net/", .details.expect_transaction.amount = "EUR:0.01" }, @@ -932,6 +946,7 @@ run_test () .label = "expect-deposit-7", .details.expect_transaction.debit_account = 3, .details.expect_transaction.credit_account = 4, + .details.expect_transaction.exchange_base_url = "https://exchange.taler.net/", .details.expect_transaction.amount = "EUR:0.01" }, /* Now check profit was actually taken */ @@ -953,6 +968,7 @@ run_test () .label = "expect-deposit-7", .details.expect_transaction.debit_account = 3, .details.expect_transaction.credit_account = 4, + .details.expect_transaction.exchange_base_url = "https://exchange.taler.net/", .details.expect_transaction.amount = "EUR:0.02" }, @@ -1010,6 +1026,7 @@ run_test () .label = "expect-deposit-8", .details.expect_transaction.debit_account = 3, .details.expect_transaction.credit_account = 4, + .details.expect_transaction.exchange_base_url = "https://exchange.taler.net/", .details.expect_transaction.amount = "EUR:0.04" }, @@ -1069,6 +1086,7 @@ run_test () .label = "expect-deposit-9", .details.expect_transaction.debit_account = 3, .details.expect_transaction.credit_account = 4, + .details.expect_transaction.exchange_base_url = "https://exchange.taler.net/", .details.expect_transaction.amount = "EUR:0.02" }, @@ -1142,7 +1160,8 @@ run (void *cls) GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), - &maint_child_death, NULL); + &maint_child_death, + NULL); GNUNET_SCHEDULER_add_shutdown (&shutdown_action, NULL); timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, @@ -1195,9 +1214,11 @@ main (int argc, } plugin_name++; (void) GNUNET_asprintf (&testname, - "test-taler-exchange-aggregator-%s", plugin_name); + "test-taler-exchange-aggregator-%s", + plugin_name); (void) GNUNET_asprintf (&config_filename, - "%s.conf", testname); + "%s.conf", + testname); /* these might get in the way */ unsetenv ("XDG_DATA_HOME"); unsetenv ("XDG_CONFIG_HOME"); @@ -1214,13 +1235,16 @@ main (int argc, GNUNET_free (testname); return 2; } - sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO); + 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); + GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, + &sighandler_child_death); coin_pk = GNUNET_CRYPTO_rsa_private_key_create (1024); coin_pub = GNUNET_CRYPTO_rsa_private_key_get_public (coin_pk); - GNUNET_SCHEDULER_run (&run, cfg); + GNUNET_SCHEDULER_run (&run, + cfg); GNUNET_CRYPTO_rsa_private_key_free (coin_pk); GNUNET_CRYPTO_rsa_public_key_free (coin_pub); GNUNET_SIGNAL_handler_uninstall (shc_chld); diff --git a/src/include/taler_bank_service.h b/src/include/taler_bank_service.h index 221e9b013..e5ea42123 100644 --- a/src/include/taler_bank_service.h +++ b/src/include/taler_bank_service.h @@ -57,8 +57,9 @@ typedef void * to the operators of the bank. * * @param ctx curl context for the event loop - * @param bank_base_url URL of the bank - * @param reserve_pub public key of the reserve + * @param bank_base_url URL of the bank (used to execute this request) + * @param exchange_base_url base URL of the exchange (for tracking) + * @param wtid wire transfer identifier for the transfer * @param amount amount that was deposited * @param execution_date when did we receive the amount * @param debit_account_no account number to withdraw from (53 bits at most) @@ -72,6 +73,7 @@ typedef void struct TALER_BANK_AdminAddIncomingHandle * TALER_BANK_admin_add_incoming (struct GNUNET_CURL_Context *ctx, const char *bank_base_url, + const char *exchange_base_url, const struct TALER_WireTransferIdentifierRawP *wtid, const struct TALER_Amount *amount, uint64_t debit_account_no, diff --git a/src/include/taler_fakebank_lib.h b/src/include/taler_fakebank_lib.h index d2267cfba..f584cb85c 100644 --- a/src/include/taler_fakebank_lib.h +++ b/src/include/taler_fakebank_lib.h @@ -71,15 +71,18 @@ TALER_FAKEBANK_check_empty (struct TALER_FAKEBANK_Handle *h); * @param want_amount transfer amount desired * @param want_debit account that should have been debited * @param want_debit account that should have been credited + * @param exchange_base_url expected base URL of the exchange, + * i.e. "https://example.com/"; may include a port * @param[out] wtid set to the wire transfer identifier * @return #GNUNET_OK on success */ int TALER_FAKEBANK_check (struct TALER_FAKEBANK_Handle *h, - const struct TALER_Amount *want_amount, - uint64_t want_debit, - uint64_t want_credit, - struct TALER_WireTransferIdentifierRawP *wtid); + const struct TALER_Amount *want_amount, + uint64_t want_debit, + uint64_t want_credit, + const char *exchange_base_url, + struct TALER_WireTransferIdentifierRawP *wtid); /** diff --git a/src/include/taler_wire_plugin.h b/src/include/taler_wire_plugin.h index 6c06e8247..7a3460357 100644 --- a/src/include/taler_wire_plugin.h +++ b/src/include/taler_wire_plugin.h @@ -155,6 +155,7 @@ struct TALER_WIRE_Plugin * @param cls the @e cls of this struct with the plugin-specific state * @param wire valid wire account information * @param amount amount to transfer, already rounded + * @param exchange_base_url base URL of this exchange * @param wtid wire transfer identifier to use * @param ptc function to call with the prepared data to persist * @param ptc_cls closure for @a ptc @@ -164,6 +165,7 @@ struct TALER_WIRE_Plugin (*prepare_wire_transfer) (void *cls, const json_t *wire, const struct TALER_Amount *amount, + const char *exchange_base_url, const struct TALER_WireTransferIdentifierRawP *wtid, TALER_WIRE_PrepareTransactionCallback ptc, void *ptc_cls); diff --git a/src/wire/plugin_wire_sepa.c b/src/wire/plugin_wire_sepa.c index 4f1d50414..e15eabbf9 100644 --- a/src/wire/plugin_wire_sepa.c +++ b/src/wire/plugin_wire_sepa.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2016 GNUnet e.V. & Inria + Copyright (C) 2016, 2017 GNUnet e.V. & Inria TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -658,6 +658,7 @@ sepa_sign_wire_details (void *cls, * @param cls the @e cls of this struct with the plugin-specific state * @param wire valid wire account information * @param amount amount to transfer, already rounded + * @param exchange_base_url base URL of the exchange (for tracking) * @param wtid wire transfer identifier to use * @param psc function to call with the prepared data to persist * @param psc_cls closure for @a psc @@ -667,6 +668,7 @@ static struct TALER_WIRE_PrepareHandle * sepa_prepare_wire_transfer (void *cls, const json_t *wire, const struct TALER_Amount *amount, + const char *exchange_base_url, const struct TALER_WireTransferIdentifierRawP *wtid, TALER_WIRE_PrepareTransactionCallback psc, void *psc_cls) diff --git a/src/wire/plugin_wire_template.c b/src/wire/plugin_wire_template.c index 416eb9c58..aa4e1a3b3 100644 --- a/src/wire/plugin_wire_template.c +++ b/src/wire/plugin_wire_template.c @@ -120,6 +120,7 @@ template_wire_validate (void *cls, * @param cls the @e cls of this struct with the plugin-specific state * @param wire valid wire account information * @param amount amount to transfer, already rounded + * @param exchange_base_url base URL of the exchange (for tracking) * @param wtid wire transfer identifier to use * @param ptc function to call with the prepared data to persist * @param ptc_cls closure for @a ptc @@ -129,6 +130,7 @@ static struct TALER_WIRE_PrepareHandle * template_prepare_wire_transfer (void *cls, const json_t *wire, const struct TALER_Amount *amount, + const char *exchange_base_url, const struct TALER_WireTransferIdentifierRawP *wtid, TALER_WIRE_PrepareTransactionCallback ptc, void *ptc_cls) diff --git a/src/wire/plugin_wire_test.c b/src/wire/plugin_wire_test.c index 7b52dee40..84bff98bd 100644 --- a/src/wire/plugin_wire_test.c +++ b/src/wire/plugin_wire_test.c @@ -85,6 +85,11 @@ struct TALER_WIRE_PrepareHandle */ json_t *wire; + /** + * Base URL to use for the exchange. + */ + char *exchange_base_url; + /** * Function to call with the serialized data. */ @@ -397,7 +402,9 @@ struct BufFormatP */ struct TALER_AmountNBO amount; - /* followed by serialized 'wire' JSON data */ + /* followed by serialized 'wire' JSON data (0-terminated) */ + + /* followed by 0-terminated base URL */ }; GNUNET_NETWORK_STRUCT_END @@ -417,6 +424,7 @@ test_prepare_wire_transfer_cancel (void *cls, if (NULL != pth->task) GNUNET_SCHEDULER_cancel (pth->task); json_decref (pth->wire); + GNUNET_free (pth->exchange_base_url); GNUNET_free (pth); } @@ -432,7 +440,8 @@ do_prepare (void *cls) { struct TALER_WIRE_PrepareHandle *pth = cls; char *wire_enc; - size_t len; + size_t len_w; + size_t len_b; struct BufFormatP bf; pth->task = NULL; @@ -449,19 +458,23 @@ do_prepare (void *cls) pth); return; } - len = strlen (wire_enc) + 1; + len_w = strlen (wire_enc) + 1; + len_b = strlen (pth->exchange_base_url) + 1; bf.wtid = pth->wtid; TALER_amount_hton (&bf.amount, &pth->amount); { - char buf[sizeof (struct BufFormatP) + len]; + char buf[sizeof (struct BufFormatP) + len_w + len_b]; memcpy (buf, &bf, sizeof (struct BufFormatP)); memcpy (&buf[sizeof (struct BufFormatP)], wire_enc, - len); + len_w); + memcpy (&buf[sizeof (struct BufFormatP) + len_w], + pth->exchange_base_url, + len_b); /* finally give the state back */ pth->ptc (pth->ptc_cls, @@ -485,6 +498,7 @@ do_prepare (void *cls) * @param cls the @e cls of this struct with the plugin-specific state * @param wire valid wire account information * @param amount amount to transfer, already rounded + * @param exchange_base_url base URL of this exchange * @param wtid wire transfer identifier to use * @param ptc function to call with the prepared data to persist * @param ptc_cls closure for @a ptc @@ -494,6 +508,7 @@ static struct TALER_WIRE_PrepareHandle * test_prepare_wire_transfer (void *cls, const json_t *wire, const struct TALER_Amount *amount, + const char *exchange_base_url, const struct TALER_WireTransferIdentifierRawP *wtid, TALER_WIRE_PrepareTransactionCallback ptc, void *ptc_cls) @@ -515,6 +530,7 @@ test_prepare_wire_transfer (void *cls, pth = GNUNET_new (struct TALER_WIRE_PrepareHandle); pth->tc = tc; pth->wire = json_incref ((json_t *) wire); + pth->exchange_base_url = GNUNET_strdup (exchange_base_url); pth->wtid = *wtid; pth->ptc = ptc; pth->ptc_cls = ptc_cls; @@ -650,6 +666,8 @@ test_execute_wire_transfer (void *cls, json_int_t account_no; struct BufFormatP bf; char *emsg; + const char *json_s; + const char *exchange_base_url; if (NULL == tc->ctx) { @@ -658,7 +676,14 @@ test_execute_wire_transfer (void *cls, return NULL; /* not initialized with configuration, cannot do transfers */ } if ( (buf_size <= sizeof (struct BufFormatP)) || - ('\0' != buf[buf_size -1]) ) + ('\0' != buf[buf_size - 1]) ) + { + GNUNET_break (0); + return NULL; + } + json_s = &buf[sizeof (struct BufFormatP)]; + exchange_base_url = &json_s[strlen (json_s) + 1]; + if (exchange_base_url > &buf[buf_size - 1]) { GNUNET_break (0); return NULL; @@ -668,7 +693,7 @@ test_execute_wire_transfer (void *cls, sizeof (bf)); TALER_amount_ntoh (&amount, &bf.amount); - wire = json_loads (&buf[sizeof (struct BufFormatP)], + wire = json_loads (json_s, JSON_REJECT_DUPLICATES, NULL); if (NULL == wire) @@ -697,6 +722,7 @@ test_execute_wire_transfer (void *cls, eh->cc_cls = cc_cls; eh->aaih = TALER_BANK_admin_add_incoming (tc->ctx, tc->bank_uri, + exchange_base_url, &bf.wtid, &amount, (uint64_t) tc->exchange_account_outgoing_no, -- cgit v1.2.3