Put logic to sum KYC-monitored wire transfers.

This commit is contained in:
Marcello Stanisci 2018-07-10 15:30:17 +02:00
parent 109a4a5aa1
commit 61e737f03e
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F
2 changed files with 131 additions and 19 deletions

View File

@ -1295,12 +1295,24 @@ postgres_prepare (PGconn *db_conn)
* 1 Sum money flow for a (unchecked) merchant. * 1 Sum money flow for a (unchecked) merchant.
* 2 Change KYC status for a merchant. V * 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. V
* 5 Delete money flow records for a fresh-checked merchant. * 5 Delete money flow records for a fresh-checked merchant.
* 6 Put a merchant. V * 6 Put a merchant. V
* 7 Change KYC status flag for a merchant. V * 7 Change KYC status flag for a merchant. V
*/ */
/* Assume a merchant _unchecked_ if their events
* are stored into the table queried below. */
GNUNET_PQ_make_prepare ("get_kyc_events",
"SELECT"
" merchant_serial_id,"
",amount_val"
",amount_frac"
",amount_curr"
" FROM kyc_events"
" WHERE merchant_serial_id=$1",
1),
GNUNET_PQ_make_prepare ("get_kyc_status", GNUNET_PQ_make_prepare ("get_kyc_status",
"SELECT" "SELECT"
" kyc_checked" " kyc_checked"
@ -6634,6 +6646,87 @@ postgres_mark_kyc_merchant
params); params);
} }
/**
* Function to be called with the results of a SELECT statement
* that has returned @a num_results results.
*
* @param cls closure
* @param result the postgres result
* @param num_result the number of results in @a result
*/
static void
sum_kyc_events (void *cls,
PGresult *result,
unsigned int num_results)
{
struct TALER_Amount *tot = cls;
struct TALER_Amount tmp;
int ntuples = PQntuples (result);
struct GNUNET_PQ_ResultSpec rs[] = {
TALER_PQ_result_spec_amount ("amount", &tmp),
GNUNET_PQ_result_spec_end
};
for (unsigned int i = 0; i < ntuples; i++)
{
GNUNET_assert
(GNUNET_OK == GNUNET_PQ_extract_result (result,
rs,
i));
if ((0 == tot->value) && (0 == tot->fraction))
*tot = tmp;
else
GNUNET_assert
(GNUNET_SYSERR != TALER_amount_add (tot,
tot,
&tmp));
}
}
/**
* Calculate sum of money flow related to a particular merchant,
* used for KYC monitoring.
*
* @param cls closure
* @param session DB session
* @param merchant_serial_id serial id identifying the merchant
* into the KYC monitoring system.
* @param amount[out] will store the amount of money received
* by this merchant.
*/
static enum GNUNET_DB_QueryStatus
postgres_get_kyc_events (void *cls,
struct TALER_EXCHANGEDB_Session *session,
uint64_t merchant_serial_id,
struct TALER_Amount *amount)
{
enum GNUNET_DB_QueryStatus qs;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint64 (&merchant_serial_id),
GNUNET_PQ_query_param_end
};
/* make sure sum object starts virgin. */
memset (amount,
0,
sizeof (struct TALER_Amount));
qs = GNUNET_PQ_eval_prepared_multi_select (session->conn,
"get_kyc_events",
params,
sum_kyc_events,
amount);
return qs;
}
/** /**
* Retrieve KYC-check status related to a particular merchant. * Retrieve KYC-check status related to a particular merchant.
* *
@ -6848,6 +6941,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
plugin->unmark_kyc_merchant = postgres_unmark_kyc_merchant; plugin->unmark_kyc_merchant = postgres_unmark_kyc_merchant;
plugin->get_kyc_status = postgres_get_kyc_status; plugin->get_kyc_status = postgres_get_kyc_status;
plugin->insert_kyc_event = postgres_insert_kyc_event; plugin->insert_kyc_event = postgres_insert_kyc_event;
plugin->get_kyc_events = postgres_get_kyc_events;
return plugin; return plugin;
} }

View File

@ -2251,9 +2251,9 @@ struct TALER_EXCHANGEDB_Plugin
* @return database transaction status. * @return database transaction status.
*/ */
enum GNUNET_DB_QueryStatus enum GNUNET_DB_QueryStatus
(*insert_kyc_merchant) (void *cls, (*insert_kyc_merchant)(void *cls,
struct TALER_EXCHANGEDB_Session *session, struct TALER_EXCHANGEDB_Session *session,
const char *payto_url); const char *payto_url);
/** /**
* Mark a merchant as KYC-checked. * Mark a merchant as KYC-checked.
@ -2266,9 +2266,9 @@ struct TALER_EXCHANGEDB_Plugin
* @return database transaction status. * @return database transaction status.
*/ */
enum GNUNET_DB_QueryStatus enum GNUNET_DB_QueryStatus
(*mark_kyc_merchant) (void *cls, (*mark_kyc_merchant)(void *cls,
struct TALER_EXCHANGEDB_Session *session, struct TALER_EXCHANGEDB_Session *session,
const char *payto_url); const char *payto_url);
/** /**
@ -2282,9 +2282,9 @@ struct TALER_EXCHANGEDB_Plugin
* @return database transaction status. * @return database transaction status.
*/ */
enum GNUNET_DB_QueryStatus enum GNUNET_DB_QueryStatus
(*unmark_kyc_merchant) (void *cls, (*unmark_kyc_merchant)(void *cls,
struct TALER_EXCHANGEDB_Session *session, struct TALER_EXCHANGEDB_Session *session,
const char *payto_url); const char *payto_url);
/** /**
@ -2300,11 +2300,11 @@ struct TALER_EXCHANGEDB_Plugin
* @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,
TALER_EXCHANGEDB_KycStatusCallback ksc, TALER_EXCHANGEDB_KycStatusCallback ksc,
void *ksc_cls); void *ksc_cls);
/** /**
* Record timestamp where a particular merchant performed * Record timestamp where a particular merchant performed
@ -2318,10 +2318,28 @@ struct TALER_EXCHANGEDB_Plugin
* @return database transaction status. * @return database transaction status.
*/ */
enum GNUNET_DB_QueryStatus enum GNUNET_DB_QueryStatus
(*insert_kyc_event) (void *cls, (*insert_kyc_event)(void *cls,
struct TALER_EXCHANGEDB_Session *session, struct TALER_EXCHANGEDB_Session *session,
uint64_t merchant_serial_id, uint64_t merchant_serial_id,
struct TALER_Amount *amount); struct TALER_Amount *amount);
/**
* Calculate sum of money flow related to a particular merchant,
* used for KYC monitoring.
*
* @param cls closure
* @param session DB session
* @param merchant_serial_id serial id identifying the merchant
* into the KYC monitoring system.
* @param amount[out] will store the amount of money received
* by this merchant.
*/
enum GNUNET_DB_QueryStatus
(*get_kyc_events)(void *cls,
struct TALER_EXCHANGEDB_Session *session,
uint64_t merchant_serial_id,
struct TALER_Amount *amount);
}; };
#endif /* _TALER_EXCHANGE_DB_H */ #endif /* _TALER_EXCHANGE_DB_H */