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 (4048B)


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