summaryrefslogtreecommitdiff
path: root/src/authorization/anastasis-helper-authorization-iban.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-08-19 13:41:30 +0200
committerChristian Grothoff <christian@grothoff.org>2021-08-19 13:41:30 +0200
commit81d0e570be0db784e98fdb7ad63f9b65c6745be3 (patch)
tree578a91bd888abfac827c23ba2933174c7d2341de /src/authorization/anastasis-helper-authorization-iban.c
parent87bc2f469bf120bbd57e98a0a8ea46e80de84927 (diff)
downloadanastasis-81d0e570be0db784e98fdb7ad63f9b65c6745be3.tar.gz
anastasis-81d0e570be0db784e98fdb7ad63f9b65c6745be3.tar.bz2
anastasis-81d0e570be0db784e98fdb7ad63f9b65c6745be3.zip
-implement DB triggers and check for inbound wire transfers in IBAN plugin
Diffstat (limited to 'src/authorization/anastasis-helper-authorization-iban.c')
-rw-r--r--src/authorization/anastasis-helper-authorization-iban.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/src/authorization/anastasis-helper-authorization-iban.c b/src/authorization/anastasis-helper-authorization-iban.c
index 0d3200a..d509c0e 100644
--- a/src/authorization/anastasis-helper-authorization-iban.c
+++ b/src/authorization/anastasis-helper-authorization-iban.c
@@ -17,10 +17,6 @@
* @file anastasis-helper-authorization-iban.c
* @brief Process that watches for wire transfers to Anastasis bank account
* @author Christian Grothoff
- *
- * TODO:
- * - needs to add DB triggers to notify main service of inbound activity
- * - needs man page
*/
#include "platform.h"
#include "anastasis_eufin_lib.h"
@@ -31,6 +27,7 @@
#include <jansson.h>
#include <pthread.h>
#include <microhttpd.h>
+#include "iban.h"
/**
* How long to wait for an HTTP reply if there
@@ -108,6 +105,37 @@ static struct GNUNET_SCHEDULER_Task *task;
/**
+ * Notify anastasis-http that we received @a amount
+ * from @a sender_account_uri with @a code.
+ *
+ * @param sender_account_uri payto:// URI of the sending account
+ * @param code numeric code used in the wire transfer subject
+ * @param amount the amount that was wired
+ */
+static void
+notify (const char *sender_account_uri,
+ uint64_t code,
+ const struct TALER_Amount *amount)
+{
+ struct IbanEventP ev = {
+ .header.type = htons (TALER_DBEVENT_ANASTASIS_AUTH_IBAN_TRANSFER),
+ .header.size = htons (sizeof (ev)),
+ .code = GNUNET_htonll (code)
+ };
+ const char *as;
+
+ GNUNET_CRYPTO_hash (sender_account_uri,
+ strlen (sender_account_uri),
+ &ev.debit_iban_hash);
+ as = TALER_amount2s (amount);
+ db_plugin->event_notify (db_plugin->cls,
+ &ev.header,
+ as,
+ strlen (as));
+}
+
+
+/**
* We're being aborted with CTRL-C (or SIGTERM). Shut down.
*
* @param cls closure
@@ -152,6 +180,9 @@ static void
find_transfers (void *cls);
+#include "iban.c"
+
+
/**
* Callbacks of this type are used to serve the result of asking
* the bank for the transaction history.
@@ -232,6 +263,17 @@ history_cb (void *cls,
break;
}
latest_row_off = serial_id;
+ {
+ uint64_t code;
+
+ if (GNUNET_OK !=
+ extract_code (details->wire_subject,
+ &code))
+ return GNUNET_OK;
+ notify (details->debit_account_uri,
+ code,
+ &details->amount);
+ }
return GNUNET_OK;
}