exchange

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

iterate_aml_staff_above_serial_id.c (5250B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2026 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 src/exchangedb/iterate_aml_staff_above_serial_id.c
     18  * @brief Implementation of the iterate_aml_staff_above_serial_id function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "taler/taler_pq_lib.h"
     22 #include "helper.h"
     23 #include "exchange-database/iterate_aml_staff_above_serial_id.h"
     24 
     25 
     26 /**
     27  * Closure for #aml_staff_cb().
     28  */
     29 struct AmlStaffContext
     30 {
     31   /**
     32    * Function to call for each status change.
     33    */
     34   TALER_EXCHANGEDB_AmlStaffCallback cb;
     35 
     36   /**
     37    * Closure for @e cb.
     38    */
     39   void *cb_cls;
     40 
     41   /**
     42    * Query status to return.
     43    */
     44   enum GNUNET_DB_QueryStatus qs;
     45 };
     46 
     47 
     48 /**
     49  * Helper function for
     50  * #TALER_EXCHANGEDB_iterate_aml_staff_above_serial_id().
     51  * To be called with the results of a SELECT statement
     52  * that has returned @a num_results results.
     53  *
     54  * @param cls closure of type `struct AmlStaffContext *`
     55  * @param result the postgres result
     56  * @param num_results the number of results in @a result
     57  */
     58 static void
     59 aml_staff_cb (void *cls,
     60               PGresult *result,
     61               unsigned int num_results)
     62 {
     63   struct AmlStaffContext *asc = cls;
     64 
     65   for (unsigned int i = 0; i < num_results; i++)
     66   {
     67     uint64_t rowid;
     68     struct TALER_AmlOfficerPublicKeyP decider_pub;
     69     struct TALER_MasterSignatureP master_sig;
     70     char *decider_name = NULL;
     71     bool is_active;
     72     bool read_only;
     73     struct GNUNET_TIME_Timestamp last_change;
     74     bool no_master_sig;
     75     struct GNUNET_PQ_ResultSpec rs[] = {
     76       GNUNET_PQ_result_spec_uint64 ("aml_staff_uuid",
     77                                     &rowid),
     78       GNUNET_PQ_result_spec_auto_from_type ("decider_pub",
     79                                             &decider_pub),
     80       /* the column has no NOT NULL constraint, and a row without a
     81          signature is exactly what the auditor has to complain about */
     82       GNUNET_PQ_result_spec_allow_null (
     83         GNUNET_PQ_result_spec_auto_from_type ("master_sig",
     84                                               &master_sig),
     85         &no_master_sig),
     86       GNUNET_PQ_result_spec_string ("decider_name",
     87                                     &decider_name),
     88       GNUNET_PQ_result_spec_bool ("is_active",
     89                                   &is_active),
     90       GNUNET_PQ_result_spec_bool ("read_only",
     91                                   &read_only),
     92       GNUNET_PQ_result_spec_timestamp ("last_change",
     93                                        &last_change),
     94       GNUNET_PQ_result_spec_end
     95     };
     96     enum GNUNET_GenericReturnValue rval;
     97 
     98     if (GNUNET_OK !=
     99         GNUNET_PQ_extract_result (result,
    100                                   rs,
    101                                   i))
    102     {
    103       GNUNET_break (0);
    104       asc->qs = GNUNET_DB_STATUS_HARD_ERROR;
    105       return;
    106     }
    107     asc->qs = i + 1;
    108     rval = asc->cb (asc->cb_cls,
    109                     rowid,
    110                     &decider_pub,
    111                     no_master_sig ? NULL : &master_sig,
    112                     decider_name,
    113                     is_active,
    114                     read_only,
    115                     last_change);
    116     GNUNET_PQ_cleanup_result (rs);
    117     if (GNUNET_OK != rval)
    118       break;
    119   }
    120 }
    121 
    122 
    123 enum GNUNET_DB_QueryStatus
    124 TALER_EXCHANGEDB_iterate_aml_staff_above_serial_id (
    125   struct TALER_EXCHANGEDB_PostgresContext *pg,
    126   uint64_t serial_id,
    127   TALER_EXCHANGEDB_AmlStaffCallback cb,
    128   TALER_EXCHANGEDB_AML_STAFF_RESULT_CLOSURE *cb_cls)
    129 {
    130   struct GNUNET_PQ_QueryParam params[] = {
    131     GNUNET_PQ_query_param_uint64 (&serial_id),
    132     GNUNET_PQ_query_param_end
    133   };
    134   struct AmlStaffContext asc = {
    135     .cb = cb,
    136     .cb_cls = cb_cls
    137   };
    138   enum GNUNET_DB_QueryStatus qs;
    139 
    140   /* Ordered by the serial ID and not by last_change: the caller is told
    141      about the changes in the order the exchange recorded them, which is
    142      what makes a status backdated after the fact stand out. */
    143   PREPARE (pg,
    144            "iterate_aml_staff_above_serial_id",
    145            "SELECT"
    146            " aml_staff_uuid"
    147            ",decider_pub"
    148            ",master_sig"
    149            ",decider_name"
    150            ",is_active"
    151            ",read_only"
    152            ",last_change"
    153            " FROM aml_staff"
    154            " WHERE aml_staff_uuid>=$1"
    155            " ORDER BY aml_staff_uuid ASC;");
    156   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
    157                                              "iterate_aml_staff_above_serial_id",
    158                                              params,
    159                                              &aml_staff_cb,
    160                                              &asc);
    161   if (qs > 0)
    162     return asc.qs;
    163   GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
    164   return qs;
    165 }