aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb/pg_do_deposit.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2023-09-10 19:13:49 +0200
committerChristian Grothoff <christian@grothoff.org>2023-09-10 19:13:49 +0200
commit852c46668f1c9f766de9473c50e787e32a0f8697 (patch)
tree6106427e8da10610507b12cd4d663f3e66d8eae7 /src/exchangedb/pg_do_deposit.c
parentcf595fa8480e87e1522710cd8ea7db9174aa028b (diff)
downloadexchange-852c46668f1c9f766de9473c50e787e32a0f8697.tar.xz
major exchange DB schema change: store common properties of batch deposit in batch_deposits table, and coin-specific ones in coin_deposits table; plus minor cleanups
Diffstat (limited to 'src/exchangedb/pg_do_deposit.c')
-rw-r--r--src/exchangedb/pg_do_deposit.c85
1 files changed, 55 insertions, 30 deletions
diff --git a/src/exchangedb/pg_do_deposit.c b/src/exchangedb/pg_do_deposit.c
index ce09fb72c..11720d7d9 100644
--- a/src/exchangedb/pg_do_deposit.c
+++ b/src/exchangedb/pg_do_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
@@ -30,53 +30,78 @@
enum GNUNET_DB_QueryStatus
TEH_PG_do_deposit (
void *cls,
- const struct TALER_EXCHANGEDB_Deposit *deposit,
- uint64_t known_coin_id,
- const struct TALER_PaytoHashP *h_payto,
- uint64_t *policy_details_serial_id,
+ const struct TALER_EXCHANGEDB_BatchDeposit *bd,
struct GNUNET_TIME_Timestamp *exchange_timestamp,
bool *balance_ok,
- bool *in_conflict)
+ uint32_t *bad_balance_index,
+ bool *ctr_conflict)
{
struct PostgresClosure *pg = cls;
- uint64_t deposit_shard = TEH_PG_compute_shard (&deposit->merchant_pub);
+ uint64_t deposit_shard = TEH_PG_compute_shard (&bd->merchant_pub);
+ const struct TALER_CoinSpendPublicKeyP *coin_pubs[GNUNET_NZL (bd->num_cdis)];
+ const struct TALER_CoinSpendSignatureP *coin_sigs[GNUNET_NZL (bd->num_cdis)];
+ struct TALER_Amount amounts_with_fee[GNUNET_NZL (bd->num_cdis)];
struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (pg->conn,
- &deposit->amount_with_fee),
- GNUNET_PQ_query_param_auto_from_type (&deposit->h_contract_terms),
- GNUNET_PQ_query_param_auto_from_type (&deposit->wire_salt),
- GNUNET_PQ_query_param_timestamp (&deposit->timestamp),
- GNUNET_PQ_query_param_timestamp (exchange_timestamp),
- GNUNET_PQ_query_param_timestamp (&deposit->refund_deadline),
- GNUNET_PQ_query_param_timestamp (&deposit->wire_deadline),
- GNUNET_PQ_query_param_auto_from_type (&deposit->merchant_pub),
- GNUNET_PQ_query_param_string (deposit->receiver_wire_account),
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_uint64 (&known_coin_id),
- GNUNET_PQ_query_param_auto_from_type (&deposit->coin.coin_pub),
- GNUNET_PQ_query_param_auto_from_type (&deposit->csig),
+ /* data for batch_deposits */
GNUNET_PQ_query_param_uint64 (&deposit_shard),
- GNUNET_PQ_query_param_bool (deposit->has_policy),
- (NULL == policy_details_serial_id)
+ GNUNET_PQ_query_param_auto_from_type (&bd->merchant_pub),
+ GNUNET_PQ_query_param_timestamp (&bd->wallet_timestamp),
+ GNUNET_PQ_query_param_timestamp (exchange_timestamp),
+ GNUNET_PQ_query_param_timestamp (&bd->refund_deadline),
+ GNUNET_PQ_query_param_timestamp (&bd->wire_deadline),
+ GNUNET_PQ_query_param_auto_from_type (&bd->h_contract_terms),
+ (0 == bd->has_wallet_data_hash)
? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_uint64 (policy_details_serial_id),
+ : GNUNET_PQ_query_param_auto_from_type (&bd->wallet_data_hash),
+ GNUNET_PQ_query_param_auto_from_type (&bd->wire_salt),
+ GNUNET_PQ_query_param_auto_from_type (&bd->wire_target_h_payto),
+ (0 == bd->policy_details_serial_id)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_uint64 (&bd->policy_details_serial_id),
+ GNUNET_PQ_query_param_bool (bd->policy_blocked),
+ /* to create entry in wire_targets */
+ GNUNET_PQ_query_param_string (bd->receiver_wire_account),
+ /* arrays for coin_deposits */
+ GNUNET_PQ_query_param_array_ptrs_auto_from_type (bd->num_cdis,
+ coin_pubs,
+ pg->conn),
+ GNUNET_PQ_query_param_array_ptrs_auto_from_type (bd->num_cdis,
+ coin_sigs,
+ pg->conn),
+ TALER_PQ_query_param_array_amount (bd->num_cdis,
+ amounts_with_fee,
+ pg->conn),
GNUNET_PQ_query_param_end
};
+ bool no_time;
struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("balance_ok",
- balance_ok),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
+ exchange_timestamp),
+ &no_time),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint32 ("insufficient_balance_coin_index",
+ bad_balance_index),
+ balance_ok),
GNUNET_PQ_result_spec_bool ("conflicted",
- in_conflict),
- GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
- exchange_timestamp),
+ ctr_conflict),
GNUNET_PQ_result_spec_end
};
+ for (unsigned int i = 0; i < bd->num_cdis; i++)
+ {
+ const struct TALER_EXCHANGEDB_CoinDepositInformation *cdi
+ = &bd->cdis[i];
+
+ amounts_with_fee[i] = cdi->amount_with_fee;
+ coin_pubs[i] = &cdi->coin.coin_pub;
+ coin_sigs[i] = &cdi->csig;
+ }
PREPARE (pg,
"call_deposit",
"SELECT "
" out_exchange_timestamp AS exchange_timestamp"
- ",out_balance_ok AS balance_ok"
+ ",out_insufficient_balance_coin_index AS insufficient_balance_coin_index"
",out_conflict AS conflicted"
" FROM exchange_do_deposit"
" ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);");