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 exchangedb/add_denomination_key.c
18 : * @brief Implementation of the add_denomination_key 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/add_denomination_key.h"
24 : #include "helper.h"
25 :
26 :
27 : enum GNUNET_DB_QueryStatus
28 469 : TALER_EXCHANGEDB_add_denomination_key (
29 : struct TALER_EXCHANGEDB_PostgresContext *pg,
30 : const struct TALER_DenominationHashP *h_denom_pub,
31 : const struct TALER_DenominationPublicKey *denom_pub,
32 : const struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta,
33 : const struct TALER_MasterSignatureP *master_sig)
34 : {
35 469 : struct GNUNET_PQ_QueryParam iparams[] = {
36 469 : GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
37 469 : TALER_PQ_query_param_denom_pub (denom_pub),
38 469 : GNUNET_PQ_query_param_auto_from_type (master_sig),
39 469 : GNUNET_PQ_query_param_timestamp (&meta->start),
40 469 : GNUNET_PQ_query_param_timestamp (&meta->expire_withdraw),
41 469 : GNUNET_PQ_query_param_timestamp (&meta->expire_deposit),
42 469 : GNUNET_PQ_query_param_timestamp (&meta->expire_legal),
43 469 : TALER_PQ_query_param_amount (pg->conn,
44 : &meta->value),
45 469 : TALER_PQ_query_param_amount (pg->conn,
46 : &meta->fees.withdraw),
47 469 : TALER_PQ_query_param_amount (pg->conn,
48 : &meta->fees.deposit),
49 469 : TALER_PQ_query_param_amount (pg->conn,
50 : &meta->fees.refresh),
51 469 : TALER_PQ_query_param_amount (pg->conn,
52 : &meta->fees.refund),
53 469 : GNUNET_PQ_query_param_uint32 (&meta->age_mask.bits),
54 : GNUNET_PQ_query_param_end
55 : };
56 :
57 : /* Sanity check: ensure fees match coin currency */
58 469 : GNUNET_assert (GNUNET_YES ==
59 : TALER_denom_fee_check_currency (meta->value.currency,
60 : &meta->fees));
61 469 : PREPARE (pg,
62 : "denomination_insert",
63 : "INSERT INTO denominations "
64 : "(denom_pub_hash"
65 : ",denom_pub"
66 : ",master_sig"
67 : ",valid_from"
68 : ",expire_withdraw"
69 : ",expire_deposit"
70 : ",expire_legal"
71 : ",coin" /* value of this denom */
72 : ",fee_withdraw"
73 : ",fee_deposit"
74 : ",fee_refresh"
75 : ",fee_refund"
76 : ",age_mask"
77 : ") VALUES "
78 : "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
79 : " $11, $12, $13);");
80 469 : return GNUNET_PQ_eval_prepared_non_select (pg->conn,
81 : "denomination_insert",
82 : iparams);
83 : }
|