Line data Source code
1 : /*
2 : This file is part of TALER
3 : (C) 2024 Taler Systems SA
4 :
5 : TALER is free software; you can redistribute it and/or
6 : modify it under the terms of the GNU General Public License
7 : as published by the Free Software Foundation; either version 3,
8 : or (at your option) any later version.
9 :
10 : TALER is distributed in the hope that it will be useful,
11 : but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 : GNU General Public License for more details.
14 :
15 : You should have received a copy of the GNU General Public
16 : License along with TALER; see the file COPYING. If not,
17 : see <http://www.gnu.org/licenses/>
18 : */
19 : /**
20 : * @file bank-lib/fakebank_twg_get_transfers_id.c
21 : * @brief routines to return outgoing transfer details
22 : * @author Christian Grothoff <christian@grothoff.org>
23 : */
24 : #include <pthread.h>
25 : #include "taler/taler_fakebank_lib.h"
26 : #include "taler/taler_bank_service.h"
27 : #include "taler/taler_mhd_lib.h"
28 : #include <gnunet/gnunet_mhd_compat.h>
29 : #include "fakebank.h"
30 : #include "fakebank_common_lookup.h"
31 : #include "fakebank_common_lp.h"
32 : #include "fakebank_common_parser.h"
33 : #include "fakebank_twg_get_transfers.h"
34 :
35 :
36 : MHD_RESULT
37 0 : TALER_FAKEBANK_twg_get_transfers_id_ (
38 : struct TALER_FAKEBANK_Handle *h,
39 : struct MHD_Connection *connection,
40 : const char *account,
41 : const char *id,
42 : void **con_cls)
43 : {
44 : struct Account *acc;
45 : unsigned long long row_id;
46 : json_t *trans;
47 :
48 0 : GNUNET_log (GNUNET_ERROR_TYPE_INFO,
49 : "Handling /transfers/%s connection %p\n",
50 : id,
51 : connection);
52 : {
53 : char dummy;
54 :
55 0 : if (1 !=
56 0 : sscanf (id,
57 : "%llu%c",
58 : &row_id,
59 : &dummy))
60 : {
61 0 : return TALER_MHD_reply_with_error (
62 : connection,
63 : MHD_HTTP_BAD_REQUEST,
64 : TALER_EC_GENERIC_PARAMETER_MALFORMED,
65 : id);
66 : }
67 : }
68 0 : GNUNET_assert (0 ==
69 : pthread_mutex_lock (&h->big_lock));
70 0 : acc = TALER_FAKEBANK_lookup_account_ (h,
71 : account,
72 : NULL);
73 0 : if (NULL == acc)
74 : {
75 0 : GNUNET_assert (0 ==
76 : pthread_mutex_unlock (&h->big_lock));
77 0 : return TALER_MHD_reply_with_error (connection,
78 : MHD_HTTP_NOT_FOUND,
79 : TALER_EC_BANK_UNKNOWN_ACCOUNT,
80 : account);
81 : }
82 : {
83 0 : struct Transaction *t = h->transactions[row_id % h->ram_limit];
84 : char *credit_payto;
85 :
86 0 : if (t->debit_account != acc)
87 : {
88 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
89 : "Invalid ID specified, transaction %llu not with account %s!\n",
90 : (unsigned long long) row_id,
91 : account);
92 0 : GNUNET_assert (0 ==
93 : pthread_mutex_unlock (&h->big_lock));
94 0 : return MHD_NO;
95 : }
96 0 : GNUNET_asprintf (&credit_payto,
97 : "payto://x-taler-bank/localhost/%s?receiver-name=%s",
98 0 : t->credit_account->account_name,
99 0 : t->credit_account->receiver_name);
100 0 : trans = GNUNET_JSON_PACK (
101 : GNUNET_JSON_pack_data_auto (
102 : "wtid",
103 : &t->subject.debit.wtid),
104 : GNUNET_JSON_pack_string (
105 : "exchange_base_url",
106 : t->subject.debit.exchange_base_url),
107 : GNUNET_JSON_pack_timestamp (
108 : "timestamp",
109 : t->date),
110 : TALER_JSON_pack_amount (
111 : "amount",
112 : &t->amount),
113 : GNUNET_JSON_pack_string (
114 : "credit_account",
115 : credit_payto),
116 : GNUNET_JSON_pack_string (
117 : "status",
118 : "success"));
119 0 : GNUNET_assert (NULL != trans);
120 0 : GNUNET_free (credit_payto);
121 : }
122 0 : GNUNET_assert (0 ==
123 : pthread_mutex_unlock (&h->big_lock));
124 0 : return TALER_MHD_reply_json (
125 : connection,
126 : trans,
127 : MHD_HTTP_OK);
128 : }
|