exchange

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

pg_persist_kyc_attributes.c (3986B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 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_persist_kyc_attributes.c
     18  * @brief Implementation of the persist_kyc_attributes function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "taler/taler_pq_lib.h"
     22 #include "taler/exchange-database/persist_kyc_attributes.h"
     23 #include "helper.h"
     24 
     25 
     26 enum GNUNET_DB_QueryStatus
     27 TALER_EXCHANGEDB_persist_kyc_attributes (
     28   struct TALER_EXCHANGEDB_PostgresContext *pg,
     29   uint64_t process_row,
     30   const struct TALER_NormalizedPaytoHashP *h_payto,
     31   const char *provider_name,
     32   const char *provider_account_id,
     33   const char *provider_legitimization_id,
     34   uint32_t birthday,
     35   struct GNUNET_TIME_Absolute expiration_time,
     36   const char *form_name,
     37   size_t enc_attributes_size,
     38   const void *enc_attributes)
     39 {
     40   struct GNUNET_TIME_Timestamp collection_time
     41     = GNUNET_TIME_timestamp_get ();
     42   struct GNUNET_TIME_Timestamp expiration
     43     = GNUNET_TIME_absolute_to_timestamp (expiration_time);
     44   struct TALER_EXCHANGEDB_KycCompletedEventP rep = {
     45     .header.size = htons (sizeof (rep)),
     46     .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
     47     .h_payto = *h_payto
     48   };
     49   char *kyc_completed_notify_s
     50     = GNUNET_PQ_get_event_notify_channel (&rep.header);
     51   struct GNUNET_PQ_QueryParam params[] = {
     52     (0 == process_row)
     53     ? GNUNET_PQ_query_param_null ()
     54     : GNUNET_PQ_query_param_uint64 (&process_row),
     55     GNUNET_PQ_query_param_auto_from_type (h_payto),
     56     GNUNET_PQ_query_param_uint32 (&birthday),
     57     GNUNET_PQ_query_param_string (provider_name),
     58     (NULL == provider_account_id)
     59     ? GNUNET_PQ_query_param_null ()
     60     : GNUNET_PQ_query_param_string (provider_account_id),
     61     (NULL == provider_legitimization_id)
     62     ? GNUNET_PQ_query_param_null ()
     63     : GNUNET_PQ_query_param_string (provider_legitimization_id),
     64     GNUNET_PQ_query_param_timestamp (&collection_time),
     65     GNUNET_PQ_query_param_absolute_time (&expiration_time),
     66     GNUNET_PQ_query_param_timestamp (&expiration),
     67     (NULL == enc_attributes)
     68     ? GNUNET_PQ_query_param_null ()
     69     : GNUNET_PQ_query_param_fixed_size (enc_attributes,
     70                                         enc_attributes_size),
     71     GNUNET_PQ_query_param_string (kyc_completed_notify_s),
     72     (NULL == form_name)
     73     ? GNUNET_PQ_query_param_null ()
     74     : GNUNET_PQ_query_param_string (form_name),
     75     GNUNET_PQ_query_param_end
     76   };
     77   bool ok;
     78   struct GNUNET_PQ_ResultSpec rs[] = {
     79     GNUNET_PQ_result_spec_bool ("out_ok",
     80                                 &ok),
     81     GNUNET_PQ_result_spec_end
     82   };
     83   enum GNUNET_DB_QueryStatus qs;
     84 
     85   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     86               "Inserting KYC attributes, wake up on %s\n",
     87               kyc_completed_notify_s);
     88   GNUNET_break (NULL != h_payto);
     89   PREPARE (pg,
     90            "persist_kyc_attributes",
     91            "SELECT "
     92            " out_ok"
     93            " FROM exchange_do_persist_kyc_attributes "
     94            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);");
     95   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     96                                                  "persist_kyc_attributes",
     97                                                  params,
     98                                                  rs);
     99   GNUNET_PQ_cleanup_query_params_closures (params);
    100   GNUNET_free (kyc_completed_notify_s);
    101   GNUNET_PQ_event_do_poll (pg->conn);
    102   return qs;
    103 }