diff options
Diffstat (limited to 'src/exchangedb/pg_insert_records_by_table.c')
-rw-r--r-- | src/exchangedb/pg_insert_records_by_table.c | 651 |
1 files changed, 483 insertions, 168 deletions
diff --git a/src/exchangedb/pg_insert_records_by_table.c b/src/exchangedb/pg_insert_records_by_table.c index d6630797a..6ecec5bcf 100644 --- a/src/exchangedb/pg_insert_records_by_table.c +++ b/src/exchangedb/pg_insert_records_by_table.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet - Copyright (C) 2020, 2021, 2022 Taler Systems SA + Copyright (C) 2020-2023 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 @@ -19,8 +19,9 @@ */ /** * @file exchangedb/pg_insert_records_by_table.c - * @brief insert_records_by_table implementation + * @brief replicate_records_by_table implementation * @author Christian Grothoff + * @author Özgür Kesim */ #include "platform.h" #include "taler_error_codes.h" @@ -28,6 +29,7 @@ #include "taler_pq_lib.h" #include "pg_insert_records_by_table.h" #include "pg_helper.h" +#include <gnunet/gnunet_pq_lib.h> /** @@ -72,14 +74,20 @@ irbt_cb_table_denominations (struct PostgresClosure *pg, &td->details.denominations.expire_deposit), GNUNET_PQ_query_param_timestamp ( &td->details.denominations.expire_legal), - TALER_PQ_query_param_amount (&td->details.denominations.coin), TALER_PQ_query_param_amount ( + pg->conn, + &td->details.denominations.coin), + TALER_PQ_query_param_amount ( + pg->conn, &td->details.denominations.fees.withdraw), TALER_PQ_query_param_amount ( + pg->conn, &td->details.denominations.fees.deposit), TALER_PQ_query_param_amount ( + pg->conn, &td->details.denominations.fees.refresh), TALER_PQ_query_param_amount ( + pg->conn, &td->details.denominations.fees.refund), GNUNET_PQ_query_param_end }; @@ -97,19 +105,14 @@ irbt_cb_table_denominations (struct PostgresClosure *pg, ",expire_withdraw" ",expire_deposit" ",expire_legal" - ",coin_val" - ",coin_frac" - ",fee_withdraw_val" - ",fee_withdraw_frac" - ",fee_deposit_val" - ",fee_deposit_frac" - ",fee_refresh_val" - ",fee_refresh_frac" - ",fee_refund_val" - ",fee_refund_frac" + ",coin" + ",fee_withdraw" + ",fee_deposit" + ",fee_refresh" + ",fee_refund" ") VALUES " "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10," - " $11, $12, $13, $14, $15, $16, $17, $18, $19, $20);"); + " $11, $12, $13, $14, $15);"); TALER_denom_pub_hash ( &td->details.denominations.denom_pub, @@ -227,7 +230,7 @@ irbt_cb_table_legitimization_processes (struct PostgresClosure *pg, ",provider_user_id" ",provider_legitimization_id" ") VALUES " - "($1, $2, $3, $4, $5, $6);"); + "($1, $3, $4, $5, $6, %7);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_legitimization_processes", params); @@ -249,6 +252,10 @@ irbt_cb_table_legitimization_requirements (struct PostgresClosure *pg, 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), GNUNET_PQ_query_param_string ( td->details.legitimization_requirements.required_checks), GNUNET_PQ_query_param_end @@ -259,6 +266,7 @@ irbt_cb_table_legitimization_requirements (struct PostgresClosure *pg, "INSERT INTO legitimization_requirements" "(legitimization_requirement_serial_id" ",h_payto" + ",reserve_pub" ",required_checks" ") VALUES " "($1, $2, $3);"); @@ -314,7 +322,9 @@ irbt_cb_table_reserves_in (struct PostgresClosure *pg, struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_uint64 (&td->details.reserves_in.wire_reference), - TALER_PQ_query_param_amount (&td->details.reserves_in.credit), + 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 ( @@ -330,14 +340,13 @@ irbt_cb_table_reserves_in (struct PostgresClosure *pg, "INSERT INTO reserves_in" "(reserve_in_serial_id" ",wire_reference" - ",credit_val" - ",credit_frac" + ",credit" ",wire_source_h_payto" ",exchange_account_section" ",execution_date" ",reserve_pub" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8);"); + "($1, $2, $3, $4, $5, $6, $7);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_reserves_in", params); @@ -362,6 +371,7 @@ irbt_cb_table_reserves_open_requests (struct PostgresClosure *pg, GNUNET_PQ_query_param_auto_from_type ( &td->details.reserves_open_requests.reserve_sig), TALER_PQ_query_param_amount ( + pg->conn, &td->details.reserves_open_requests.reserve_payment), GNUNET_PQ_query_param_uint32 ( &td->details.reserves_open_requests.requested_purse_limit), @@ -376,11 +386,10 @@ irbt_cb_table_reserves_open_requests (struct PostgresClosure *pg, ",request_timestamp" ",expiration_date" ",reserve_sig" - ",reserve_payment_val" - ",reserve_payment_frac" + ",reserve_payment" ",requested_purse_limit" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8);"); + "($1, $2, $3, $4, $5, $6, $7);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_reserves_open_requests", params); @@ -407,6 +416,7 @@ irbt_cb_table_reserves_open_deposits ( GNUNET_PQ_query_param_auto_from_type ( &td->details.reserves_open_deposits.reserve_sig), TALER_PQ_query_param_amount ( + pg->conn, &td->details.reserves_open_deposits.contribution), GNUNET_PQ_query_param_end }; @@ -419,10 +429,9 @@ irbt_cb_table_reserves_open_deposits ( ",reserve_pub" ",coin_pub" ",coin_sig" - ",contribution_val" - ",contribution_frac" + ",contribution" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7);"); + "($1, $2, $3, $4, $5, $6);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_reserves_open_deposits", params); @@ -447,8 +456,12 @@ irbt_cb_table_reserves_close (struct PostgresClosure *pg, &td->details.reserves_close.wtid), GNUNET_PQ_query_param_auto_from_type ( &td->details.reserves_close.sender_account_h_payto), - TALER_PQ_query_param_amount (&td->details.reserves_close.amount), - TALER_PQ_query_param_amount (&td->details.reserves_close.closing_fee), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.reserves_close.amount), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.reserves_close.closing_fee), GNUNET_PQ_query_param_auto_from_type ( &td->details.reserves_close.reserve_pub), GNUNET_PQ_query_param_end @@ -461,13 +474,11 @@ irbt_cb_table_reserves_close (struct PostgresClosure *pg, ",execution_date" ",wtid" ",wire_target_h_payto" - ",amount_val" - ",amount_frac" - ",closing_fee_val" - ",closing_fee_frac" + ",amount" + ",closing_fee" ",reserve_pub" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9);"); + "($1, $2, $3, $4, $5, $6, $7);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_reserves_close", params); @@ -499,6 +510,7 @@ irbt_cb_table_reserves_out (struct PostgresClosure *pg, GNUNET_PQ_query_param_timestamp ( &td->details.reserves_out.execution_date), TALER_PQ_query_param_amount ( + pg->conn, &td->details.reserves_out.amount_with_fee), GNUNET_PQ_query_param_end }; @@ -513,10 +525,9 @@ irbt_cb_table_reserves_out (struct PostgresClosure *pg, ",reserve_uuid" ",reserve_sig" ",execution_date" - ",amount_with_fee_val" - ",amount_with_fee_frac" + ",amount_with_fee" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9);"); + "($1, $2, $3, $4, $5, $6, $7, $8);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_reserves_out", params); @@ -721,6 +732,7 @@ irbt_cb_table_refresh_commitments (struct PostgresClosure *pg, GNUNET_PQ_query_param_auto_from_type ( &td->details.refresh_commitments.old_coin_sig), TALER_PQ_query_param_amount ( + pg->conn, &td->details.refresh_commitments.amount_with_fee), GNUNET_PQ_query_param_uint32 ( &td->details.refresh_commitments.noreveal_index), @@ -735,12 +747,11 @@ irbt_cb_table_refresh_commitments (struct PostgresClosure *pg, "(melt_serial_id" ",rc" ",old_coin_sig" - ",amount_with_fee_val" - ",amount_with_fee_frac" + ",amount_with_fee" ",noreveal_index" ",old_coin_pub" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7);"); + "($1, $2, $3, $4, $5, $6);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_refresh_commitments", params); @@ -844,67 +855,106 @@ irbt_cb_table_refresh_transfer_keys ( /** - * Function called with deposits records to insert into table. + * Function called with batch deposits records to insert into table. * * @param pg plugin context * @param td record to insert */ static enum GNUNET_DB_QueryStatus -irbt_cb_table_deposits (struct PostgresClosure *pg, - const struct TALER_EXCHANGEDB_TableData *td) +irbt_cb_table_batch_deposits (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.deposits.shard), - GNUNET_PQ_query_param_uint64 (&td->details.deposits.known_coin_id), + GNUNET_PQ_query_param_uint64 (&td->details.batch_deposits.shard), GNUNET_PQ_query_param_auto_from_type ( - &td->details.deposits.coin_pub), - TALER_PQ_query_param_amount (&td->details.deposits.amount_with_fee), - GNUNET_PQ_query_param_timestamp (&td->details.deposits.wallet_timestamp), + &td->details.batch_deposits.merchant_pub), + GNUNET_PQ_query_param_timestamp ( + &td->details.batch_deposits.wallet_timestamp), + GNUNET_PQ_query_param_timestamp ( + &td->details.batch_deposits.exchange_timestamp), GNUNET_PQ_query_param_timestamp ( - &td->details.deposits.exchange_timestamp), - GNUNET_PQ_query_param_timestamp (&td->details.deposits.refund_deadline), - GNUNET_PQ_query_param_timestamp (&td->details.deposits.wire_deadline), - GNUNET_PQ_query_param_auto_from_type (&td->details.deposits.merchant_pub), - GNUNET_PQ_query_param_auto_from_type ( - &td->details.deposits.h_contract_terms), - GNUNET_PQ_query_param_auto_from_type (&td->details.deposits.coin_sig), - GNUNET_PQ_query_param_auto_from_type (&td->details.deposits.wire_salt), - GNUNET_PQ_query_param_auto_from_type ( - &td->details.deposits.wire_target_h_payto), - GNUNET_PQ_query_param_bool (td->details.deposits.policy_blocked), - 0 == td->details.deposits.policy_details_serial_id + &td->details.batch_deposits.refund_deadline), + GNUNET_PQ_query_param_timestamp (&td->details.batch_deposits.wire_deadline), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.batch_deposits.h_contract_terms), + td->details.batch_deposits.no_wallet_data_hash + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_auto_from_type ( + &td->details.batch_deposits.wallet_data_hash), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.batch_deposits.wire_salt), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.batch_deposits.wire_target_h_payto), + GNUNET_PQ_query_param_bool (td->details.batch_deposits.policy_blocked), + td->details.batch_deposits.no_policy_details ? GNUNET_PQ_query_param_null () : GNUNET_PQ_query_param_uint64 ( - &td->details.deposits.policy_details_serial_id), + &td->details.batch_deposits.policy_details_serial_id), GNUNET_PQ_query_param_end }; PREPARE (pg, - "insert_into_table_deposits", - "INSERT INTO deposits" - "(deposit_serial_id" + "insert_into_table_batch_deposits", + "INSERT INTO batch_deposits" + "(batch_deposit_serial_id" ",shard" - ",known_coin_id" - ",coin_pub" - ",amount_with_fee_val" - ",amount_with_fee_frac" + ",merchant_pub" ",wallet_timestamp" ",exchange_timestamp" ",refund_deadline" ",wire_deadline" - ",merchant_pub" ",h_contract_terms" - ",coin_sig" + ",wallet_data_hash" ",wire_salt" ",wire_target_h_payto" - ",policy_blocked" ",policy_details_serial_id" + ",policy_blocked" ") VALUES " "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10," - " $11, $12, $13, $14, $15, $16, $17);"); + " $11, $12, $13);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_into_table_batch_deposits", + params); +} + + +/** + * Function called with deposits records to insert into table. + * + * @param pg plugin context + * @param td record to insert + */ +static enum GNUNET_DB_QueryStatus +irbt_cb_table_coin_deposits (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.coin_deposits.batch_deposit_serial_id), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.coin_deposits.coin_pub), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.coin_deposits.coin_sig), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.coin_deposits.amount_with_fee), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "insert_into_table_coin_deposits", + "INSERT INTO coin_deposits" + "(coin_deposit_serial_id" + ",batch_deposit_serial_id" + ",coin_pub" + ",coin_sig" + ",amount_with_fee" + ") VALUES " + "($1, $2, $3, $4, $5);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "insert_into_table_deposits", + "insert_into_table_coin_deposits", params); } @@ -924,8 +974,11 @@ irbt_cb_table_refunds (struct PostgresClosure *pg, GNUNET_PQ_query_param_auto_from_type (&td->details.refunds.coin_pub), GNUNET_PQ_query_param_auto_from_type (&td->details.refunds.merchant_sig), GNUNET_PQ_query_param_uint64 (&td->details.refunds.rtransaction_id), - TALER_PQ_query_param_amount (&td->details.refunds.amount_with_fee), - GNUNET_PQ_query_param_uint64 (&td->details.refunds.deposit_serial_id), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.refunds.amount_with_fee), + GNUNET_PQ_query_param_uint64 ( + &td->details.refunds.batch_deposit_serial_id), GNUNET_PQ_query_param_end }; @@ -936,11 +989,10 @@ irbt_cb_table_refunds (struct PostgresClosure *pg, ",coin_pub" ",merchant_sig" ",rtransaction_id" - ",amount_with_fee_val" - ",amount_with_fee_frac" - ",deposit_serial_id" + ",amount_with_fee" + ",batch_deposit_serial_id" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7);"); + "($1, $2, $3, $4, $5, $6);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_refunds", params); @@ -965,7 +1017,9 @@ irbt_cb_table_wire_out (struct PostgresClosure *pg, &td->details.wire_out.wire_target_h_payto), GNUNET_PQ_query_param_string ( td->details.wire_out.exchange_account_section), - TALER_PQ_query_param_amount (&td->details.wire_out.amount), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.wire_out.amount), GNUNET_PQ_query_param_end }; @@ -977,10 +1031,9 @@ irbt_cb_table_wire_out (struct PostgresClosure *pg, ",wtid_raw" ",wire_target_h_payto" ",exchange_account_section" - ",amount_val" - ",amount_frac" + ",amount" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7);"); + "($1, $2, $3, $4, $5, $6);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_wire_out", params); @@ -1000,7 +1053,7 @@ irbt_cb_table_aggregation_tracking (struct PostgresClosure *pg, struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_uint64 ( - &td->details.aggregation_tracking.deposit_serial_id), + &td->details.aggregation_tracking.batch_deposit_serial_id), GNUNET_PQ_query_param_auto_from_type ( &td->details.aggregation_tracking.wtid_raw), GNUNET_PQ_query_param_end @@ -1010,7 +1063,7 @@ irbt_cb_table_aggregation_tracking (struct PostgresClosure *pg, "insert_into_table_aggregation_tracking", "INSERT INTO aggregation_tracking" "(aggregation_serial_id" - ",deposit_serial_id" + ",batch_deposit_serial_id" ",wtid_raw" ") VALUES " "($1, $2, $3);"); @@ -1035,8 +1088,12 @@ irbt_cb_table_wire_fee (struct PostgresClosure *pg, GNUNET_PQ_query_param_string (td->details.wire_fee.wire_method), GNUNET_PQ_query_param_timestamp (&td->details.wire_fee.start_date), GNUNET_PQ_query_param_timestamp (&td->details.wire_fee.end_date), - TALER_PQ_query_param_amount (&td->details.wire_fee.fees.wire), - TALER_PQ_query_param_amount (&td->details.wire_fee.fees.closing), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.wire_fee.fees.wire), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.wire_fee.fees.closing), GNUNET_PQ_query_param_auto_from_type (&td->details.wire_fee.master_sig), GNUNET_PQ_query_param_end }; @@ -1048,13 +1105,11 @@ irbt_cb_table_wire_fee (struct PostgresClosure *pg, ",wire_method" ",start_date" ",end_date" - ",wire_fee_val" - ",wire_fee_frac" - ",closing_fee_val" - ",closing_fee_frac" + ",wire_fee" + ",closing_fee" ",master_sig" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9);"); + "($1, $2, $3, $4, $5, $6, $7);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_wire_fee", params); @@ -1079,10 +1134,13 @@ irbt_cb_table_global_fee (struct PostgresClosure *pg, GNUNET_PQ_query_param_timestamp ( &td->details.global_fee.end_date), TALER_PQ_query_param_amount ( + pg->conn, &td->details.global_fee.fees.history), TALER_PQ_query_param_amount ( + pg->conn, &td->details.global_fee.fees.account), TALER_PQ_query_param_amount ( + pg->conn, &td->details.global_fee.fees.purse), GNUNET_PQ_query_param_relative_time ( &td->details.global_fee.purse_timeout), @@ -1101,18 +1159,15 @@ irbt_cb_table_global_fee (struct PostgresClosure *pg, "(global_fee_serial" ",start_date" ",end_date" - ",history_fee_val" - ",history_fee_frac" - ",account_fee_val" - ",account_fee_frac" - ",purse_fee_val" - ",purse_fee_frac" + ",history_fee" + ",account_fee" + ",purse_fee" ",purse_timeout" ",history_expiration" ",purse_account_limit" ",master_sig" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);"); + "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_global_fee", params); @@ -1133,7 +1188,9 @@ irbt_cb_table_recoup (struct PostgresClosure *pg, GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_auto_from_type (&td->details.recoup.coin_sig), GNUNET_PQ_query_param_auto_from_type (&td->details.recoup.coin_blind), - TALER_PQ_query_param_amount (&td->details.recoup.amount), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.recoup.amount), GNUNET_PQ_query_param_timestamp (&td->details.recoup.timestamp), GNUNET_PQ_query_param_auto_from_type ( &td->details.recoup.coin_pub), @@ -1147,13 +1204,12 @@ irbt_cb_table_recoup (struct PostgresClosure *pg, "(recoup_uuid" ",coin_sig" ",coin_blind" - ",amount_val" - ",amount_frac" + ",amount" ",recoup_timestamp" ",coin_pub" ",reserve_out_serial_id" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8);"); + "($1, $2, $3, $4, $5, $6, $7);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_recoup", params); @@ -1175,7 +1231,9 @@ irbt_cb_table_recoup_refresh (struct PostgresClosure *pg, GNUNET_PQ_query_param_auto_from_type (&td->details.recoup_refresh.coin_sig), GNUNET_PQ_query_param_auto_from_type ( &td->details.recoup_refresh.coin_blind), - TALER_PQ_query_param_amount (&td->details.recoup_refresh.amount), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.recoup_refresh.amount), GNUNET_PQ_query_param_timestamp (&td->details.recoup_refresh.timestamp), GNUNET_PQ_query_param_uint64 (&td->details.recoup_refresh.known_coin_id), GNUNET_PQ_query_param_auto_from_type ( @@ -1190,14 +1248,13 @@ irbt_cb_table_recoup_refresh (struct PostgresClosure *pg, "(recoup_refresh_uuid" ",coin_sig" ",coin_blind" - ",amount_val" - ",amount_frac" + ",amount" ",recoup_timestamp" ",known_coin_id" ",coin_pub" ",rrc_serial" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9);"); + "($1, $2, $3, $4, $5, $6, $7, $8);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_recoup_refresh", params); @@ -1254,10 +1311,17 @@ irbt_cb_table_policy_details (struct PostgresClosure *pg, (td->details.policy_details.no_policy_json) ? GNUNET_PQ_query_param_null () : TALER_PQ_query_param_json (td->details.policy_details.policy_json), - TALER_PQ_query_param_amount (&td->details.policy_details.commitment), - TALER_PQ_query_param_amount (&td->details.policy_details.accumulated_total), - TALER_PQ_query_param_amount (&td->details.policy_details.fee), - TALER_PQ_query_param_amount (&td->details.policy_details.transferable), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.policy_details.commitment), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.policy_details.accumulated_total), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.policy_details.fee), + TALER_PQ_query_param_amount (pg->conn, + &td->details.policy_details.transferable), GNUNET_PQ_query_param_timestamp (&td->details.policy_details.deadline), GNUNET_PQ_query_param_uint16 ( &td->details.policy_details.fulfillment_state), @@ -1275,18 +1339,14 @@ irbt_cb_table_policy_details (struct PostgresClosure *pg, ",policy_hash_code" ",policy_json" ",deadline" - ",commitment_val" - ",commitment_frac" - ",accumulated_total_val" - ",accumulated_total_frac" - ",fee_val" - ",fee_frac" - ",transferable_val" - ",transferable_frac" + ",commitment" + ",accumulated_total" + ",fee" + ",transferable" ",fulfillment_state" ",fulfillment_id" ") VALUES " - "($1, $2);"); + "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_policy_details", params); @@ -1359,8 +1419,12 @@ irbt_cb_table_purse_requests (struct PostgresClosure *pg, &td->details.purse_requests.h_contract_terms), GNUNET_PQ_query_param_uint32 (&td->details.purse_requests.age_limit), GNUNET_PQ_query_param_uint32 (&td->details.purse_requests.flags), - TALER_PQ_query_param_amount (&td->details.purse_requests.amount_with_fee), - TALER_PQ_query_param_amount (&td->details.purse_requests.purse_fee), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.purse_requests.amount_with_fee), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.purse_requests.purse_fee), GNUNET_PQ_query_param_auto_from_type ( &td->details.purse_requests.purse_sig), GNUNET_PQ_query_param_end @@ -1377,13 +1441,11 @@ irbt_cb_table_purse_requests (struct PostgresClosure *pg, ",h_contract_terms" ",age_limit" ",flags" - ",amount_with_fee_val" - ",amount_with_fee_frac" - ",purse_fee_val" - ",purse_fee_frac" + ",amount_with_fee" + ",purse_fee" ",purse_sig" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);"); + "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_purse_requests", params); @@ -1407,7 +1469,7 @@ irbt_cb_table_purse_decision (struct PostgresClosure *pg, GNUNET_PQ_query_param_timestamp ( &td->details.purse_decision.action_timestamp), GNUNET_PQ_query_param_bool ( - &td->details.purse_decision.refunded), + td->details.purse_decision.refunded), GNUNET_PQ_query_param_end }; @@ -1481,7 +1543,9 @@ irbt_cb_table_purse_deposits (struct PostgresClosure *pg, GNUNET_PQ_query_param_auto_from_type ( &td->details.purse_deposits.purse_pub), GNUNET_PQ_query_param_auto_from_type (&td->details.purse_deposits.coin_pub), - TALER_PQ_query_param_amount (&td->details.purse_deposits.amount_with_fee), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.purse_deposits.amount_with_fee), GNUNET_PQ_query_param_auto_from_type (&td->details.purse_deposits.coin_sig), GNUNET_PQ_query_param_end }; @@ -1493,11 +1557,10 @@ irbt_cb_table_purse_deposits (struct PostgresClosure *pg, ",partner_serial_id" ",purse_pub" ",coin_pub" - ",amount_with_fee_val" - ",amount_with_fee_frac" + ",amount_with_fee" ",coin_sig" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7);"); + "($1, $2, $3, $4, $5, $6);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_purse_deposits", params); @@ -1562,6 +1625,7 @@ irbt_cb_table_history_requests (struct PostgresClosure *pg, GNUNET_PQ_query_param_auto_from_type ( &td->details.history_requests.reserve_sig), TALER_PQ_query_param_amount ( + pg->conn, &td->details.history_requests.history_fee), GNUNET_PQ_query_param_end }; @@ -1573,10 +1637,9 @@ irbt_cb_table_history_requests (struct PostgresClosure *pg, ",reserve_pub" ",request_timestamp" ",reserve_sig" - ",history_fee_val" - ",history_fee_frac" + ",history_fee" ") VALUES " - "($1, $2, $3, $4, $5, $6);"); + "($1, $2, $3, $4, $5);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_history_requests", params); @@ -1602,8 +1665,10 @@ irbt_cb_table_close_requests (struct PostgresClosure *pg, GNUNET_PQ_query_param_auto_from_type ( &td->details.close_requests.reserve_sig), TALER_PQ_query_param_amount ( + pg->conn, &td->details.close_requests.close), TALER_PQ_query_param_amount ( + pg->conn, &td->details.close_requests.close_fee), GNUNET_PQ_query_param_string ( td->details.close_requests.payto_uri), @@ -1617,13 +1682,11 @@ irbt_cb_table_close_requests (struct PostgresClosure *pg, ",reserve_pub" ",close_timestamp" ",reserve_sig" - ",close_val" - ",close_frac" - ",close_fee_val" - ",close_fee_frac" + ",close" + ",close_fee" ",payto_uri" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9);"); + "($1, $2, $3, $4, $5, $6, $7);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_close_requests", params); @@ -1644,7 +1707,9 @@ irbt_cb_table_wads_out (struct PostgresClosure *pg, GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_auto_from_type (&td->details.wads_out.wad_id), GNUNET_PQ_query_param_uint64 (&td->details.wads_out.partner_serial_id), - TALER_PQ_query_param_amount (&td->details.wads_out.amount), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.wads_out.amount), GNUNET_PQ_query_param_timestamp (&td->details.wads_out.execution_time), GNUNET_PQ_query_param_end }; @@ -1655,11 +1720,10 @@ irbt_cb_table_wads_out (struct PostgresClosure *pg, "(wad_out_serial_id" ",wad_id" ",partner_serial_id" - ",amount_val" - ",amount_frac" + ",amount" ",execution_time" ") VALUES " - "($1, $2, $3, $4, $5, $6);"); + "($1, $2, $3, $4, $5);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_wads_out", params); @@ -1691,10 +1755,13 @@ irbt_cb_table_wads_out_entries (struct PostgresClosure *pg, GNUNET_PQ_query_param_timestamp ( &td->details.wads_out_entries.merge_timestamp), TALER_PQ_query_param_amount ( + pg->conn, &td->details.wads_out_entries.amount_with_fee), TALER_PQ_query_param_amount ( + pg->conn, &td->details.wads_out_entries.wad_fee), TALER_PQ_query_param_amount ( + pg->conn, &td->details.wads_out_entries.deposit_fees), GNUNET_PQ_query_param_auto_from_type ( &td->details.wads_out_entries.reserve_sig), @@ -1713,16 +1780,13 @@ irbt_cb_table_wads_out_entries (struct PostgresClosure *pg, ",h_contract" ",purse_expiration" ",merge_timestamp" - ",amount_with_fee_val" - ",amount_with_fee_frac" - ",wad_fee_val" - ",wad_fee_frac" - ",deposit_fees_val" - ",deposit_fees_frac" + ",amount_with_fee" + ",wad_fee" + ",deposit_fees" ",reserve_sig" ",purse_sig" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);"); + "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_wads_out_entries", params); @@ -1743,7 +1807,9 @@ irbt_cb_table_wads_in (struct PostgresClosure *pg, GNUNET_PQ_query_param_uint64 (&td->serial), GNUNET_PQ_query_param_auto_from_type (&td->details.wads_in.wad_id), GNUNET_PQ_query_param_string (td->details.wads_in.origin_exchange_url), - TALER_PQ_query_param_amount (&td->details.wads_in.amount), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.wads_in.amount), GNUNET_PQ_query_param_timestamp (&td->details.wads_in.arrival_time), GNUNET_PQ_query_param_end }; @@ -1754,11 +1820,10 @@ irbt_cb_table_wads_in (struct PostgresClosure *pg, "(wad_in_serial_id" ",wad_id" ",origin_exchange_url" - ",amount_val" - ",amount_frac" + ",amount" ",arrival_time" ") VALUES " - "($1, $2, $3, $4, $5, $6);"); + "($1, $2, $3, $4, $5);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_wads_in", params); @@ -1788,10 +1853,13 @@ irbt_cb_table_wads_in_entries (struct PostgresClosure *pg, GNUNET_PQ_query_param_timestamp ( &td->details.wads_in_entries.merge_timestamp), TALER_PQ_query_param_amount ( + pg->conn, &td->details.wads_in_entries.amount_with_fee), TALER_PQ_query_param_amount ( + pg->conn, &td->details.wads_in_entries.wad_fee), TALER_PQ_query_param_amount ( + pg->conn, &td->details.wads_in_entries.deposit_fees), GNUNET_PQ_query_param_auto_from_type ( &td->details.wads_in_entries.reserve_sig), @@ -1810,16 +1878,13 @@ irbt_cb_table_wads_in_entries (struct PostgresClosure *pg, ",h_contract" ",purse_expiration" ",merge_timestamp" - ",amount_with_fee_val" - ",amount_with_fee_frac" - ",wad_fee_val" - ",wad_fee_frac" - ",deposit_fees_val" - ",deposit_fees_frac" + ",amount_with_fee" + ",wad_fee" + ",deposit_fees" ",reserve_sig" ",purse_sig" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);"); + "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_wads_in_entries", params); @@ -1847,6 +1912,7 @@ irbt_cb_table_profit_drains (struct PostgresClosure *pg, GNUNET_PQ_query_param_timestamp ( &td->details.profit_drains.trigger_date), TALER_PQ_query_param_amount ( + pg->conn, &td->details.profit_drains.amount), GNUNET_PQ_query_param_auto_from_type ( &td->details.profit_drains.master_sig), @@ -1861,23 +1927,252 @@ irbt_cb_table_profit_drains (struct PostgresClosure *pg, ",account_section" ",payto_uri" ",trigger_date" - ",amount_val" - ",amount_frac" + ",amount" ",master_sig" ") VALUES " - "($1, $2, $3, $4, $5, $6, $7, $8);"); + "($1, $2, $3, $4, $5, $6, $7);"); return GNUNET_PQ_eval_prepared_non_select (pg->conn, "insert_into_table_profit_drains", params); } +/** + * Function called with aml_staff records to insert into table. + * + * @param pg plugin context + * @param td record to insert + */ +static enum GNUNET_DB_QueryStatus +irbt_cb_table_aml_staff (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.aml_staff.decider_pub), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.aml_staff.master_sig), + GNUNET_PQ_query_param_string ( + td->details.aml_staff.decider_name), + GNUNET_PQ_query_param_bool ( + td->details.aml_staff.is_active), + GNUNET_PQ_query_param_bool ( + td->details.aml_staff.read_only), + GNUNET_PQ_query_param_timestamp ( + &td->details.aml_staff.last_change), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "insert_into_table_aml_staff", + "INSERT INTO aml_staff" + "(aml_staff_uuid" + ",decider_pub" + ",master_sig" + ",decider_name" + ",is_active" + ",read_only" + ",last_change" + ") VALUES " + "($1, $2, $3, $4, $5, $6, $7);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_into_table_aml_staff", + params); +} + + +/** + * Function called with aml_history records to insert into table. + * + * @param pg plugin context + * @param td record to insert + */ +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_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 ( + &td->details.aml_history.decider_sig), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "insert_into_table_aml_history", + "INSERT INTO aml_history" + "(aml_history_serial_id" + ",h_payto" + ",new_threshold" + ",new_status" + ",decision_time" + ",justification" + ",kyc_requirements" + ",kyc_req_row" + ",decider_pub" + ",decider_sig" + ") VALUES " + "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_into_table_aml_history", + params); +} + + +/** + * 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_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), + 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" + ") 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 purse_deletion records to insert into table. + * + * @param pg plugin context + * @param td record to insert + */ +static enum GNUNET_DB_QueryStatus +irbt_cb_table_purse_deletion (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.purse_deletion.purse_pub), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.purse_deletion.purse_sig), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "insert_into_table_purse_deletion", + "INSERT INTO purse_deletion" + "(purse_deletion_serial_id" + ",purse_pub" + ",purse_sig" + ") VALUES " + "($1, $2, $3);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_into_table_purse_deletion", + params); +} + + +/** + * Function called with age_withdraw records to insert into table. + * + * @param pg plugin context + * @param td record to insert + */ +static enum GNUNET_DB_QueryStatus +irbt_cb_table_age_withdraw (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.age_withdraw.h_commitment), + TALER_PQ_query_param_amount ( + pg->conn, + &td->details.age_withdraw.amount_with_fee), + GNUNET_PQ_query_param_uint16 ( + &td->details.age_withdraw.max_age), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.age_withdraw.reserve_pub), + GNUNET_PQ_query_param_auto_from_type ( + &td->details.age_withdraw.reserve_sig), + GNUNET_PQ_query_param_uint32 ( + &td->details.age_withdraw.noreveal_index), + /* TODO: other fields, too! */ + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "insert_into_table_age_withdraw", + "INSERT INTO age_withdraw" + "(age_withdraw_commitment_id" + ",h_commitment" + ",amount_with_fee" + ",max_age" + ",reserve_pub" + ",reserve_sig" + ",noreveal_index" + ") VALUES " + "($1, $2, $3, $4, $5, $6, $7, $8);"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "insert_into_table_age_withdraw", + params); +} + + enum GNUNET_DB_QueryStatus TEH_PG_insert_records_by_table (void *cls, const struct TALER_EXCHANGEDB_TableData *td) { struct PostgresClosure *pg = cls; - InsertRecordCallback rh; + InsertRecordCallback rh = NULL; switch (td->table) { @@ -1938,8 +2233,11 @@ TEH_PG_insert_records_by_table (void *cls, case TALER_EXCHANGEDB_RT_REFRESH_TRANSFER_KEYS: rh = &irbt_cb_table_refresh_transfer_keys; break; - case TALER_EXCHANGEDB_RT_DEPOSITS: - rh = &irbt_cb_table_deposits; + case TALER_EXCHANGEDB_RT_BATCH_DEPOSITS: + rh = &irbt_cb_table_batch_deposits; + break; + case TALER_EXCHANGEDB_RT_COIN_DEPOSITS: + rh = &irbt_cb_table_coin_deposits; break; case TALER_EXCHANGEDB_RT_REFUNDS: rh = &irbt_cb_table_refunds; @@ -2007,7 +2305,24 @@ TEH_PG_insert_records_by_table (void *cls, case TALER_EXCHANGEDB_RT_PROFIT_DRAINS: rh = &irbt_cb_table_profit_drains; break; - default: + 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; + } + if (NULL == rh) + { GNUNET_break (0); return GNUNET_DB_STATUS_HARD_ERROR; } @@ -2016,4 +2331,4 @@ TEH_PG_insert_records_by_table (void *cls, } -/* end of irbt_callbacks.c */ +/* end of pg_insert_records_by_table.c */ |