Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2022 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 select_purse.c
18 : * @brief Implementation of the select_purse function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "taler/taler_pq_lib.h"
22 : #include "exchange-database/select_purse.h"
23 : #include "helper.h"
24 :
25 :
26 : enum GNUNET_DB_QueryStatus
27 27 : TALER_EXCHANGEDB_select_purse (
28 : struct TALER_EXCHANGEDB_PostgresContext *pg,
29 : const struct TALER_PurseContractPublicKeyP *purse_pub,
30 : struct GNUNET_TIME_Timestamp *purse_creation,
31 : struct GNUNET_TIME_Timestamp *purse_expiration,
32 : struct TALER_Amount *amount,
33 : struct TALER_Amount *deposited,
34 : struct TALER_PrivateContractHashP *h_contract_terms,
35 : struct GNUNET_TIME_Timestamp *merge_timestamp,
36 : bool *purse_deleted,
37 : bool *purse_refunded)
38 : {
39 27 : struct GNUNET_PQ_QueryParam params[] = {
40 27 : GNUNET_PQ_query_param_auto_from_type (purse_pub),
41 : GNUNET_PQ_query_param_end
42 : };
43 27 : struct GNUNET_PQ_ResultSpec rs[] = {
44 27 : GNUNET_PQ_result_spec_timestamp ("purse_expiration",
45 : purse_expiration),
46 27 : GNUNET_PQ_result_spec_timestamp ("purse_creation",
47 : purse_creation),
48 27 : TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
49 : amount),
50 27 : TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
51 : deposited),
52 27 : GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
53 : h_contract_terms),
54 27 : GNUNET_PQ_result_spec_allow_null (
55 : GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
56 : merge_timestamp),
57 : NULL),
58 27 : GNUNET_PQ_result_spec_bool ("purse_deleted",
59 : purse_deleted),
60 27 : GNUNET_PQ_result_spec_allow_null (
61 : GNUNET_PQ_result_spec_bool ("purse_refunded",
62 : purse_refunded),
63 : NULL),
64 : GNUNET_PQ_result_spec_end
65 : };
66 :
67 27 : PREPARE (pg,
68 : "select_purse",
69 : "SELECT "
70 : " pr.merge_pub"
71 : ",pr.purse_creation"
72 : ",pr.purse_expiration"
73 : ",pr.h_contract_terms"
74 : ",pr.amount_with_fee"
75 : ",pr.balance"
76 : ",pm.merge_timestamp"
77 : ",pd.purse_sig IS NOT NULL AS purse_deleted"
78 : ",pc.refunded AS purse_refunded"
79 : " FROM purse_requests pr"
80 : " LEFT JOIN purse_merges pm ON (pm.purse_pub = pr.purse_pub)"
81 : " LEFT JOIN purse_decision pc ON (pc.purse_pub = pr.purse_pub)"
82 : " LEFT JOIN purse_deletion pd ON (pd.purse_pub = pr.purse_pub)"
83 : " WHERE pr.purse_pub=$1;");
84 27 : *merge_timestamp = GNUNET_TIME_UNIT_FOREVER_TS;
85 27 : *purse_refunded = false;
86 27 : return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
87 : "select_purse",
88 : params,
89 : rs);
90 : }
|