Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2023, 2024 Taler Systems SA
4 :
5 : TALER is free software; you can redistribute it and/or modify it under the
6 : terms of the GNU General Public License as published by the Free Software
7 : Foundation; either version 3, or (at your option) any later version.
8 :
9 : TALER is distributed in the hope that it will be useful, but WITHOUT ANY
10 : WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 : A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 :
13 : You should have received a copy of the GNU General Public License along with
14 : TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
15 : */
16 : /**
17 : * @file exchangedb/pg_get_wire_hash_for_contract.c
18 : * @brief Implementation of the get_wire_hash_for_contract function for Postgres
19 : * @author Özgür Kesim
20 : */
21 : #include "taler/platform.h"
22 : #include "taler/taler_error_codes.h"
23 : #include "taler/taler_dbevents.h"
24 : #include "taler/taler_exchangedb_plugin.h"
25 : #include "taler/taler_pq_lib.h"
26 : #include "pg_get_wire_hash_for_contract.h"
27 : #include "pg_helper.h"
28 :
29 :
30 : enum GNUNET_DB_QueryStatus
31 4 : TEH_PG_get_wire_hash_for_contract (
32 : void *cls,
33 : const struct TALER_MerchantPublicKeyP *merchant_pub,
34 : const struct TALER_PrivateContractHashP *h_contract_terms,
35 : struct TALER_MerchantWireHashP *h_wire)
36 : {
37 4 : struct PostgresClosure *pg = cls;
38 : enum GNUNET_DB_QueryStatus qs;
39 4 : struct GNUNET_PQ_QueryParam params[] = {
40 4 : GNUNET_PQ_query_param_auto_from_type (merchant_pub),
41 4 : GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
42 : GNUNET_PQ_query_param_end
43 : };
44 : struct TALER_FullPayto payto_uri;
45 : struct TALER_WireSaltP wire_salt;
46 4 : struct GNUNET_PQ_ResultSpec rs[] = {
47 4 : GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
48 : &wire_salt),
49 4 : GNUNET_PQ_result_spec_string ("payto_uri",
50 : &payto_uri.full_payto),
51 : GNUNET_PQ_result_spec_end
52 : };
53 :
54 : /* check if the necessary records exist and get them */
55 4 : PREPARE (pg,
56 : "get_wire_hash_for_contract",
57 : "SELECT"
58 : " bdep.wire_salt"
59 : " ,wt.payto_uri"
60 : " FROM coin_deposits"
61 : " JOIN batch_deposits bdep"
62 : " USING (batch_deposit_serial_id)"
63 : " JOIN wire_targets wt"
64 : " USING (wire_target_h_payto)"
65 : " WHERE bdep.merchant_pub=$1"
66 : " AND bdep.h_contract_terms=$2");
67 : /* NOTE: above query might be more efficient if we computed the shard
68 : from the merchant_pub and included that in the query */
69 4 : qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
70 : "get_wire_hash_for_contract",
71 : params,
72 : rs);
73 4 : if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
74 : {
75 4 : TALER_merchant_wire_signature_hash (payto_uri,
76 : &wire_salt,
77 : h_wire);
78 4 : GNUNET_PQ_cleanup_result (rs);
79 : }
80 4 : return qs;
81 : }
|