exchange

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

pg_lookup_kyc_requirement_by_row.c (3781B)


      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 "taler/taler_pq_lib.h"
     22 #include "taler/exchange-database/lookup_kyc_requirement_by_row.h"
     23 #include "helper.h"
     24 
     25 
     26 enum GNUNET_DB_QueryStatus
     27 TALER_EXCHANGEDB_lookup_kyc_requirement_by_row (
     28   struct TALER_EXCHANGEDB_PostgresContext *pg,
     29   const struct TALER_NormalizedPaytoHashP *h_payto,
     30   const union TALER_AccountPublicKeyP *account_pub,
     31   enum GNUNET_GenericReturnValue *is_wallet,
     32   struct TALER_AccountAccessTokenP *access_token,
     33   uint64_t *rule_gen,
     34   json_t **jrules,
     35   bool *aml_review,
     36   bool *kyc_required)
     37 {
     38   struct GNUNET_PQ_QueryParam params[] = {
     39     GNUNET_PQ_query_param_auto_from_type (h_payto),
     40     GNUNET_PQ_query_param_auto_from_type (account_pub),
     41     GNUNET_PQ_query_param_end
     42   };
     43   bool bis_wallet;
     44   bool bis_wallet_unknown;
     45   bool not_found;
     46   struct GNUNET_PQ_ResultSpec rs[] = {
     47     GNUNET_PQ_result_spec_allow_null (
     48       GNUNET_PQ_result_spec_auto_from_type ("access_token",
     49                                             access_token),
     50       NULL),
     51     GNUNET_PQ_result_spec_allow_null (
     52       /* can be NULL due to LEFT JOIN */
     53       TALER_PQ_result_spec_json ("jrules",
     54                                  jrules),
     55       NULL),
     56     GNUNET_PQ_result_spec_allow_null (
     57       /* can be NULL due to LEFT JOIN */
     58       GNUNET_PQ_result_spec_bool ("is_wallet",
     59                                   &bis_wallet),
     60       &bis_wallet_unknown),
     61     GNUNET_PQ_result_spec_allow_null (
     62       /* can be NULL due to LEFT JOIN */
     63       GNUNET_PQ_result_spec_bool ("aml_review",
     64                                   aml_review),
     65       NULL),
     66     GNUNET_PQ_result_spec_allow_null (
     67       GNUNET_PQ_result_spec_uint64 ("rule_gen",
     68                                     rule_gen),
     69       NULL),
     70     GNUNET_PQ_result_spec_bool ("kyc_required",
     71                                 kyc_required),
     72     GNUNET_PQ_result_spec_bool ("not_found",
     73                                 &not_found),
     74     GNUNET_PQ_result_spec_end
     75   };
     76   enum GNUNET_DB_QueryStatus qs;
     77 
     78   *jrules = NULL;
     79   *aml_review = false;
     80   *is_wallet = GNUNET_SYSERR;
     81   *rule_gen = 0;
     82   memset (access_token,
     83           0,
     84           sizeof (*access_token));
     85   PREPARE (pg,
     86            "lookup_kyc_requirement_by_row",
     87            "SELECT "
     88            " out_access_token AS access_token"
     89            ",out_jrules::TEXT AS jrules"
     90            ",out_is_wallet AS is_wallet"
     91            ",out_not_found AS not_found"
     92            ",out_aml_review AS aml_review"
     93            ",out_kyc_required AS kyc_required"
     94            ",out_rule_gen AS rule_gen"
     95            " FROM exchange_do_lookup_kyc_requirement_by_row"
     96            " ($1, $2);");
     97   qs = GNUNET_PQ_eval_prepared_singleton_select (
     98     pg->conn,
     99     "lookup_kyc_requirement_by_row",
    100     params,
    101     rs);
    102   if (qs <= 0)
    103     return qs;
    104   if (! bis_wallet_unknown)
    105     *is_wallet = (bis_wallet) ? GNUNET_YES : GNUNET_NO;
    106   if (not_found)
    107     return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
    108   return qs;
    109 }