exchange

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

commit ce7baf5dcf29064c1fdcfa7e8591b4aa3c3b8fe2
parent 5f042c913f5a43ffb587bf3c0c9f3c4c3597d197
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 28 Jul 2024 17:15:53 +0200

DCE, remove duplicate field, get wallet test_kyc_api test to pass

Diffstat:
Msrc/exchange/taler-exchange-httpd_reserves_get_attest.c | 140++++++++++++++++++++++++++++---------------------------------------------------
Msrc/exchangedb/0005-kyc_attributes.sql | 7-------
Msrc/exchangedb/Makefile.am | 1-
Msrc/exchangedb/pg_insert_records_by_table.c | 4++--
Msrc/exchangedb/pg_lookup_records_by_table.c | 6+++---
Msrc/exchangedb/pg_select_kyc_attributes.c | 2+-
Dsrc/exchangedb/pg_select_similar_kyc_attributes.c | 154-------------------------------------------------------------------------------
Dsrc/exchangedb/pg_select_similar_kyc_attributes.h | 45---------------------------------------------
Msrc/exchangedb/plugin_exchangedb_postgres.c | 3---
Msrc/include/taler_exchangedb_plugin.h | 19+------------------
Msrc/testing/test_kyc_api.c | 13++++++++++---
Msrc/testing/testing_api_cmd_kyc_wallet_get.c | 14++++++++------
12 files changed, 75 insertions(+), 333 deletions(-)

diff --git a/src/exchange/taler-exchange-httpd_reserves_get_attest.c b/src/exchange/taler-exchange-httpd_reserves_get_attest.c @@ -50,10 +50,6 @@ struct ReserveAttestContext */ json_t *attributes; - /** - * Set to true if we did not find the reserve. - */ - bool not_found; }; @@ -114,115 +110,79 @@ kyc_process_cb (void *cls, } -/** - * Function implementing GET /reserves/$RID/attest transaction. - * Execute a /reserves/ get attest. Given the public key of a reserve, - * return the associated transaction attest. Runs the - * transaction logic; IF it returns a non-error code, the transaction - * logic MUST NOT queue a MHD response. IF it returns an hard error, - * the transaction logic MUST queue a MHD response and set @a mhd_ret. - * IF it returns the soft error code, the function MAY be called again - * to retry and MUST not queue a MHD response. - * - * @param cls a `struct ReserveAttestContext *` - * @param connection MHD request which triggered the transaction - * @param[out] mhd_ret set to MHD response status for @a connection, - * if transaction failed (!) - * @return transaction status - */ -static enum GNUNET_DB_QueryStatus -reserve_attest_transaction (void *cls, - struct MHD_Connection *connection, - MHD_RESULT *mhd_ret) -{ - struct ReserveAttestContext *rsc = cls; - enum GNUNET_DB_QueryStatus qs; - - rsc->attributes = json_array (); - GNUNET_assert (NULL != rsc->attributes); - qs = TEH_plugin->select_kyc_attributes (TEH_plugin->cls, - &rsc->h_payto, - &kyc_process_cb, - rsc); - switch (qs) - { - case GNUNET_DB_STATUS_HARD_ERROR: - GNUNET_break (0); - *mhd_ret - = TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_FETCH_FAILED, - "iterate_kyc_reference"); - return qs; - case GNUNET_DB_STATUS_SOFT_ERROR: - GNUNET_break (0); - return qs; - case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - rsc->not_found = true; - return qs; - case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: - rsc->not_found = false; - break; - } - return qs; -} - - MHD_RESULT -TEH_handler_reserves_get_attest (struct TEH_RequestContext *rc, - const char *const args[1]) +TEH_handler_reserves_get_attest ( + struct TEH_RequestContext *rc, + const char *const args[1]) { struct ReserveAttestContext rsc = { .attributes = NULL }; if (GNUNET_OK != - GNUNET_STRINGS_string_to_data (args[0], - strlen (args[0]), - &rsc.reserve_pub, - sizeof (rsc.reserve_pub))) + GNUNET_STRINGS_string_to_data ( + args[0], + strlen (args[0]), + &rsc.reserve_pub, + sizeof (rsc.reserve_pub))) { GNUNET_break_op (0); - return TALER_MHD_reply_with_error (rc->connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_RESERVE_PUB_MALFORMED, - args[0]); + return TALER_MHD_reply_with_error ( + rc->connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_RESERVE_PUB_MALFORMED, + args[0]); } { char *payto_uri; - payto_uri = TALER_reserve_make_payto (TEH_base_url, - &rsc.reserve_pub); + payto_uri + = TALER_reserve_make_payto (TEH_base_url, + &rsc.reserve_pub); TALER_payto_hash (payto_uri, &rsc.h_payto); GNUNET_free (payto_uri); } { - MHD_RESULT mhd_ret; - - if (GNUNET_OK != - TEH_DB_run_transaction (rc->connection, - "get-attestable", - TEH_MT_REQUEST_OTHER, - &mhd_ret, - &reserve_attest_transaction, - &rsc)) + enum GNUNET_DB_QueryStatus qs; + + rsc.attributes = json_array (); + GNUNET_assert (NULL != rsc.attributes); + qs = TEH_plugin->select_kyc_attributes (TEH_plugin->cls, + &rsc.h_payto, + &kyc_process_cb, + &rsc); + switch (qs) { + case GNUNET_DB_STATUS_HARD_ERROR: + GNUNET_break (0); + json_decref (rsc.attributes); + rsc.attributes = NULL; + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "select_kyc_attributes"); + case GNUNET_DB_STATUS_SOFT_ERROR: + GNUNET_break (0); json_decref (rsc.attributes); rsc.attributes = NULL; - return mhd_ret; + return TALER_MHD_reply_with_error (rc->connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + "select_kyc_attributes"); + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + GNUNET_break_op (0); + json_decref (rsc.attributes); + rsc.attributes = NULL; + return TALER_MHD_reply_with_error ( + rc->connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_EXCHANGE_GENERIC_RESERVE_UNKNOWN, + NULL); + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + break; } } - /* generate proper response */ - if (rsc.not_found) - { - json_decref (rsc.attributes); - rsc.attributes = NULL; - return TALER_MHD_reply_with_error (rc->connection, - MHD_HTTP_NOT_FOUND, - TALER_EC_EXCHANGE_GENERIC_RESERVE_UNKNOWN, - args[0]); - } return TALER_MHD_REPLY_JSON_PACK ( rc->connection, MHD_HTTP_OK, diff --git a/src/exchangedb/0005-kyc_attributes.sql b/src/exchangedb/0005-kyc_attributes.sql @@ -28,7 +28,6 @@ BEGIN ' DROP COLUMN kyc_prox' ',DROP COLUMN provider' ',DROP COLUMN satisfied_checks' - ',ADD COLUMN legitimization_process_serial_id INT8 DEFAULT NULL' ',ADD COLUMN trigger_outcome_serial INT8 NOT NULL' ';' ,table_name @@ -36,12 +35,6 @@ BEGIN ,partition_suffix ); PERFORM comment_partitioned_column( - 'serial ID of the legitimization process that resulted in these attributes, NULL if the attributes are from a form directly supplied by the account owner via a form' - ,'legitimization_process_serial_id' - ,table_name - ,partition_suffix - ); - PERFORM comment_partitioned_column( 'ID of the outcome that was returned by the AML program based on the KYC data collected' ,'trigger_outcome_serial' ,table_name diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am @@ -167,7 +167,6 @@ libtaler_plugin_exchangedb_postgres_la_SOURCES = \ pg_aggregate.h pg_aggregate.c \ pg_create_aggregation_transient.h pg_create_aggregation_transient.c \ pg_insert_kyc_attributes.h pg_insert_kyc_attributes.c \ - pg_select_similar_kyc_attributes.h pg_select_similar_kyc_attributes.c \ pg_select_kyc_attributes.h pg_select_kyc_attributes.c \ pg_insert_aml_officer.h pg_insert_aml_officer.c \ pg_test_aml_officer.h pg_test_aml_officer.c \ diff --git a/src/exchangedb/pg_insert_records_by_table.c b/src/exchangedb/pg_insert_records_by_table.c @@ -2059,7 +2059,7 @@ irbt_cb_table_kyc_attributes (struct PostgresClosure *pg, GNUNET_PQ_query_param_auto_from_type ( &td->details.kyc_attributes.h_payto), GNUNET_PQ_query_param_uint64 ( - &td->details.kyc_attributes.legitimization_process_serial_id), + &td->details.kyc_attributes.legitimization_serial), GNUNET_PQ_query_param_timestamp ( &td->details.kyc_attributes.collection_time), GNUNET_PQ_query_param_timestamp ( @@ -2077,7 +2077,7 @@ irbt_cb_table_kyc_attributes (struct PostgresClosure *pg, "INSERT INTO kyc_attributes" "(kyc_attributes_serial_id" ",h_payto" - ",legitimization_process_serial_id" + ",legitimization_serial" ",collection_time" ",expiration_time" ",trigger_outcome_serial" diff --git a/src/exchangedb/pg_lookup_records_by_table.c b/src/exchangedb/pg_lookup_records_by_table.c @@ -2845,8 +2845,8 @@ lrbt_cb_table_kyc_attributes (void *cls, "h_payto", &td.details.kyc_attributes.h_payto), GNUNET_PQ_result_spec_uint64 ( - "legitimization_process_serial_id", - &td.details.kyc_attributes.legitimization_process_serial_id), + "legitimization_serial", + &td.details.kyc_attributes.legitimization_serial), GNUNET_PQ_result_spec_timestamp ( "collection_time", &td.details.kyc_attributes.collection_time), @@ -3674,7 +3674,7 @@ TEH_PG_lookup_records_by_table (void *cls, "SELECT" " kyc_attributes_serial_id" ",h_payto" - ",legitimization_process_serial_id" + ",legitimization_serial" ",collection_time" ",expiration_time" ",trigger_outcome_serial" diff --git a/src/exchangedb/pg_select_kyc_attributes.c b/src/exchangedb/pg_select_kyc_attributes.c @@ -144,7 +144,7 @@ TEH_PG_select_kyc_attributes ( ",ka.encrypted_attributes" " FROM kyc_attributes ka" " JOIN legitimization_processes lp" - " USING (legitimization_process_serial_id)" + " ON (ka.legitimization_serial = lp.legitimization_process_serial_id)" " WHERE ka.h_payto=$1"); qs = GNUNET_PQ_eval_prepared_multi_select ( pg->conn, diff --git a/src/exchangedb/pg_select_similar_kyc_attributes.c b/src/exchangedb/pg_select_similar_kyc_attributes.c @@ -1,154 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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/> - */ -/** - * @file exchangedb/pg_select_similar_kyc_attributes.c - * @brief Implementation of the select_similar_kyc_attributes function for Postgres - * @author Christian Grothoff - */ -#include "platform.h" -#include "taler_error_codes.h" -#include "taler_dbevents.h" -#include "taler_pq_lib.h" -#include "pg_select_similar_kyc_attributes.h" -#include "pg_helper.h" - - -/** - * Closure for #get_similar_attributes_cb(). - */ -struct GetAttributesContext -{ - /** - * Function to call per result. - */ - TALER_EXCHANGEDB_AttributeCallback cb; - - /** - * Closure for @e cb. - */ - void *cb_cls; - - /** - * Plugin context. - */ - struct PostgresClosure *pg; - - /** - * Flag set to #GNUNET_OK as long as everything is fine. - */ - enum GNUNET_GenericReturnValue status; - -}; - - -/** - * Invoke the callback for each result. - * - * @param cls a `struct GetAttributesContext *` - * @param result SQL result - * @param num_results number of rows in @a result - */ -static void -get_attributes_cb (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct GetAttributesContext *ctx = cls; - - for (unsigned int i = 0; i < num_results; i++) - { - struct TALER_PaytoHashP h_payto; - struct GNUNET_TIME_Timestamp collection_time; - struct GNUNET_TIME_Timestamp expiration_time; - size_t enc_attributes_size; - void *enc_attributes; - char *provider; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("h_payto", - &h_payto), - GNUNET_PQ_result_spec_string ("provider", - &provider), - GNUNET_PQ_result_spec_timestamp ("collection_time", - &collection_time), - GNUNET_PQ_result_spec_timestamp ("expiration_time", - &expiration_time), - GNUNET_PQ_result_spec_variable_size ("encrypted_attributes", - &enc_attributes, - &enc_attributes_size), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ctx->status = GNUNET_SYSERR; - return; - } - ctx->cb (ctx->cb_cls, - &h_payto, - provider, - collection_time, - expiration_time, - enc_attributes_size, - enc_attributes); - GNUNET_PQ_cleanup_result (rs); - } -} - - -enum GNUNET_DB_QueryStatus -TEH_PG_select_similar_kyc_attributes ( - void *cls, - const struct GNUNET_ShortHashCode *kyc_prox, - TALER_EXCHANGEDB_AttributeCallback cb, - void *cb_cls) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_auto_from_type (kyc_prox), - GNUNET_PQ_query_param_end - }; - struct GetAttributesContext ctx = { - .cb = cb, - .cb_cls = cb_cls, - .pg = pg, - .status = GNUNET_OK - }; - enum GNUNET_DB_QueryStatus qs; - - PREPARE (pg, - "select_similar_kyc_attributes", - "SELECT " - " h_payto" - ",provider" - ",collection_time" - ",expiration_time" - ",encrypted_attributes" - " FROM kyc_attributes" - " WHERE kyc_prox=$1"); - qs = GNUNET_PQ_eval_prepared_multi_select ( - pg->conn, - "select_similar_kyc_attributes", - params, - &get_attributes_cb, - &ctx); - if (GNUNET_OK != ctx.status) - return GNUNET_DB_STATUS_HARD_ERROR; - return qs; -} diff --git a/src/exchangedb/pg_select_similar_kyc_attributes.h b/src/exchangedb/pg_select_similar_kyc_attributes.h @@ -1,45 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2022 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/> - */ -/** - * @file exchangedb/pg_select_similar_kyc_attributes.h - * @brief implementation of the select_similar_kyc_attributes function for Postgres - * @author Christian Grothoff - */ -#ifndef PG_SELECT_SIMILAR_KYC_ATTRIBUTES_H -#define PG_SELECT_SIMILAR_KYC_ATTRIBUTES_H - -#include "taler_util.h" -#include "taler_json_lib.h" -#include "taler_exchangedb_plugin.h" - - -/** - * Lookup similar KYC attribute data. - * - * @param cls closure - * @param kyc_prox key for similarity search - * @param cb callback to invoke on each match - * @param cb_cls closure for @a cb - * @return database transaction status - */ -enum GNUNET_DB_QueryStatus -TEH_PG_select_similar_kyc_attributes ( - void *cls, - const struct GNUNET_ShortHashCode *kyc_prox, - TALER_EXCHANGEDB_AttributeCallback cb, - void *cb_cls); - -#endif diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c @@ -218,7 +218,6 @@ #include "pg_setup_wire_target.h" #include "pg_compute_shard.h" #include "pg_insert_kyc_attributes.h" -#include "pg_select_similar_kyc_attributes.h" #include "pg_select_kyc_attributes.h" #include "pg_insert_aml_officer.h" #include "pg_test_aml_officer.h" @@ -792,8 +791,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) = &TEH_PG_get_pending_kyc_requirement_process; plugin->insert_kyc_attributes = &TEH_PG_insert_kyc_attributes; - plugin->select_similar_kyc_attributes - = &TEH_PG_select_similar_kyc_attributes; plugin->select_kyc_attributes = &TEH_PG_select_kyc_attributes; plugin->insert_aml_officer diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h @@ -420,7 +420,7 @@ struct TALER_EXCHANGEDB_TableData struct { struct TALER_PaytoHashP h_payto; - uint64_t legitimization_process_serial_id; + uint64_t legitimization_serial; struct GNUNET_TIME_Timestamp collection_time; struct GNUNET_TIME_Timestamp expiration_time; uint64_t trigger_outcome_serial; @@ -7186,23 +7186,6 @@ struct TALER_EXCHANGEDB_Plugin /** - * Lookup similar KYC attribute data. - * - * @param cls closure - * @param kyc_prox key for similarity search - * @param cb callback to invoke on each match - * @param cb_cls closure for @a cb - * @return database transaction status - */ - enum GNUNET_DB_QueryStatus - (*select_similar_kyc_attributes)( - void *cls, - const struct GNUNET_ShortHashCode *kyc_prox, - TALER_EXCHANGEDB_AttributeCallback cb, - void *cb_cls); - - - /** * Lookup KYC attribute data for a specific account. * * @param cls closure diff --git a/src/testing/test_kyc_api.c b/src/testing/test_kyc_api.c @@ -296,6 +296,15 @@ run (void *cls, "wallet-kyc-fail", "wallet-kyc-fail", MHD_HTTP_ACCEPTED), + TALER_TESTING_cmd_get_kyc_info ( + "get-kyc-info-kyc-wallet", + "check-kyc-wallet", + MHD_HTTP_OK), + TALER_TESTING_cmd_post_kyc_start ( + "start-kyc-wallet", + "get-kyc-info-kyc-wallet", + 0, + MHD_HTTP_OK), TALER_TESTING_cmd_proof_kyc_oauth2 ( "proof-wallet-kyc", "wallet-kyc-fail", @@ -306,7 +315,7 @@ run (void *cls, "wallet-kyc-check", "wallet-kyc-fail", "wallet-kyc-fail", - MHD_HTTP_NO_CONTENT), + MHD_HTTP_OK), TALER_TESTING_cmd_reserve_get_attestable ( "wallet-get-attestable", "wallet-kyc-fail", @@ -707,11 +716,9 @@ run (void *cls, TALER_TESTING_cmd_batch ( "withdraw-kyc", withdraw_kyc), -#if FIXME TALER_TESTING_cmd_batch ( "wallet-kyc", wallet_kyc), -#endif TALER_TESTING_cmd_batch ( "p2p_withdraw", p2p_withdraw), diff --git a/src/testing/testing_api_cmd_kyc_wallet_get.c b/src/testing/testing_api_cmd_kyc_wallet_get.c @@ -213,8 +213,9 @@ wallet_kyc_run (void *cls, * @param cmd the command which is being cleaned up. */ static void -wallet_kyc_cleanup (void *cls, - const struct TALER_TESTING_Command *cmd) +wallet_kyc_cleanup ( + void *cls, + const struct TALER_TESTING_Command *cmd) { struct KycWalletGetState *kwg = cls; @@ -272,10 +273,11 @@ wallet_kyc_traits (void *cls, struct TALER_TESTING_Command -TALER_TESTING_cmd_wallet_kyc_get (const char *label, - const char *reserve_reference, - const char *threshold_balance, - unsigned int expected_response_code) +TALER_TESTING_cmd_wallet_kyc_get ( + const char *label, + const char *reserve_reference, + const char *threshold_balance, + unsigned int expected_response_code) { struct KycWalletGetState *kwg;