summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-08-15 19:01:17 +0200
committerChristian Grothoff <christian@grothoff.org>2021-08-15 19:01:17 +0200
commit3b90e437e26013f5570d6c216b832c7bcd740712 (patch)
tree13ab0dddb4e13c49b86b4526208f05dddfa10e95
parent622eba29d8675ce12640cf513350891246fd90c8 (diff)
downloadanastasis-3b90e437e26013f5570d6c216b832c7bcd740712.tar.gz
anastasis-3b90e437e26013f5570d6c216b832c7bcd740712.tar.bz2
anastasis-3b90e437e26013f5570d6c216b832c7bcd740712.zip
add logic to resume wire transfer checks from last checkpoint
-rw-r--r--src/authorization/anastasis-helper-authorization-iban.c19
-rw-r--r--src/include/anastasis_database_plugin.h19
-rw-r--r--src/stasis/plugin_anastasis_postgres.c47
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 @@
* - blocked on #6992
* - needs XXX_bank_service to access new facade once #6992 is implemented
* - needs to load authentication information
- * - needs to load 'last known' transaction from DB
* - needs to add DB triggers to notify main service of inbound activity
*/
#include "platform.h"
@@ -46,6 +45,11 @@
static struct BANK_AccountInfo *auth;
/**
+ * Bank account payto://-URI this process is monitoring.
+ */
+static struct credit_account_uri;
+
+/**
* Active request for history.
*/
static struct BANK_CreditHistoryHandle *hh;
@@ -282,7 +286,20 @@ run (void *cls,
return;
}
// FIXME: initialize 'auth' from cfg!
+ {
+ enum GNUNET_DB_QueryStatus qs;
+ qs = db_plugin->get_last_auth_iban_payment_row (db_plugin->cls,
+ credit_account_uri,
+ &latest_row_off);
+ if (qs < 0)
+ {
+ GNUNET_break (0);
+ ANASTASIS_DB_plugin_unload (db_plugin);
+ db_plugin = NULL;
+ return;
+ }
+ }
GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
cls);
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
/**
+ * Function to check the last known IBAN payment.
+ *
+ * @param cls closure
+ * @param credit_account which credit account to check
+ * @param[out] last_row set to the last known row
+ * @return transaction status,
+ * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if @a cb
+ * returned 'true' once
+ * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if no
+ * wire transfers existed for which @a cb returned true
+ */
+ enum GNUNET_DB_QueryStatus
+ (*get_last_auth_iban_payment_row)(
+ void *cls,
+ const char *credit_account,
+ uint64_t *last_row);
+
+
+ /**
* Function called to remove all expired codes from the database.
*
* @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 (
/**
+ * Function to check the last known IBAN payment.
+ *
+ * @param cls closure
+ * @param credit_account which credit account to check
+ * @param[out] last_row set to the last known row
+ * @return transaction status,
+ * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT if @a cb
+ * returned 'true' once
+ * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if no
+ * wire transfers existed for which @a cb returned true
+ */
+static enum GNUNET_DB_QueryStatus
+postgres_get_last_auth_iban_payment_row (
+ void *cls,
+ const char *credit_account,
+ uint64_t *last_row)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (credit_account),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("wire_reference",
+ last_row),
+ GNUNET_PQ_result_spec_end
+ };
+
+ check_connection (pg);
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_last_auth_iban_payment",
+ params,
+ rs);
+}
+
+
+/**
* Check payment identifier. Used to check if a payment identifier given by
* the user is valid (existing and paid).
*
@@ -2530,6 +2567,14 @@ libanastasis_plugin_db_postgres_init (void *cls)
" ORDER BY creation_date DESC"
" LIMIT 1);",
3),
+ GNUNET_PQ_make_prepare ("get_last_auth_iban_payment",
+ "SELECT "
+ " wire_reference"
+ " FROM anastasis_auth_iban_in"
+ " WHERE credit_account_details=$1"
+ " ORDER BY wire_reference DESC"
+ " LIMIT 1;",
+ 1),
GNUNET_PQ_make_prepare ("gc_challengecodes",
"DELETE FROM anastasis_challengecode "
"WHERE "
@@ -2604,6 +2649,8 @@ libanastasis_plugin_db_postgres_init (void *cls)
plugin->update_challenge_payment = &postgres_update_challenge_payment;
plugin->record_auth_iban_payment = &postgres_record_auth_iban_payment;
plugin->test_auth_iban_payment = &postgres_test_auth_iban_payment;
+ plugin->get_last_auth_iban_payment_row
+ = &postgres_get_last_auth_iban_payment_row;
return plugin;
}