diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-08-15 19:01:17 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-08-15 19:01:17 +0200 |
commit | 3b90e437e26013f5570d6c216b832c7bcd740712 (patch) | |
tree | 13ab0dddb4e13c49b86b4526208f05dddfa10e95 | |
parent | 622eba29d8675ce12640cf513350891246fd90c8 (diff) | |
download | anastasis-3b90e437e26013f5570d6c216b832c7bcd740712.tar.gz anastasis-3b90e437e26013f5570d6c216b832c7bcd740712.zip |
add logic to resume wire transfer checks from last checkpoint
-rw-r--r-- | src/authorization/anastasis-helper-authorization-iban.c | 19 | ||||
-rw-r--r-- | src/include/anastasis_database_plugin.h | 19 | ||||
-rw-r--r-- | src/stasis/plugin_anastasis_postgres.c | 47 |
3 files changed, 84 insertions, 1 deletions
diff --git a/src/authorization/anastasis-helper-authorization-iban.c b/src/authorization/anastasis-helper-authorization-iban.c index b66d181..946b008 100644 --- a/src/authorization/anastasis-helper-authorization-iban.c +++ b/src/authorization/anastasis-helper-authorization-iban.c | |||
@@ -22,7 +22,6 @@ | |||
22 | * - blocked on #6992 | 22 | * - blocked on #6992 |
23 | * - needs XXX_bank_service to access new facade once #6992 is implemented | 23 | * - needs XXX_bank_service to access new facade once #6992 is implemented |
24 | * - needs to load authentication information | 24 | * - needs to load authentication information |
25 | * - needs to load 'last known' transaction from DB | ||
26 | * - needs to add DB triggers to notify main service of inbound activity | 25 | * - needs to add DB triggers to notify main service of inbound activity |
27 | */ | 26 | */ |
28 | #include "platform.h" | 27 | #include "platform.h" |
@@ -46,6 +45,11 @@ | |||
46 | static struct BANK_AccountInfo *auth; | 45 | static struct BANK_AccountInfo *auth; |
47 | 46 | ||
48 | /** | 47 | /** |
48 | * Bank account payto://-URI this process is monitoring. | ||
49 | */ | ||
50 | static struct credit_account_uri; | ||
51 | |||
52 | /** | ||
49 | * Active request for history. | 53 | * Active request for history. |
50 | */ | 54 | */ |
51 | static struct BANK_CreditHistoryHandle *hh; | 55 | static struct BANK_CreditHistoryHandle *hh; |
@@ -282,7 +286,20 @@ run (void *cls, | |||
282 | return; | 286 | return; |
283 | } | 287 | } |
284 | // FIXME: initialize 'auth' from cfg! | 288 | // FIXME: initialize 'auth' from cfg! |
289 | { | ||
290 | enum GNUNET_DB_QueryStatus qs; | ||
285 | 291 | ||
292 | qs = db_plugin->get_last_auth_iban_payment_row (db_plugin->cls, | ||
293 | credit_account_uri, | ||
294 | &latest_row_off); | ||
295 | if (qs < 0) | ||
296 | { | ||
297 | GNUNET_break (0); | ||
298 | ANASTASIS_DB_plugin_unload (db_plugin); | ||
299 | db_plugin = NULL; | ||
300 | return; | ||
301 | } | ||
302 | } | ||
286 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 303 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
287 | cls); | 304 | cls); |
288 | ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule, | 305 | ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule, |
diff --git a/src/include/anastasis_database_plugin.h b/src/include/anastasis_database_plugin.h index ae414dc..7ad47ca 100644 --- a/src/include/anastasis_database_plugin.h +++ b/src/include/anastasis_database_plugin.h | |||
@@ -779,6 +779,25 @@ struct ANASTASIS_DatabasePlugin | |||
779 | 779 | ||
780 | 780 | ||
781 | /** | 781 | /** |
782 | * Function to check the last known IBAN payment. | ||
783 | * | ||
784 | * @param cls closure | ||
785 | * @param credit_account which credit account to check | ||
786 | * @param[out] last_row set to the last known row | ||
787 | * @return transaction status, | ||
788 | * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if @a cb | ||
789 | * returned 'true' once | ||
790 | * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if no | ||
791 | * wire transfers existed for which @a cb returned true | ||
792 | */ | ||
793 | enum GNUNET_DB_QueryStatus | ||
794 | (*get_last_auth_iban_payment_row)( | ||
795 | void *cls, | ||
796 | const char *credit_account, | ||
797 | uint64_t *last_row); | ||
798 | |||
799 | |||
800 | /** | ||
782 | * Function called to remove all expired codes from the database. | 801 | * Function called to remove all expired codes from the database. |
783 | * | 802 | * |
784 | * @return transaction status | 803 | * @return transaction status |
diff --git a/src/stasis/plugin_anastasis_postgres.c b/src/stasis/plugin_anastasis_postgres.c index 1544367..9d206c7 100644 --- a/src/stasis/plugin_anastasis_postgres.c +++ b/src/stasis/plugin_anastasis_postgres.c | |||
@@ -1290,6 +1290,43 @@ postgres_test_auth_iban_payment ( | |||
1290 | 1290 | ||
1291 | 1291 | ||
1292 | /** | 1292 | /** |
1293 | * Function to check the last known IBAN payment. | ||
1294 | * | ||
1295 | * @param cls closure | ||
1296 | * @param credit_account which credit account to check | ||
1297 | * @param[out] last_row set to the last known row | ||
1298 | * @return transaction status, | ||
1299 | * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if @a cb | ||
1300 | * returned 'true' once | ||
1301 | * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if no | ||
1302 | * wire transfers existed for which @a cb returned true | ||
1303 | */ | ||
1304 | static enum GNUNET_DB_QueryStatus | ||
1305 | postgres_get_last_auth_iban_payment_row ( | ||
1306 | void *cls, | ||
1307 | const char *credit_account, | ||
1308 | uint64_t *last_row) | ||
1309 | { | ||
1310 | struct PostgresClosure *pg = cls; | ||
1311 | struct GNUNET_PQ_QueryParam params[] = { | ||
1312 | GNUNET_PQ_query_param_string (credit_account), | ||
1313 | GNUNET_PQ_query_param_end | ||
1314 | }; | ||
1315 | struct GNUNET_PQ_ResultSpec rs[] = { | ||
1316 | GNUNET_PQ_result_spec_uint64 ("wire_reference", | ||
1317 | last_row), | ||
1318 | GNUNET_PQ_result_spec_end | ||
1319 | }; | ||
1320 | |||
1321 | check_connection (pg); | ||
1322 | return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, | ||
1323 | "get_last_auth_iban_payment", | ||
1324 | params, | ||
1325 | rs); | ||
1326 | } | ||
1327 | |||
1328 | |||
1329 | /** | ||
1293 | * Check payment identifier. Used to check if a payment identifier given by | 1330 | * Check payment identifier. Used to check if a payment identifier given by |
1294 | * the user is valid (existing and paid). | 1331 | * the user is valid (existing and paid). |
1295 | * | 1332 | * |
@@ -2530,6 +2567,14 @@ libanastasis_plugin_db_postgres_init (void *cls) | |||
2530 | " ORDER BY creation_date DESC" | 2567 | " ORDER BY creation_date DESC" |
2531 | " LIMIT 1);", | 2568 | " LIMIT 1);", |
2532 | 3), | 2569 | 3), |
2570 | GNUNET_PQ_make_prepare ("get_last_auth_iban_payment", | ||
2571 | "SELECT " | ||
2572 | " wire_reference" | ||
2573 | " FROM anastasis_auth_iban_in" | ||
2574 | " WHERE credit_account_details=$1" | ||
2575 | " ORDER BY wire_reference DESC" | ||
2576 | " LIMIT 1;", | ||
2577 | 1), | ||
2533 | GNUNET_PQ_make_prepare ("gc_challengecodes", | 2578 | GNUNET_PQ_make_prepare ("gc_challengecodes", |
2534 | "DELETE FROM anastasis_challengecode " | 2579 | "DELETE FROM anastasis_challengecode " |
2535 | "WHERE " | 2580 | "WHERE " |
@@ -2604,6 +2649,8 @@ libanastasis_plugin_db_postgres_init (void *cls) | |||
2604 | plugin->update_challenge_payment = &postgres_update_challenge_payment; | 2649 | plugin->update_challenge_payment = &postgres_update_challenge_payment; |
2605 | plugin->record_auth_iban_payment = &postgres_record_auth_iban_payment; | 2650 | plugin->record_auth_iban_payment = &postgres_record_auth_iban_payment; |
2606 | plugin->test_auth_iban_payment = &postgres_test_auth_iban_payment; | 2651 | plugin->test_auth_iban_payment = &postgres_test_auth_iban_payment; |
2652 | plugin->get_last_auth_iban_payment_row | ||
2653 | = &postgres_get_last_auth_iban_payment_row; | ||
2607 | return plugin; | 2654 | return plugin; |
2608 | } | 2655 | } |
2609 | 2656 | ||