Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2022, 2023 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 backenddb/pg_insert_deposit.c
18 : * @brief Implementation of the insert_deposit function for Postgres
19 : * @author Christian Grothoff
20 : * @author Iván Ávalos
21 : */
22 : #include "platform.h"
23 : #include <taler/taler_error_codes.h>
24 : #include <taler/taler_dbevents.h>
25 : #include <taler/taler_pq_lib.h>
26 : #include "pg_insert_deposit.h"
27 : #include "pg_helper.h"
28 :
29 :
30 : enum GNUNET_DB_QueryStatus
31 34 : TMH_PG_insert_deposit (
32 : void *cls,
33 : uint32_t offset,
34 : uint64_t deposit_confirmation_serial,
35 : const struct TALER_CoinSpendPublicKeyP *coin_pub,
36 : const struct TALER_CoinSpendSignatureP *coin_sig,
37 : const struct TALER_Amount *amount_with_fee,
38 : const struct TALER_Amount *deposit_fee,
39 : const struct TALER_Amount *refund_fee)
40 : {
41 34 : struct PostgresClosure *pg = cls;
42 34 : struct GNUNET_PQ_QueryParam params[] = {
43 34 : GNUNET_PQ_query_param_uint64 (&deposit_confirmation_serial),
44 34 : GNUNET_PQ_query_param_uint32 (&offset),
45 34 : GNUNET_PQ_query_param_auto_from_type (coin_pub),
46 34 : GNUNET_PQ_query_param_auto_from_type (coin_sig),
47 34 : TALER_PQ_query_param_amount_with_currency (pg->conn,
48 : amount_with_fee),
49 34 : TALER_PQ_query_param_amount_with_currency (pg->conn,
50 : deposit_fee),
51 34 : TALER_PQ_query_param_amount_with_currency (pg->conn,
52 : refund_fee),
53 : GNUNET_PQ_query_param_end
54 : };
55 :
56 : /* no preflight check here, run in transaction by caller! */
57 34 : GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
58 : "Storing deposit for coin_pub: `%s', amount_with_fee: %s\n",
59 : TALER_B2S (coin_pub),
60 : TALER_amount2s (amount_with_fee));
61 34 : check_connection (pg);
62 34 : PREPARE (pg,
63 : "insert_deposit",
64 : "INSERT INTO merchant_deposits"
65 : "(deposit_confirmation_serial"
66 : ",coin_offset"
67 : ",coin_pub"
68 : ",coin_sig"
69 : ",amount_with_fee"
70 : ",deposit_fee"
71 : ",refund_fee"
72 : ") VALUES ($1, $2, $3, $4, $5, $6, $7)");
73 34 : return GNUNET_PQ_eval_prepared_non_select (pg->conn,
74 : "insert_deposit",
75 : params);
76 : }
|