get_denomination_info.c (3734B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2022,2025 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/get_denomination_info.c 18 * @brief Implementation of the get_denomination_info function for Postgres 19 * @author Christian Grothoff 20 * @author Özgür Kesim 21 */ 22 #include "taler/taler_error_codes.h" 23 #include "taler/taler_pq_lib.h" 24 #include "exchange-database/get_denomination_info.h" 25 #include "helper.h" 26 27 28 enum GNUNET_DB_QueryStatus 29 TALER_EXCHANGEDB_get_denomination_info ( 30 struct TALER_EXCHANGEDB_PostgresContext *pg, 31 const struct TALER_DenominationHashP *denom_pub_hash, 32 uint64_t *denom_serial, 33 struct TALER_EXCHANGEDB_DenominationKeyInformation *issue) 34 { 35 enum GNUNET_DB_QueryStatus qs; 36 uint64_t serial; 37 struct GNUNET_PQ_QueryParam params[] = { 38 GNUNET_PQ_query_param_auto_from_type (denom_pub_hash), 39 GNUNET_PQ_query_param_end 40 }; 41 struct GNUNET_PQ_ResultSpec rs[] = { 42 GNUNET_PQ_result_spec_uint64 ("denominations_serial", 43 &serial), 44 GNUNET_PQ_result_spec_auto_from_type ("master_sig", 45 &issue->signature), 46 GNUNET_PQ_result_spec_timestamp ("valid_from", 47 &issue->start), 48 GNUNET_PQ_result_spec_timestamp ("expire_withdraw", 49 &issue->expire_withdraw), 50 GNUNET_PQ_result_spec_timestamp ("expire_deposit", 51 &issue->expire_deposit), 52 GNUNET_PQ_result_spec_timestamp ("expire_legal", 53 &issue->expire_legal), 54 TALER_PQ_RESULT_SPEC_AMOUNT ("coin", 55 &issue->value), 56 TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw", 57 &issue->fees.withdraw), 58 TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit", 59 &issue->fees.deposit), 60 TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh", 61 &issue->fees.refresh), 62 TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund", 63 &issue->fees.refund), 64 GNUNET_PQ_result_spec_uint32 ("age_mask", 65 &issue->age_mask.bits), 66 GNUNET_PQ_result_spec_end 67 }; 68 69 PREPARE (pg, 70 "denomination_get", 71 "SELECT" 72 " denominations_serial" 73 ",master_sig" 74 ",valid_from" 75 ",expire_withdraw" 76 ",expire_deposit" 77 ",expire_legal" 78 ",coin" /* value of this denom */ 79 ",fee_withdraw" 80 ",fee_deposit" 81 ",fee_refresh" 82 ",fee_refund" 83 ",age_mask" 84 " FROM denominations" 85 " WHERE denom_pub_hash=$1;"); 86 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 87 "denomination_get", 88 params, 89 rs); 90 if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) 91 return qs; 92 issue->denom_hash = *denom_pub_hash; 93 if (NULL != denom_serial) 94 *denom_serial = serial; 95 return qs; 96 }