summaryrefslogtreecommitdiff
path: root/src/wire
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-05-04 18:35:53 +0200
committerChristian Grothoff <christian@grothoff.org>2017-05-04 18:35:53 +0200
commitf4df63e448c9bcd990ec9a41eb6cb19a36246099 (patch)
treec53f8f31dfc346b416cbfeb43a715b4060e19bc3 /src/wire
parent234dbcc7b71ac98e7f63393e454377d1e2ae11c7 (diff)
downloadexchange-f4df63e448c9bcd990ec9a41eb6cb19a36246099.tar.gz
exchange-f4df63e448c9bcd990ec9a41eb6cb19a36246099.tar.bz2
exchange-f4df63e448c9bcd990ec9a41eb6cb19a36246099.zip
adding support for transaction history to wire plugin API (#4959)
Diffstat (limited to 'src/wire')
-rw-r--r--src/wire/plugin_wire_sepa.c48
-rw-r--r--src/wire/plugin_wire_template.c48
-rw-r--r--src/wire/plugin_wire_test.c186
-rw-r--r--src/wire/test_wire_plugin.conf2
-rw-r--r--src/wire/wire-sepa.conf1
-rw-r--r--src/wire/wire-test.conf10
6 files changed, 274 insertions, 21 deletions
diff --git a/src/wire/plugin_wire_sepa.c b/src/wire/plugin_wire_sepa.c
index 20a7af858..5baa3eaba 100644
--- a/src/wire/plugin_wire_sepa.c
+++ b/src/wire/plugin_wire_sepa.c
@@ -736,6 +736,52 @@ sepa_execute_wire_transfer_cancel (void *cls,
/**
+ * Query transfer history of an account. We use the variable-size
+ * @a start_off to indicate which transfers we are interested in as
+ * different banking systems may have different ways to identify
+ * transfers. The @a start_off value must thus match the value of
+ * a `row_off` argument previously given to the @a hres_cb. Use
+ * NULL to query transfers from the beginning of time (with
+ * positive @a num_results) or from the latest committed transfers
+ * (with negative @a num_results).
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param direction what kinds of wire transfers should be returned
+ * @param start_off from which row on do we want to get results, use NULL for the latest; exclusive
+ * @param start_off_len number of bytes in @a start_off; must be `sizeof(uint64_t)`.
+ * @param num_results how many results do we want; negative numbers to go into the past,
+ * positive numbers to go into the future starting at @a start_row;
+ * must not be zero.
+ * @param hres_cb the callback to call with the transaction history
+ * @param hres_cb_cls closure for the above callback
+ */
+static struct TALER_WIRE_HistoryHandle *
+sepa_get_history (void *cls,
+ enum TALER_BANK_Direction direction,
+ const void *start_off,
+ size_t start_off_len,
+ int64_t num_results,
+ TALER_WIRE_HistoryResultCallback hres_cb,
+ void *hres_cb_cls)
+{
+ GNUNET_break (0);
+ return NULL;
+}
+
+
+/**
+ * Cancel going over the account's history.
+ *
+ * @param whh operation to cancel
+ */
+static void
+sepa_get_history_cancel (struct TALER_WIRE_HistoryHandle *whh)
+{
+ GNUNET_break (0);
+}
+
+
+/**
* Initialize sepa-wire subsystem.
*
* @param cls a configuration instance
@@ -774,6 +820,8 @@ libtaler_plugin_wire_sepa_init (void *cls)
plugin->prepare_wire_transfer_cancel = &sepa_prepare_wire_transfer_cancel;
plugin->execute_wire_transfer = &sepa_execute_wire_transfer;
plugin->execute_wire_transfer_cancel = &sepa_execute_wire_transfer_cancel;
+ plugin->get_history = &sepa_get_history;
+ plugin->get_history_cancel = &sepa_get_history_cancel;
return plugin;
}
diff --git a/src/wire/plugin_wire_template.c b/src/wire/plugin_wire_template.c
index 95db1583e..e94b2f05b 100644
--- a/src/wire/plugin_wire_template.c
+++ b/src/wire/plugin_wire_template.c
@@ -220,6 +220,52 @@ template_execute_wire_transfer_cancel (void *cls,
/**
+ * Query transfer history of an account. We use the variable-size
+ * @a start_off to indicate which transfers we are interested in as
+ * different banking systems may have different ways to identify
+ * transfers. The @a start_off value must thus match the value of
+ * a `row_off` argument previously given to the @a hres_cb. Use
+ * NULL to query transfers from the beginning of time (with
+ * positive @a num_results) or from the latest committed transfers
+ * (with negative @a num_results).
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param direction what kinds of wire transfers should be returned
+ * @param start_off from which row on do we want to get results, use NULL for the latest; exclusive
+ * @param start_off_len number of bytes in @a start_off; must be `sizeof(uint64_t)`.
+ * @param num_results how many results do we want; negative numbers to go into the past,
+ * positive numbers to go into the future starting at @a start_row;
+ * must not be zero.
+ * @param hres_cb the callback to call with the transaction history
+ * @param hres_cb_cls closure for the above callback
+ */
+static struct TALER_WIRE_HistoryHandle *
+template_get_history (void *cls,
+ enum TALER_BANK_Direction direction,
+ const void *start_off,
+ size_t start_off_len,
+ int64_t num_results,
+ TALER_WIRE_HistoryResultCallback hres_cb,
+ void *hres_cb_cls)
+{
+ GNUNET_break (0);
+ return NULL;
+}
+
+
+/**
+ * Cancel going over the account's history.
+ *
+ * @param whh operation to cancel
+ */
+static void
+template_get_history_cancel (struct TALER_WIRE_HistoryHandle *whh)
+{
+ GNUNET_break (0);
+}
+
+
+/**
* Initialize template-wire subsystem.
*
* @param cls a configuration instance
@@ -270,6 +316,8 @@ libtaler_plugin_wire_template_init (void *cls)
plugin->prepare_wire_transfer_cancel = &template_prepare_wire_transfer_cancel;
plugin->execute_wire_transfer = &template_execute_wire_transfer;
plugin->execute_wire_transfer_cancel = &template_execute_wire_transfer_cancel;
+ plugin->get_history = &template_get_history;
+ plugin->get_history_cancel = &template_get_history_cancel;
return plugin;
}
diff --git a/src/wire/plugin_wire_test.c b/src/wire/plugin_wire_test.c
index 12adade81..b034fea80 100644
--- a/src/wire/plugin_wire_test.c
+++ b/src/wire/plugin_wire_test.c
@@ -62,9 +62,9 @@ struct TestClosure
/**
* Number of the account that the exchange has at the bank for
- * outgoing transfers.
+ * transfers.
*/
- unsigned long long exchange_account_outgoing_no;
+ unsigned long long exchange_account_no;
};
@@ -731,7 +731,7 @@ test_execute_wire_transfer (void *cls,
exchange_base_url,
&bf.wtid,
&amount,
- (uint64_t) tc->exchange_account_outgoing_no,
+ (uint64_t) tc->exchange_account_no,
(uint64_t) account_no,
&execute_cb,
eh);
@@ -768,6 +768,166 @@ test_execute_wire_transfer_cancel (void *cls,
/**
+ * Handle for a #test_get_history() request.
+ */
+struct TALER_WIRE_HistoryHandle
+{
+
+ /**
+ * Function to call with results.
+ */
+ TALER_WIRE_HistoryResultCallback hres_cb;
+
+ /**
+ * Closure for @e hres_cb.
+ */
+ void *hres_cb_cls;
+
+ /**
+ * Request to the bank.
+ */
+ struct TALER_BANK_HistoryHandle *hh;
+
+};
+
+
+/**
+ * Function called with results from the bank about the transaction history.
+ *
+ * @param cls the `struct TALER_WIRE_HistoryHandle`
+ * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request
+ * 0 if the bank's reply is bogus (fails to follow the protocol),
+ * #MHD_HTTP_NO_CONTENT if there are no more results; on success the
+ * last callback is always of this status (even if `abs(num_results)` were
+ * already returned).
+ * @param dir direction of the transfer
+ * @param serial_id monotonically increasing counter corresponding to the transaction
+ * @param details details about the wire transfer
+ * @param json detailed response from the HTTPD, or NULL if reply was not in JSON
+ */
+static void
+bhist_cb (void *cls,
+ unsigned int http_status,
+ enum TALER_BANK_Direction dir,
+ uint64_t serial_id,
+ const struct TALER_BANK_TransferDetails *details,
+ const json_t *json)
+{
+ struct TALER_WIRE_HistoryHandle *whh = cls;
+ uint64_t bserial_id = GNUNET_htonll (serial_id);
+
+ whh->hres_cb (whh->hres_cb_cls,
+ http_status,
+ dir,
+ &bserial_id,
+ sizeof (bserial_id),
+ details,
+ json);
+ if (MHD_HTTP_OK != http_status)
+ {
+ whh->hh = NULL;
+ GNUNET_free (whh);
+ return;
+ }
+}
+
+
+/**
+ * Query transfer history of an account. We use the variable-size
+ * @a start_off to indicate which transfers we are interested in as
+ * different banking systems may have different ways to identify
+ * transfers. The @a start_off value must thus match the value of
+ * a `row_off` argument previously given to the @a hres_cb. Use
+ * NULL to query transfers from the beginning of time (with
+ * positive @a num_results) or from the latest committed transfers
+ * (with negative @a num_results).
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param direction what kinds of wire transfers should be returned
+ * @param start_off from which row on do we want to get results, use NULL for the latest; exclusive
+ * @param start_off_len number of bytes in @a start_off; must be `sizeof(uint64_t)`.
+ * @param num_results how many results do we want; negative numbers to go into the past,
+ * positive numbers to go into the future starting at @a start_row;
+ * must not be zero.
+ * @param hres_cb the callback to call with the transaction history
+ * @param hres_cb_cls closure for the above callback
+ */
+static struct TALER_WIRE_HistoryHandle *
+test_get_history (void *cls,
+ enum TALER_BANK_Direction direction,
+ const void *start_off,
+ size_t start_off_len,
+ int64_t num_results,
+ TALER_WIRE_HistoryResultCallback hres_cb,
+ void *hres_cb_cls)
+{
+ struct TestClosure *tc = cls;
+ struct TALER_WIRE_HistoryHandle *whh;
+ const uint64_t *start_off_b64;
+ uint64_t start_row;
+
+ if (0 == num_results)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ if (TALER_BANK_DIRECTION_NONE == direction)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ if ( (NULL != start_off) &&
+ (sizeof (uint64_t) != start_off_len) )
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ if (NULL == start_off)
+ {
+ start_row = (num_results > 0) ? 0 : UINT64_MAX;
+ }
+ else
+ {
+ start_off_b64 = start_off;
+ start_row = GNUNET_ntohll (*start_off_b64);
+ }
+
+ whh = GNUNET_new (struct TALER_WIRE_HistoryHandle);
+ whh->hres_cb = hres_cb;
+ whh->hres_cb_cls = hres_cb_cls;
+ whh->hh = TALER_BANK_history (tc->ctx,
+ tc->bank_uri,
+ &tc->auth,
+ (uint64_t) tc->exchange_account_no,
+ direction,
+ start_row,
+ num_results,
+ &bhist_cb,
+ whh);
+ if (NULL == whh->hh)
+ {
+ GNUNET_break (0);
+ GNUNET_free (whh);
+ return NULL;
+ }
+ return whh;
+}
+
+
+/**
+ * Cancel going over the account's history.
+ *
+ * @param whh operation to cancel
+ */
+static void
+test_get_history_cancel (struct TALER_WIRE_HistoryHandle *whh)
+{
+ TALER_BANK_history_cancel (whh->hh);
+ GNUNET_free (whh);
+}
+
+
+/**
* Initialize test-wire subsystem.
*
* @param cls a configuration instance
@@ -787,24 +947,24 @@ libtaler_plugin_wire_test_init (void *cls)
{
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- "exchange-wire-outgoing-test",
+ "exchange-wire-test",
"BANK_URI",
&tc->bank_uri))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange-wire-outgoing-test",
+ "exchange-wire-test",
"BANK_URI");
GNUNET_free (tc);
return NULL;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg,
- "exchange-wire-outgoing-test",
+ "exchange-wire-test",
"EXCHANGE_ACCOUNT_NUMBER",
- &tc->exchange_account_outgoing_no))
+ &tc->exchange_account_no))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange-wire-outgoing-test",
+ "exchange-wire-test",
"EXCHANGE_ACCOUNT_NUMBER");
GNUNET_free (tc->bank_uri);
GNUNET_free (tc);
@@ -825,12 +985,12 @@ libtaler_plugin_wire_test_init (void *cls)
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- "exchange-wire-outgoing-test",
+ "exchange-wire-test",
"USERNAME",
&user))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange-wire-outgoing-test",
+ "exchange-wire-test",
"USERNAME");
GNUNET_free (tc->bank_uri);
GNUNET_free (tc);
@@ -838,12 +998,12 @@ libtaler_plugin_wire_test_init (void *cls)
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
- "exchange-wire-outgoing-test",
+ "exchange-wire-test",
"PASSWORD",
&pass))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange-wire-outgoing-test",
+ "exchange-wire-test",
"PASSWORD");
GNUNET_free (tc->bank_uri);
GNUNET_free (tc);
@@ -877,6 +1037,8 @@ libtaler_plugin_wire_test_init (void *cls)
plugin->prepare_wire_transfer_cancel = &test_prepare_wire_transfer_cancel;
plugin->execute_wire_transfer = &test_execute_wire_transfer;
plugin->execute_wire_transfer_cancel = &test_execute_wire_transfer_cancel;
+ plugin->get_history = &test_get_history;
+ plugin->get_history_cancel = &test_get_history_cancel;
return plugin;
}
diff --git a/src/wire/test_wire_plugin.conf b/src/wire/test_wire_plugin.conf
index 8f7e311a6..717c1667c 100644
--- a/src/wire/test_wire_plugin.conf
+++ b/src/wire/test_wire_plugin.conf
@@ -11,7 +11,7 @@ TEST_RESPONSE_FILE = test_wire_plugin_test.json
SEPA_RESPONSE_FILE = test_wire_plugin_sepa.json
-[exchange-wire-outgoing-test]
+[exchange-wire-test]
# For transfers made by the exchange, we need to know
# the URI of the bank (where the /admin/add/incoming API
# is avaialble).
diff --git a/src/wire/wire-sepa.conf b/src/wire/wire-sepa.conf
index 88d2ac03c..eb43d3dcc 100644
--- a/src/wire/wire-sepa.conf
+++ b/src/wire/wire-sepa.conf
@@ -6,7 +6,6 @@
# Set to "YES" to activate the 'sepa' plugin.
ENABLE = NO
-[exchange-wire-incoming-sepa]
# This is the response we give out for the /wire request. It provides
# wallets with the bank information for transfers to the exchange.
SEPA_RESPONSE_FILE = ${TALER_CONFIG_HOME}/exchange/wire/sepa.json
diff --git a/src/wire/wire-test.conf b/src/wire/wire-test.conf
index bd282ff65..29846ce53 100644
--- a/src/wire/wire-test.conf
+++ b/src/wire/wire-test.conf
@@ -6,19 +6,15 @@
# Set to "YES" to activate the 'test' plugin.
ENABLE = NO
-[exchange-wire-incoming-test]
# This is the response we give out for the /wire request. It provides
# wallets with the bank information for transfers to the exchange.
TEST_RESPONSE_FILE = ${TALER_CONFIG_HOME}/exchange/wire/test.json
-[exchange-wire-outgoing-test]
-# For outgoing transfers, we need to know the exchange's
-# account number at the bank.
+# We need to know the exchange's account number at the bank.
EXCHANGE_ACCOUNT_NUMBER = 2
-# For transfers made by the exchange, we need to know
-# the URI of the bank (where the /admin/add/incoming API
-# is avaialble).
+# For accessing transfers, we need to know
+# the URI of the bank (where the /history API is available).
# BANK_URI = https://bank.demo.taler.net/
# Authentication information for basic authentication