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