LCOV - code coverage report
Current view: top level - exchangedb - get_open_legitimization_measure.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 8 8
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) 2026 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 src/exchangedb/get_open_legitimization_measure.c
      18              :  * @brief Implementation of the get_open_legitimization_measure function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/taler_pq_lib.h"
      22              : #include "helper.h"
      23              : #include "exchange-database/get_open_legitimization_measure.h"
      24              : 
      25              : 
      26              : enum GNUNET_DB_QueryStatus
      27            3 : TALER_EXCHANGEDB_get_open_legitimization_measure (
      28              :   struct TALER_EXCHANGEDB_PostgresContext *pg,
      29              :   const struct TALER_NormalizedPaytoHashP *h_payto,
      30              :   uint64_t *legitimization_measure_serial_id,
      31              :   struct GNUNET_TIME_Absolute *start_time)
      32              : {
      33            3 :   struct GNUNET_PQ_QueryParam params[] = {
      34            3 :     GNUNET_PQ_query_param_auto_from_type (h_payto),
      35              :     GNUNET_PQ_query_param_end
      36              :   };
      37            3 :   struct GNUNET_PQ_ResultSpec rs[] = {
      38            3 :     GNUNET_PQ_result_spec_uint64 ("legitimization_measure_serial_id",
      39              :                                   legitimization_measure_serial_id),
      40            3 :     GNUNET_PQ_result_spec_absolute_time ("start_time",
      41              :                                          start_time),
      42              :     GNUNET_PQ_result_spec_end
      43              :   };
      44              : 
      45              :   /* `legitimization_measures' is keyed by the account's access token, which
      46              :      lives in `kyc_targets', while `legitimization_processes' and
      47              :      `legitimization_outcomes' are keyed by the normalized payto hash --
      48              :      hence the join.
      49              : 
      50              :      The second of slack on `start_time' is the same one as in
      51              :      iterate_legitimization_outcomes_above_serial_id.c: `decision_time' is a
      52              :      rounded timestamp while `start_time' is not, so an honest process can
      53              :      start up to a second "after" the decision it fed.  Subtracting from
      54              :      start_time rather than adding to decision_time keeps a decision_time of
      55              :      "forever" from overflowing. */
      56            3 :   PREPARE (pg,
      57              :            "get_open_legitimization_measure",
      58              :            "SELECT"
      59              :            " lm.legitimization_measure_serial_id"
      60              :            ",lm.start_time"
      61              :            " FROM legitimization_measures lm"
      62              :            " JOIN kyc_targets kt"
      63              :            "   USING (access_token)"
      64              :            " WHERE kt.h_normalized_payto=$1"
      65              :            "   AND NOT EXISTS ("
      66              :            "     SELECT 1"
      67              :            "       FROM legitimization_processes lp"
      68              :            "      WHERE lp.legitimization_measure_serial_id"
      69              :            "            =lm.legitimization_measure_serial_id"
      70              :            "        AND EXISTS ("
      71              :            "          SELECT 1"
      72              :            "            FROM legitimization_outcomes lo"
      73              :            "           WHERE lo.h_payto=kt.h_normalized_payto"
      74              :            "             AND lo.decision_time>=lp.start_time-1000000))"
      75              :            " ORDER BY lm.legitimization_measure_serial_id ASC"
      76              :            " LIMIT 1;");
      77            3 :   return GNUNET_PQ_eval_prepared_singleton_select (
      78              :     pg->conn,
      79              :     "get_open_legitimization_measure",
      80              :     params,
      81              :     rs);
      82              : }
        

Generated by: LCOV version 2.0-1