LCOV - code coverage report
Current view: top level - exchangedb - pg_get_reserve_balance.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 11 11 100.0 %
Date: 2025-06-22 12:09:43 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :    This file is part of TALER
       3             :    Copyright (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 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 exchangedb/pg_get_reserve_balance.c
      18             :  * @brief Implementation of the get_reserve_balance function for Postgres
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "taler/platform.h"
      22             : #include "taler/taler_error_codes.h"
      23             : #include "taler/taler_dbevents.h"
      24             : #include "taler/taler_pq_lib.h"
      25             : #include "pg_get_reserve_balance.h"
      26             : #include "pg_helper.h"
      27             : 
      28             : 
      29             : enum GNUNET_DB_QueryStatus
      30          43 : TEH_PG_get_reserve_balance (
      31             :   void *cls,
      32             :   const struct TALER_ReservePublicKeyP *reserve_pub,
      33             :   struct TALER_Amount *balance,
      34             :   struct TALER_FullPayto *origin_account)
      35             : {
      36          43 :   struct PostgresClosure *pg = cls;
      37          43 :   struct GNUNET_PQ_QueryParam params[] = {
      38          43 :     GNUNET_PQ_query_param_auto_from_type (reserve_pub),
      39             :     GNUNET_PQ_query_param_end
      40             :   };
      41          43 :   struct GNUNET_PQ_ResultSpec rs[] = {
      42          43 :     TALER_PQ_result_spec_amount ("current_balance",
      43          43 :                                  pg->currency,
      44             :                                  balance),
      45          43 :     GNUNET_PQ_result_spec_allow_null (
      46             :       GNUNET_PQ_result_spec_string ("payto_uri",
      47             :                                     &origin_account->full_payto),
      48             :       NULL),
      49             :     GNUNET_PQ_result_spec_end
      50             :   };
      51             : 
      52          43 :   origin_account->full_payto = NULL;
      53          43 :   PREPARE (pg,
      54             :            "get_reserve_balance",
      55             :            "SELECT"
      56             :            "  r.current_balance"
      57             :            " ,wt.payto_uri"
      58             :            " FROM reserves r"
      59             :            " LEFT JOIN reserves_in ri"
      60             :            "   USING (reserve_pub)"
      61             :            " LEFT JOIN wire_targets wt"
      62             :            "   ON (wt.wire_target_h_payto = ri.wire_source_h_payto)"
      63             :            " WHERE r.reserve_pub=$1"
      64             :            " LIMIT 1;");
      65          43 :   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
      66             :                                                    "get_reserve_balance",
      67             :                                                    params,
      68             :                                                    rs);
      69             : }

Generated by: LCOV version 1.16