aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-07-17 10:22:54 +0200
committerChristian Grothoff <christian@grothoff.org>2024-07-29 12:18:45 +0200
commitaa8f4440159f267a576d4d56f5f7c05e4136fc09 (patch)
tree23f7301338c5e86d5df8c100197f2626356f4657 /src/exchangedb
parent5dee406eec4ac6d44ccfaa746b2fb3e104dd60c2 (diff)
implement kycauth_in_insert
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/0005-kycauths_in.sql101
-rw-r--r--src/exchangedb/exchange-0005.sql.in1
-rw-r--r--src/exchangedb/exchange_do_kycauth_in_insert.sql69
-rw-r--r--src/exchangedb/pg_gc.c1
-rw-r--r--src/exchangedb/pg_kycauth_in_insert.c29
-rw-r--r--src/exchangedb/pg_kycauth_in_insert.h2
-rw-r--r--src/exchangedb/procedures.sql.in2
7 files changed, 201 insertions, 4 deletions
diff --git a/src/exchangedb/0005-kycauths_in.sql b/src/exchangedb/0005-kycauths_in.sql
new file mode 100644
index 000000000..d1fa3f536
--- /dev/null
+++ b/src/exchangedb/0005-kycauths_in.sql
@@ -0,0 +1,101 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2024 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/>
+--
+
+CREATE FUNCTION create_table_kycauths_in(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'kycauths_in';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(kycauth_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',account_pub BYTEA CHECK (LENGTH(account_pub)=32)'
+ ',wire_reference INT8 NOT NULL'
+ ',credit taler_amount NOT NULL'
+ ',wire_source_h_payto BYTEA CHECK (LENGTH(wire_source_h_payto)=32)'
+ ',exchange_account_section TEXT NOT NULL'
+ ',execution_date INT8 NOT NULL'
+ ',PRIMARY KEY(wire_source_h_payto, wire_reference)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (wire_source_h_payto)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'list of transfers to register a key for KYC authentication, one per incoming wire transfer'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Identifies the debited bank account and KYC status'
+ ,'wire_source_h_payto'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Public key to be associated with the account.'
+ ,'account_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Amount that was transferred into the account'
+ ,'credit'
+ ,table_name
+ ,partition_suffix
+ );
+END $$;
+
+
+CREATE FUNCTION constrain_table_kycauths_in(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'kycauths_in';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_kycauth_in_serial_id_key'
+ ' UNIQUE (kycauth_in_serial_id)'
+ );
+END
+$$;
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('kycauths_in'
+ ,'exchange-0005'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('kycauths_in'
+ ,'exchange-0005'
+ ,'constrain'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/exchange-0005.sql.in b/src/exchangedb/exchange-0005.sql.in
index a7f0e2029..af02951ec 100644
--- a/src/exchangedb/exchange-0005.sql.in
+++ b/src/exchangedb/exchange-0005.sql.in
@@ -26,6 +26,7 @@ SET search_path TO exchange;
#include "0005-kyc_attributes.sql"
#include "0005-aml_history.sql"
#include "0005-kyc_events.sql"
+#include "0005-kycauths_in.sql"
-- drops:
#include "0005-aml_status.sql"
diff --git a/src/exchangedb/exchange_do_kycauth_in_insert.sql b/src/exchangedb/exchange_do_kycauth_in_insert.sql
new file mode 100644
index 000000000..94add64ee
--- /dev/null
+++ b/src/exchangedb/exchange_do_kycauth_in_insert.sql
@@ -0,0 +1,69 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2024 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/>
+--
+
+
+CREATE OR REPLACE PROCEDURE exchange_do_kycauth_insert(
+ IN in_account_pub BYTEA,
+ IN in_wire_reference INT8,
+ IN in_credit taler_amount,
+ IN in_wire_source_h_payto BYTEA,
+ IN in_payto_uri TEXT,
+ IN in_exchange_account_name TEXT,
+ IN in_execution_date INT8)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+
+ INSERT INTO kycauths_in
+ (account_pub
+ ,wire_reference
+ ,credit
+ ,wire_source_h_payto
+ ,exchange_account_section
+ ,execution_date
+ ) VALUES (
+ in_account_pub
+ ,in_wire_reference
+ ,in_credit
+ ,in_wire_source_h_payto
+ ,in_exchange_account_name
+ ,in_execution_date
+ )
+ ON CONFLICT DO NOTHING;
+
+ IF NOT FOUND
+ THEN
+ -- presumably already done
+ RETURN;
+ END IF;
+
+ UPDATE wire_targets
+ SET target_pub=in_account_pub
+ WHERE wire_target_h_payto=in_wire_source_h_payto;
+
+ IF NOT FOUND
+ THEN
+ INSERT INTO wire_targets
+ (wire_target_h_payto
+ ,payto_uri
+ ,target_pub
+ ) VALUES (
+ in_wire_source_h_payto
+ ,in_payto_uri
+ ,in_account_pub);
+ END IF;
+
+END $$;
diff --git a/src/exchangedb/pg_gc.c b/src/exchangedb/pg_gc.c
index e01c1e101..7e5adf715 100644
--- a/src/exchangedb/pg_gc.c
+++ b/src/exchangedb/pg_gc.c
@@ -54,7 +54,6 @@ TEH_PG_gc (void *cls)
GNUNET_PQ_EXECUTE_STATEMENT_END
};
struct GNUNET_PQ_PreparedStatement ps[] = {
- /* Used in #postgres_gc() */
GNUNET_PQ_make_prepare ("run_gc",
"CALL"
" exchange_do_gc"
diff --git a/src/exchangedb/pg_kycauth_in_insert.c b/src/exchangedb/pg_kycauth_in_insert.c
index 506c4a011..aafbe2acb 100644
--- a/src/exchangedb/pg_kycauth_in_insert.c
+++ b/src/exchangedb/pg_kycauth_in_insert.c
@@ -25,15 +25,40 @@
#include "pg_kycauth_in_insert.h"
#include "pg_helper.h"
+
enum GNUNET_DB_QueryStatus
TEH_PG_kycauth_in_insert (
void *cls,
const union TALER_AccountPublicKeyP *account_pub,
+ const struct TALER_Amount *credit_amount,
struct GNUNET_TIME_Timestamp execution_date,
const char *debit_account_uri,
const char *section_name,
uint64_t serial_id)
{
- // FIXME: not implemented
- return -1;
+ struct PostgresClosure *pg = cls;
+ struct TALER_PaytoHashP h_payto;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (account_pub),
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ TALER_PQ_query_param_amount (pg->conn,
+ credit_amount),
+ GNUNET_PQ_query_param_auto_from_type (&h_payto),
+ GNUNET_PQ_query_param_string (debit_account_uri),
+ GNUNET_PQ_query_param_string (section_name),
+ GNUNET_PQ_query_param_timestamp (&execution_date),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "kycauth_in_insert",
+ "CALL"
+ " exchange_do_kycauth_in_insert"
+ " ($1,$2,$3,$4,$5,$6,$7);");
+ TALER_payto_hash (debit_account_uri,
+ &h_payto);
+ return GNUNET_PQ_eval_prepared_non_select (
+ pg->conn,
+ "kycauth_in_insert",
+ params);
}
diff --git a/src/exchangedb/pg_kycauth_in_insert.h b/src/exchangedb/pg_kycauth_in_insert.h
index 2222a998b..0dcad04be 100644
--- a/src/exchangedb/pg_kycauth_in_insert.h
+++ b/src/exchangedb/pg_kycauth_in_insert.h
@@ -32,6 +32,7 @@
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param account_pub public key of the account
+ * @param credit_amount amount we were credited
* @param execution_date when was the transfer made
* @param debit_account_uri URI of the debit account
* @param section_name section of the exchange bank account that received the transfer
@@ -41,6 +42,7 @@ enum GNUNET_DB_QueryStatus
TEH_PG_kycauth_in_insert (
void *cls,
const union TALER_AccountPublicKeyP *account_pub,
+ const struct TALER_Amount *credit_amount,
struct GNUNET_TIME_Timestamp execution_date,
const char *debit_account_uri,
const char *section_name,
diff --git a/src/exchangedb/procedures.sql.in b/src/exchangedb/procedures.sql.in
index 55cef3a6e..cba356c7e 100644
--- a/src/exchangedb/procedures.sql.in
+++ b/src/exchangedb/procedures.sql.in
@@ -49,6 +49,6 @@ SET search_path TO exchange;
#include "exchange_do_batch_reserves_update.sql"
#include "exchange_do_get_link_data.sql"
#include "exchange_do_batch_coin_known.sql"
-#include "auditor-triggers-0001.sql"
+#include "exchange_do_kycauth_in_insert.sql"
COMMIT;