exchange

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

commit 9988229acbdb8bacb848cd48d003e01bb6685093
parent 22ee139c44476a44c472335b06f63cf6b3ef8820
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu, 25 Apr 2024 21:06:11 +0200

get DB to build with new tables

Diffstat:
Msrc/exchangedb/pg_insert_records_by_table.c | 279+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
Msrc/exchangedb/pg_lookup_records_by_table.c | 635++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Msrc/exchangedb/pg_lookup_serial_by_table.c | 90++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Msrc/include/taler_exchangedb_plugin.h | 11+++++++----
4 files changed, 627 insertions(+), 388 deletions(-)

diff --git a/src/exchangedb/pg_insert_records_by_table.c b/src/exchangedb/pg_insert_records_by_table.c @@ -172,22 +172,25 @@ irbt_cb_table_wire_targets (struct PostgresClosure *pg, struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_auto_from_type (&payto_hash), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.wire_targets.target_token), GNUNET_PQ_query_param_string ( td->details.wire_targets.payto_uri), GNUNET_PQ_query_param_end }; + TALER_payto_hash ( + td->details.wire_targets.payto_uri, + &payto_hash); PREPARE (pg, "insert_into_table_wire_targets", "INSERT INTO wire_targets" "(wire_target_serial_id" ",wire_target_h_payto" + ",target_token" ",payto_uri" ") VALUES " - "($1, $2, $3);"); - TALER_payto_hash ( - td->details.wire_targets.payto_uri, - &payto_hash); + "($1, $2, $3, $4);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_wire_targets", params); @@ -201,38 +204,81 @@ irbt_cb_table_wire_targets (struct PostgresClosure *pg, * @param td record to insert */ static enum GNUNET_DB_QueryStatus -irbt_cb_table_legitimization_processes (struct PostgresClosure *pg, - const struct - TALER_EXCHANGEDB_TableData *td) +irbt_cb_table_legitimization_measures ( + struct PostgresClosure *pg, + const struct TALER_EXCHANGEDB_TableData *td) { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_auto_from_type ( - &td->details.legitimization_processes.h_payto), + &td->details.legitimization_measures.target_token), GNUNET_PQ_query_param_timestamp ( - &td->details.legitimization_processes.expiration_time), - GNUNET_PQ_query_param_string ( - td->details.legitimization_processes.provider_section), - GNUNET_PQ_query_param_string ( - td->details.legitimization_processes.provider_user_id), - GNUNET_PQ_query_param_string ( - td->details.legitimization_processes.provider_legitimization_id), + &td->details.legitimization_measures.start_time), + TALER_PQ_query_param_json ( + td->details.legitimization_measures.measures), + GNUNET_PQ_query_param_uint32 ( + &td->details.legitimization_measures.display_priority), GNUNET_PQ_query_param_end }; PREPARE (pg, - "insert_into_table_legitimization_processes", - "INSERT INTO legitimization_processes" - "(legitimization_process_serial_id" + "insert_into_table_legitimization_measures", + "INSERT INTO legitimization_measures" + "(legitimization_measure_serial_id" + ",access_token" + ",start_time" + ",jmeasures" + ",display_priority" + ") VALUES " + "($1, $2, $3, $4, $5);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_into_table_legitimization_measures", + params); +} + + +/** + * Function called with records to insert into table. + * + * @param pg plugin context + * @param td record to insert + */ +static enum GNUNET_DB_QueryStatus +irbt_cb_table_legitimization_outcomes ( + struct PostgresClosure *pg, + const struct TALER_EXCHANGEDB_TableData *td) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&td->serial), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.legitimization_outcomes.h_payto), + GNUNET_PQ_query_param_timestamp ( + &td->details.legitimization_outcomes.decision_time), + GNUNET_PQ_query_param_timestamp ( + &td->details.legitimization_outcomes.expiration_time), + TALER_PQ_query_param_json ( + td->details.legitimization_outcomes.properties), + GNUNET_PQ_query_param_bool ( + td->details.legitimization_outcomes.to_investigate), + TALER_PQ_query_param_json ( + td->details.legitimization_outcomes.new_rules), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "insert_into_table_legitimization_outcomes", + "INSERT INTO legitimization_outcomes" + "(outcome_serial_id" ",h_payto" + ",decision_time" ",expiration_time" - ",provider_section" - ",provider_user_id" - ",provider_legitimization_id" + ",jproperties" + ",to_investigate" + ",jnew_rules" ") VALUES " - "($1, $3, $4, $5, $6, %7);"); + "($1, $2, $3, $4, $5, $6, $7);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_into_table_legitimization_processes", + "insert_into_table_legitimization_outcomes", params); } @@ -244,34 +290,50 @@ irbt_cb_table_legitimization_processes (struct PostgresClosure *pg, * @param td record to insert */ static enum GNUNET_DB_QueryStatus -irbt_cb_table_legitimization_requirements (struct PostgresClosure *pg, - const struct - TALER_EXCHANGEDB_TableData *td) +irbt_cb_table_legitimization_processes ( + struct PostgresClosure *pg, + const struct TALER_EXCHANGEDB_TableData *td) { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_auto_from_type ( - &td->details.legitimization_requirements.h_payto), - td->details.legitimization_requirements.no_reserve_pub - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_auto_from_type ( - &td->details.legitimization_requirements.reserve_pub), + &td->details.legitimization_processes.h_payto), + GNUNET_PQ_query_param_timestamp ( + &td->details.legitimization_processes.start_time), + GNUNET_PQ_query_param_timestamp ( + &td->details.legitimization_processes.expiration_time), + GNUNET_PQ_query_param_uint64 ( + &td->details.legitimization_processes.legitimization_measure_serial_id), + GNUNET_PQ_query_param_uint32 ( + &td->details.legitimization_processes.measure_index), + GNUNET_PQ_query_param_string ( + td->details.legitimization_processes.provider_section), + GNUNET_PQ_query_param_string ( + td->details.legitimization_processes.provider_user_id), GNUNET_PQ_query_param_string ( - td->details.legitimization_requirements.required_checks), + td->details.legitimization_processes.provider_legitimization_id), + GNUNET_PQ_query_param_string ( + td->details.legitimization_processes.redirect_url), GNUNET_PQ_query_param_end }; PREPARE (pg, - "insert_into_table_legitimization_requirements", - "INSERT INTO legitimization_requirements" - "(legitimization_requirement_serial_id" + "insert_into_table_legitimization_processes", + "INSERT INTO legitimization_processes" + "(legitimization_process_serial_id" ",h_payto" - ",reserve_pub" - ",required_checks" + ",start_time" + ",expiration_time" + ",legitimization_measure_serial_id" + ",measure_index" + ",provider_section" + ",provider_user_id" + ",provider_legitimization_id" + ",redirect_url" ") VALUES " - "($1, $2, $3);"); + "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_into_table_legitimization_requirements", + "insert_into_table_legitimization_processes", params); } @@ -1983,6 +2045,52 @@ irbt_cb_table_aml_staff (struct PostgresClosure *pg, /** + * Function called with kyc_attributes records to insert into table. + * + * @param pg plugin context + * @param td record to insert + */ +static enum GNUNET_DB_QueryStatus +irbt_cb_table_kyc_attributes (struct PostgresClosure *pg, + const struct TALER_EXCHANGEDB_TableData *td) +{ + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (&td->serial), + 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), + GNUNET_PQ_query_param_timestamp ( + &td->details.kyc_attributes.collection_time), + GNUNET_PQ_query_param_timestamp ( + &td->details.kyc_attributes.expiration_time), + GNUNET_PQ_query_param_uint64 ( + &td->details.kyc_attributes.trigger_outcome_serial), + GNUNET_PQ_query_param_fixed_size ( + &td->details.kyc_attributes.encrypted_attributes, + td->details.kyc_attributes.encrypted_attributes_size), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "insert_into_table_kyc_attributes", + "INSERT INTO kyc_attributes" + "(kyc_attributes_serial_id" + ",h_payto" + ",legitimization_process_serial_id" + ",collection_time" + ",expiration_time" + ",trigger_outcome_serial" + ",encrypted_attributes" + ") VALUES " + "($1, $2, $3, $4, $5, $6, $7);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_into_table_kyc_attributes", + params); +} + + +/** * Function called with aml_history records to insert into table. * * @param pg plugin context @@ -1992,26 +2100,14 @@ static enum GNUNET_DB_QueryStatus irbt_cb_table_aml_history (struct PostgresClosure *pg, const struct TALER_EXCHANGEDB_TableData *td) { - uint32_t status32 = td->details.aml_history.new_status; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_auto_from_type ( &td->details.aml_history.h_payto), - TALER_PQ_query_param_amount ( - pg->conn, - &td->details.aml_history.new_threshold), - GNUNET_PQ_query_param_uint32 ( - &status32), - GNUNET_PQ_query_param_timestamp ( - &td->details.aml_history.decision_time), + GNUNET_PQ_query_param_uint64 ( + &td->details.aml_history.outcome_serial_id), GNUNET_PQ_query_param_string ( td->details.aml_history.justification), - (NULL == td->details.aml_history.kyc_requirements) - ? GNUNET_PQ_query_param_null () - : GNUNET_PQ_query_param_string ( - td->details.aml_history.kyc_requirements), - GNUNET_PQ_query_param_uint64 ( - &td->details.aml_history.kyc_req_row), GNUNET_PQ_query_param_auto_from_type ( &td->details.aml_history.decider_pub), GNUNET_PQ_query_param_auto_from_type ( @@ -2024,16 +2120,12 @@ irbt_cb_table_aml_history (struct PostgresClosure *pg, "INSERT INTO aml_history" "(aml_history_serial_id" ",h_payto" - ",new_threshold" - ",new_status" - ",decision_time" + ",outcome_serial_id" ",justification" - ",kyc_requirements" - ",kyc_req_row" ",decider_pub" ",decider_sig" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);"); + "($1, $2, $3, $4, $5, $6);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_aml_history", params); @@ -2041,47 +2133,34 @@ irbt_cb_table_aml_history (struct PostgresClosure *pg, /** - * Function called with kyc_attributes records to insert into table. + * Function called with kyc_event records to insert into table. * * @param pg plugin context * @param td record to insert */ static enum GNUNET_DB_QueryStatus -irbt_cb_table_kyc_attributes (struct PostgresClosure *pg, - const struct TALER_EXCHANGEDB_TableData *td) +irbt_cb_table_kyc_events (struct PostgresClosure *pg, + const struct TALER_EXCHANGEDB_TableData *td) { struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&td->serial), - GNUNET_PQ_query_param_auto_from_type ( - &td->details.kyc_attributes.h_payto), - GNUNET_PQ_query_param_auto_from_type ( - &td->details.kyc_attributes.kyc_prox), - GNUNET_PQ_query_param_string ( - td->details.kyc_attributes.provider), GNUNET_PQ_query_param_timestamp ( - &td->details.kyc_attributes.collection_time), - GNUNET_PQ_query_param_timestamp ( - &td->details.kyc_attributes.expiration_time), - GNUNET_PQ_query_param_fixed_size ( - &td->details.kyc_attributes.encrypted_attributes, - td->details.kyc_attributes.encrypted_attributes_size), + &td->details.kyc_events.event_timestamp), + GNUNET_PQ_query_param_string ( + td->details.kyc_events.event_type), GNUNET_PQ_query_param_end }; PREPARE (pg, - "insert_into_table_kyc_attributes", - "INSERT INTO kyc_attributes" - "(kyc_attributes_serial_id" - ",h_payto" - ",kyc_prox" - ",provider" - ",collection_time" - ",expiration_time" - ",encrypted_attributes" + "insert_into_table_kyc_events", + "INSERT INTO kyc_events" + "(kyc_event_serial_id" + ",event_timestamp" + ",event_type" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7);"); + "($1, $2, $3);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_into_table_kyc_attributes", + "insert_into_table_kyc_events", params); } @@ -2185,12 +2264,6 @@ TEH_PG_insert_records_by_table (void *cls, case TALER_EXCHANGEDB_RT_WIRE_TARGETS: rh = &irbt_cb_table_wire_targets; break; - case TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES: - rh = &irbt_cb_table_legitimization_processes; - break; - case TALER_EXCHANGEDB_RT_LEGITIMIZATION_REQUIREMENTS: - rh = &irbt_cb_table_legitimization_requirements; - break; case TALER_EXCHANGEDB_RT_RESERVES: rh = &irbt_cb_table_reserves; break; @@ -2308,18 +2381,30 @@ TEH_PG_insert_records_by_table (void *cls, case TALER_EXCHANGEDB_RT_AML_STAFF: rh = &irbt_cb_table_aml_staff; break; - case TALER_EXCHANGEDB_RT_AML_HISTORY: - rh = &irbt_cb_table_aml_history; - break; - case TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES: - rh = &irbt_cb_table_kyc_attributes; - break; case TALER_EXCHANGEDB_RT_PURSE_DELETION: rh = &irbt_cb_table_purse_deletion; break; case TALER_EXCHANGEDB_RT_AGE_WITHDRAW: rh = &irbt_cb_table_age_withdraw; break; + case TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES: + rh = &irbt_cb_table_legitimization_measures; + break; + case TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES: + rh = &irbt_cb_table_legitimization_outcomes; + break; + case TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES: + rh = &irbt_cb_table_legitimization_processes; + break; + case TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES: + rh = &irbt_cb_table_kyc_attributes; + break; + case TALER_EXCHANGEDB_RT_AML_HISTORY: + rh = &irbt_cb_table_aml_history; + break; + case TALER_EXCHANGEDB_RT_KYC_EVENTS: + rh = &irbt_cb_table_kyc_events; + break; } if (NULL == rh) { diff --git a/src/exchangedb/pg_lookup_records_by_table.c b/src/exchangedb/pg_lookup_records_by_table.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet - Copyright (C) 2020-2023 Taler Systems SA + Copyright (C) 2020-2024 Taler Systems SA GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -210,118 +210,15 @@ lrbt_cb_table_wire_targets (void *cls, for (unsigned int i = 0; i<num_results; i++) { struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("serial", - &td.serial), - GNUNET_PQ_result_spec_string ("payto_uri", - &td.details.wire_targets.payto_uri), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ctx->error = true; - return; - } - ctx->cb (ctx->cb_cls, - &td); - GNUNET_PQ_cleanup_result (rs); - } -} - - -/** - * Function called with legitimization_processes table entries. - * - * @param cls closure - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lrbt_cb_table_legitimization_processes (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupRecordsByTableContext *ctx = cls; - struct TALER_EXCHANGEDB_TableData td = { - .table = TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES - }; - - for (unsigned int i = 0; i<num_results; i++) - { - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("serial", - &td.serial), - GNUNET_PQ_result_spec_auto_from_type ( - "h_payto", - &td.details.legitimization_processes.h_payto), - GNUNET_PQ_result_spec_timestamp ( - "expiration_time", - &td.details.legitimization_processes.expiration_time), - GNUNET_PQ_result_spec_string ( - "provider_section", - &td.details.legitimization_processes.provider_section), - GNUNET_PQ_result_spec_string ( - "provider_user_id", - &td.details.legitimization_processes.provider_user_id), - GNUNET_PQ_result_spec_string ( - "provider_legitimization_id", - &td.details.legitimization_processes.provider_legitimization_id), - GNUNET_PQ_result_spec_end - }; - - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - i)) - { - GNUNET_break (0); - ctx->error = true; - return; - } - ctx->cb (ctx->cb_cls, - &td); - GNUNET_PQ_cleanup_result (rs); - } -} - - -/** - * Function called with legitimization_requirements table entries. - * - * @param cls closure - * @param result the postgres result - * @param num_results the number of results in @a result - */ -static void -lrbt_cb_table_legitimization_requirements (void *cls, - PGresult *result, - unsigned int num_results) -{ - struct LookupRecordsByTableContext *ctx = cls; - struct TALER_EXCHANGEDB_TableData td = { - .table = TALER_EXCHANGEDB_RT_LEGITIMIZATION_REQUIREMENTS - }; - - for (unsigned int i = 0; i<num_results; i++) - { - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("serial", - &td.serial), + GNUNET_PQ_result_spec_uint64 ( + "serial", + &td.serial), GNUNET_PQ_result_spec_auto_from_type ( - "h_payto", - &td.details.legitimization_requirements.h_payto), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_auto_from_type ( - "reserve_pub", - &td.details.legitimization_requirements.reserve_pub), - &td.details.legitimization_requirements.no_reserve_pub), + "access_token", + &td.details.wire_targets.target_token), GNUNET_PQ_result_spec_string ( - "required_checks", - &td.details.legitimization_requirements.required_checks), + "payto_uri", + &td.details.wire_targets.payto_uri), GNUNET_PQ_result_spec_end }; @@ -1093,7 +990,8 @@ lrbt_cb_table_refresh_transfer_keys (void *cls, GNUNET_PQ_result_spec_uint64 ("serial", &td.serial), GNUNET_PQ_result_spec_auto_from_type ("transfer_pub", - &td.details.refresh_transfer_keys.tp), + &td.details.refresh_transfer_keys.tp + ), GNUNET_PQ_result_spec_variable_size ("transfer_privs", &tpriv, &tpriv_size), @@ -1638,7 +1536,8 @@ lrbt_cb_table_recoup_refresh (void *cls, GNUNET_PQ_result_spec_uint64 ("serial", &td.serial), GNUNET_PQ_result_spec_auto_from_type ("coin_sig", - &td.details.recoup_refresh.coin_sig), + &td.details.recoup_refresh.coin_sig) + , GNUNET_PQ_result_spec_auto_from_type ( "coin_blind", &td.details.recoup_refresh.coin_blind), @@ -2630,63 +2529,279 @@ lrbt_cb_table_aml_staff (void *cls, /** - * Function called with aml_history table entries. + * Function called with purse_deletion table entries. * * @param cls closure * @param result the postgres result * @param num_results the number of results in @a result */ static void -lrbt_cb_table_aml_history (void *cls, - PGresult *result, - unsigned int num_results) +lrbt_cb_table_purse_deletion (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupRecordsByTableContext *ctx = cls; + struct TALER_EXCHANGEDB_TableData td = { + .table = TALER_EXCHANGEDB_RT_PURSE_DELETION + }; + + for (unsigned int i = 0; i<num_results; i++) + { + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ( + "purse_deletion_serial_id", + &td.serial), + GNUNET_PQ_result_spec_auto_from_type ( + "purse_sig", + &td.details.purse_deletion.purse_sig), + GNUNET_PQ_result_spec_auto_from_type ( + "purse_pub", + &td.details.purse_deletion.purse_pub), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ctx->error = true; + return; + } + ctx->cb (ctx->cb_cls, + &td); + GNUNET_PQ_cleanup_result (rs); + } +} + + +/** + * Function called with age_withdraw table entries. + * + * @param cls closure + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lrbt_cb_table_age_withdraw (void *cls, + PGresult *result, + unsigned int num_results) { struct LookupRecordsByTableContext *ctx = cls; struct PostgresClosure *pg = ctx->pg; struct TALER_EXCHANGEDB_TableData td = { - .table = TALER_EXCHANGEDB_RT_AML_HISTORY + .table = TALER_EXCHANGEDB_RT_AGE_WITHDRAW }; for (unsigned int i = 0; i<num_results; i++) { - uint32_t status32; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ( - "aml_history_serial_id", + "age_withdraw_id", &td.serial), GNUNET_PQ_result_spec_auto_from_type ( - "h_payto", - &td.details.aml_history.h_payto), + "h_commitment", + &td.details.age_withdraw.h_commitment), + GNUNET_PQ_result_spec_uint16 ( + "max_age", + &td.details.age_withdraw.max_age), TALER_PQ_RESULT_SPEC_AMOUNT ( - "new_threshold", - &td.details.aml_history.new_threshold), + "amount_with_fee", + &td.details.age_withdraw.amount_with_fee), + GNUNET_PQ_result_spec_auto_from_type ( + "reserve_pub", + &td.details.age_withdraw.reserve_pub), + GNUNET_PQ_result_spec_auto_from_type ( + "reserve_sig", + &td.details.age_withdraw.reserve_sig), GNUNET_PQ_result_spec_uint32 ( - "new_status", - &status32), + "noreveal_index", + &td.details.age_withdraw.noreveal_index), + /* TODO[oec]: more fields! */ + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ctx->error = true; + return; + } + ctx->cb (ctx->cb_cls, + &td); + GNUNET_PQ_cleanup_result (rs); + } +} + + +/** + * Function called with legitimization_measures table entries. + * + * @param cls closure + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lrbt_cb_table_legitimization_measures (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupRecordsByTableContext *ctx = cls; + struct TALER_EXCHANGEDB_TableData td = { + .table = TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES + }; + + for (unsigned int i = 0; i<num_results; i++) + { + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("serial", + &td.serial), + GNUNET_PQ_result_spec_auto_from_type ( + "access_token", + &td.details.legitimization_measures.target_token), GNUNET_PQ_result_spec_timestamp ( - "decision_time", - &td.details.aml_history.decision_time), - GNUNET_PQ_result_spec_string ( - "justification", - &td.details.aml_history.justification), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_string ( - "kyc_requirements", - &td.details.aml_history.kyc_requirements), - NULL), - GNUNET_PQ_result_spec_uint64 ( - "kyc_req_row", - &td.details.aml_history.kyc_req_row), + "start_time", + &td.details.legitimization_measures.start_time), + TALER_PQ_result_spec_json ( + "jmeasures", + &td.details.legitimization_measures.measures), + GNUNET_PQ_result_spec_uint32 ( + "display_priority", + &td.details.legitimization_measures.display_priority), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ctx->error = true; + return; + } + ctx->cb (ctx->cb_cls, + &td); + GNUNET_PQ_cleanup_result (rs); + } +} + + +/** + * Function called with legitimization_outcomes table entries. + * + * @param cls closure + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lrbt_cb_table_legitimization_outcomes (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupRecordsByTableContext *ctx = cls; + struct TALER_EXCHANGEDB_TableData td = { + .table = TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES + }; + + for (unsigned int i = 0; i<num_results; i++) + { + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("serial", + &td.serial), GNUNET_PQ_result_spec_auto_from_type ( - "decider_pub", - &td.details.aml_history.decider_pub), + "h_payto", + &td.details.legitimization_outcomes.h_payto), + GNUNET_PQ_result_spec_timestamp ( + "decision_time", + &td.details.legitimization_outcomes.decision_time), + GNUNET_PQ_result_spec_timestamp ( + "expiration_time", + &td.details.legitimization_outcomes.expiration_time), + TALER_PQ_result_spec_json ( + "jproperties", + &td.details.legitimization_outcomes.properties), + GNUNET_PQ_result_spec_bool ( + "to_investigate_id", + &td.details.legitimization_outcomes.to_investigate), + TALER_PQ_result_spec_json ( + "jnew_rules", + &td.details.legitimization_outcomes.new_rules), + GNUNET_PQ_result_spec_end + }; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + ctx->error = true; + return; + } + ctx->cb (ctx->cb_cls, + &td); + GNUNET_PQ_cleanup_result (rs); + } +} + + +/** + * Function called with legitimization_processes table entries. + * + * @param cls closure + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +lrbt_cb_table_legitimization_processes (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupRecordsByTableContext *ctx = cls; + struct TALER_EXCHANGEDB_TableData td = { + .table = TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES + }; + + for (unsigned int i = 0; i<num_results; i++) + { + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("serial", + &td.serial), GNUNET_PQ_result_spec_auto_from_type ( - "decider_sig", - &td.details.aml_history.decider_sig), + "h_payto", + &td.details.legitimization_processes.h_payto), + GNUNET_PQ_result_spec_timestamp ( + "start_time", + &td.details.legitimization_processes.start_time), + GNUNET_PQ_result_spec_timestamp ( + "expiration_time", + &td.details.legitimization_processes.expiration_time), + GNUNET_PQ_result_spec_uint64 ( + "legitimization_measure_serial_id", + &td.details.legitimization_processes.legitimization_measure_serial_id), + GNUNET_PQ_result_spec_uint32 ( + "measure_index", + &td.details.legitimization_processes.measure_index), + GNUNET_PQ_result_spec_string ( + "provider_section", + &td.details.legitimization_processes.provider_section), + GNUNET_PQ_result_spec_string ( + "provider_user_id", + &td.details.legitimization_processes.provider_user_id), + GNUNET_PQ_result_spec_string ( + "provider_legitimization_id", + &td.details.legitimization_processes.provider_legitimization_id), + GNUNET_PQ_result_spec_string ( + "redirect_url", + &td.details.legitimization_processes.redirect_url), GNUNET_PQ_result_spec_end }; - td.details.aml_history.kyc_requirements = NULL; if (GNUNET_OK != GNUNET_PQ_extract_result (result, rs, @@ -2696,8 +2811,6 @@ lrbt_cb_table_aml_history (void *cls, ctx->error = true; return; } - td.details.aml_history.new_status - = (enum TALER_AmlDecisionState) status32; ctx->cb (ctx->cb_cls, &td); GNUNET_PQ_cleanup_result (rs); @@ -2731,18 +2844,18 @@ lrbt_cb_table_kyc_attributes (void *cls, GNUNET_PQ_result_spec_auto_from_type ( "h_payto", &td.details.kyc_attributes.h_payto), - GNUNET_PQ_result_spec_auto_from_type ( - "kyc_prox", - &td.details.kyc_attributes.kyc_prox), - GNUNET_PQ_result_spec_string ( - "provider", - &td.details.kyc_attributes.provider), + GNUNET_PQ_result_spec_uint64 ( + "legitimization_process_serial_id", + &td.details.kyc_attributes.legitimization_process_serial_id), GNUNET_PQ_result_spec_timestamp ( "collection_time", &td.details.kyc_attributes.collection_time), GNUNET_PQ_result_spec_timestamp ( "expiration_time", &td.details.kyc_attributes.expiration_time), + GNUNET_PQ_result_spec_uint64 ( + "trigger_outcome_serial", + &td.details.kyc_attributes.trigger_outcome_serial), GNUNET_PQ_result_spec_variable_size ( "encrypted_attributes", &td.details.kyc_attributes.encrypted_attributes, @@ -2767,34 +2880,43 @@ lrbt_cb_table_kyc_attributes (void *cls, /** - * Function called with purse_deletion table entries. + * Function called with aml_history table entries. * * @param cls closure * @param result the postgres result * @param num_results the number of results in @a result */ static void -lrbt_cb_table_purse_deletion (void *cls, - PGresult *result, - unsigned int num_results) +lrbt_cb_table_aml_history (void *cls, + PGresult *result, + unsigned int num_results) { struct LookupRecordsByTableContext *ctx = cls; struct TALER_EXCHANGEDB_TableData td = { - .table = TALER_EXCHANGEDB_RT_PURSE_DELETION + .table = TALER_EXCHANGEDB_RT_AML_HISTORY }; for (unsigned int i = 0; i<num_results; i++) { struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ( - "purse_deletion_serial_id", + "aml_history_serial_id", &td.serial), GNUNET_PQ_result_spec_auto_from_type ( - "purse_sig", - &td.details.purse_deletion.purse_sig), + "h_payto", + &td.details.aml_history.h_payto), + GNUNET_PQ_result_spec_uint64 ( + "outcome_serial_id", + &td.details.aml_history.outcome_serial_id), + GNUNET_PQ_result_spec_string ( + "justification", + &td.details.aml_history.justification), GNUNET_PQ_result_spec_auto_from_type ( - "purse_pub", - &td.details.purse_deletion.purse_pub), + "decider_pub", + &td.details.aml_history.decider_pub), + GNUNET_PQ_result_spec_auto_from_type ( + "decider_sig", + &td.details.aml_history.decider_sig), GNUNET_PQ_result_spec_end }; @@ -2815,48 +2937,34 @@ lrbt_cb_table_purse_deletion (void *cls, /** - * Function called with age_withdraw table entries. + * Function called with kyc_events table entries. * * @param cls closure * @param result the postgres result * @param num_results the number of results in @a result */ static void -lrbt_cb_table_age_withdraw (void *cls, - PGresult *result, - unsigned int num_results) +lrbt_cb_table_kyc_events (void *cls, + PGresult *result, + unsigned int num_results) { struct LookupRecordsByTableContext *ctx = cls; - struct PostgresClosure *pg = ctx->pg; struct TALER_EXCHANGEDB_TableData td = { - .table = TALER_EXCHANGEDB_RT_AGE_WITHDRAW + .table = TALER_EXCHANGEDB_RT_KYC_EVENTS }; for (unsigned int i = 0; i<num_results; i++) { struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ( - "age_withdraw_id", + "kyc_event_serial_id", &td.serial), - GNUNET_PQ_result_spec_auto_from_type ( - "h_commitment", - &td.details.age_withdraw.h_commitment), - GNUNET_PQ_result_spec_uint16 ( - "max_age", - &td.details.age_withdraw.max_age), - TALER_PQ_RESULT_SPEC_AMOUNT ( - "amount_with_fee", - &td.details.age_withdraw.amount_with_fee), - GNUNET_PQ_result_spec_auto_from_type ( - "reserve_pub", - &td.details.age_withdraw.reserve_pub), - GNUNET_PQ_result_spec_auto_from_type ( - "reserve_sig", - &td.details.age_withdraw.reserve_sig), - GNUNET_PQ_result_spec_uint32 ( - "noreveal_index", - &td.details.age_withdraw.noreveal_index), - /* TODO[oec]: more fields! */ + GNUNET_PQ_result_spec_timestamp ( + "event_timestamp", + &td.details.kyc_events.event_timestamp), + GNUNET_PQ_result_spec_string ( + "event_type", + &td.details.kyc_events.event_type), GNUNET_PQ_result_spec_end }; @@ -2881,8 +2989,8 @@ lrbt_cb_table_age_withdraw (void *cls, * @a sql under name @a n. */ #define XPREPARE(n,sql) \ - statement = n; \ - PREPARE (pg, n, sql); + statement = n; \ + PREPARE (pg, n, sql); enum GNUNET_DB_QueryStatus @@ -2945,39 +3053,13 @@ TEH_PG_lookup_records_by_table (void *cls, XPREPARE ("select_above_serial_by_table_wire_targets", "SELECT" " wire_target_serial_id AS serial" + ",access_token" ",payto_uri" " FROM wire_targets" " WHERE wire_target_serial_id > $1" " ORDER BY wire_target_serial_id ASC;"); rh = &lrbt_cb_table_wire_targets; break; - case TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES: - XPREPARE ("select_above_serial_by_table_legitimization_processes", - "SELECT" - " legitimization_process_serial_id AS serial" - ",h_payto" - ",reserve_pub" - ",expiration_time" - ",provider_section" - ",provider_user_id" - ",provider_legitimization_id" - " FROM legitimization_processes" - " WHERE legitimization_process_serial_id > $1" - " ORDER BY legitimization_process_serial_id ASC;"); - rh = &lrbt_cb_table_legitimization_processes; - break; - case TALER_EXCHANGEDB_RT_LEGITIMIZATION_REQUIREMENTS: - XPREPARE ("select_above_serial_by_table_legitimization_requirements", - "SELECT" - " legitimization_requirement_serial_id AS serial" - ",h_payto" - ",reserve_pub" - ",required_checks" - " FROM legitimization_requirements" - " WHERE legitimization_requirement_serial_id > $1" - " ORDER BY legitimization_requirement_serial_id ASC;"); - rh = &lrbt_cb_table_legitimization_requirements; - break; case TALER_EXCHANGEDB_RT_RESERVES: XPREPARE ("select_above_serial_by_table_reserves", "SELECT" @@ -3514,39 +3596,6 @@ TEH_PG_lookup_records_by_table (void *cls, " ORDER BY aml_staff_uuid ASC;"); rh = &lrbt_cb_table_aml_staff; break; - case TALER_EXCHANGEDB_RT_AML_HISTORY: - XPREPARE ("select_above_serial_by_table_aml_history", - "SELECT" - " aml_history_serial_id" - ",h_payto" - ",new_threshold" - ",new_status" - ",decision_time" - ",justification" - ",kyc_requirements" - ",kyc_req_row" - ",decider_pub" - ",decider_sig" - " FROM aml_history" - " WHERE aml_history_serial_id > $1" - " ORDER BY aml_history_serial_id ASC;"); - rh = &lrbt_cb_table_aml_history; - break; - case TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES: - XPREPARE ("select_above_serial_by_table_kyc_attributes", - "SELECT" - " kyc_attributes_serial_id" - ",h_payto" - ",kyc_prox" - ",provider" - ",collection_time" - ",expiration_time" - ",encrypted_attributes" - " FROM kyc_attributes" - " WHERE kyc_attributes_serial_id > $1" - " ORDER BY kyc_attributes_serial_id ASC;"); - rh = &lrbt_cb_table_kyc_attributes; - break; case TALER_EXCHANGEDB_RT_PURSE_DELETION: XPREPARE ("select_above_serial_by_table_purse_deletion", "SELECT" @@ -3574,6 +3623,92 @@ TEH_PG_lookup_records_by_table (void *cls, /* TODO[oec]: MORE FIELDS! */ rh = &lrbt_cb_table_age_withdraw; break; + case TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES: + XPREPARE ("select_above_serial_by_table_legitimization_measures", + "SELECT" + " legitimization_measure_serial_id AS serial" + ",access_token" + ",start_time" + ",jmeasures" + ",display_priority" + " FROM legitimization_measures" + " WHERE legitimization_measure_serial_id > $1" + " ORDER BY legitimization_measure_serial_id ASC;"); + rh = &lrbt_cb_table_legitimization_measures; + break; + case TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES: + XPREPARE ("select_above_serial_by_table_legitimization_outcomes", + "SELECT" + " outcome_serial_id AS serial" + ",h_payto" + ",decision_time" + ",expiration_time" + ",jproperties" + ",to_investigate" + ",jnew_rules" + " FROM legitimization_outcomes" + " WHERE outcome_serial_id > $1" + " ORDER BY outcome_serial_id ASC;"); + rh = &lrbt_cb_table_legitimization_outcomes; + break; + case TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES: + XPREPARE ("select_above_serial_by_table_legitimization_processes", + "SELECT" + " legitimization_process_serial_id AS serial" + ",h_payto" + ",start_time" + ",expiration_time" + ",legitimization_measure_serial_id" + ",measure_index" + ",provider_section" + ",provider_user_id" + ",provider_legitimization_id" + ",redirect_url" + " FROM legitimization_processes" + " WHERE legitimization_process_serial_id > $1" + " ORDER BY legitimization_process_serial_id ASC;"); + rh = &lrbt_cb_table_legitimization_processes; + break; + case TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES: + XPREPARE ("select_above_serial_by_table_kyc_attributes", + "SELECT" + " kyc_attributes_serial_id" + ",h_payto" + ",legitimization_process_serial_id" + ",collection_time" + ",expiration_time" + ",trigger_outcome_serial" + ",encrypted_attributes" + " FROM kyc_attributes" + " WHERE kyc_attributes_serial_id > $1" + " ORDER BY kyc_attributes_serial_id ASC;"); + rh = &lrbt_cb_table_kyc_attributes; + break; + case TALER_EXCHANGEDB_RT_AML_HISTORY: + XPREPARE ("select_above_serial_by_table_aml_history", + "SELECT" + " aml_history_serial_id" + ",h_payto" + ",outcome_serial_id" + ",justification" + ",decider_pub" + ",decider_sig" + " FROM aml_history" + " WHERE aml_history_serial_id > $1" + " ORDER BY aml_history_serial_id ASC;"); + rh = &lrbt_cb_table_aml_history; + break; + case TALER_EXCHANGEDB_RT_KYC_EVENTS: + XPREPARE ("select_above_serial_by_table_kyc_events", + "SELECT" + " kyc_event_serial_id AS serial" + ",event_timestamp" + ",event_type" + " FROM kyc_events" + " WHERE kyc_event_serial_id > $1" + " ORDER BY kyc_event_serial_id ASC;"); + rh = &lrbt_cb_table_kyc_events; + break; } if (NULL == rh) { diff --git a/src/exchangedb/pg_lookup_serial_by_table.c b/src/exchangedb/pg_lookup_serial_by_table.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022-2023 Taler Systems SA + Copyright (C) 2022-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 @@ -31,8 +31,8 @@ * @a sql under name @a n. */ #define XPREPARE(n,sql) \ - statement = n; \ - PREPARE (pg, n, sql); + statement = n; \ + PREPARE (pg, n, sql); enum GNUNET_DB_QueryStatus @@ -77,22 +77,6 @@ TEH_PG_lookup_serial_by_table (void *cls, " ORDER BY wire_target_serial_id DESC" " LIMIT 1;"); break; - case TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES: - XPREPARE ("select_serial_by_table_legitimization_processes", - "SELECT" - " legitimization_process_serial_id AS serial" - " FROM legitimization_processes" - " ORDER BY legitimization_process_serial_id DESC" - " LIMIT 1;"); - break; - case TALER_EXCHANGEDB_RT_LEGITIMIZATION_REQUIREMENTS: - XPREPARE ("select_serial_by_table_legitimization_requiremetns", - "SELECT" - " legitimization_requirement_serial_id AS serial" - " FROM legitimization_requirements" - " ORDER BY legitimization_requirement_serial_id DESC" - " LIMIT 1;"); - break; case TALER_EXCHANGEDB_RT_RESERVES: XPREPARE ("select_serial_by_table_reserves", "SELECT" @@ -407,24 +391,6 @@ TEH_PG_lookup_serial_by_table (void *cls, " LIMIT 1;"); statement = "select_serial_by_table_aml_staff"; break; - case TALER_EXCHANGEDB_RT_AML_HISTORY: - XPREPARE ("select_serial_by_table_aml_history", - "SELECT" - " aml_history_serial_id AS serial" - " FROM aml_history" - " ORDER BY aml_history_serial_id DESC" - " LIMIT 1;"); - statement = "select_serial_by_table_aml_history"; - break; - case TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES: - XPREPARE ("select_serial_by_table_kyc_attributes", - "SELECT" - " kyc_attributes_serial_id AS serial" - " FROM kyc_attributes" - " ORDER BY kyc_attributes_serial_id DESC" - " LIMIT 1;"); - statement = "select_serial_by_table_kyc_attributes"; - break; case TALER_EXCHANGEDB_RT_PURSE_DELETION: XPREPARE ("select_serial_by_table_purse_deletion", "SELECT" @@ -443,6 +409,56 @@ TEH_PG_lookup_serial_by_table (void *cls, " LIMIT 1;"); statement = "select_serial_by_table_age_withdraw"; break; + case TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES: + XPREPARE ("select_serial_by_table_legitimization_measures", + "SELECT" + " legitimization_measure_serial_id AS serial" + " FROM legitimization_measures" + " ORDER BY legitimization_measure_serial_id DESC" + " LIMIT 1;"); + break; + case TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES: + XPREPARE ("select_serial_by_table_legitimization_outcomes", + "SELECT" + " outcome_serial_id AS serial" + " FROM legitimization_outcomes" + " ORDER BY outcome_serial_id DESC" + " LIMIT 1;"); + break; + case TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES: + XPREPARE ("select_serial_by_table_legitimization_processes", + "SELECT" + " legitimization_process_serial_id AS serial" + " FROM legitimization_processes" + " ORDER BY legitimization_process_serial_id DESC" + " LIMIT 1;"); + break; + case TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES: + XPREPARE ("select_serial_by_table_kyc_attributes", + "SELECT" + " kyc_attributes_serial_id AS serial" + " FROM kyc_attributes" + " ORDER BY kyc_attributes_serial_id DESC" + " LIMIT 1;"); + statement = "select_serial_by_table_kyc_attributes"; + break; + case TALER_EXCHANGEDB_RT_AML_HISTORY: + XPREPARE ("select_serial_by_table_aml_history", + "SELECT" + " aml_history_serial_id AS serial" + " FROM aml_history" + " ORDER BY aml_history_serial_id DESC" + " LIMIT 1;"); + statement = "select_serial_by_table_aml_history"; + break; + case TALER_EXCHANGEDB_RT_KYC_EVENTS: + XPREPARE ("select_serial_by_table_kyc_events", + "SELECT" + " kyc_event_serial_id AS serial" + " FROM kyc_events" + " ORDER BY kyc_event_serial_id DESC" + " LIMIT 1;"); + break; } if (NULL == statement) { diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h @@ -283,8 +283,6 @@ enum TALER_EXCHANGEDB_ReplicatedTable TALER_EXCHANGEDB_RT_DENOMINATIONS, TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS, TALER_EXCHANGEDB_RT_WIRE_TARGETS, - TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES, - TALER_EXCHANGEDB_RT_LEGITIMIZATION_REQUIREMENTS, TALER_EXCHANGEDB_RT_RESERVES, TALER_EXCHANGEDB_RT_RESERVES_IN, TALER_EXCHANGEDB_RT_RESERVES_CLOSE, @@ -325,10 +323,15 @@ enum TALER_EXCHANGEDB_ReplicatedTable TALER_EXCHANGEDB_RT_PROFIT_DRAINS, /* From exchange-0003.sql: */ TALER_EXCHANGEDB_RT_AML_STAFF, - TALER_EXCHANGEDB_RT_AML_HISTORY, - TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES, TALER_EXCHANGEDB_RT_PURSE_DELETION, TALER_EXCHANGEDB_RT_AGE_WITHDRAW, + /* From exchange-0005.sql: */ + TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES, + TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES, + TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES, + TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES, + TALER_EXCHANGEDB_RT_AML_HISTORY, + TALER_EXCHANGEDB_RT_KYC_EVENTS, };