summaryrefslogtreecommitdiff
path: root/src/exchange-tools/taler-wire.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchange-tools/taler-wire.c')
-rw-r--r--src/exchange-tools/taler-wire.c268
1 files changed, 114 insertions, 154 deletions
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",