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