taler-auditor-httpd_denomination-pending-get.c (4005B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2024 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU 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 #include "taler/platform.h" 17 #include <gnunet/gnunet_util_lib.h> 18 #include <gnunet/gnunet_json_lib.h> 19 #include <jansson.h> 20 #include <microhttpd.h> 21 #include <pthread.h> 22 #include "taler/taler_json_lib.h" 23 #include "taler/taler_mhd_lib.h" 24 #include "taler-auditor-httpd.h" 25 #include "taler-auditor-httpd_denomination-pending-get.h" 26 27 /** 28 * Add denomination-pending to the list. 29 * 30 * @param[in,out] cls a `json_t *` array to extend 31 * @param serial_id location of the @a dc in the database 32 * @param dc struct of inconsistencies 33 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating 34 */ 35 static enum GNUNET_GenericReturnValue 36 process_denomination_pending ( 37 void *cls, 38 uint64_t serial_id, 39 const struct TALER_AUDITORDB_DenominationPending *dc) 40 { 41 json_t *list = cls; 42 json_t *obj; 43 44 obj = GNUNET_JSON_PACK ( 45 GNUNET_JSON_pack_data_auto ("denom_pub_hash", 46 &dc->denom_pub_hash), 47 TALER_JSON_pack_amount ("denom_balance", 48 &dc->denom_balance), 49 TALER_JSON_pack_amount ("denom_loss", 50 &dc->denom_loss), 51 GNUNET_JSON_pack_int64 ("num_issued", 52 dc->num_issued), 53 TALER_JSON_pack_amount ("denom_risk", 54 &dc->denom_risk), 55 TALER_JSON_pack_amount ("recoup_loss", 56 &dc->recoup_loss) 57 ); 58 GNUNET_break (0 == 59 json_array_append_new (list, 60 obj)); 61 return GNUNET_OK; 62 } 63 64 65 MHD_RESULT 66 TAH_DENOMINATION_PENDING_handler_get ( 67 struct TAH_RequestHandler *rh, 68 struct MHD_Connection *connection, 69 void **connection_cls, 70 const char *upload_data, 71 size_t *upload_data_size, 72 const char *const args[]) 73 { 74 json_t *ja; 75 enum GNUNET_DB_QueryStatus qs; 76 int64_t limit = -20; 77 uint64_t offset; 78 79 (void) rh; 80 (void) connection_cls; 81 (void) upload_data; 82 (void) upload_data_size; 83 if (GNUNET_SYSERR == 84 TAH_plugin->preflight (TAH_plugin->cls)) 85 { 86 GNUNET_break (0); 87 return TALER_MHD_reply_with_error (connection, 88 MHD_HTTP_INTERNAL_SERVER_ERROR, 89 TALER_EC_GENERIC_DB_SETUP_FAILED, 90 NULL); 91 } 92 TALER_MHD_parse_request_snumber (connection, 93 "limit", 94 &limit); 95 if (limit < 0) 96 offset = INT64_MAX; 97 else 98 offset = 0; 99 TALER_MHD_parse_request_number (connection, 100 "offset", 101 &offset); 102 ja = json_array (); 103 GNUNET_break (NULL != ja); 104 qs = TAH_plugin->get_denomination_pending ( 105 TAH_plugin->cls, 106 limit, 107 offset, 108 &process_denomination_pending, 109 ja); 110 111 if (0 > qs) 112 { 113 GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); 114 json_decref (ja); 115 TALER_LOG_WARNING ( 116 "Failed to handle GET /denomination-pending"); 117 return TALER_MHD_reply_with_error ( 118 connection, 119 MHD_HTTP_INTERNAL_SERVER_ERROR, 120 TALER_EC_GENERIC_DB_FETCH_FAILED, 121 "get_denomination_pending"); 122 } 123 return TALER_MHD_REPLY_JSON_PACK ( 124 connection, 125 MHD_HTTP_OK, 126 GNUNET_JSON_pack_array_steal ("denomination_pending", 127 ja)); 128 }