exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit aa8f4440159f267a576d4d56f5f7c05e4136fc09
parent 5dee406eec4ac6d44ccfaa746b2fb3e104dd60c2
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed, 17 Jul 2024 10:22:54 +0200

implement kycauth_in_insert

Diffstat:
Msrc/exchange-tools/taler-exchange-dbinit.c | 3++-
Msrc/exchange/taler-exchange-wirewatch.c | 1+
Asrc/exchangedb/0005-kycauths_in.sql | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/exchangedb/exchange-0005.sql.in | 1+
Asrc/exchangedb/exchange_do_kycauth_in_insert.sql | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/exchangedb/pg_gc.c | 1-
Msrc/exchangedb/pg_kycauth_in_insert.c | 29+++++++++++++++++++++++++++--
Msrc/exchangedb/pg_kycauth_in_insert.h | 2++
Msrc/exchangedb/procedures.sql.in | 2+-
Msrc/include/taler_exchangedb_plugin.h | 2++
10 files changed, 206 insertions(+), 5 deletions(-)

diff --git a/src/exchange-tools/taler-exchange-dbinit.c b/src/exchange-tools/taler-exchange-dbinit.c @@ -140,7 +140,8 @@ run (void *cls, } if (inject_auditor) { - if (GNUNET_SYSERR == plugin->inject_auditor_triggers (plugin->cls)) + if (GNUNET_SYSERR == + plugin->inject_auditor_triggers (plugin->cls)) { fprintf (stderr, "Injecting auditor triggers failed!\n"); diff --git a/src/exchange/taler-exchange-wirewatch.c b/src/exchange/taler-exchange-wirewatch.c @@ -592,6 +592,7 @@ process_reply (const struct TALER_BANK_CreditDetails *details, qs = db_plugin->kycauth_in_insert ( db_plugin->cls, &cd->details.kycauth.account_pub, + &cd->amount, cd->execution_date, cd->debit_account_uri, ai->section_name, diff --git a/src/exchangedb/0005-kycauths_in.sql 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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; diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h @@ -3897,6 +3897,7 @@ struct TALER_EXCHANGEDB_Plugin * * @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 @@ -3906,6 +3907,7 @@ struct TALER_EXCHANGEDB_Plugin (*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,