From 136d2b2e70852628c18245e85fd9c6821f810557 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 15 Apr 2023 23:43:20 +0200 Subject: implement more of lookup_records_by_table --- src/exchangedb/pg_lookup_records_by_table.c | 448 ++++++++++++++++++++++++++++ src/exchangedb/pg_lookup_serial_by_table.c | 54 ++++ src/include/taler_exchangedb_plugin.h | 6 +- 3 files changed, 505 insertions(+), 3 deletions(-) diff --git a/src/exchangedb/pg_lookup_records_by_table.c b/src/exchangedb/pg_lookup_records_by_table.c index aa9ab046d..a23c034c5 100644 --- a/src/exchangedb/pg_lookup_records_by_table.c +++ b/src/exchangedb/pg_lookup_records_by_table.c @@ -2295,6 +2295,374 @@ lrbt_cb_table_profit_drains (void *cls, } +/** + * Function called with aml_staff 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_staff (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupRecordsByTableContext *ctx = cls; + struct TALER_EXCHANGEDB_TableData td = { + .table = TALER_EXCHANGEDB_RT_AML_STAFF + }; + + for (unsigned int i = 0; ierror = true; + return; + } + ctx->cb (ctx->cb_cls, + &td); + GNUNET_PQ_cleanup_result (rs); + } +} + + +/** + * 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_aml_history (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 + }; + + for (unsigned int i = 0; ierror = true; + return; + } + td.details.aml_history.new_status + = (enum TALER_AmlDecisionState) status32; + ctx->cb (ctx->cb_cls, + &td); + GNUNET_PQ_cleanup_result (rs); + } +} + + +/** + * Function called with kyc_attributes 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_kyc_attributes (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupRecordsByTableContext *ctx = cls; + struct TALER_EXCHANGEDB_TableData td = { + .table = TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES + }; + + for (unsigned int i = 0; ierror = true; + return; + } + ctx->cb (ctx->cb_cls, + &td); + GNUNET_PQ_cleanup_result (rs); + } +} + + +/** + * 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_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; ierror = true; + return; + } + ctx->cb (ctx->cb_cls, + &td); + GNUNET_PQ_cleanup_result (rs); + } +} + + +/** + * Function called with withdraw_age_commitments 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_withdraw_age_commitments (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_WITHDRAW_AGE_COMMITMENTS + }; + + for (unsigned int i = 0; ierror = true; + return; + } + ctx->cb (ctx->cb_cls, + &td); + GNUNET_PQ_cleanup_result (rs); + } +} + + +/** + * Function called with withdraw_age_reveals 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_withdraw_age_reveals (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct LookupRecordsByTableContext *ctx = cls; + struct TALER_EXCHANGEDB_TableData td = { + .table = TALER_EXCHANGEDB_RT_WITHDRAW_AGE_REVEALS + }; + + for (unsigned int i = 0; ierror = true; + return; + } + ctx->cb (ctx->cb_cls, + &td); + GNUNET_PQ_cleanup_result (rs); + } +} + + /** * Assign statement to @a n and PREPARE * @a sql under name @a n. @@ -2885,6 +3253,86 @@ TEH_PG_lookup_records_by_table (void *cls, " ORDER BY profit_drain_serial_id ASC;"); rh = &lrbt_cb_table_profit_drains; break; + + case TALER_EXCHANGEDB_RT_AML_STAFF: + XPREPARE ("select_above_serial_by_table_aml_staff", + "SELECT" + " aml_staff_uuid" + ",decider_pub" + ",master_sig" + ",decider_name" + ",is_active" + ",read_only" + ",last_change" + " FROM aml_staff" + " WHERE aml_staff_uuid > $1" + " 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_val" + ",new_threshold_frac" + ",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" + ",birthdate" + ",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" + " purse_deletion_serial_id" + ",purse_pub" + ",purse_sig" + " FROM purse_deletion" + " WHERE purse_deletion_serial_id > $1" + " ORDER BY purse_deletion_serial_id ASC;"); + rh = &lrbt_cb_table_purse_deletion; + break; + case TALER_EXCHANGEDB_RT_WITHDRAW_AGE_COMMITMENTS: + XPREPARE ("select_above_serial_by_table_withdraw_age_commitments", + "SELECT" + " withdraw_age_commitment_id" + ",h_commitment" + ",amount_with_fee_val" + ",amount_with_fee_frac" + ",max_age" + ",reserve_pub" + ",reserve_sig" + ",noreveal_index" + ",timestamp" + " FROM withdraw_age_commitments" + " WHERE withdraw_age_commitment_id > $1" + " ORDER BY withdraw_age_commitment_id ASC;"); + rh = &lrbt_cb_table_withdraw_age_commitments; + break; + } if (NULL == rh) { diff --git a/src/exchangedb/pg_lookup_serial_by_table.c b/src/exchangedb/pg_lookup_serial_by_table.c index 7e150cd28..d2554af2e 100644 --- a/src/exchangedb/pg_lookup_serial_by_table.c +++ b/src/exchangedb/pg_lookup_serial_by_table.c @@ -390,6 +390,60 @@ TEH_PG_lookup_serial_by_table (void *cls, " LIMIT 1;"); statement = "select_serial_by_table_profit_drains"; break; + case TALER_EXCHANGEDB_RT_AML_STAFF: + XPREPARE ("select_serial_by_table_aml_staff", + "SELECT" + " aml_staff_uuid AS serial" + " FROM aml_staff" + " ORDER BY aml_staff_uuid DESC" + " 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" + " purse_deletion_serial_id AS serial" + " FROM purse_deletion" + " ORDER BY purse_deletion_serial_id DESC" + " LIMIT 1;"); + statement = "select_serial_by_table_purse_deletion"; + break; + case TALER_EXCHANGEDB_RT_WITHDRAW_AGE_COMMITMENTS: + XPREPARE ("select_serial_by_table_withdraw_age_commitments", + "SELECT" + " withdraw_age_commitment_id AS serial" + " FROM withdraw_age_commitments" + " ORDER BY withdraw_age_commitment_id DESC" + " LIMIT 1;"); + statement = "select_serial_by_table_withdraw_age_commitments"; + break; + case TALER_EXCHANGEDB_RT_WITHDRAW_AGE_REVEALS: + XPREPARE ("select_serial_by_table_withdraw_age_reveals", + "SELECT" + " withdraw_age_reveals_id AS serial" + " FROM withdraw_age_reveals" + " ORDER BY withdraw_age_reveals_id DESC" + " LIMIT 1;"); + statement = "select_serial_by_table_withdraw_age_reveals"; + break; } if (NULL == statement) { diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index 1ed5ab585..f60c3cf05 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -278,9 +278,9 @@ enum TALER_EXCHANGEDB_ReplicatedTable TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES, TALER_EXCHANGEDB_RT_PROFIT_DRAINS, /* From exchange-0003.sql: */ - TALER_EXCHAGNEDB_RT_AML_STAFF, - TALER_EXCHAGNEDB_RT_AML_HISTORY, - TALER_EXCHAGNEDB_RT_KYC_ATTRIBUTES, + TALER_EXCHANGEDB_RT_AML_STAFF, + TALER_EXCHANGEDB_RT_AML_HISTORY, + TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES, TALER_EXCHANGEDB_RT_PURSE_DELETION, TALER_EXCHANGEDB_RT_WITHDRAW_AGE_COMMITMENTS, TALER_EXCHANGEDB_RT_WITHDRAW_AGE_REVEALS, -- cgit v1.2.3