Line data Source code
1 : /*
2 : This file is part of TALER
3 : (C) 2016-2023 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_bank_get_withdrawals.c
21 : * @brief implements the Taler Bank API "GET /withdrawals/$WID" handler
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_bank_get_withdrawals.h"
31 : #include "fakebank_common_lookup.h"
32 :
33 :
34 : /**
35 : * Handle GET /withdrawals/{withdrawal_id} request
36 : * to the Taler bank access API.
37 : *
38 : * @param h the handle
39 : * @param connection the connection
40 : * @param withdrawal_id withdrawal ID to return status of
41 : * @return MHD result code
42 : */
43 : MHD_RESULT
44 0 : TALER_FAKEBANK_bank_get_withdrawals_ (
45 : struct TALER_FAKEBANK_Handle *h,
46 : struct MHD_Connection *connection,
47 : const char *withdrawal_id)
48 : {
49 : struct WithdrawalOperation *wo;
50 :
51 0 : GNUNET_assert (0 ==
52 : pthread_mutex_lock (&h->big_lock));
53 0 : wo = TALER_FAKEBANK_lookup_withdrawal_operation_ (h,
54 : withdrawal_id);
55 0 : if (NULL == wo)
56 : {
57 0 : GNUNET_assert (0 ==
58 : pthread_mutex_unlock (&h->big_lock));
59 0 : return TALER_MHD_reply_with_error (connection,
60 : MHD_HTTP_NOT_FOUND,
61 : TALER_EC_BANK_TRANSACTION_NOT_FOUND,
62 : withdrawal_id);
63 : }
64 0 : GNUNET_assert (0 ==
65 : pthread_mutex_unlock (&h->big_lock));
66 0 : return TALER_MHD_REPLY_JSON_PACK (
67 : connection,
68 : MHD_HTTP_OK,
69 : GNUNET_JSON_pack_bool ("aborted",
70 : wo->aborted),
71 : GNUNET_JSON_pack_bool ("selection_done",
72 : wo->selection_done),
73 : GNUNET_JSON_pack_bool ("transfer_done",
74 : wo->confirmation_done),
75 : GNUNET_JSON_pack_allow_null (
76 : GNUNET_JSON_pack_string ("selected_exchange_account",
77 : wo->exchange_account->payto_uri)),
78 : GNUNET_JSON_pack_allow_null (
79 : wo->selection_done
80 : ? GNUNET_JSON_pack_data_auto ("selected_reserve_pub",
81 : &wo->reserve_pub)
82 : : GNUNET_JSON_pack_string ("selected_reserve_pub",
83 : NULL)),
84 : GNUNET_JSON_pack_string ("currency",
85 : h->currency),
86 : GNUNET_JSON_pack_allow_null (
87 : TALER_JSON_pack_amount ("amount",
88 : wo->amount)));
89 : }
|