aboutsummaryrefslogtreecommitdiff
path: root/src/exchange/taler-exchange-transfer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchange/taler-exchange-transfer.c')
-rw-r--r--src/exchange/taler-exchange-transfer.c46
1 files changed, 13 insertions, 33 deletions
diff --git a/src/exchange/taler-exchange-transfer.c b/src/exchange/taler-exchange-transfer.c
index 567943437..d6d44eb05 100644
--- a/src/exchange/taler-exchange-transfer.c
+++ b/src/exchange/taler-exchange-transfer.c
@@ -38,11 +38,6 @@ struct WirePrepareData
38{ 38{
39 39
40 /** 40 /**
41 * Database session for all of our transactions.
42 */
43 struct TALER_EXCHANGEDB_Session *session;
44
45 /**
46 * Wire execution handle. 41 * Wire execution handle.
47 */ 42 */
48 struct TALER_BANK_TransferHandle *eh; 43 struct TALER_BANK_TransferHandle *eh;
@@ -140,8 +135,7 @@ shutdown_task (void *cls)
140 TALER_BANK_transfer_cancel (wpd->eh); 135 TALER_BANK_transfer_cancel (wpd->eh);
141 wpd->eh = NULL; 136 wpd->eh = NULL;
142 } 137 }
143 db_plugin->rollback (db_plugin->cls, 138 db_plugin->rollback (db_plugin->cls);
144 wpd->session);
145 GNUNET_free (wpd); 139 GNUNET_free (wpd);
146 wpd = NULL; 140 wpd = NULL;
147 } 141 }
@@ -196,16 +190,14 @@ parse_wirewatch_config (void)
196/** 190/**
197 * Perform a database commit. If it fails, print a warning. 191 * Perform a database commit. If it fails, print a warning.
198 * 192 *
199 * @param session session to perform the commit for.
200 * @return status of commit 193 * @return status of commit
201 */ 194 */
202static enum GNUNET_DB_QueryStatus 195static enum GNUNET_DB_QueryStatus
203commit_or_warn (struct TALER_EXCHANGEDB_Session *session) 196commit_or_warn (void)
204{ 197{
205 enum GNUNET_DB_QueryStatus qs; 198 enum GNUNET_DB_QueryStatus qs;
206 199
207 qs = db_plugin->commit (db_plugin->cls, 200 qs = db_plugin->commit (db_plugin->cls);
208 session);
209 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) 201 if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
210 return qs; 202 return qs;
211 GNUNET_log ((GNUNET_DB_STATUS_SOFT_ERROR == qs) 203 GNUNET_log ((GNUNET_DB_STATUS_SOFT_ERROR == qs)
@@ -245,7 +237,6 @@ wire_confirm_cb (void *cls,
245 uint64_t row_id, 237 uint64_t row_id,
246 struct GNUNET_TIME_Absolute wire_timestamp) 238 struct GNUNET_TIME_Absolute wire_timestamp)
247{ 239{
248 struct TALER_EXCHANGEDB_Session *session = wpd->session;
249 enum GNUNET_DB_QueryStatus qs; 240 enum GNUNET_DB_QueryStatus qs;
250 241
251 (void) cls; 242 (void) cls;
@@ -256,7 +247,6 @@ wire_confirm_cb (void *cls,
256 { 247 {
257 case MHD_HTTP_OK: 248 case MHD_HTTP_OK:
258 qs = db_plugin->wire_prepare_data_mark_finished (db_plugin->cls, 249 qs = db_plugin->wire_prepare_data_mark_finished (db_plugin->cls,
259 session,
260 wpd->row_id); 250 wpd->row_id);
261 /* continued below */ 251 /* continued below */
262 break; 252 break;
@@ -267,7 +257,6 @@ wire_confirm_cb (void *cls,
267 http_status_code, 257 http_status_code,
268 ec); 258 ec);
269 qs = db_plugin->wire_prepare_data_mark_failed (db_plugin->cls, 259 qs = db_plugin->wire_prepare_data_mark_failed (db_plugin->cls,
270 session,
271 wpd->row_id); 260 wpd->row_id);
272 /* continued below */ 261 /* continued below */
273 break; 262 break;
@@ -276,8 +265,7 @@ wire_confirm_cb (void *cls,
276 "Wire transaction failed: %u/%d\n", 265 "Wire transaction failed: %u/%d\n",
277 http_status_code, 266 http_status_code,
278 ec); 267 ec);
279 db_plugin->rollback (db_plugin->cls, 268 db_plugin->rollback (db_plugin->cls);
280 session);
281 global_ret = EXIT_FAILURE; 269 global_ret = EXIT_FAILURE;
282 GNUNET_SCHEDULER_shutdown (); 270 GNUNET_SCHEDULER_shutdown ();
283 GNUNET_free (wpd); 271 GNUNET_free (wpd);
@@ -287,8 +275,7 @@ wire_confirm_cb (void *cls,
287 if (0 >= qs) 275 if (0 >= qs)
288 { 276 {
289 GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); 277 GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
290 db_plugin->rollback (db_plugin->cls, 278 db_plugin->rollback (db_plugin->cls);
291 session);
292 if (GNUNET_DB_STATUS_SOFT_ERROR == qs) 279 if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
293 { 280 {
294 /* try again */ 281 /* try again */
@@ -307,7 +294,7 @@ wire_confirm_cb (void *cls,
307 } 294 }
308 GNUNET_free (wpd); 295 GNUNET_free (wpd);
309 wpd = NULL; 296 wpd = NULL;
310 switch (commit_or_warn (session)) 297 switch (commit_or_warn ())
311 { 298 {
312 case GNUNET_DB_STATUS_SOFT_ERROR: 299 case GNUNET_DB_STATUS_SOFT_ERROR:
313 /* try again */ 300 /* try again */
@@ -362,8 +349,7 @@ wire_prepare_cb (void *cls,
362 (NULL == buf) ) 349 (NULL == buf) )
363 { 350 {
364 GNUNET_break (0); 351 GNUNET_break (0);
365 db_plugin->rollback (db_plugin->cls, 352 db_plugin->rollback (db_plugin->cls);
366 wpd->session);
367 global_ret = EXIT_FAILURE; 353 global_ret = EXIT_FAILURE;
368 goto cleanup; 354 goto cleanup;
369 } 355 }
@@ -377,8 +363,7 @@ wire_prepare_cb (void *cls,
377 /* Should really never happen here, as when we get 363 /* Should really never happen here, as when we get
378 here the wire account should be in the cache. */ 364 here the wire account should be in the cache. */
379 GNUNET_break (0); 365 GNUNET_break (0);
380 db_plugin->rollback (db_plugin->cls, 366 db_plugin->rollback (db_plugin->cls);
381 wpd->session);
382 global_ret = EXIT_NOTCONFIGURED; 367 global_ret = EXIT_NOTCONFIGURED;
383 goto cleanup; 368 goto cleanup;
384 } 369 }
@@ -392,8 +377,7 @@ wire_prepare_cb (void *cls,
392 if (NULL == wpd->eh) 377 if (NULL == wpd->eh)
393 { 378 {
394 GNUNET_break (0); /* Irrecoverable */ 379 GNUNET_break (0); /* Irrecoverable */
395 db_plugin->rollback (db_plugin->cls, 380 db_plugin->rollback (db_plugin->cls);
396 wpd->session);
397 global_ret = EXIT_FAILURE; 381 global_ret = EXIT_FAILURE;
398 goto cleanup; 382 goto cleanup;
399 } 383 }
@@ -415,23 +399,22 @@ static void
415run_transfers (void *cls) 399run_transfers (void *cls)
416{ 400{
417 enum GNUNET_DB_QueryStatus qs; 401 enum GNUNET_DB_QueryStatus qs;
418 struct TALER_EXCHANGEDB_Session *session;
419 402
420 (void) cls; 403 (void) cls;
421 task = NULL; 404 task = NULL;
422 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 405 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
423 "Checking for pending wire transfers\n"); 406 "Checking for pending wire transfers\n");
424 if (NULL == (session = db_plugin->get_session (db_plugin->cls))) 407 if (GNUNET_SYSERR ==
408 db_plugin->preflight (db_plugin->cls))
425 { 409 {
426 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 410 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
427 "Failed to obtain database session!\n"); 411 "Failed to obtain database connection!\n");
428 global_ret = EXIT_FAILURE; 412 global_ret = EXIT_FAILURE;
429 GNUNET_SCHEDULER_shutdown (); 413 GNUNET_SCHEDULER_shutdown ();
430 return; 414 return;
431 } 415 }
432 if (GNUNET_OK != 416 if (GNUNET_OK !=
433 db_plugin->start (db_plugin->cls, 417 db_plugin->start (db_plugin->cls,
434 session,
435 "aggregator run transfer")) 418 "aggregator run transfer"))
436 { 419 {
437 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 420 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -441,15 +424,12 @@ run_transfers (void *cls)
441 return; 424 return;
442 } 425 }
443 wpd = GNUNET_new (struct WirePrepareData); 426 wpd = GNUNET_new (struct WirePrepareData);
444 wpd->session = session;
445 qs = db_plugin->wire_prepare_data_get (db_plugin->cls, 427 qs = db_plugin->wire_prepare_data_get (db_plugin->cls,
446 session,
447 &wire_prepare_cb, 428 &wire_prepare_cb,
448 NULL); 429 NULL);
449 if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) 430 if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
450 return; /* continued via continuation set in #wire_prepare_cb() */ 431 return; /* continued via continuation set in #wire_prepare_cb() */
451 db_plugin->rollback (db_plugin->cls, 432 db_plugin->rollback (db_plugin->cls);
452 session);
453 GNUNET_free (wpd); 433 GNUNET_free (wpd);
454 wpd = NULL; 434 wpd = NULL;
455 switch (qs) 435 switch (qs)