exchange

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

insert_aml_decision.c (7119B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2022, 2023, 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/insert_aml_decision.c
     18  * @brief Implementation of the insert_aml_decision function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "taler/taler_pq_lib.h"
     22 #include "exchange-database/insert_aml_decision.h"
     23 #include "helper.h"
     24 #include <gnunet/gnunet_pq_lib.h>
     25 
     26 
     27 enum GNUNET_DB_QueryStatus
     28 TALER_EXCHANGEDB_insert_aml_decision (
     29   struct TALER_EXCHANGEDB_PostgresContext *pg,
     30   const struct TALER_FullPayto payto_uri,
     31   const struct TALER_NormalizedPaytoHashP *h_payto,
     32   struct GNUNET_TIME_Timestamp decision_time,
     33   struct GNUNET_TIME_Timestamp expiration_time,
     34   const json_t *properties,
     35   const json_t *new_rules,
     36   bool to_investigate,
     37   const char *new_measure_name,
     38   const json_t *jmeasures,
     39   const char *justification,
     40   const struct TALER_AmlOfficerPublicKeyP *decider_pub,
     41   const struct TALER_AmlOfficerSignatureP *decider_sig,
     42   size_t num_events,
     43   const char *events[static num_events],
     44   const char *form_name,
     45   size_t enc_attributes_size,
     46   const void *enc_attributes,
     47   struct GNUNET_HashCode *attributes_hash,
     48   struct GNUNET_TIME_Timestamp attributes_expiration_time,
     49   bool *invalid_officer,
     50   bool *unknown_account,
     51   struct GNUNET_TIME_Timestamp *last_date,
     52   uint64_t *legitimization_measure_serial_id,
     53   bool *is_wallet)
     54 {
     55   struct TALER_EXCHANGEDB_KycCompletedEventP rep = {
     56     .header.size = htons (sizeof (rep)),
     57     .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
     58     .h_payto = *h_payto
     59   };
     60   struct TALER_FullPaytoHashP h_full_payto;
     61   char *notify_s
     62     = GNUNET_PQ_get_event_notify_channel (&rep.header);
     63   bool account_unknown;
     64   struct GNUNET_PQ_QueryParam params[] = {
     65     /* $1: in_payto_uri */
     66     NULL == payto_uri.full_payto
     67       ? GNUNET_PQ_query_param_null ()
     68       : GNUNET_PQ_query_param_string (payto_uri.full_payto),
     69     /* $2: in_h_normalized_payto */
     70     GNUNET_PQ_query_param_auto_from_type (h_payto),
     71     /* $3: in_h_full_payto */
     72     NULL == payto_uri.full_payto
     73       ? GNUNET_PQ_query_param_null ()
     74       : GNUNET_PQ_query_param_auto_from_type (&h_full_payto),
     75     /* $4: in_decision_time */
     76     GNUNET_PQ_query_param_timestamp (&decision_time),
     77     /* $5: in_expiration_time*/
     78     GNUNET_PQ_query_param_timestamp (&expiration_time),
     79     /* $6: in_properties */
     80     NULL != properties
     81       ? TALER_PQ_query_param_json (properties)
     82       : GNUNET_PQ_query_param_null (),
     83     /* $7: in_kyc_attributes_enc */
     84     NULL != enc_attributes
     85       ? GNUNET_PQ_query_param_fixed_size (enc_attributes,
     86                                           enc_attributes_size)
     87       : GNUNET_PQ_query_param_null (),
     88     /* $8: in_kyc_attributes_hash */
     89     NULL != attributes_hash
     90         ? GNUNET_PQ_query_param_auto_from_type (attributes_hash)
     91         : GNUNET_PQ_query_param_null (),
     92     /* $9: in_kyc_attributes_expiration */
     93     GNUNET_PQ_query_param_timestamp (&attributes_expiration_time),
     94     /* $10: in_new_rules */
     95     TALER_PQ_query_param_json (new_rules),
     96     /* $11: in_to_investigate */
     97     GNUNET_PQ_query_param_bool (to_investigate),
     98     /* $12: in_new_measure_name */
     99     NULL != new_measure_name
    100       ? GNUNET_PQ_query_param_string (new_measure_name)
    101       : GNUNET_PQ_query_param_null (),
    102     /* $13: in_jmeasures */
    103     NULL != jmeasures
    104       ? TALER_PQ_query_param_json (jmeasures)
    105       : GNUNET_PQ_query_param_null (),
    106     /* $14: in_justification */
    107     NULL != justification
    108       ? GNUNET_PQ_query_param_string (justification)
    109       : GNUNET_PQ_query_param_null (),
    110     /* $15: in_decider_pub */
    111     NULL != decider_pub
    112       ? GNUNET_PQ_query_param_auto_from_type (decider_pub)
    113       : GNUNET_PQ_query_param_null (),
    114     /* $16: in_decider_sig */
    115     NULL != decider_sig
    116       ? GNUNET_PQ_query_param_auto_from_type (decider_sig)
    117       : GNUNET_PQ_query_param_null (),
    118     /* $17: in_notify_s*/
    119     GNUNET_PQ_query_param_string (notify_s),
    120     /* $18: ina_events */
    121     GNUNET_PQ_query_param_array_ptrs_string (num_events,
    122                                              events,
    123                                              pg->conn),
    124     (NULL == form_name)
    125     ? GNUNET_PQ_query_param_null ()
    126     : GNUNET_PQ_query_param_string (form_name),
    127     GNUNET_PQ_query_param_end
    128   };
    129   struct GNUNET_PQ_ResultSpec rs[] = {
    130     GNUNET_PQ_result_spec_bool ("out_invalid_officer",
    131                                 invalid_officer),
    132     GNUNET_PQ_result_spec_bool ("out_account_unknown",
    133                                 unknown_account),
    134     GNUNET_PQ_result_spec_timestamp ("out_last_date",
    135                                      last_date),
    136     GNUNET_PQ_result_spec_uint64 ("out_legitimization_measure_serial_id",
    137                                   legitimization_measure_serial_id),
    138     GNUNET_PQ_result_spec_allow_null (
    139       GNUNET_PQ_result_spec_bool ("out_is_wallet",
    140                                   is_wallet),
    141       &account_unknown),
    142     GNUNET_PQ_result_spec_end
    143   };
    144   enum GNUNET_DB_QueryStatus qs;
    145 
    146   *is_wallet = false;
    147   GNUNET_assert ( ( (NULL == decider_pub) &&
    148                     (NULL == decider_sig) &&
    149                     (NULL == justification) ) ||
    150                   ( (NULL != decider_pub) &&
    151                     (NULL != decider_sig) &&
    152                     (NULL != justification) ) );
    153 
    154   if (NULL != payto_uri.full_payto)
    155     TALER_full_payto_hash (payto_uri,
    156                            &h_full_payto);
    157   PREPARE (pg,
    158            "do_insert_aml_decision",
    159            "SELECT"
    160            " out_invalid_officer"
    161            ",out_account_unknown"
    162            ",out_last_date"
    163            ",out_legitimization_measure_serial_id"
    164            ",out_is_wallet"
    165            " FROM exchange_do_insert_aml_decision"
    166            "($1,$2,$3,$4,$5,$6::TEXT::JSONB,$7,$8,$9,$10::TEXT::JSONB"
    167            ",$11,$12,$13::TEXT::JSONB,$14,$15,$16,$17,$18,$19);");
    168   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
    169               "Inserting LEGI OUTCOME from AML decision with notification on %s\n",
    170               notify_s);
    171   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
    172                                                  "do_insert_aml_decision",
    173                                                  params,
    174                                                  rs);
    175   GNUNET_PQ_cleanup_query_params_closures (params);
    176   GNUNET_free (notify_s);
    177   GNUNET_PQ_event_do_poll (pg->conn);
    178   if (qs <= 0)
    179     return qs;
    180   if (account_unknown)
    181   {
    182     GNUNET_assert ((*invalid_officer) || (*unknown_account));
    183   }
    184   return qs;
    185 }