diff options
author | Özgür Kesim <oec-taler@kesim.org> | 2023-12-23 23:33:22 +0100 |
---|---|---|
committer | Özgür Kesim <oec-taler@kesim.org> | 2023-12-23 23:33:22 +0100 |
commit | 234b0cd56f69305f27ac5f6cd3828c0d115dcd0f (patch) | |
tree | 10d8f0872098d308cbaf2f0b6abb69936a104fb8 /src/exchangedb/pg_get_wire_hash_for_contract.c | |
parent | 13bb37b6a811451accc14b3501173637f2c28d10 (diff) | |
download | exchange-234b0cd56f69305f27ac5f6cd3828c0d115dcd0f.tar.xz |
Added appropriate response on contract-conflict during deposit
In case of a detected conflict during deposit, because
(merchant_pub, h_contract_terms) already existed, with different other
field values, we now provide the client an error response that contains
the h_wire. This way, the client can retrieve further details about the
conflicting transaction via
/deposits/$H_WIRE/$MERCHANT_PUB/$H_CONTRACT_TERMS/$COIN_PUB
Fixes #8002
Diffstat (limited to 'src/exchangedb/pg_get_wire_hash_for_contract.c')
-rw-r--r-- | src/exchangedb/pg_get_wire_hash_for_contract.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/exchangedb/pg_get_wire_hash_for_contract.c b/src/exchangedb/pg_get_wire_hash_for_contract.c new file mode 100644 index 000000000..5ff092a6c --- /dev/null +++ b/src/exchangedb/pg_get_wire_hash_for_contract.c @@ -0,0 +1,81 @@ +/* + This file is part of TALER + Copyright (C) 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 + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file exchangedb/pg_get_wire_hash_for_contract.c + * @brief Implementation of the get_wire_hash_for_contract function for Postgres + * @author Özgür Kesim + */ +#include "platform.h" +#include "taler_error_codes.h" +#include "taler_dbevents.h" +#include "taler_exchangedb_plugin.h" +#include "taler_pq_lib.h" +#include "pg_get_wire_hash_for_contract.h" +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TEH_PG_get_wire_hash_for_contract ( + void *cls, + const struct TALER_MerchantPublicKeyP *merchant_pub, + const struct TALER_PrivateContractHashP *h_contract_terms, + struct TALER_MerchantWireHashP *h_wire) +{ + struct PostgresClosure *pg = cls; + enum GNUNET_DB_QueryStatus qs; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (merchant_pub), + GNUNET_PQ_query_param_auto_from_type (h_contract_terms), + GNUNET_PQ_query_param_end + }; + char *payto_uri; + struct TALER_WireSaltP wire_salt; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("wire_salt", + &wire_salt), + GNUNET_PQ_result_spec_string ("payto_uri", + &payto_uri), + GNUNET_PQ_result_spec_end + }; + + /* check if the necessary records exist and get them */ + PREPARE (pg, + "get_wire_hash_for_contract", + "SELECT" + "bdep.wire_salt" + ",wt.payto_uri" + " FROM coin_deposits" + " JOIN batch_deposits bdep" + " USING (batch_deposit_serial_id)" + " JOIN wire_targets wt" + " USING (wire_target_h_payto)" + " WHERE bdep.merchant_pub=$1" + " 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, + "get_wire_hash_for_contract", + params, + rs); + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) + { + TALER_merchant_wire_signature_hash (payto_uri, + &wire_salt, + h_wire); + GNUNET_PQ_cleanup_result (rs); + } + return qs; +} |