Improve KYC status callback.

More parameters for this callback.
This commit is contained in:
Marcello Stanisci 2018-07-09 21:15:47 +02:00
parent 01158a4817
commit 5e25d7dbcf
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F
3 changed files with 102 additions and 37 deletions

View File

@ -432,9 +432,9 @@ postgres_create_tables (void *cls)
");"), ");"),
GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS kyc_merchants " GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS kyc_merchants "
"(payto_url VARCHAR UNIQUE NOT NULL" "(merchant_serial_id BIGSERIAL PRIMARY KEY"
",kyc_checked BOOLEAN NOT NULL" ",kyc_checked BOOLEAN NOT NULL DEFAULT FALSE"
",merchant_serial_id BIGSERIAL PRIMARY KEY" ",payto_url VARCHAR UNIQUE NOT NULL"
");"), ");"),
GNUNET_PQ_make_try_execute ("CREATE INDEX kyc_merchants_payto_url ON " 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. * Methods needed to implement KYC monitoring.
* *
* 1 Sum money flow for a (unchecked) merchant. * 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 * 3 Get KYC status for a merchant. V
* 4 Put money flow event for a merchant. * 4 Put money flow event for a merchant.
* 5 Delete money flow records for a fresh-checked merchant. * 5 Delete money flow records for a fresh-checked merchant.
@ -1303,7 +1303,8 @@ postgres_prepare (PGconn *db_conn)
GNUNET_PQ_make_prepare ("get_kyc_status", GNUNET_PQ_make_prepare ("get_kyc_status",
"SELECT " "SELECT "
" (kyc_checked)" "(kyc_checked"
",merchant_serial_id)"
" FROM kyc_merchants" " FROM kyc_merchants"
" WHERE payto_url=$1", " WHERE payto_url=$1",
1), 1),
@ -1330,6 +1331,16 @@ postgres_prepare (PGconn *db_conn)
" payto_url=$1", " payto_url=$1",
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 */ /* Used in #postgres_select_deposits_missing_wire */
GNUNET_PQ_make_prepare ("deposits_get_overdue", GNUNET_PQ_make_prepare ("deposits_get_overdue",
"SELECT" "SELECT"
@ -6602,24 +6613,41 @@ static enum GNUNET_DB_QueryStatus
postgres_get_kyc_status (void *cls, postgres_get_kyc_status (void *cls,
struct TALER_EXCHANGEDB_Session *session, struct TALER_EXCHANGEDB_Session *session,
const char *payto_url, 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[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_string (payto_url), GNUNET_PQ_query_param_string (payto_url),
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
struct GNUNET_PQ_ResultSpec rs[] = { struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_auto_from_type ("kyc_checked", 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 GNUNET_PQ_result_spec_end
}; };
return GNUNET_PQ_eval_prepared_singleton_select qs = GNUNET_PQ_eval_prepared_singleton_select (session->conn,
(session->conn,
"get_kyc_status", "get_kyc_status",
params, params,
rs); rs);
if (0 >= qs)
return qs;
ksc (ksc_cls,
payto_url,
status,
merchant_serial_id);
return qs;
} }

View File

@ -344,6 +344,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. * Function called with information about a refresh order.
* Checks that the response matches what we expect to see. * Checks that the response matches what we expect to see.
@ -2190,29 +2210,17 @@ run (void *cls)
plugin->mark_kyc_merchant (NULL, plugin->mark_kyc_merchant (NULL,
session, session,
"payto://mock")); "payto://mock"));
{
uint8_t kyc_checked;
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->get_kyc_status (NULL, plugin->get_kyc_status (NULL,
session, session,
"payto://mock", "payto://mock",
&kyc_checked)); &kcs,
FAILIF (GNUNET_NO == kyc_checked); NULL));
FAILIF (GNUNET_OK != FAILIF (GNUNET_OK !=
plugin->unmark_kyc_merchant (NULL, plugin->unmark_kyc_merchant (NULL,
session, session,
"payto://mock")); "payto://mock"));
FAILIF (GNUNET_OK !=
plugin->get_kyc_status (NULL,
session,
"payto://mock",
&kyc_checked));
FAILIF (GNUNET_YES == kyc_checked);
}
plugin->preflight (plugin->cls, plugin->preflight (plugin->cls,
session); session);

View File

@ -711,6 +711,24 @@ typedef int
int done); int done);
/**
* 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.
*/
typedef void
(*TALER_EXCHANGEDB_KycStatusCallback)(void *cls,
const char *payto_url,
uint8_t kyc_checked,
uint64_t merchant_serial_id);
/** /**
* Function called with details about coins that were melted, * Function called with details about coins that were melted,
* with the goal of auditing the refresh's execution. * with the goal of auditing the refresh's execution.
@ -2226,6 +2244,8 @@ struct TALER_EXCHANGEDB_Plugin
* associates a flag to the merchant that indicates whether * associates a flag to the merchant that indicates whether
* a KYC check has been done or not on this merchant. * a KYC check has been done or not on this merchant.
* *
* @param cls closure
* @param session db session
* @param payto_url payto:// URL indentifying the merchant * @param payto_url payto:// URL indentifying the merchant
* bank account. * bank account.
* @return database transaction status. * @return database transaction status.
@ -2238,6 +2258,8 @@ struct TALER_EXCHANGEDB_Plugin
/** /**
* Mark a merchant as KYC-checked. * Mark a merchant as KYC-checked.
* *
* @param cls closure
* @param session db session
* @param payto_url payto:// URL indentifying the merchant * @param payto_url payto:// URL indentifying the merchant
* to check. Note, different banks may have different * to check. Note, different banks may have different
* policies to check their customers. * policies to check their customers.
@ -2252,6 +2274,8 @@ struct TALER_EXCHANGEDB_Plugin
/** /**
* Mark a merchant as NOT KYC-checked. * Mark a merchant as NOT KYC-checked.
* *
* @param cls closure
* @param session db session
* @param payto_url payto:// URL indentifying the merchant * @param payto_url payto:// URL indentifying the merchant
* to unmark. Note, different banks may have different * to unmark. Note, different banks may have different
* policies to check their customers. * policies to check their customers.
@ -2266,16 +2290,21 @@ struct TALER_EXCHANGEDB_Plugin
/** /**
* Retrieve KYC-check status related to a particular merchant. * Retrieve KYC-check status related to a particular merchant.
* *
* @param cls closure
* @param session db session
* @param payto_url URL identifying a merchant bank account, * @param payto_url URL identifying a merchant bank account,
* whose KYC is going to be retrieved. * whose KYC is going to be retrieved.
* @param[out] status store the result. * @param ksc callback to process all the row's columns. As
* expectable, it will only be called _if_ a row is found.
* @param ksc_cls closure for above callback.
* @return transaction status. * @return transaction status.
*/ */
enum GNUNET_DB_QueryStatus enum GNUNET_DB_QueryStatus
(*get_kyc_status) (void *cls, (*get_kyc_status) (void *cls,
struct TALER_EXCHANGEDB_Session *session, struct TALER_EXCHANGEDB_Session *session,
const char *payto_url, const char *payto_url,
uint8_t *status); TALER_EXCHANGEDB_KycStatusCallback ksc,
void *ksc_cls);
}; };
#endif /* _TALER_EXCHANGE_DB_H */ #endif /* _TALER_EXCHANGE_DB_H */