diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2018-07-09 21:15:47 +0200 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2018-07-09 21:15:47 +0200 |
commit | 5e25d7dbcfbfe1859862a719e4392f17cd356a9b (patch) | |
tree | 16cc3a13fcbda9cc122976f46c65ef7e9cb3a23a /src/exchangedb | |
parent | 01158a48171d6dbfddec1cf274b70d2e730a1a04 (diff) |
Improve KYC status callback.
More parameters for this callback.
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 54 | ||||
-rw-r--r-- | src/exchangedb/test_exchangedb.c | 52 |
2 files changed, 71 insertions, 35 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index dbd29481b..7cf78c1e9 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -432,9 +432,9 @@ postgres_create_tables (void *cls) ");"), GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS kyc_merchants " - "(payto_url VARCHAR UNIQUE NOT NULL" - ",kyc_checked BOOLEAN NOT NULL" - ",merchant_serial_id BIGSERIAL PRIMARY KEY" + "(merchant_serial_id BIGSERIAL PRIMARY KEY" + ",kyc_checked BOOLEAN NOT NULL DEFAULT FALSE" + ",payto_url VARCHAR UNIQUE NOT NULL" ");"), GNUNET_PQ_make_try_execute ("CREATE INDEX kyc_merchants_payto_url ON " @@ -1293,7 +1293,7 @@ postgres_prepare (PGconn *db_conn) * Methods needed to implement KYC monitoring. * * 1 Sum money flow for a (unchecked) merchant. - * 2 Change KYC status for a merchant. + * 2 Change KYC status for a merchant. V * 3 Get KYC status for a merchant. V * 4 Put money flow event for a merchant. * 5 Delete money flow records for a fresh-checked merchant. @@ -1302,8 +1302,9 @@ postgres_prepare (PGconn *db_conn) */ GNUNET_PQ_make_prepare ("get_kyc_status", - "SELECT" - " (kyc_checked)" + "SELECT " + "(kyc_checked" + ",merchant_serial_id)" " FROM kyc_merchants" " WHERE payto_url=$1", 1), @@ -1330,6 +1331,16 @@ postgres_prepare (PGconn *db_conn) " payto_url=$1", 1), + GNUNET_PQ_make_prepare ("insert_kyc_event", + "INSERT INTO kyc_events " + "(merchant_serial_id" + ",amount_val" + ",amount_frac" + ",amount_curr" + ",timestamp)" + " VALUES ($1, $2, $3, $4, $5)", + 5), + /* Used in #postgres_select_deposits_missing_wire */ GNUNET_PQ_make_prepare ("deposits_get_overdue", "SELECT" @@ -6602,24 +6613,41 @@ static enum GNUNET_DB_QueryStatus postgres_get_kyc_status (void *cls, struct TALER_EXCHANGEDB_Session *session, const char *payto_url, - uint8_t *status) + TALER_EXCHANGEDB_KycStatusCallback ksc, + void *ksc_cls) { + uint8_t status; + uint64_t merchant_serial_id; + enum GNUNET_DB_QueryStatus qs; + struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (payto_url), GNUNET_PQ_query_param_end }; + struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_auto_from_type ("kyc_checked", - status), + &status), + GNUNET_PQ_result_spec_uint64 ("merchant_serial_id", + &merchant_serial_id), + GNUNET_PQ_result_spec_end }; - return GNUNET_PQ_eval_prepared_singleton_select - (session->conn, - "get_kyc_status", - params, - rs); + qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn, + "get_kyc_status", + params, + rs); + if (0 >= qs) + return qs; + + ksc (ksc_cls, + payto_url, + status, + merchant_serial_id); + + return qs; } diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index 535077fbd..8b3486b45 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -345,6 +345,26 @@ never_called_cb (void *cls, /** + * Callback used to process data of a merchant under KYC monitoring. + * + * @param cls closure + * @param payto_url payto URL of this particular merchant (bank account) + * @param kyc_checked status of KYC check: if GNUNET_OK, the merchant was + * checked at least once, never otherwise. + * @param merchant_serial_id serial ID identifying this merchant (bank + * account) into the database system; it helps making more efficient + * queries instead of the payto URL. + */ +static void +kcs (void *cls, + const char *payto_url, + uint8_t kyc_checked, + uint64_t merchant_serial_id) +{ + GNUNET_break (0); +} + +/** * Function called with information about a refresh order. * Checks that the response matches what we expect to see. * @@ -2190,29 +2210,17 @@ run (void *cls) plugin->mark_kyc_merchant (NULL, session, "payto://mock")); + FAILIF (GNUNET_OK != + plugin->get_kyc_status (NULL, + session, + "payto://mock", + &kcs, + NULL)); - { - uint8_t kyc_checked; - - FAILIF (GNUNET_OK != - plugin->get_kyc_status (NULL, - session, - "payto://mock", - &kyc_checked)); - FAILIF (GNUNET_NO == kyc_checked); - - FAILIF (GNUNET_OK != - plugin->unmark_kyc_merchant (NULL, - session, - "payto://mock")); - FAILIF (GNUNET_OK != - plugin->get_kyc_status (NULL, - session, - "payto://mock", - &kyc_checked)); - - FAILIF (GNUNET_YES == kyc_checked); - } + FAILIF (GNUNET_OK != + plugin->unmark_kyc_merchant (NULL, + session, + "payto://mock")); plugin->preflight (plugin->cls, session); |