aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2019-09-05 10:58:19 +0200
committerMarcello Stanisci <stanisci.m@gmail.com>2019-09-05 11:01:15 +0200
commitb0836a8c0c6e2a9e4e677290f4f56601f1aae8bc (patch)
tree4a5dda12d4da8cbe1217c18e49b2817e172d08ce
parent997b40e7052474b6e7b6924291bb7c7b120c2690 (diff)
downloadexchange-b0836a8c0c6e2a9e4e677290f4f56601f1aae8bc.tar.gz
exchange-b0836a8c0c6e2a9e4e677290f4f56601f1aae8bc.zip
Removing date-range-based logic from wire-plugin
-rw-r--r--src/include/taler_wire_plugin.h25
-rw-r--r--src/wire-plugins/Makefile.am14
-rw-r--r--src/wire-plugins/plugin_wire_taler-bank.c86
-rw-r--r--src/wire-plugins/test_wire_plugin_legacy_taler-bank.c373
-rw-r--r--src/wire-plugins/test_wire_plugin_legacy_taler-bank.conf12
5 files changed, 1 insertions, 509 deletions
diff --git a/src/include/taler_wire_plugin.h b/src/include/taler_wire_plugin.h
index 1ee1b6b49..eb43f2277 100644
--- a/src/include/taler_wire_plugin.h
+++ b/src/include/taler_wire_plugin.h
@@ -314,31 +314,6 @@ struct TALER_WIRE_Plugin
314 void *hres_cb_cls); 314 void *hres_cb_cls);
315 315
316 /** 316 /**
317 * Query transfer history of an account. The query is based on
318 * the dates where the wire transfers got settled at the bank.
319 *
320 * @param cls the @e cls of this struct with the plugin-specific state
321 * @param account_section specifies the configuration section which
322 * identifies the account for which we should get the history
323 * @param direction what kinds of wire transfers should be returned
324 * @param start_date each history entry in the result will be time
325 * stamped after, or at this date.
326 * @param end_date each history entry in the result will be time
327 * stamped before, or at this date.
328 * @param hres_cb the callback to call with the transaction history
329 * @param hres_cb_cls closure for the above callback
330 * @param return the operation handle, or NULL on errors.
331 */
332 struct TALER_WIRE_HistoryHandle *
333 (*get_history_range) (void *cls,
334 const char *account_section,
335 enum TALER_BANK_Direction direction,
336 struct GNUNET_TIME_Absolute start_date,
337 struct GNUNET_TIME_Absolute end_date,
338 TALER_WIRE_HistoryResultCallback hres_cb,
339 void *hres_cb_cls);
340
341 /**
342 * Cancel going over the account's history. 317 * Cancel going over the account's history.
343 * 318 *
344 * @param cls plugins' closure 319 * @param cls plugins' closure
diff --git a/src/wire-plugins/Makefile.am b/src/wire-plugins/Makefile.am
index 83bb9f05f..468e95a0b 100644
--- a/src/wire-plugins/Makefile.am
+++ b/src/wire-plugins/Makefile.am
@@ -74,8 +74,7 @@ AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=
74TESTS = \ 74TESTS = \
75 test_ebics_wireformat \ 75 test_ebics_wireformat \
76 test_wire_plugin \ 76 test_wire_plugin \
77 test_wire_plugin_transactions_taler_bank \ 77 test_wire_plugin_transactions_taler_bank
78 test_wire_plugin_legacy_taler_bank
79 78
80check_PROGRAMS= $(TESTS) 79check_PROGRAMS= $(TESTS)
81 80
@@ -95,17 +94,6 @@ test_wire_plugin_LDADD = \
95 $(top_builddir)/src/util/libtalerutil.la 94 $(top_builddir)/src/util/libtalerutil.la
96 95
97 96
98test_wire_plugin_legacy_taler_bank_SOURCES = \
99 test_wire_plugin_legacy_taler-bank.c
100test_wire_plugin_legacy_taler_bank_LDADD = \
101 -lgnunetjson \
102 -lgnunetutil \
103 -ljansson \
104 $(top_builddir)/src/wire/libtalerwire.la \
105 $(top_builddir)/src/bank-lib/libtalerbank.la \
106 $(top_builddir)/src/bank-lib/libtalerfakebank.la \
107 $(top_builddir)/src/util/libtalerutil.la
108
109test_wire_plugin_transactions_taler_bank_SOURCES = \ 97test_wire_plugin_transactions_taler_bank_SOURCES = \
110 test_wire_plugin_transactions_taler-bank.c 98 test_wire_plugin_transactions_taler-bank.c
111test_wire_plugin_transactions_taler_bank_LDADD = \ 99test_wire_plugin_transactions_taler_bank_LDADD = \
diff --git a/src/wire-plugins/plugin_wire_taler-bank.c b/src/wire-plugins/plugin_wire_taler-bank.c
index 282856ecf..c9d8cf2ac 100644
--- a/src/wire-plugins/plugin_wire_taler-bank.c
+++ b/src/wire-plugins/plugin_wire_taler-bank.c
@@ -1050,92 +1050,6 @@ taler_bank_get_history (void *cls,
1050 return whh; 1050 return whh;
1051} 1051}
1052 1052
1053
1054
1055/**
1056 * Query transfer history of an account. The query is based on
1057 * the dates where the wire transfers got settled at the bank.
1058 *
1059 * @param cls the @e cls of this struct with the plugin-specific
1060 * state
1061 * @param account_section specifies the configuration section which
1062 * identifies the account for which we should get the
1063 * history
1064 * @param direction what kinds of wire transfers should be returned
1065 * @param start_date each history entry in the result will be time
1066 * stamped after, or at this date.
1067 * @param end_date each history entry in the result will be time
1068 * stamped before, or at this date.
1069 * @param hres_cb the callback to call with the transaction history
1070 * @param hres_cb_cls closure for the above callback
1071 * @param return the operation handle, or NULL on errors.
1072 */
1073static struct TALER_WIRE_HistoryHandle *
1074taler_bank_get_history_range
1075 (void *cls,
1076 const char *account_section,
1077 enum TALER_BANK_Direction direction,
1078 struct GNUNET_TIME_Absolute start_date,
1079 struct GNUNET_TIME_Absolute end_date,
1080 TALER_WIRE_HistoryResultCallback hres_cb,
1081 void *hres_cb_cls)
1082{
1083 struct TALER_Account account;
1084 struct TalerBankClosure *tc = cls;
1085 struct TALER_WIRE_HistoryHandle *whh;
1086
1087 if (GNUNET_OK !=
1088 parse_account_cfg (tc->cfg,
1089 account_section,
1090 &account))
1091 {
1092 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1093 "Could not parse the config section '%s'\n",
1094 account_section);
1095 return NULL;
1096 }
1097
1098 whh = GNUNET_new (struct TALER_WIRE_HistoryHandle);
1099 whh->hres_cb = hres_cb;
1100 whh->hres_cb_cls = hres_cb_cls;
1101
1102 if (GNUNET_OK !=
1103 TALER_BANK_auth_parse_cfg (tc->cfg,
1104 account_section,
1105 &whh->auth))
1106 {
1107 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1108 "Could not parse the auth values from '%s'\n",
1109 account_section);
1110 GNUNET_free (whh);
1111 return NULL;
1112 }
1113 whh->hh = TALER_BANK_history_range (tc->ctx,
1114 account.details.x_taler_bank.bank_base_url,
1115 &whh->auth,
1116 account.details.x_taler_bank.no,
1117 direction,
1118 /* Just always descending. */
1119 GNUNET_NO,
1120 start_date,
1121 end_date,
1122 &bhist_cb,
1123 whh);
1124 if (NULL == whh->hh)
1125 {
1126 GNUNET_break (0);
1127 taler_bank_get_history_cancel (NULL,
1128 whh);
1129 TALER_WIRE_account_free (&account);
1130 return NULL;
1131 }
1132 TALER_WIRE_account_free (&account);
1133 GNUNET_assert (NULL != whh);
1134
1135 return whh;
1136}
1137
1138
1139/** 1053/**
1140 * Context for a rejection operation. 1054 * Context for a rejection operation.
1141 */ 1055 */
diff --git a/src/wire-plugins/test_wire_plugin_legacy_taler-bank.c b/src/wire-plugins/test_wire_plugin_legacy_taler-bank.c
deleted file mode 100644
index 690666f87..000000000
--- a/src/wire-plugins/test_wire_plugin_legacy_taler-bank.c
+++ /dev/null
@@ -1,373 +0,0 @@
1/*
2 This file is part of TALER
3 (C) 2015-2018 Taler Systems SA
4
5 TALER is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 3, or
8 (at your option) any later version.
9
10 TALER is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with TALER; see the file COPYING. If not,
17 see <http://www.gnu.org/licenses/>
18*/
19
20/**
21 * @file wire/test_wire_plugin_legacy_taler-bank.c
22 * @brief Tests legacy history-range API against the Fakebank.
23 * Version for the real Python bank forthcoming.
24 *
25 * @author Christian Grothoff
26 * @author Marcello Stanisci
27 */
28#include "platform.h"
29#include "taler_util.h"
30#include "taler_wire_lib.h"
31#include "taler_wire_plugin.h"
32#include "taler_fakebank_lib.h"
33#include <gnunet/gnunet_json_lib.h>
34
35/**
36 * How many wire transfers this test should accomplish, before
37 * delving into actual checks.
38 */
39#define NTRANSACTIONS 5
40
41/**
42 * Destination account to use.
43 */
44static const char *dest_account = "payto://x-taler-bank/localhost:8088/42";
45
46/**
47 * Origin account, section in the configuration file.
48 */
49static const char *my_account = "account-test";
50
51/**
52 * Our configuration.
53 */
54static struct GNUNET_CONFIGURATION_Handle *cfg;
55
56/**
57 * Set to #GNUNET_SYSERR if the test failed.
58 */
59static int global_ret;
60
61/**
62 * The 'test' plugin that we are using for the test.
63 */
64static struct TALER_WIRE_Plugin *plugin;
65
66/**
67 * Active preparation handle, or NULL if not active.
68 */
69static struct TALER_WIRE_PrepareHandle *ph;
70
71/**
72 * Active execution handle, or NULL if not active.
73 */
74static struct TALER_WIRE_ExecuteHandle *eh;
75
76/**
77 * Handle to the bank.
78 */
79static struct TALER_FAKEBANK_Handle *fb;
80
81/**
82 * Handle to the history-range request (the "legacy" bank API).
83 */
84static struct TALER_WIRE_HistoryHandle *hhr;
85
86/**
87 * Wire transfer identifier we are using.
88 */
89static struct TALER_WireTransferIdentifierRawP wtid;
90
91/**
92 * Number of total transaction to make it happen in the test.
93 */
94static int Ntransactions = NTRANSACTIONS;
95static int ntransactions = NTRANSACTIONS;
96static int ztransactions = 0;
97
98/**
99 * Timestamp used as the oldest extreme in the query range.
100 */
101static struct GNUNET_TIME_Absolute first_timestamp;
102
103/**
104 * Function called on shutdown (regular, error or CTRL-C).
105 *
106 * @param cls NULL
107 */
108static void
109do_shutdown (void *cls)
110{
111 TALER_FAKEBANK_stop (fb);
112 fb = NULL;
113 if (NULL != eh)
114 {
115 plugin->execute_wire_transfer_cancel (plugin->cls,
116 eh);
117 eh = NULL;
118 }
119 if (NULL != ph)
120 {
121 plugin->prepare_wire_transfer_cancel (plugin->cls,
122 ph);
123 ph = NULL;
124 }
125
126 if (NULL != hhr)
127 {
128 plugin->get_history_cancel (plugin->cls,
129 hhr);
130 hhr = NULL;
131 }
132
133 TALER_WIRE_plugin_unload (plugin);
134}
135
136
137/**
138 * Callbacks of this type are used to serve the result of asking
139 * the bank for the transaction history.
140 *
141 * @param cls closure
142 * @param ec taler status code
143 * @param dir direction of the transfer
144 * @param row_off identification of the position at
145 * which we are querying
146 * @param row_off_size number of bytes in @a row_off
147 * @param details details about the wire transfer
148 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to
149 * abort iteration
150 */
151static int
152history_result_cb
153 (void *cls,
154 enum TALER_ErrorCode ec,
155 enum TALER_BANK_Direction dir,
156 const void *row_off,
157 size_t row_off_size,
158 const struct TALER_WIRE_TransferDetails *details)
159{
160 int *expected_number = cls;
161 static int accumulator = 0;
162
163 if ( (TALER_BANK_DIRECTION_NONE == dir) &&
164 (GNUNET_OK == global_ret) )
165 {
166 /* End-of-list, check all the transactions got accounted
167 * into the history. */
168
169 if (*expected_number != accumulator)
170 {
171 GNUNET_break (0);
172 TALER_LOG_ERROR
173 ("Unexpected # of transactions: %d, %d were expected.\n",
174 accumulator,
175 *expected_number);
176 global_ret = GNUNET_NO;
177 }
178
179 if (ztransactions != *expected_number)
180 {
181 /* Call the second test, under the assumption that after
182 * running the test with ztransactions expected entries,
183 * we shut the test down. */
184
185 accumulator = 0;
186 GNUNET_assert
187 (NULL != (hhr = plugin->get_history_range
188 (plugin->cls,
189 my_account,
190 TALER_BANK_DIRECTION_BOTH,
191 GNUNET_TIME_UNIT_ZERO_ABS,
192 GNUNET_TIME_absolute_subtract
193 (first_timestamp,
194 GNUNET_TIME_UNIT_HOURS),
195 &history_result_cb,
196
197 /**
198 * Zero results are expected from 1970 up to 1 hour ago.
199 */
200 &ztransactions)));
201
202 return GNUNET_OK;
203 }
204
205 GNUNET_SCHEDULER_shutdown ();
206 return GNUNET_OK;
207 }
208
209 accumulator++;
210 return GNUNET_OK;
211}
212
213
214/**
215 * Function called with the result from the execute step.
216 *
217 * @param cls closure
218 * @param success #GNUNET_OK on success,
219 * #GNUNET_SYSERR on failure
220 * @param row_id ID of the fresh transaction,
221 * in _network_ byte order.
222 * @param emsg NULL on success, otherwise an error message
223 */
224static void
225confirmation_cb (void *cls,
226 int success,
227 const void *row_id,
228 size_t row_id_size,
229 const char *emsg);
230
231/**
232 * Callback with prepared transaction.
233 *
234 * @param cls closure
235 * @param buf transaction data to persist, NULL on error
236 * @param buf_size number of bytes in @a buf, 0 on error
237 */
238static void
239prepare_cb (void *cls,
240 const char *buf,
241 size_t buf_size)
242{
243 ph = NULL;
244 if (NULL == buf)
245 {
246 GNUNET_break (0);
247 global_ret = GNUNET_SYSERR;
248 GNUNET_SCHEDULER_shutdown ();
249 return;
250 }
251 plugin->execute_wire_transfer (plugin->cls,
252 buf,
253 buf_size,
254 &confirmation_cb,
255 NULL);
256}
257
258/**
259 * Function called with the result from the execute step.
260 *
261 * @param cls closure
262 * @param success #GNUNET_OK on success,
263 * #GNUNET_SYSERR on failure
264 * @param row_id ID of the fresh transaction,
265 * in _network_ byte order.
266 * @param emsg NULL on success, otherwise an error message
267 */
268static void
269confirmation_cb (void *cls,
270 int success,
271 const void *row_id,
272 size_t row_id_size,
273 const char *emsg)
274{
275 struct TALER_Amount amount;
276
277 eh = NULL;
278 if (GNUNET_OK != success)
279 {
280 GNUNET_break (0);
281 global_ret = GNUNET_SYSERR;
282 GNUNET_SCHEDULER_shutdown ();
283 return;
284 }
285
286 if (0 >= --Ntransactions)
287 {
288 GNUNET_assert
289 (NULL != (hhr = plugin->get_history_range
290 (plugin->cls,
291 my_account,
292 TALER_BANK_DIRECTION_BOTH,
293 GNUNET_TIME_UNIT_ZERO_ABS,
294 GNUNET_TIME_UNIT_FOREVER_ABS,
295 &history_result_cb,
296 &ntransactions)));
297 return;
298 }
299
300 /* Issue a new wire transfer! */
301 GNUNET_assert
302 (GNUNET_OK == TALER_string_to_amount ("KUDOS:5.01",
303 &amount));
304
305 ph = plugin->prepare_wire_transfer (plugin->cls,
306 my_account,
307 dest_account,
308 &amount,
309 "https://exchange.net/",
310 &wtid,
311 &prepare_cb,
312 NULL);
313}
314
315
316/**
317 * Run the test.
318 *
319 * @param cls NULL
320 */
321static void
322run (void *cls)
323{
324 struct TALER_Amount amount;
325 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
326 NULL);
327
328 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
329 &wtid,
330 sizeof (wtid));
331 GNUNET_assert
332 (GNUNET_OK == TALER_string_to_amount ("KUDOS:5.01",
333 &amount));
334 fb = TALER_FAKEBANK_start (8088);
335
336
337 first_timestamp = GNUNET_TIME_absolute_get ();
338 ph = plugin->prepare_wire_transfer (plugin->cls,
339 my_account,
340 dest_account,
341 &amount,
342 "https://exchange.net/",
343 &wtid,
344 &prepare_cb,
345 NULL);
346}
347
348
349int
350main (int argc,
351 const char *const argv[])
352{
353 GNUNET_log_setup ("test-wire-plugin-legacy-test",
354 "WARNING",
355 NULL);
356 cfg = GNUNET_CONFIGURATION_create ();
357 GNUNET_assert
358 (GNUNET_OK == GNUNET_CONFIGURATION_load
359 (cfg,
360 "test_wire_plugin_legacy_taler-bank.conf"));
361 global_ret = GNUNET_OK;
362 plugin = TALER_WIRE_plugin_load (cfg,
363 "taler_bank");
364 GNUNET_assert (NULL != plugin);
365 GNUNET_SCHEDULER_run (&run,
366 NULL);
367 GNUNET_CONFIGURATION_destroy (cfg);
368 if (GNUNET_OK != global_ret)
369 return 1;
370 return 0;
371}
372
373/* end of test_wire_plugin_legacy_taler-bank.c */
diff --git a/src/wire-plugins/test_wire_plugin_legacy_taler-bank.conf b/src/wire-plugins/test_wire_plugin_legacy_taler-bank.conf
deleted file mode 100644
index d6d2e8346..000000000
--- a/src/wire-plugins/test_wire_plugin_legacy_taler-bank.conf
+++ /dev/null
@@ -1,12 +0,0 @@
1# This file is in the public domain.
2#
3[account-test]
4# This is the response we give out for the /wire request. It provides
5# wallets with the bank information for transfers to the exchange.
6
7TALER_BANK_AUTH_METHOD = NONE
8
9URL = payto://x-taler-bank/localhost:8088/2
10
11[taler]
12CURRENCY = "KUDOS"