Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2025 Taler Systems SA
4 :
5 : TALER is free software; you can redistribute it and/or modify it
6 : under the terms of the GNU General Public License as published by the
7 : Free Software Foundation; either version 3, or (at your option) any
8 : later version.
9 :
10 : TALER is distributed in the hope that it will be useful, but WITHOUT
11 : ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 : or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
13 : License for more details.
14 :
15 : You should have received a copy of the GNU General Public License
16 : along with TALER; see the file COPYING. If not, see
17 : <http://www.gnu.org/licenses/>
18 : */
19 : /**
20 : * @file src/backenddb/get_donau_instance_by_url.c
21 : * @brief Implementation for retrieving Donau charity_id and corresponding private key
22 : * by Donau URL.
23 : * @author Bohdan Potuzhnyi
24 : * @author Vlada Svirsh
25 : */
26 : #include "platform.h"
27 : #include <taler/taler_error_codes.h>
28 : #include <taler/taler_dbevents.h>
29 : #include <taler/taler_pq_lib.h>
30 : #include "merchantdb_lib.h"
31 : #include "donau/donau_service.h"
32 : #include "merchant-database/get_donau_instance_by_url.h"
33 : #include "helper.h"
34 :
35 :
36 : enum GNUNET_DB_QueryStatus
37 1 : TALER_MERCHANTDB_get_donau_instance_by_url (
38 : struct TALER_MERCHANTDB_PostgresContext *pg,
39 : const char *instance_id,
40 : const char *donau_url,
41 : uint64_t *charity_id,
42 : struct TALER_Amount *charity_max_per_year,
43 : struct TALER_Amount *charity_receipts_to_date,
44 : json_t **donau_keys_json,
45 : uint64_t *donau_instance_serial)
46 : {
47 1 : struct GNUNET_PQ_QueryParam params[] = {
48 1 : GNUNET_PQ_query_param_string (donau_url),
49 : GNUNET_PQ_query_param_end
50 : };
51 1 : struct GNUNET_PQ_ResultSpec rs[] = {
52 1 : GNUNET_PQ_result_spec_uint64 ("charity_id",
53 : charity_id),
54 1 : TALER_PQ_result_spec_json ("keys_json",
55 : donau_keys_json),
56 1 : TALER_PQ_result_spec_amount_with_currency ("charity_max_per_year",
57 : charity_max_per_year),
58 1 : TALER_PQ_result_spec_amount_with_currency ("charity_receipts_to_date",
59 : charity_receipts_to_date),
60 1 : GNUNET_PQ_result_spec_uint64 ("donau_instances_serial",
61 : donau_instance_serial),
62 : GNUNET_PQ_result_spec_end
63 : };
64 :
65 1 : GNUNET_assert (NULL != pg->current_merchant_id);
66 1 : GNUNET_assert (0 == strcmp (instance_id,
67 : pg->current_merchant_id));
68 1 : TMH_PQ_prepare_anon (pg,
69 : "SELECT"
70 : " di.donau_instances_serial"
71 : " ,di.charity_id"
72 : " ,dk.keys_json::TEXT"
73 : " ,di.charity_max_per_year"
74 : " ,di.charity_receipts_to_date"
75 : " FROM merchant_donau_instances di"
76 : " JOIN merchant.merchant_donau_keys dk"
77 : " ON dk.donau_url = di.donau_url"
78 : " WHERE di.donau_url = $1;");
79 1 : return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
80 : "",
81 : params,
82 : rs);
83 : }
|