diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-01-11 15:19:56 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-01-11 15:20:17 +0100 |
commit | 9443c10d7feb0d91323869dd08ec61ca781564f4 (patch) | |
tree | fd617ea56cc1d2ea370ce7e5467574a536b52d28 /src/exchange-tools | |
parent | 554da10133eb491b352a106b98ebeaed797133bb (diff) | |
download | exchange-9443c10d7feb0d91323869dd08ec61ca781564f4.tar.xz |
major refactoring, eliminating wire-plugins and moving towards new bank API. main code compiles, testcases known to fail, code sure not to fully work yet
Diffstat (limited to 'src/exchange-tools')
-rw-r--r-- | src/exchange-tools/Makefile.am | 4 | ||||
-rw-r--r-- | src/exchange-tools/taler-exchange-keyup.c | 23 | ||||
-rw-r--r-- | src/exchange-tools/taler-wire.c | 268 |
3 files changed, 123 insertions, 172 deletions
diff --git a/src/exchange-tools/Makefile.am b/src/exchange-tools/Makefile.am index 64b4cee87..0b9a2d528 100644 --- a/src/exchange-tools/Makefile.am +++ b/src/exchange-tools/Makefile.am @@ -23,7 +23,9 @@ taler_wire_SOURCES = \ taler-wire.c taler_wire_LDADD = \ $(top_builddir)/src/util/libtalerutil.la \ + $(top_builddir)/src/bank-lib/libtalerbank.la \ $(top_builddir)/src/wire/libtalerwire.la \ + -lgnunetcurl \ -lgnunetutil taler_exchange_keyup_SOURCES = \ @@ -32,6 +34,7 @@ taler_exchange_keyup_LDADD = \ $(LIBGCRYPT_LIBS) \ $(top_builddir)/src/util/libtalerutil.la \ $(top_builddir)/src/pq/libtalerpq.la \ + $(top_builddir)/src/bank-lib/libtalerbank.la \ $(top_builddir)/src/wire/libtalerwire.la \ $(top_builddir)/src/exchangedb/libtalerexchangedb.la \ -lgnunetutil $(XLIB) @@ -44,6 +47,7 @@ taler_exchange_wire_LDADD = \ $(LIBGCRYPT_LIBS) \ $(top_builddir)/src/json/libtalerjson.la \ $(top_builddir)/src/exchangedb/libtalerexchangedb.la \ + $(top_builddir)/src/bank-lib/libtalerbank.la \ $(top_builddir)/src/wire/libtalerwire.la \ $(top_builddir)/src/util/libtalerutil.la \ -lgnunetjson \ diff --git a/src/exchange-tools/taler-exchange-keyup.c b/src/exchange-tools/taler-exchange-keyup.c index e6e3db0d1..f2ec3ca8f 100644 --- a/src/exchange-tools/taler-exchange-keyup.c +++ b/src/exchange-tools/taler-exchange-keyup.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2018 Taler Systems SA + Copyright (C) 2014-2020 Taler Systems SA 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 @@ -923,17 +923,17 @@ exchange_keys_update_denomkeys () * Sign @a af with @a priv * * @param[in,out] af fee structure to sign - * @param wireplugin name of the plugin for which we sign + * @param method name of the wire method for which we sign * @param priv private key to use for signing */ static void sign_af (struct TALER_EXCHANGEDB_AggregateFees *af, - const char *wireplugin, + const char *method, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv) { struct TALER_MasterWireFeePS wf; - TALER_EXCHANGEDB_fees_2_wf (wireplugin, + TALER_EXCHANGEDB_fees_2_wf (method, af, &wf); GNUNET_assert (GNUNET_OK == @@ -1101,28 +1101,15 @@ create_wire_fee_by_account (void *cls, const struct TALER_EXCHANGEDB_AccountInfo *ai) { int *ret = cls; - struct TALER_WIRE_Plugin *plugin; if (GNUNET_NO == ai->credit_enabled) return; - plugin = TALER_WIRE_plugin_load (kcfg, - ai->plugin_name); - if (NULL == plugin) - { - fprintf (stderr, - "Failed to load wire plugin `%s' configured for account `%s'\n", - ai->plugin_name, - ai->section_name); - *ret = GNUNET_SYSERR; - return; - } /* We may call this function repeatedly for the same method if there are multiple accounts with plugins using the same method, but except for some minor performance loss, this is harmless. */ create_wire_fee_for_method (ret, - plugin->method); - TALER_WIRE_plugin_unload (plugin); + ai->method); } diff --git a/src/exchange-tools/taler-wire.c b/src/exchange-tools/taler-wire.c index 12963324a..5e3c18a61 100644 --- a/src/exchange-tools/taler-wire.c +++ b/src/exchange-tools/taler-wire.c @@ -22,11 +22,10 @@ * @author Marcello Stanisci * @author Christian Grothoff */ - #include <platform.h> #include <gnunet/gnunet_util_lib.h> #include "taler_util.h" -#include "taler_wire_lib.h" +#include "taler_bank_service.h" /** * If set to #GNUNET_YES, then we'll ask the bank for a list @@ -36,17 +35,12 @@ static int history; /** - * If set to GNUNET_YES, then we'll ask the bank to execute a + * If set to #GNUNET_YES, then we'll ask the bank to execute a * wire transfer. */ static int transfer; /** - * Name of the wire plugin to use with the bank. - */ -static char *plugin_name; - -/** * Global return code. */ static unsigned int global_ret = 1; @@ -59,11 +53,9 @@ static unsigned int global_ret = 1; static char *amount; /** - * Base32 encoding of a transaction ID. When asking the - * bank for a transaction history, all the results will - * have a transaction ID settled *after* this one. + * Starting row. */ -static char *since_when; +static unsigned long long start_row; /** * Which config section has the credentials to access the bank. @@ -77,19 +69,29 @@ static char *account_section; static char *destination_account_url; /** - * Handle for the wire transfer preparation task. + * Handle for executing the wire transfer. */ -static struct TALER_WIRE_PrepareHandle *ph; +static struct TALER_BANK_WireExecuteHandle *eh; /** - * Wire plugin handle. + * Handle to ongoing history operation. */ -static struct TALER_WIRE_Plugin *plugin_handle; +static struct TALER_BANK_CreditHistoryHandle *hh; /** - * Handle to ongoing history operation. + * For authentication. + */ +static struct TALER_BANK_AuthenticationData auth; + +/** + * Handle to the context for interacting with the bank. */ -static struct TALER_WIRE_HistoryHandle *hh; +static struct GNUNET_CURL_Context *ctx; + +/** + * Scheduler context for running the @e ctx. + */ +static struct GNUNET_CURL_RescheduleContext *rc; /** @@ -108,16 +110,16 @@ static struct TALER_WIRE_HistoryHandle *hh; */ static int history_cb (void *cls, + unsigned int http_status, enum TALER_ErrorCode ec, - enum TALER_BANK_Direction dir, - const void *row_off, - size_t row_off_size, - const struct TALER_WIRE_TransferDetails *details) + uint64_t serial_id, + const struct TALER_BANK_CreditDetails *details, + const json_t *json) { - char *row_off_enc; - (void) cls; - if (TALER_BANK_DIRECTION_NONE == dir) + (void) ec; + (void) http_status; + if (NULL == details) { fprintf (stdout, "End of transactions list.\n"); @@ -126,15 +128,9 @@ history_cb (void *cls, return GNUNET_NO; } - row_off_enc = GNUNET_STRINGS_data_to_string_alloc (row_off, - row_off_size); - /* Give more details on screen (??) */ fprintf (stdout, - "%s\n", - row_off_enc); - - GNUNET_free (row_off_enc); - + "%llu\n", + (unsigned long long) serial_id); return GNUNET_OK; } @@ -142,72 +138,37 @@ history_cb (void *cls, /** * Callback that processes the outcome of a wire transfer * execution. + * + * @param cls closure + * @param response_code HTTP status code + * @param ec taler error code + * @param row_id unique ID of the wire transfer in the bank's records + * @param timestamp when did the transaction go into effect */ static void confirmation_cb (void *cls, - int success, - const void *row_id, - size_t row_id_size, - const char *emsg) + unsigned int response_code, + enum TALER_ErrorCode ec, + uint64_t row_id, + struct GNUNET_TIME_Absolute timestamp) { - if (GNUNET_YES != success) + if (MHD_HTTP_OK != response_code) { fprintf (stderr, - "The wire transfer didn't execute correctly.\n"); - GNUNET_assert (NULL != emsg); - fprintf (stderr, - "%s", - emsg); + "The wire transfer didn't execute correctly (%d).\n", + ec); GNUNET_SCHEDULER_shutdown (); return; } fprintf (stdout, "Wire transfer executed successfully.\n"); - global_ret = 0; GNUNET_SCHEDULER_shutdown (); } /** - * Takes prepared blob and executes the wire-transfer. - * - * @param cls NULL. - * @param buf prepared wire transfer data. - * @param buf_size size of the prepared wire transfer data. - */ -static void -prepare_cb (void *cls, - const char *buf, - size_t buf_size) -{ - struct TALER_WIRE_ExecuteHandle *eh; - - if (NULL == (eh = plugin_handle->execute_wire_transfer - (plugin_handle->cls, - buf, - buf_size, - confirmation_cb, - NULL))) - { - fprintf (stderr, - "Could not execute the wire transfer\n"); - - plugin_handle->prepare_wire_transfer_cancel - (plugin_handle->cls, - ph); - - plugin_handle->execute_wire_transfer_cancel - (plugin_handle->cls, - eh); - - GNUNET_SCHEDULER_shutdown (); - } -} - - -/** * Ask the bank to execute a wire transfer. */ static void @@ -215,6 +176,8 @@ execute_wire_transfer () { struct TALER_Amount a; struct TALER_WireTransferIdentifierRawP wtid; + void *buf; + size_t buf_size; if (NULL == amount) { @@ -223,7 +186,6 @@ execute_wire_transfer () GNUNET_SCHEDULER_shutdown (); return; } - if (GNUNET_OK != TALER_string_to_amount (amount, &a)) { @@ -240,19 +202,25 @@ execute_wire_transfer () GNUNET_SCHEDULER_shutdown (); return; } - if (NULL == (ph = plugin_handle->prepare_wire_transfer - (plugin_handle->cls, - account_section, - destination_account_url, - &a, - "http://exchange.example.com/", - &wtid, /* Any value will do. */ - prepare_cb, - NULL))) + TALER_BANK_prepare_wire_transfer (destination_account_url, + &a, + "http://exchange.example.com/", + &wtid, + &buf, + &buf_size); + eh = TALER_BANK_execute_wire_transfer (ctx, + destination_account_url, + &auth, + buf, + buf_size, + &confirmation_cb, + NULL); + if (NULL == eh) { fprintf (stderr, - "Could not prepare the wire transfer\n"); + "Could not execute the wire transfer\n"); GNUNET_SCHEDULER_shutdown (); + return; } } @@ -264,30 +232,14 @@ execute_wire_transfer () static void execute_history () { - size_t bin_len = 0; - void *since_when_bin = NULL; - - if (NULL != since_when) - { - bin_len = (strlen (since_when) * 5) / 8; - - since_when_bin = GNUNET_malloc (bin_len); - GNUNET_assert - (GNUNET_OK == GNUNET_STRINGS_string_to_data - (since_when, - strlen (since_when), - since_when_bin, - bin_len)); - } - - if (NULL == (hh = plugin_handle->get_history (plugin_handle->cls, - account_section, - TALER_BANK_DIRECTION_BOTH, - since_when_bin, - bin_len, - -10, - &history_cb, - NULL))) + hh = TALER_BANK_credit_history (ctx, + destination_account_url, + &auth, + start_row, + -10, + &history_cb, + NULL); + if (NULL == hh) { fprintf (stderr, "Could not request the transaction history.\n"); @@ -305,19 +257,27 @@ execute_history () static void do_shutdown (void *cls) { + if (NULL != ctx) + { + GNUNET_CURL_fini (ctx); + ctx = NULL; + } + if (NULL != rc) + { + GNUNET_CURL_gnunet_rc_destroy (rc); + rc = NULL; + } if (NULL != hh) { - plugin_handle->get_history_cancel (plugin_handle->cls, - hh); + TALER_BANK_credit_history_cancel (hh); hh = NULL; } - if (NULL != ph) + if (NULL != eh) { - plugin_handle->prepare_wire_transfer_cancel (plugin_handle->cls, - ph); - ph = NULL; + TALER_BANK_execute_wire_transfer_cancel (eh); + eh = NULL; } - TALER_WIRE_plugin_unload (plugin_handle); + TALER_BANK_auth_free (&auth); } @@ -342,27 +302,18 @@ run (void *cls, "The option: -s ACCOUNT-SECTION, is mandatory.\n"); return; } - - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string - (cfg, - account_section, - "plugin", - &plugin_name)) + if (GNUNET_OK != + TALER_BANK_auth_parse_cfg (cfg, + account_section, + &auth)) { fprintf (stderr, - "Could not find the 'plugin' value under %s\n", + "Authentication information not found in configuration section `%s'\n", account_section); + GNUNET_SCHEDULER_shutdown (); return; } - plugin_handle = TALER_WIRE_plugin_load (cfg, - plugin_name); - if (NULL == plugin_handle) - { - fprintf (stderr, - "Could not load the wire plugin\n"); - return; - } if (GNUNET_YES == history) execute_history (); @@ -372,6 +323,14 @@ run (void *cls, fprintf (stderr, "Please give either --history/-H or --transfer/t\n"); + ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule, + &rc); + rc = GNUNET_CURL_gnunet_rc_create (ctx); + if (NULL == ctx) + { + GNUNET_break (0); + return; + } GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); } @@ -400,22 +359,23 @@ main (int argc, "transfer", "Execute a wire transfer.", &transfer), - GNUNET_GETOPT_option_string ('w', - "since-when", - "SW", - "When asking the bank for" - " transactions history, this" - " option commands that all the" - " results should have IDs settled" - " after SW. If not given, then" - " the 10 youngest transactions" - " are returned.", - &since_when), - GNUNET_GETOPT_option_string ('s', - "section", - "ACCOUNT-SECTION", - "Which config section has the credentials to access the bank. Mandatory.\n", - &account_section), + GNUNET_GETOPT_option_ulong ('w', + "since-when", + "SW", + "When asking the bank for" + " transactions history, this" + " option commands that all the" + " results should have IDs settled" + " after SW. If not given, then" + " the 10 youngest transactions" + " are returned.", + &start_row), + GNUNET_GETOPT_option_mandatory + (GNUNET_GETOPT_option_string ('s', + "section", + "ACCOUNT-SECTION", + "Which config section has the credentials to access the bank. Mandatory.\n", + &account_section)), GNUNET_GETOPT_option_string ('a', "amount", "AMOUNT", |