From 4e3b133e47e2549682209feca61590f7e8fcd0ac Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 17 Oct 2021 14:12:13 +0200 Subject: -incomplete draft for /kyc-wallet handler --- src/exchangedb/plugin_exchangedb_postgres.c | 76 +++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'src/exchangedb') diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 54a03dce9..b4738ef4a 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -369,6 +369,23 @@ prepare_statements (struct PostgresClosure *pg) " WHERE payto_uri=$1" " LIMIT 1;", 1), + /* Used in #postgres_inselect_wallet_kyc_status() */ + // FIXME: Note that this statement has not been debugged at all... + // It just represents the _idea_. + GNUNET_PQ_make_prepare ("inselect_wallet_kyc_status", + "INSERT INTO wire_targets" + "(payto_uri" + ") VALUES " + "($1)" + " ON CONFLICT (wire_target_serial_id) DO " + " (SELECT " + " kyc_ok" + " ,wire_target_serial_id" + " )" + " RETURNING " + " FALSE AS kyc_ok" + " wire_target_serial_id;", + 1), #endif /* Used in #reserves_get() */ GNUNET_PQ_make_prepare ("reserves_get", @@ -3542,12 +3559,15 @@ postgres_get_kyc_status (void *cls, const char *payto_uri, struct TALER_EXCHANGEDB_KycStatus *kyc) { +#if FIXME_DD23 struct PostgresClosure *pg = cls; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (payto_uri), GNUNET_PQ_query_param_end }; +#endif uint8_t ok8; +#if FIXME_DD23 struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ("payment_target_uuid", &kyc->payment_target_uuid), @@ -3555,6 +3575,7 @@ postgres_get_kyc_status (void *cls, &ok8), GNUNET_PQ_result_spec_end }; +#endif enum GNUNET_DB_QueryStatus qs; #if FIXME_DD23 @@ -3573,6 +3594,60 @@ postgres_get_kyc_status (void *cls, } +/** + * Get the KYC status for a wallet. If the status is unknown, + * inserts a new status record (hence INsertSELECT). + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param reserve_pub public key of the wallet + * @param[out] kyc set to the KYC status of the wallet + * @return transaction status + */ +static enum GNUNET_DB_QueryStatus +postgres_inselect_wallet_kyc_status ( + void *cls, + const struct TALER_ReservePublicKeyP *reserve_pub, + struct TALER_EXCHANGEDB_KycStatus *kyc) +{ +#if FIXME_DD23 + struct PostgresClosure *pg = cls; + /* FIXME: maybe prepared statement will take + a payto:// URI instead of the reserve public key? + => figure out once DB schema is stable! */ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", + reserve_pub), + GNUNET_PQ_query_param_end + }; +#endif + uint8_t ok8; +#if FIXME_DD23 + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("payment_target_uuid", + &kyc->payment_target_uuid), + GNUNET_PQ_result_spec_auto_from_type ("kyc_ok", + &ok8), + GNUNET_PQ_result_spec_end + }; +#endif + enum GNUNET_DB_QueryStatus qs; + +#if FIXME_DD23 + qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "inselect_wallet_kyc_status", + params, + rs); +#else + qs = 1; + ok8 = 0; + kyc->payment_target_uuid = 0; +#endif + kyc->type = TALER_EXCHANGEDB_KYC_BALANCE; + kyc->ok = (0 != ok8); + return qs; +} + + /** * Get the summary of a reserve. * @@ -11128,6 +11203,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) &postgres_iterate_auditor_denominations; plugin->reserves_get = &postgres_reserves_get; plugin->get_kyc_status = &postgres_get_kyc_status; + plugin->inselect_wallet_kyc_status = &postgres_inselect_wallet_kyc_status; plugin->reserves_in_insert = &postgres_reserves_in_insert; plugin->get_latest_reserve_in_reference = &postgres_get_latest_reserve_in_reference; -- cgit v1.2.3