LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_get-private-accounts.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 78.6 % 14 11
Test Date: 2026-09-04 23:42:01 Functions: 100.0 % 2 2

            Line data    Source code
       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/iterate_accounts_by_instance.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            3 : add_account (void *cls,
      36              :              const struct TALER_MerchantPrivateKeyP *merchant_priv,
      37              :              const struct TALER_MERCHANTDB_AccountDetails *ad)
      38              : {
      39            3 :   json_t *pa = cls;
      40              : 
      41              :   (void) merchant_priv;
      42            3 :   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            3 : }
      53              : 
      54              : 
      55              : enum MHD_Result
      56            2 : 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            2 :   pa = json_array ();
      64            2 :   GNUNET_assert (NULL != pa);
      65            2 :   qs = TALER_MERCHANTDB_iterate_accounts_by_instance (
      66              :     TMH_db,
      67            2 :     hc->instance->settings.id,
      68              :     &add_account,
      69              :     pa);
      70            2 :   if (0 > qs)
      71              :   {
      72            0 :     GNUNET_break (0);
      73            0 :     json_decref (pa);
      74            0 :     return TALER_MHD_reply_with_error (connection,
      75              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      76              :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
      77              :                                        NULL);
      78              :   }
      79            2 :   return TALER_MHD_REPLY_JSON_PACK (connection,
      80              :                                     MHD_HTTP_OK,
      81              :                                     GNUNET_JSON_pack_array_steal ("accounts",
      82              :                                                                   pa));
      83              : }
      84              : 
      85              : 
      86              : /* end of taler-merchant-httpd_get-private-accounts.c */
        

Generated by: LCOV version 2.0-1