KYC db methods.
Add method to insert a merchant into the monitored entries, and associates a "FALSE" KYC status to it.
This commit is contained in:
parent
edf3738b3f
commit
c13973626b
@ -106,6 +106,7 @@ postgres_drop_tables (void *cls)
|
|||||||
struct PostgresClosure *pc = cls;
|
struct PostgresClosure *pc = cls;
|
||||||
struct GNUNET_PQ_ExecuteStatement es[] = {
|
struct GNUNET_PQ_ExecuteStatement es[] = {
|
||||||
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS kyc_events CASCADE;"),
|
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS kyc_events CASCADE;"),
|
||||||
|
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS kyc_merchants CASCADE;"),
|
||||||
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS prewire CASCADE;"),
|
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS prewire CASCADE;"),
|
||||||
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS payback CASCADE;"),
|
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS payback CASCADE;"),
|
||||||
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS aggregation_tracking CASCADE;"),
|
GNUNET_PQ_make_execute ("DROP TABLE IF EXISTS aggregation_tracking CASCADE;"),
|
||||||
@ -430,14 +431,26 @@ postgres_create_tables (void *cls)
|
|||||||
",buf BYTEA NOT NULL"
|
",buf BYTEA NOT NULL"
|
||||||
");"),
|
");"),
|
||||||
|
|
||||||
|
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"
|
||||||
|
");"),
|
||||||
|
|
||||||
|
GNUNET_PQ_make_try_execute ("CREATE INDEX kyc_merchants_payto_url ON "
|
||||||
|
"kyc_merchants (payto_url);"),
|
||||||
|
|
||||||
GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS kyc_events "
|
GNUNET_PQ_make_execute("CREATE TABLE IF NOT EXISTS kyc_events "
|
||||||
"(url TEXT NOT NULL"
|
"(merchant_serial_id BIGSERIAL NOT NULL REFERENCES kyc_merchants (merchant_serial_id) ON DELETE CASCADE"
|
||||||
",timestamp INT8 NOT NULL"
|
|
||||||
",amount_val INT8 NOT NULL"
|
",amount_val INT8 NOT NULL"
|
||||||
",amount_frac INT4 NOT NULL"
|
",amount_frac INT4 NOT NULL"
|
||||||
",amount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
|
",amount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
|
||||||
|
",timestamp INT8 NOT NULL"
|
||||||
");"),
|
");"),
|
||||||
|
|
||||||
|
GNUNET_PQ_make_try_execute ("CREATE INDEX kyc_events_timestamp ON "
|
||||||
|
"kyc_events (timestamp);"),
|
||||||
|
|
||||||
/* Index for wire_prepare_data_get and gc_prewire statement */
|
/* Index for wire_prepare_data_get and gc_prewire statement */
|
||||||
GNUNET_PQ_make_try_execute("CREATE INDEX prepare_iteration_index "
|
GNUNET_PQ_make_try_execute("CREATE INDEX prepare_iteration_index "
|
||||||
"ON prewire(finished);"),
|
"ON prewire(finished);"),
|
||||||
@ -1275,31 +1288,22 @@ postgres_prepare (PGconn *db_conn)
|
|||||||
" ORDER BY prewire_uuid ASC"
|
" ORDER BY prewire_uuid ASC"
|
||||||
" LIMIT 1;",
|
" LIMIT 1;",
|
||||||
0),
|
0),
|
||||||
/* Used in #postgres_insert_kyc_event */
|
|
||||||
GNUNET_PQ_make_prepare ("kyc_event_insert",
|
|
||||||
"INSERT INTO kyc_events "
|
|
||||||
"(url"
|
|
||||||
",timestamp"
|
|
||||||
",amount_val"
|
|
||||||
",amount_frac"
|
|
||||||
",amount_curr"
|
|
||||||
") VALUES "
|
|
||||||
"($1, $2, $3, $4);",
|
|
||||||
4),
|
|
||||||
|
|
||||||
/* Used in #postgres_kyc_event_get_last */
|
/**
|
||||||
GNUNET_PQ_make_prepare ("kyc_event_get_last",
|
* Methods needed to implement KYC monitoring.
|
||||||
"SELECT "
|
*
|
||||||
" url"
|
* 1 Sum money flow for a (unchecked) merchant.
|
||||||
",timestamp"
|
* 2 Change KYC status for a merchant.
|
||||||
",amount_val"
|
* 3 Get KYC status for a merchant.
|
||||||
",amount_frac"
|
* 4 Put money flow event for a merchant.
|
||||||
",amount_curr"
|
* 5 Delete money flow records for a fresh-checked merchant.
|
||||||
" FROM kyc_events"
|
* 6 Put a merchant.
|
||||||
" WHERE url=$1"
|
*/
|
||||||
" ORDER BY timestamp"
|
|
||||||
" LIMIT 1"
|
GNUNET_PQ_make_prepare ("insert_kyc_merchant",
|
||||||
" OFFSET 0;",
|
"INSERT INTO kyc_merchants "
|
||||||
|
"(payto_url, kyc_checked) VALUES "
|
||||||
|
"($1, FALSE)",
|
||||||
1),
|
1),
|
||||||
|
|
||||||
/* Used in #postgres_select_deposits_missing_wire */
|
/* Used in #postgres_select_deposits_missing_wire */
|
||||||
@ -6512,80 +6516,26 @@ postgres_select_deposits_missing_wire (void *cls,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save a amount threshold for a KYC check that
|
* Insert a merchant into the KYC monitor table.
|
||||||
* has been triggered for a certain merchant.
|
|
||||||
*
|
*
|
||||||
* @param cls plugins' closure
|
* @param payto_url payto:// URL indentifying the merchant
|
||||||
* @param url "payto" url identifying the merchant to be checked.
|
* bank account.
|
||||||
* @param amount the threshold amount associated with the check.
|
* @return database transaction status.
|
||||||
* @return transaction status code.
|
|
||||||
*/
|
*/
|
||||||
static enum GNUNET_DB_QueryStatus
|
static enum GNUNET_DB_QueryStatus
|
||||||
postgres_insert_kyc_event (void *cls,
|
postgres_insert_kyc_merchant (void *cls,
|
||||||
struct TALER_EXCHANGEDB_Session *session,
|
struct TALER_EXCHANGEDB_Session *session,
|
||||||
const char *url,
|
const char *payto_url)
|
||||||
const struct TALER_Amount *amount)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
enum GNUNET_DB_QueryStatus qs;
|
|
||||||
|
|
||||||
struct GNUNET_PQ_QueryParam params[] = {
|
struct GNUNET_PQ_QueryParam params[] = {
|
||||||
GNUNET_PQ_query_param_string (url),
|
GNUNET_PQ_query_param_string (payto_url),
|
||||||
TALER_PQ_query_param_amount (amount),
|
|
||||||
GNUNET_PQ_query_param_end
|
GNUNET_PQ_query_param_end
|
||||||
};
|
};
|
||||||
|
return GNUNET_PQ_eval_prepared_non_select (session->conn,
|
||||||
qs = GNUNET_PQ_eval_prepared_non_select (session->conn,
|
"insert_kyc_merchant",
|
||||||
"kyc_event_insert",
|
params);
|
||||||
params);
|
|
||||||
return qs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the _last_ KYC event associated with a certain merchant.
|
|
||||||
*
|
|
||||||
* @param cls plugin closure
|
|
||||||
* @param url the payto URL associated with the merchant whose
|
|
||||||
* KYC has to be returned.
|
|
||||||
* @param kyc_cb callback invoked with the timeout of last KYC event
|
|
||||||
* @param kyc_cb_cls closure for callback above
|
|
||||||
* @return transaction status
|
|
||||||
*/
|
|
||||||
static enum GNUNET_DB_QueryStatus
|
|
||||||
postgres_kyc_event_get_last (void *cls,
|
|
||||||
struct TALER_EXCHANGEDB_Session *session,
|
|
||||||
const char *url,
|
|
||||||
TALER_EXCHANGEDB_KycCallback kyc_cb,
|
|
||||||
void *kyc_cb_cls)
|
|
||||||
{
|
|
||||||
enum GNUNET_DB_QueryStatus qs;
|
|
||||||
struct GNUNET_TIME_Absolute ts;
|
|
||||||
|
|
||||||
struct GNUNET_PQ_QueryParam params[] = {
|
|
||||||
GNUNET_PQ_query_param_string (url),
|
|
||||||
GNUNET_PQ_query_param_end
|
|
||||||
};
|
|
||||||
|
|
||||||
struct GNUNET_PQ_ResultSpec rs[] = {
|
|
||||||
TALER_PQ_result_spec_absolute_time
|
|
||||||
("timestamp", &ts),
|
|
||||||
GNUNET_PQ_result_spec_end
|
|
||||||
};
|
|
||||||
|
|
||||||
qs = GNUNET_PQ_eval_prepared_singleton_select
|
|
||||||
(session->conn,
|
|
||||||
"kyc_event_get_last",
|
|
||||||
params,
|
|
||||||
rs);
|
|
||||||
|
|
||||||
kyc_cb (kyc_cb_cls,
|
|
||||||
ts);
|
|
||||||
|
|
||||||
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
|
|
||||||
GNUNET_PQ_cleanup_result (rs);
|
|
||||||
|
|
||||||
return qs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize Postgres database subsystem.
|
* Initialize Postgres database subsystem.
|
||||||
@ -6721,8 +6671,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
|
|||||||
plugin->select_deposits_missing_wire
|
plugin->select_deposits_missing_wire
|
||||||
= &postgres_select_deposits_missing_wire;
|
= &postgres_select_deposits_missing_wire;
|
||||||
|
|
||||||
plugin->insert_kyc_event = postgres_insert_kyc_event;
|
plugin->insert_kyc_merchant = postgres_insert_kyc_merchant;
|
||||||
plugin->kyc_event_get_last = postgres_kyc_event_get_last;
|
|
||||||
|
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
@ -2182,6 +2182,11 @@ run (void *cls)
|
|||||||
FAILIF (GNUNET_OK !=
|
FAILIF (GNUNET_OK !=
|
||||||
test_wire_fees (session));
|
test_wire_fees (session));
|
||||||
|
|
||||||
|
FAILIF (GNUNET_OK !=
|
||||||
|
plugin->insert_kyc_merchant (NULL,
|
||||||
|
session,
|
||||||
|
"payto:///mock"));
|
||||||
|
|
||||||
plugin->preflight (plugin->cls,
|
plugin->preflight (plugin->cls,
|
||||||
session);
|
session);
|
||||||
|
|
||||||
|
@ -807,8 +807,17 @@ typedef void
|
|||||||
const struct TALER_TransferPublicKeyP *tp);
|
const struct TALER_TransferPublicKeyP *tp);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for handling a KYC timestamped event associated with
|
||||||
|
* a certain customer (= merchant).
|
||||||
|
*
|
||||||
|
* @param cls closure
|
||||||
|
* @param url "payto" URL associated with the customer
|
||||||
|
* @param timeout last time when the KYC was issued to the customer.
|
||||||
|
*/
|
||||||
typedef void
|
typedef void
|
||||||
(*TALER_EXCHANGEDB_KycCallback)(void *cls,
|
(*TALER_EXCHANGEDB_KycCallback)(void *cls,
|
||||||
|
const char *url,
|
||||||
struct GNUNET_TIME_Absolute timeout);
|
struct GNUNET_TIME_Absolute timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2213,34 +2222,20 @@ struct TALER_EXCHANGEDB_Plugin
|
|||||||
void *cb_cls);
|
void *cb_cls);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save a amount threshold for a KYC check that
|
* Insert a merchant into the KYC monitor table, namely it
|
||||||
* has been triggered for a certain merchant.
|
* associates a flag to the merchant that indicates whether
|
||||||
|
* a KYC check has been done or not on this merchant.
|
||||||
*
|
*
|
||||||
* @param cls plugins' closure
|
* @param payto_url payto:// URL indentifying the merchant
|
||||||
* @param url "payto" url identifying the merchant to be checked.
|
* bank account.
|
||||||
* @param amount the threshold amount associated with the check.
|
* @return database transaction status.
|
||||||
* @return transaction status code.
|
|
||||||
*/
|
*/
|
||||||
enum GNUNET_DB_QueryStatus
|
enum GNUNET_DB_QueryStatus
|
||||||
(*insert_kyc_event)(void *cls,
|
(*insert_kyc_merchant) (void *cls,
|
||||||
struct TALER_EXCHANGEDB_Session *session,
|
struct TALER_EXCHANGEDB_Session *session,
|
||||||
const char *url,
|
const char *payto_url);
|
||||||
const struct TALER_Amount *amount);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the _last_ KYC event associated with a certain merchant.
|
|
||||||
*
|
|
||||||
* @param cls plugin closure
|
|
||||||
* @param url the payto URL associated with the merchant whose
|
|
||||||
* KYC has to be returned.
|
|
||||||
* @return transaction status.
|
|
||||||
*/
|
|
||||||
enum GNUNET_DB_QueryStatus
|
|
||||||
(*kyc_event_get_last) (void *cls,
|
|
||||||
struct TALER_EXCHANGEDB_Session *session,
|
|
||||||
const char *url,
|
|
||||||
TALER_EXCHANGEDB_KycCallback kyc_cb,
|
|
||||||
void *kyc_cb_cls);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _TALER_EXCHANGE_DB_H */
|
#endif /* _TALER_EXCHANGE_DB_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user