From 81d0e570be0db784e98fdb7ad63f9b65c6745be3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 19 Aug 2021 13:41:30 +0200 Subject: -implement DB triggers and check for inbound wire transfers in IBAN plugin --- .../anastasis-helper-authorization-iban.c | 50 ++++++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) (limited to 'src/authorization/anastasis-helper-authorization-iban.c') 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 #include #include +#include "iban.h" /** * How long to wait for an HTTP reply if there @@ -107,6 +104,37 @@ static int test_mode; 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. * @@ -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; } -- cgit v1.2.3