fakebank_twg_get_transfers_id.c (3968B)
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 enum MHD_Result 37 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 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 49 "Handling /transfers/%s connection %p\n", 50 id, 51 connection); 52 { 53 char dummy; 54 55 if (1 != 56 sscanf (id, 57 "%llu%c", 58 &row_id, 59 &dummy)) 60 { 61 return TALER_MHD_reply_with_error ( 62 connection, 63 MHD_HTTP_BAD_REQUEST, 64 TALER_EC_GENERIC_PARAMETER_MALFORMED, 65 id); 66 } 67 } 68 GNUNET_assert (0 == 69 pthread_mutex_lock (&h->big_lock)); 70 acc = TALER_FAKEBANK_lookup_account_ (h, 71 account, 72 NULL); 73 if (NULL == acc) 74 { 75 GNUNET_assert (0 == 76 pthread_mutex_unlock (&h->big_lock)); 77 return TALER_MHD_reply_with_error (connection, 78 MHD_HTTP_NOT_FOUND, 79 TALER_EC_BANK_UNKNOWN_ACCOUNT, 80 account); 81 } 82 { 83 struct Transaction *t = h->transactions[row_id % h->ram_limit]; 84 char *credit_payto; 85 86 if ( (NULL == t) || 87 (t->row_id != row_id) || 88 (t->type != T_DEBIT) || 89 (t->debit_account != acc) ) 90 { 91 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 92 "Invalid ID specified, transaction %llu not with account %s!\n", 93 (unsigned long long) row_id, 94 account); 95 GNUNET_assert (0 == 96 pthread_mutex_unlock (&h->big_lock)); 97 return MHD_NO; 98 } 99 GNUNET_asprintf (&credit_payto, 100 "payto://x-taler-bank/%s/%s?receiver-name=%s", 101 h->hostname, 102 t->credit_account->account_name, 103 t->credit_account->receiver_name); 104 trans = GNUNET_JSON_PACK ( 105 GNUNET_JSON_pack_data_auto ( 106 "wtid", 107 &t->subject.debit.wtid), 108 GNUNET_JSON_pack_string ( 109 "exchange_base_url", 110 t->subject.debit.exchange_base_url), 111 GNUNET_JSON_pack_timestamp ( 112 "timestamp", 113 t->date), 114 TALER_JSON_pack_amount ( 115 "amount", 116 &t->amount), 117 GNUNET_JSON_pack_string ( 118 "credit_account", 119 credit_payto), 120 GNUNET_JSON_pack_string ( 121 "status", 122 "success")); 123 GNUNET_assert (NULL != trans); 124 GNUNET_free (credit_payto); 125 } 126 GNUNET_assert (0 == 127 pthread_mutex_unlock (&h->big_lock)); 128 return TALER_MHD_reply_json ( 129 connection, 130 trans, 131 MHD_HTTP_OK); 132 }