commit 830ebef2ea959ccbec0d62a04b947a020ff278c8
parent 3883a0e98a2d3c6421f9aca958ee77b97bd4d5c8
Author: Christian Grothoff <grothoff@gnunet.org>
Date: Fri, 2 Aug 2024 12:00:07 +0200
add kycauths_in table support to taler-auditor-sync
Diffstat:
4 files changed, 142 insertions(+), 0 deletions(-)
diff --git a/src/exchangedb/pg_insert_records_by_table.c b/src/exchangedb/pg_insert_records_by_table.c
@@ -416,6 +416,50 @@ irbt_cb_table_reserves_in (struct PostgresClosure *pg,
/**
+ * Function called with kycauth_in records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_kycauths_in (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_uint64 (&td->details.kycauth_in.wire_reference),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.reserves_in.credit),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.reserves_in.sender_account_h_payto),
+ GNUNET_PQ_query_param_string (
+ td->details.reserves_in.exchange_account_section),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.reserves_in.execution_date),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.kycauth_in.account_pub),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_kycauth_in",
+ "INSERT INTO kycauths_in"
+ "(kycauth_in_serial_id"
+ ",wire_reference"
+ ",credit"
+ ",wire_source_h_payto"
+ ",exchange_account_section"
+ ",execution_date"
+ ",account_pub"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_kycauth_in",
+ params);
+}
+
+
+/**
* Function called with reserves_open_requests records to insert into table.
*
* @param pg plugin context
@@ -2270,6 +2314,9 @@ TEH_PG_insert_records_by_table (void *cls,
case TALER_EXCHANGEDB_RT_RESERVES_IN:
rh = &irbt_cb_table_reserves_in;
break;
+ case TALER_EXCHANGEDB_RT_KYCAUTHS_IN:
+ rh = &irbt_cb_table_kycauths_in;
+ break;
case TALER_EXCHANGEDB_RT_RESERVES_CLOSE:
rh = &irbt_cb_table_reserves_close;
break;
diff --git a/src/exchangedb/pg_lookup_records_by_table.c b/src/exchangedb/pg_lookup_records_by_table.c
@@ -347,6 +347,67 @@ lrbt_cb_table_reserves_in (void *cls,
/**
+ * Function called with kycauth_in 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_kycauth_in (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_KYCAUTHS_IN
+ };
+
+ 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 (
+ "account_pub",
+ &td.details.kycauth_in.account_pub),
+ GNUNET_PQ_result_spec_uint64 (
+ "wire_reference",
+ &td.details.kycauth_in.wire_reference),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "credit",
+ &td.details.kycauth_in.credit),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wire_source_h_payto",
+ &td.details.kycauth_in.sender_account_h_payto),
+ GNUNET_PQ_result_spec_string (
+ "exchange_account_section",
+ &td.details.kycauth_in.exchange_account_section),
+ GNUNET_PQ_result_spec_timestamp (
+ "execution_date",
+ &td.details.kycauth_in.execution_date),
+ 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 reserves_close table entries.
*
* @param cls closure
@@ -3087,6 +3148,21 @@ TEH_PG_lookup_records_by_table (void *cls,
" ORDER BY reserve_in_serial_id ASC;");
rh = &lrbt_cb_table_reserves_in;
break;
+ case TALER_EXCHANGEDB_RT_KYCAUTHS_IN:
+ XPREPARE ("select_above_serial_by_table_kycauth_in",
+ "SELECT"
+ " kycauth_in_serial_id AS serial"
+ ",account_pub"
+ ",wire_reference"
+ ",credit"
+ ",wire_source_h_payto"
+ ",exchange_account_section"
+ ",execution_date"
+ " FROM kycauths_in"
+ " WHERE kycauth_in_serial_id > $1"
+ " ORDER BY kycauth_in_serial_id ASC;");
+ rh = &lrbt_cb_table_kycauth_in;
+ break;
case TALER_EXCHANGEDB_RT_RESERVES_CLOSE:
XPREPARE ("select_above_serial_by_table_reserves_close",
"SELECT"
diff --git a/src/exchangedb/pg_lookup_serial_by_table.c b/src/exchangedb/pg_lookup_serial_by_table.c
@@ -93,6 +93,14 @@ TEH_PG_lookup_serial_by_table (void *cls,
" ORDER BY reserve_in_serial_id DESC"
" LIMIT 1;");
break;
+ case TALER_EXCHANGEDB_RT_KYCAUTHS_IN:
+ XPREPARE ("select_serial_by_table_kycauths_in",
+ "SELECT"
+ " kycauth_in_serial_id AS serial"
+ " FROM kycauths_in"
+ " ORDER BY kycauths_in_serial_id DESC"
+ " LIMIT 1;");
+ break;
case TALER_EXCHANGEDB_RT_RESERVES_CLOSE:
XPREPARE ("select_serial_by_table_reserves_close",
"SELECT"
diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h
@@ -332,6 +332,7 @@ enum TALER_EXCHANGEDB_ReplicatedTable
TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES,
TALER_EXCHANGEDB_RT_AML_HISTORY,
TALER_EXCHANGEDB_RT_KYC_EVENTS,
+ TALER_EXCHANGEDB_RT_KYCAUTHS_IN,
};
@@ -472,6 +473,16 @@ struct TALER_EXCHANGEDB_TableData
struct
{
+ uint64_t wire_reference;
+ struct TALER_Amount credit;
+ struct TALER_PaytoHashP sender_account_h_payto;
+ char *exchange_account_section;
+ struct GNUNET_TIME_Timestamp execution_date;
+ union TALER_AccountPublicKeyP account_pub;
+ } kycauth_in;
+
+ struct
+ {
struct TALER_ReservePublicKeyP reserve_pub;
struct GNUNET_TIME_Timestamp request_timestamp;
struct GNUNET_TIME_Timestamp expiration_date;