insert_denomination_info.c (3962B)
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 exchangedb/insert_denomination_info.c 18 * @brief Implementation of the insert_denomination_info function for Postgres 19 * @author Christian Grothoff 20 */ 21 #include "taler/taler_error_codes.h" 22 #include "taler/taler_pq_lib.h" 23 #include "exchange-database/insert_denomination_info.h" 24 #include "helper.h" 25 26 27 enum GNUNET_DB_QueryStatus 28 TALER_EXCHANGEDB_insert_denomination_info ( 29 struct TALER_EXCHANGEDB_PostgresContext *pg, 30 const struct TALER_DenominationPublicKey *denom_pub, 31 const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue) 32 { 33 struct TALER_DenominationHashP denom_hash; 34 struct GNUNET_PQ_QueryParam params[] = { 35 GNUNET_PQ_query_param_auto_from_type (&issue->denom_hash), 36 TALER_PQ_query_param_denom_pub (denom_pub), 37 GNUNET_PQ_query_param_auto_from_type (&issue->signature), 38 GNUNET_PQ_query_param_timestamp (&issue->start), 39 GNUNET_PQ_query_param_timestamp (&issue->expire_withdraw), 40 GNUNET_PQ_query_param_timestamp (&issue->expire_deposit), 41 GNUNET_PQ_query_param_timestamp (&issue->expire_legal), 42 TALER_PQ_query_param_amount (pg->conn, 43 &issue->value), 44 TALER_PQ_query_param_amount (pg->conn, 45 &issue->fees.withdraw), 46 TALER_PQ_query_param_amount (pg->conn, 47 &issue->fees.deposit), 48 TALER_PQ_query_param_amount (pg->conn, 49 &issue->fees.refresh), 50 TALER_PQ_query_param_amount (pg->conn, 51 &issue->fees.refund), 52 GNUNET_PQ_query_param_uint32 (&denom_pub->age_mask.bits), 53 GNUNET_PQ_query_param_end 54 }; 55 56 GNUNET_assert (denom_pub->age_mask.bits == 57 issue->age_mask.bits); 58 TALER_denom_pub_hash (denom_pub, 59 &denom_hash); 60 GNUNET_assert (0 == 61 GNUNET_memcmp (&denom_hash, 62 &issue->denom_hash)); 63 GNUNET_assert (! GNUNET_TIME_absolute_is_zero ( 64 issue->start.abs_time)); 65 GNUNET_assert (! GNUNET_TIME_absolute_is_zero ( 66 issue->expire_withdraw.abs_time)); 67 GNUNET_assert (! GNUNET_TIME_absolute_is_zero ( 68 issue->expire_deposit.abs_time)); 69 GNUNET_assert (! GNUNET_TIME_absolute_is_zero ( 70 issue->expire_legal.abs_time)); 71 /* check fees match denomination currency */ 72 GNUNET_assert (GNUNET_YES == 73 TALER_denom_fee_check_currency ( 74 issue->value.currency, 75 &issue->fees)); 76 PREPARE (pg, 77 "denomination_insert", 78 "INSERT INTO denominations " 79 "(denom_pub_hash" 80 ",denom_pub" 81 ",master_sig" 82 ",valid_from" 83 ",expire_withdraw" 84 ",expire_deposit" 85 ",expire_legal" 86 ",coin" /* value of this denom */ 87 ",fee_withdraw" 88 ",fee_deposit" 89 ",fee_refresh" 90 ",fee_refund" 91 ",age_mask" 92 ") VALUES " 93 "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10," 94 " $11, $12, $13);"); 95 return GNUNET_PQ_eval_prepared_non_select (pg->conn, 96 "denomination_insert", 97 params); 98 }