LCOV - code coverage report
Current view: top level - exchangedb - pg_lookup_kyc_requirement_by_row.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 28 31 90.3 %
Date: 2025-06-05 21:03:14 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :    This file is part of TALER
       3             :    Copyright (C) 2022, 2024 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_lookup_kyc_requirement_by_row.c
      18             :  * @brief Implementation of the lookup_kyc_requirement_by_row function for Postgres
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include "taler_error_codes.h"
      23             : #include "taler_dbevents.h"
      24             : #include "taler_pq_lib.h"
      25             : #include "pg_lookup_kyc_requirement_by_row.h"
      26             : #include "pg_helper.h"
      27             : 
      28             : 
      29             : enum GNUNET_DB_QueryStatus
      30          14 : TEH_PG_lookup_kyc_requirement_by_row (
      31             :   void *cls,
      32             :   const struct TALER_NormalizedPaytoHashP *h_payto,
      33             :   bool have_pub,
      34             :   union TALER_AccountPublicKeyP *account_pub,
      35             :   bool *is_wallet,
      36             :   struct TALER_ReservePublicKeyP *reserve_pub,
      37             :   struct TALER_AccountAccessTokenP *access_token,
      38             :   uint64_t *rule_gen,
      39             :   json_t **jrules,
      40             :   bool *aml_review,
      41             :   bool *kyc_required)
      42             : {
      43          14 :   struct PostgresClosure *pg = cls;
      44          14 :   struct GNUNET_PQ_QueryParam params[] = {
      45          14 :     GNUNET_PQ_query_param_auto_from_type (h_payto),
      46             :     have_pub
      47           0 :     ? GNUNET_PQ_query_param_auto_from_type (account_pub)
      48          14 :     : GNUNET_PQ_query_param_null (),
      49             :     GNUNET_PQ_query_param_end
      50             :   };
      51             :   bool not_found;
      52          14 :   struct GNUNET_PQ_ResultSpec rs[] = {
      53          14 :     GNUNET_PQ_result_spec_allow_null (
      54             :       GNUNET_PQ_result_spec_auto_from_type ("account_pub",
      55             :                                             account_pub),
      56             :       NULL),
      57          14 :     GNUNET_PQ_result_spec_allow_null (
      58             :       GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
      59             :                                             reserve_pub),
      60             :       NULL),
      61          14 :     GNUNET_PQ_result_spec_allow_null (
      62             :       GNUNET_PQ_result_spec_auto_from_type ("access_token",
      63             :                                             access_token),
      64             :       NULL),
      65          14 :     GNUNET_PQ_result_spec_allow_null (
      66             :       /* can be NULL due to LEFT JOIN */
      67             :       TALER_PQ_result_spec_json ("jrules",
      68             :                                  jrules),
      69             :       NULL),
      70          14 :     GNUNET_PQ_result_spec_allow_null (
      71             :       /* can be NULL due to LEFT JOIN */
      72             :       GNUNET_PQ_result_spec_bool ("is_wallet",
      73             :                                   is_wallet),
      74             :       NULL),
      75          14 :     GNUNET_PQ_result_spec_allow_null (
      76             :       /* can be NULL due to LEFT JOIN */
      77             :       GNUNET_PQ_result_spec_bool ("aml_review",
      78             :                                   aml_review),
      79             :       NULL),
      80          14 :     GNUNET_PQ_result_spec_allow_null (
      81             :       GNUNET_PQ_result_spec_uint64 ("rule_gen",
      82             :                                     rule_gen),
      83             :       NULL),
      84          14 :     GNUNET_PQ_result_spec_bool ("kyc_required",
      85             :                                 kyc_required),
      86          14 :     GNUNET_PQ_result_spec_bool ("not_found",
      87             :                                 &not_found),
      88             :     GNUNET_PQ_result_spec_end
      89             :   };
      90             :   enum GNUNET_DB_QueryStatus qs;
      91             : 
      92          14 :   *jrules = NULL;
      93          14 :   *aml_review = false;
      94          14 :   *is_wallet = false;
      95          14 :   *rule_gen = 0;
      96          14 :   if (! have_pub)
      97          14 :     memset (account_pub,
      98             :             0,
      99             :             sizeof (*account_pub));
     100          14 :   memset (reserve_pub,
     101             :           0,
     102             :           sizeof (*reserve_pub));
     103          14 :   memset (access_token,
     104             :           0,
     105             :           sizeof (*access_token));
     106          14 :   PREPARE (pg,
     107             :            "lookup_kyc_requirement_by_row",
     108             :            "SELECT "
     109             :            " out_account_pub AS account_pub"
     110             :            ",out_reserve_pub AS reserve_pub"
     111             :            ",out_access_token AS access_token"
     112             :            ",out_jrules AS jrules"
     113             :            ",out_is_wallet AS is_wallet"
     114             :            ",out_not_found AS not_found"
     115             :            ",out_aml_review AS aml_review"
     116             :            ",out_kyc_required AS kyc_required"
     117             :            ",out_rule_gen AS rule_gen"
     118             :            " FROM exchange_do_lookup_kyc_requirement_by_row"
     119             :            " ($1, $2);");
     120          14 :   qs = GNUNET_PQ_eval_prepared_singleton_select (
     121             :     pg->conn,
     122             :     "lookup_kyc_requirement_by_row",
     123             :     params,
     124             :     rs);
     125          14 :   if (qs <= 0)
     126           0 :     return qs;
     127          14 :   if (not_found)
     128           0 :     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
     129          14 :   return qs;
     130             : }

Generated by: LCOV version 1.16