LCOV - code coverage report
Current view: top level - exchangedb - pg_get_kyc_rules.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 19 30 63.3 %
Date: 2025-06-22 12:09:43 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /*
       2             :    This file is part of TALER
       3             :    Copyright (C) 2022-2025 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_kyc_rules.c
      18             :  * @brief Implementation of the get_kyc_rules 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_kyc_rules.h"
      26             : #include "pg_helper.h"
      27             : 
      28             : 
      29             : enum GNUNET_DB_QueryStatus
      30         144 : TEH_PG_get_kyc_rules (
      31             :   void *cls,
      32             :   const struct TALER_NormalizedPaytoHashP *h_payto,
      33             :   const struct TALER_MerchantPublicKeyP *merchant_pub,
      34             :   bool *no_account_pub,
      35             :   union TALER_AccountPublicKeyP *account_pub,
      36             :   bool *no_reserve_pub,
      37             :   struct TALER_ReservePublicKeyP *reserve_pub,
      38             :   json_t **jrules)
      39             : {
      40         144 :   struct PostgresClosure *pg = cls;
      41             :   struct GNUNET_TIME_Timestamp now
      42         144 :     = GNUNET_TIME_timestamp_get ();
      43         144 :   struct GNUNET_PQ_QueryParam params[] = {
      44         144 :     GNUNET_PQ_query_param_auto_from_type (h_payto),
      45         144 :     GNUNET_PQ_query_param_timestamp (&now),
      46             :     NULL != merchant_pub
      47          66 :     ? GNUNET_PQ_query_param_auto_from_type (merchant_pub)
      48         144 :     : GNUNET_PQ_query_param_null (),
      49             :     GNUNET_PQ_query_param_end
      50             :   };
      51         144 :   struct GNUNET_PQ_ResultSpec rs[] = {
      52         144 :     GNUNET_PQ_result_spec_allow_null (
      53             :       GNUNET_PQ_result_spec_auto_from_type ("target_pub",
      54             :                                             account_pub),
      55             :       no_account_pub),
      56         144 :     GNUNET_PQ_result_spec_allow_null (
      57             :       GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
      58             :                                             reserve_pub),
      59             :       no_reserve_pub),
      60         144 :     GNUNET_PQ_result_spec_allow_null (
      61             :       TALER_PQ_result_spec_json ("jnew_rules",
      62             :                                  jrules),
      63             :       NULL),
      64             :     GNUNET_PQ_result_spec_end
      65             :   };
      66             : 
      67         144 :   *jrules = NULL;
      68         144 :   *no_account_pub = true;
      69         144 :   *no_reserve_pub = true;
      70         144 :   memset (account_pub,
      71             :           0,
      72             :           sizeof (*account_pub));
      73         144 :   memset (reserve_pub,
      74             :           0,
      75             :           sizeof (*reserve_pub));
      76         144 :   PREPARE (pg,
      77             :            "get_kyc_rules",
      78             :            "SELECT"
      79             :            "  out_target_pub AS target_pub"
      80             :            " ,out_jnew_rules AS jnew_rules"
      81             :            " ,out_reserve_pub AS reserve_pub"
      82             :            " FROM exchange_do_get_kyc_rules ($1,$2,$3);");
      83         144 :   return GNUNET_PQ_eval_prepared_singleton_select (
      84             :     pg->conn,
      85             :     "get_kyc_rules",
      86             :     params,
      87             :     rs);
      88             : }
      89             : 
      90             : 
      91             : enum GNUNET_DB_QueryStatus
      92           0 : TEH_PG_get_kyc_rules2 (
      93             :   void *cls,
      94             :   const struct TALER_NormalizedPaytoHashP *h_payto,
      95             :   json_t **jrules)
      96             : {
      97           0 :   struct PostgresClosure *pg = cls;
      98             :   struct GNUNET_TIME_Timestamp now
      99           0 :     = GNUNET_TIME_timestamp_get ();
     100           0 :   struct GNUNET_PQ_QueryParam params[] = {
     101           0 :     GNUNET_PQ_query_param_auto_from_type (h_payto),
     102           0 :     GNUNET_PQ_query_param_timestamp (&now),
     103             :     GNUNET_PQ_query_param_end
     104             :   };
     105           0 :   struct GNUNET_PQ_ResultSpec rs[] = {
     106           0 :     GNUNET_PQ_result_spec_allow_null (
     107             :       TALER_PQ_result_spec_json ("jnew_rules",
     108             :                                  jrules),
     109             :       NULL),
     110             :     GNUNET_PQ_result_spec_end
     111             :   };
     112             : 
     113           0 :   *jrules = NULL;
     114           0 :   PREPARE (pg,
     115             :            "get_kyc_rules2",
     116             :            "SELECT"
     117             :            "  jnew_rules"
     118             :            "  FROM legitimization_outcomes"
     119             :            " WHERE h_payto=$1"
     120             :            "   AND expiration_time >= $2"
     121             :            "   AND is_active"
     122             :            " ORDER BY expiration_time DESC"
     123             :            " LIMIT 1;");
     124           0 :   return GNUNET_PQ_eval_prepared_singleton_select (
     125             :     pg->conn,
     126             :     "get_kyc_rules2",
     127             :     params,
     128             :     rs);
     129             : }

Generated by: LCOV version 1.16