summaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-10-14 14:45:10 +0200
committerChristian Grothoff <christian@grothoff.org>2021-10-14 14:45:10 +0200
commit7d62fa065bba408860a79fe121a62ef8f515159c (patch)
treee03053b30346fb0c6e90ccef7f57c5d63ef8d174 /src/exchangedb
parent1b119edd6225567419add05e0a92170ebfa457df (diff)
downloadexchange-7d62fa065bba408860a79fe121a62ef8f515159c.tar.gz
exchange-7d62fa065bba408860a79fe121a62ef8f515159c.tar.bz2
exchange-7d62fa065bba408860a79fe121a62ef8f515159c.zip
start with KYC support in DB
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/Makefile.am4
-rw-r--r--src/exchangedb/drop0001.sql22
-rw-r--r--src/exchangedb/drop0002.sql31
-rw-r--r--src/exchangedb/drop0003.sql26
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c76
-rw-r--r--src/exchangedb/test_exchangedb.c18
6 files changed, 103 insertions, 74 deletions
diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am
index eae037267..37b5f015a 100644
--- a/src/exchangedb/Makefile.am
+++ b/src/exchangedb/Makefile.am
@@ -19,9 +19,7 @@ sql_DATA = \
exchange-0001.sql \
exchange-0002.sql \
exchange-0003.sql \
- drop0001.sql \
- drop0002.sql \
- drop0003.sql
+ drop0001.sql
EXTRA_DIST = \
exchangedb.conf \
diff --git a/src/exchangedb/drop0001.sql b/src/exchangedb/drop0001.sql
index f5a28192f..507393e57 100644
--- a/src/exchangedb/drop0001.sql
+++ b/src/exchangedb/drop0001.sql
@@ -22,6 +22,19 @@ BEGIN;
-- Unlike the other SQL files, it SHOULD be updated to reflect the
-- latest requirements for dropping tables.
+
+-- Drops for exchange-0003.sql
+DROP TABLE IF EXISTS revolving_work_shards CASCADE;
+
+
+-- Drops for exchange-0002.sql
+DROP TABLE IF EXISTS auditors CASCADE;
+DROP TABLE IF EXISTS auditor_denom_sigs CASCADE;
+DROP TABLE IF EXISTS exchange_sign_keys CASCADE;
+DROP TABLE IF EXISTS wire_accounts CASCADE;
+DROP TABLE IF EXISTS signkey_revocations CASCADE;
+DROP TABLE IF EXISTS work_shards CASCADE;
+
-- Drops for 0001.sql
DROP TABLE IF EXISTS prewire CASCADE;
DROP TABLE IF EXISTS recoup CASCADE;
@@ -42,8 +55,15 @@ DROP TABLE IF EXISTS reserves CASCADE;
DROP TABLE IF EXISTS denomination_revocations CASCADE;
DROP TABLE IF EXISTS denominations CASCADE;
--- Unregister patch (0001.sql)
+
+-- Unregister patch (exchange-0001.sql)
SELECT _v.unregister_patch('exchange-0001');
+-- Unregister patch (exchange-0002.sql)
+SELECT _v.unregister_patch('exchange-0002');
+
+-- Unregister patch (exchange-0003.sql)
+SELECT _v.unregister_patch('exchange-0003');
+
-- And we're out of here...
COMMIT;
diff --git a/src/exchangedb/drop0002.sql b/src/exchangedb/drop0002.sql
deleted file mode 100644
index 12db64c54..000000000
--- a/src/exchangedb/drop0002.sql
+++ /dev/null
@@ -1,31 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2020 Taler Systems SA
---
--- TALER is free software; you can redistribute it and/or modify it under the
--- terms of the GNU General Public License as published by the Free Software
--- Foundation; either version 3, or (at your option) any later version.
---
--- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
--- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
--- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
---
--- You should have received a copy of the GNU General Public License along with
--- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
---
-
--- Everything in one big transaction
-BEGIN;
-
--- Unregister patch (0002.sql)
-SELECT _v.unregister_patch('exchange-0002');
-
-DROP TABLE IF EXISTS auditors CASCADE;
-DROP TABLE IF EXISTS auditor_denom_sigs CASCADE;
-DROP TABLE IF EXISTS exchange_sign_keys CASCADE;
-DROP TABLE IF EXISTS wire_accounts CASCADE;
-DROP TABLE IF EXISTS signkey_revocations CASCADE;
-DROP TABLE IF EXISTS work_shards CASCADE;
-
--- And we're out of here...
-COMMIT;
diff --git a/src/exchangedb/drop0003.sql b/src/exchangedb/drop0003.sql
deleted file mode 100644
index fbdab04c6..000000000
--- a/src/exchangedb/drop0003.sql
+++ /dev/null
@@ -1,26 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2020 Taler Systems SA
---
--- TALER is free software; you can redistribute it and/or modify it under the
--- terms of the GNU General Public License as published by the Free Software
--- Foundation; either version 3, or (at your option) any later version.
---
--- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
--- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
--- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
---
--- You should have received a copy of the GNU General Public License along with
--- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
---
-
--- Everything in one big transaction
-BEGIN;
-
--- Unregister patch (0003.sql)
-SELECT _v.unregister_patch('exchange-0003');
-
-DROP TABLE IF EXISTS revolving_work_shards CASCADE;
-
--- And we're out of here...
-COMMIT;
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 74dc8779b..34b785e7f 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -347,6 +347,19 @@ prepare_statements (struct PostgresClosure *pg)
" WHERE denom_pub_hash=$1);",
1),
/* Used in #postgres_reserves_get() */
+ GNUNET_PQ_make_prepare ("reserves_get_with_kyc",
+ "SELECT"
+ " current_balance_val"
+ ",current_balance_frac"
+ ",expiration_date"
+ ",gc_date"
+ ",FALSE AS kyc_ok" // FIXME
+ ",CAST (0 AS INT8) AS payment_target_uuid" // FIXME
+ " FROM reserves"
+ " WHERE reserve_pub=$1"
+ " LIMIT 1;",
+ 1),
+ /* Used in #reserves_get() */
GNUNET_PQ_make_prepare ("reserves_get",
"SELECT"
" current_balance_val"
@@ -3464,10 +3477,56 @@ postgres_iterate_auditor_denominations (
* @param[in,out] reserve the reserve data. The public key of the reserve should be
* set in this structure; it is used to query the database. The balance
* and expiration are then filled accordingly.
+ * @param[out] kyc set to the KYC status of the reserve
* @return transaction status
*/
static enum GNUNET_DB_QueryStatus
postgres_reserves_get (void *cls,
+ struct TALER_EXCHANGEDB_Reserve *reserve,
+ struct TALER_EXCHANGEDB_KycStatus *kyc)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&reserve->pub),
+ GNUNET_PQ_query_param_end
+ };
+ uint8_t ok8;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("current_balance",
+ &reserve->balance),
+ TALER_PQ_result_spec_absolute_time ("expiration_date",
+ &reserve->expiry),
+ TALER_PQ_result_spec_absolute_time ("gc_date",
+ &reserve->gc),
+ 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
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "reserves_get_with_kyc",
+ params,
+ rs);
+ kyc->type = TALER_EXCHANGEDB_KYC_WITHDRAW;
+ kyc->ok = (0 != ok8);
+ return qs;
+}
+
+
+/**
+ * Get the summary of a reserve.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param[in,out] reserve the reserve data. The public key of the reserve should be
+ * set in this structure; it is used to query the database. The balance
+ * and expiration are then filled accordingly.
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+reserves_get_internal (void *cls,
struct TALER_EXCHANGEDB_Reserve *reserve)
{
struct PostgresClosure *pg = cls;
@@ -3476,9 +3535,12 @@ postgres_reserves_get (void *cls,
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("current_balance", &reserve->balance),
- TALER_PQ_result_spec_absolute_time ("expiration_date", &reserve->expiry),
- TALER_PQ_result_spec_absolute_time ("gc_date", &reserve->gc),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("current_balance",
+ &reserve->balance),
+ TALER_PQ_result_spec_absolute_time ("expiration_date",
+ &reserve->expiry),
+ TALER_PQ_result_spec_absolute_time ("gc_date",
+ &reserve->gc),
GNUNET_PQ_result_spec_end
};
@@ -3699,7 +3761,7 @@ postgres_reserves_in_insert (void *cls,
{
enum GNUNET_DB_QueryStatus reserve_exists;
- reserve_exists = postgres_reserves_get (pg,
+ reserve_exists = reserves_get_internal (pg,
&reserve);
switch (reserve_exists)
{
@@ -3916,7 +3978,7 @@ postgres_insert_withdraw_info (
/* update reserve balance */
reserve.pub = collectable->reserve_pub;
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- (qs = postgres_reserves_get (pg,
+ (qs = reserves_get_internal (pg,
&reserve)))
{
/* Should have been checked before we got here... */
@@ -6875,7 +6937,7 @@ postgres_insert_reserve_closed (
/* update reserve balance */
reserve.pub = *reserve_pub;
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- (qs = postgres_reserves_get (cls,
+ (qs = reserves_get_internal (cls,
&reserve)))
{
/* Existence should have been checked before we got here... */
@@ -8667,7 +8729,7 @@ postgres_insert_recoup_request (
/* Update reserve balance */
reserve.pub = *reserve_pub;
- qs = postgres_reserves_get (pg,
+ qs = reserves_get_internal (pg,
&reserve);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c
index 655d2f53e..bfe131639 100644
--- a/src/exchangedb/test_exchangedb.c
+++ b/src/exchangedb/test_exchangedb.c
@@ -154,22 +154,25 @@ drop:
* @return #GNUNET_OK if the given reserve has the same balance and expiration
* as the given parameters; #GNUNET_SYSERR if not
*/
-static int
+static enum GNUNET_GenericReturnValue
check_reserve (const struct TALER_ReservePublicKeyP *pub,
uint64_t value,
uint32_t fraction,
const char *currency)
{
struct TALER_EXCHANGEDB_Reserve reserve;
+ struct TALER_EXCHANGEDB_KycStatus kyc;
reserve.pub = *pub;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->reserves_get (plugin->cls,
- &reserve));
+ &reserve,
+ &kyc));
FAILIF (value != reserve.balance.value);
FAILIF (fraction != reserve.balance.fraction);
- FAILIF (0 != strcmp (currency, reserve.balance.currency));
-
+ FAILIF (0 != strcmp (currency,
+ reserve.balance.currency));
+ FAILIF (kyc.ok);
return GNUNET_OK;
drop:
return GNUNET_SYSERR;
@@ -1692,11 +1695,13 @@ run (void *cls)
struct TALER_EXCHANGEDB_Reserve pre_reserve;
struct TALER_EXCHANGEDB_Reserve post_reserve;
struct TALER_Amount delta;
+ struct TALER_EXCHANGEDB_KycStatus kyc;
pre_reserve.pub = reserve_pub;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->reserves_get (plugin->cls,
- &pre_reserve));
+ &pre_reserve,
+ &kyc));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_recoup_request (plugin->cls,
&reserve_pub,
@@ -1709,7 +1714,8 @@ run (void *cls)
post_reserve.pub = reserve_pub;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->reserves_get (plugin->cls,
- &post_reserve));
+ &post_reserve,
+ &kyc));
FAILIF (0 >=
TALER_amount_subtract (&delta,
&post_reserve.balance,