diff options
Diffstat (limited to 'src/exchangedb/pg_lookup_transfer_by_deposit.c')
-rw-r--r-- | src/exchangedb/pg_lookup_transfer_by_deposit.c | 85 |
1 files changed, 50 insertions, 35 deletions
diff --git a/src/exchangedb/pg_lookup_transfer_by_deposit.c b/src/exchangedb/pg_lookup_transfer_by_deposit.c index a9de0dd6d..192556130 100644 --- a/src/exchangedb/pg_lookup_transfer_by_deposit.c +++ b/src/exchangedb/pg_lookup_transfer_by_deposit.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2022 Taler Systems SA + Copyright (C) 2022-2023 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 @@ -74,29 +74,30 @@ TEH_PG_lookup_transfer_by_deposit ( PREPARE (pg, "lookup_deposit_wtid", "SELECT" - " aggregation_tracking.wtid_raw" + " atr.wtid_raw" ",wire_out.execution_date" - ",dep.amount_with_fee_val" - ",dep.amount_with_fee_frac" - ",dep.wire_salt" + ",cdep.amount_with_fee" + ",bdep.wire_salt" ",wt.payto_uri" - ",denom.fee_deposit_val" - ",denom.fee_deposit_frac" - " FROM deposits dep" + ",denom.fee_deposit" + " FROM coin_deposits cdep" + " JOIN batch_deposits bdep" + " USING (batch_deposit_serial_id)" " JOIN wire_targets wt" " USING (wire_target_h_payto)" - " JOIN aggregation_tracking" - " USING (deposit_serial_id)" + " JOIN aggregation_tracking atr" + " ON (cdep.batch_deposit_serial_id = atr.batch_deposit_serial_id)" " JOIN known_coins kc" - " ON (kc.coin_pub = dep.coin_pub)" + " ON (kc.coin_pub = cdep.coin_pub)" " JOIN denominations denom" " USING (denominations_serial)" " JOIN wire_out" " USING (wtid_raw)" - " WHERE dep.coin_pub=$1" - " AND dep.merchant_pub=$3" - " AND dep.h_contract_terms=$2"); - + " WHERE cdep.coin_pub=$1" + " AND bdep.merchant_pub=$3" + " AND bdep.h_contract_terms=$2"); + /* NOTE: above query might be more efficient if we computed the shard + from the merchant_pub and included that in the query */ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "lookup_deposit_wtid", params, @@ -108,7 +109,6 @@ TEH_PG_lookup_transfer_by_deposit ( TALER_merchant_wire_signature_hash (payto_uri, &wire_salt, &wh); - GNUNET_PQ_cleanup_result (rs); if (0 == GNUNET_memcmp (&wh, h_wire)) @@ -116,9 +116,11 @@ TEH_PG_lookup_transfer_by_deposit ( *pending = false; kyc->ok = true; *aml_decision = TALER_AML_NORMAL; + GNUNET_PQ_cleanup_result (rs); return qs; } qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; + GNUNET_PQ_cleanup_result (rs); } if (0 > qs) return qs; @@ -140,56 +142,66 @@ TEH_PG_lookup_transfer_by_deposit ( &wire_salt), GNUNET_PQ_result_spec_string ("payto_uri", &payto_uri), + /* See Postgresql bug #18380 */ +#define BUG 1 +#if BUG GNUNET_PQ_result_spec_allow_null ( GNUNET_PQ_result_spec_uint64 ("legitimization_requirement_serial_id", &kyc->requirement_row), NULL), +#endif GNUNET_PQ_result_spec_allow_null ( GNUNET_PQ_result_spec_uint64 ("kyc_requirement", &aml_kyc_row), NULL), + GNUNET_PQ_result_spec_allow_null ( + GNUNET_PQ_result_spec_uint32 ("status", + &status32), + NULL), TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", amount_with_fee), TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit", deposit_fee), GNUNET_PQ_result_spec_timestamp ("wire_deadline", exec_time), - GNUNET_PQ_result_spec_allow_null ( - GNUNET_PQ_result_spec_uint32 ("status", - &status32), - NULL), GNUNET_PQ_result_spec_end }; PREPARE (pg, "get_deposit_without_wtid", "SELECT" - " agt.legitimization_requirement_serial_id" - ",dep.wire_salt" + " bdep.wire_salt" ",wt.payto_uri" - ",dep.amount_with_fee_val" - ",dep.amount_with_fee_frac" - ",denom.fee_deposit_val" - ",denom.fee_deposit_frac" - ",dep.wire_deadline" + ",cdep.amount_with_fee" + ",denom.fee_deposit" + ",bdep.wire_deadline" +#if BUG + ",agt.legitimization_requirement_serial_id" +#endif ",aml.status" ",aml.kyc_requirement" - " FROM deposits dep" + " FROM coin_deposits cdep" + " JOIN batch_deposits bdep" + " USING (batch_deposit_serial_id)" " JOIN wire_targets wt" " USING (wire_target_h_payto)" " JOIN known_coins kc" - " ON (kc.coin_pub = dep.coin_pub)" + " ON (kc.coin_pub = cdep.coin_pub)" " JOIN denominations denom" " USING (denominations_serial)" +#if BUG " LEFT JOIN aggregation_transient agt " - " ON ( (dep.wire_target_h_payto = agt.wire_target_h_payto) AND" - " (dep.merchant_pub = agt.merchant_pub) )" + " ON ( (bdep.wire_target_h_payto = agt.wire_target_h_payto) AND" + " (bdep.merchant_pub = agt.merchant_pub) )" +#endif " LEFT JOIN aml_status aml" " ON (wt.wire_target_h_payto = aml.h_payto)" - " WHERE dep.coin_pub=$1" - " AND dep.merchant_pub=$3" - " AND dep.h_contract_terms=$2" + " WHERE cdep.coin_pub=$1" + " AND bdep.merchant_pub=$3" + " AND bdep.h_contract_terms=$2" " LIMIT 1;"); + /* NOTE: above query might be more efficient if we computed the shard + from the merchant_pub and included that in the query */ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "get_deposit_without_wtid", params, @@ -212,11 +224,14 @@ TEH_PG_lookup_transfer_by_deposit ( TALER_merchant_wire_signature_hash (payto_uri, &wire_salt, &wh); - GNUNET_PQ_cleanup_result (rs); if (0 != GNUNET_memcmp (&wh, h_wire)) + { + GNUNET_PQ_cleanup_result (rs2); return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; + } + GNUNET_PQ_cleanup_result (rs2); } *aml_decision = TALER_AML_NORMAL; return qs; |