taler-merchant-httpd_get-private-accounts.c (3018B)
1 /* 2 This file is part of TALER 3 (C) 2022 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero 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 src/backend/taler-merchant-httpd_get-private-accounts.c 18 * @brief implement GET /accounts 19 * @author Christian Grothoff 20 */ 21 #include "platform.h" 22 #include "taler-merchant-httpd_get-private-accounts.h" 23 #include <taler/taler_json_lib.h> 24 #include "merchant-database/select_accounts.h" 25 26 27 /** 28 * Add account details to our JSON array. 29 * 30 * @param cls a `json_t *` JSON array to build 31 * @param merchant_priv private key of the merchant instance 32 * @param ad details about the account 33 */ 34 static void 35 add_account (void *cls, 36 const struct TALER_MerchantPrivateKeyP *merchant_priv, 37 const struct TALER_MERCHANTDB_AccountDetails *ad) 38 { 39 json_t *pa = cls; 40 41 (void) merchant_priv; 42 GNUNET_assert (0 == 43 json_array_append_new ( 44 pa, 45 GNUNET_JSON_PACK ( 46 GNUNET_JSON_pack_bool ("active", 47 ad->active), 48 TALER_JSON_pack_full_payto ("payto_uri", 49 ad->payto_uri), 50 GNUNET_JSON_pack_data_auto ("h_wire", 51 &ad->h_wire)))); 52 } 53 54 55 enum MHD_Result 56 TMH_private_get_accounts (const struct TMH_RequestHandler *rh, 57 struct MHD_Connection *connection, 58 struct TMH_HandlerContext *hc) 59 { 60 json_t *pa; 61 enum GNUNET_DB_QueryStatus qs; 62 63 pa = json_array (); 64 GNUNET_assert (NULL != pa); 65 qs = TALER_MERCHANTDB_select_accounts (TMH_db, 66 hc->instance->settings.id, 67 &add_account, 68 pa); 69 if (0 > qs) 70 { 71 GNUNET_break (0); 72 json_decref (pa); 73 return TALER_MHD_reply_with_error (connection, 74 MHD_HTTP_INTERNAL_SERVER_ERROR, 75 TALER_EC_GENERIC_DB_FETCH_FAILED, 76 NULL); 77 } 78 return TALER_MHD_REPLY_JSON_PACK (connection, 79 MHD_HTTP_OK, 80 GNUNET_JSON_pack_array_steal ("accounts", 81 pa)); 82 } 83 84 85 /* end of taler-merchant-httpd_get-private-accounts.c */