LCOV - code coverage report
Current view: top level - exchangedb - get_ready_deposit.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 16 16
Test Date: 2026-09-11 18:55:36 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2022, 2023 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/get_ready_deposit.c
      18              :  * @brief Implementation of the get_ready_deposit function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/taler_pq_lib.h"
      22              : #include "exchange-database/get_ready_deposit.h"
      23              : #include "helper.h"
      24              : 
      25              : 
      26              : enum GNUNET_DB_QueryStatus
      27          103 : TALER_EXCHANGEDB_get_ready_deposit (struct TALER_EXCHANGEDB_PostgresContext *pg,
      28              :                                     uint64_t start_shard_row,
      29              :                                     uint64_t end_shard_row,
      30              :                                     struct TALER_MerchantPublicKeyP *
      31              :                                     merchant_pub,
      32              :                                     struct TALER_FullPayto *payto_uri,
      33              :                                     char **extra_wire_subject_metadata)
      34              : {
      35              :   struct GNUNET_TIME_Absolute now
      36          103 :     = GNUNET_TIME_absolute_get ();
      37              :   /* Must match the cut-off used by TALER_EXCHANGEDB_do_aggregate()
      38              :      exactly: a deposit whose refund deadline has not passed by that
      39              :      cut-off cannot be aggregated yet, so reporting it as "ready"
      40              :      would make the aggregator spin on it without making progress. */
      41              :   struct GNUNET_TIME_Absolute refund_cutoff
      42          103 :     = GNUNET_TIME_absolute_round_down (now,
      43              :                                        pg->aggregator_shift);
      44          103 :   struct GNUNET_PQ_QueryParam params[] = {
      45          103 :     GNUNET_PQ_query_param_absolute_time (&now),
      46          103 :     GNUNET_PQ_query_param_absolute_time (&refund_cutoff),
      47          103 :     GNUNET_PQ_query_param_uint64 (&start_shard_row),
      48          103 :     GNUNET_PQ_query_param_uint64 (&end_shard_row),
      49              :     GNUNET_PQ_query_param_end
      50              :   };
      51          103 :   struct GNUNET_PQ_ResultSpec rs[] = {
      52          103 :     GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
      53              :                                           merchant_pub),
      54          103 :     GNUNET_PQ_result_spec_string ("payto_uri",
      55              :                                   &payto_uri->full_payto),
      56          103 :     GNUNET_PQ_result_spec_allow_null (
      57              :       GNUNET_PQ_result_spec_string ("extra_wire_subject_metadata",
      58              :                                     extra_wire_subject_metadata),
      59              :       NULL),
      60              :     GNUNET_PQ_result_spec_end
      61              :   };
      62          103 :   const char *query = "deposits_get_ready";
      63              : 
      64          103 :   *extra_wire_subject_metadata = NULL;
      65          103 :   PREPARE (pg,
      66              :            query,
      67              :            "SELECT"
      68              :            " wts.payto_uri"
      69              :            ",bdep.merchant_pub"
      70              :            ",bdep.extra_wire_subject_metadata"
      71              :            " FROM batch_deposits bdep"
      72              :            " JOIN wire_targets wts"
      73              :            "   USING (wire_target_h_payto)"
      74              :            " WHERE NOT (bdep.done OR bdep.policy_blocked)"
      75              :            "   AND bdep.wire_deadline<=$1"
      76              :            "   AND bdep.refund_deadline<$2" /* see do_aggregate.c */
      77              :            "   AND bdep.shard >= $3"
      78              :            "   AND bdep.shard <= $4"
      79              :            " ORDER BY "
      80              :            "   bdep.wire_deadline ASC"
      81              :            "  ,bdep.shard ASC"
      82              :            " LIMIT 1;");
      83          103 :   return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
      84              :                                                    query,
      85              :                                                    params,
      86              :                                                    rs);
      87              : }
        

Generated by: LCOV version 2.0-1