summaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-10-17 14:12:13 +0200
committerChristian Grothoff <christian@grothoff.org>2021-10-17 14:12:13 +0200
commit4e3b133e47e2549682209feca61590f7e8fcd0ac (patch)
tree4c6c69d36306f71d2430c70b1bc7d3e59511912b /src/exchangedb
parent932d2aaf88d9c871bc64abcd8d7ab9c5a4f543fd (diff)
downloadexchange-4e3b133e47e2549682209feca61590f7e8fcd0ac.tar.gz
exchange-4e3b133e47e2549682209feca61590f7e8fcd0ac.tar.bz2
exchange-4e3b133e47e2549682209feca61590f7e8fcd0ac.zip
-incomplete draft for /kyc-wallet handler
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c76
1 files changed, 76 insertions, 0 deletions
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
@@ -3574,6 +3595,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.
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
@@ -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;