exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

get_kyc_rules.c (3931B)


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