exchange

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

insert_records_by_table.c (82409B)


      1 /*
      2    This file is part of GNUnet
      3    Copyright (C) 2020-2025 Taler Systems SA
      4 
      5    GNUnet is free software: you can redistribute it and/or modify it
      6    under the terms of the GNU Affero General Public License as published
      7    by the Free Software Foundation, either version 3 of the License,
      8    or (at your option) any later version.
      9 
     10    GNUnet is distributed in the hope that it will be useful, but
     11    WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13    Affero General Public License for more details.
     14 
     15    You should have received a copy of the GNU Affero General Public License
     16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18      SPDX-License-Identifier: AGPL3.0-or-later
     19  */
     20 /**
     21  * @file exchangedb/insert_records_by_table.c
     22  * @brief replicate_records_by_table implementation
     23  * @author Christian Grothoff
     24  * @author Özgür Kesim
     25  */
     26 #include "taler/taler_error_codes.h"
     27 #include "taler/taler_dbevents.h"
     28 #include "taler/taler_pq_lib.h"
     29 #include "exchange-database/insert_records_by_table.h"
     30 #include "helper.h"
     31 #include <gnunet/gnunet_pq_lib.h>
     32 
     33 
     34 /**
     35  * Signature of helper functions of #TALER_EXCHANGEDB_insert_records_by_table().
     36  *
     37  * @param pg plugin context
     38  * @param td record to insert
     39  * @return transaction status code
     40  */
     41 typedef enum GNUNET_DB_QueryStatus
     42 (*InsertRecordCallback)(struct TALER_EXCHANGEDB_PostgresContext *pg,
     43                         const struct TALER_EXCHANGEDB_TableData *td);
     44 
     45 
     46 /**
     47  * Function called with denominations records to insert into table.
     48  *
     49  * @param pg plugin context
     50  * @param td record to insert
     51  */
     52 static enum GNUNET_DB_QueryStatus
     53 irbt_cb_table_denominations (struct TALER_EXCHANGEDB_PostgresContext *pg,
     54                              const struct TALER_EXCHANGEDB_TableData *td)
     55 {
     56   struct TALER_DenominationHashP denom_hash;
     57   struct GNUNET_PQ_QueryParam params[] = {
     58     GNUNET_PQ_query_param_uint64 (&td->serial),
     59     GNUNET_PQ_query_param_auto_from_type (&denom_hash),
     60     GNUNET_PQ_query_param_uint32 (
     61       &td->details.denominations.denom_type),
     62     GNUNET_PQ_query_param_uint32 (
     63       &td->details.denominations.age_mask),
     64     TALER_PQ_query_param_denom_pub (
     65       &td->details.denominations.denom_pub),
     66     GNUNET_PQ_query_param_auto_from_type (
     67       &td->details.denominations.master_sig),
     68     GNUNET_PQ_query_param_timestamp (
     69       &td->details.denominations.valid_from),
     70     GNUNET_PQ_query_param_timestamp (
     71       &td->details.denominations.expire_withdraw),
     72     GNUNET_PQ_query_param_timestamp (
     73       &td->details.denominations.expire_deposit),
     74     GNUNET_PQ_query_param_timestamp (
     75       &td->details.denominations.expire_legal),
     76     TALER_PQ_query_param_amount (
     77       pg->conn,
     78       &td->details.denominations.coin),
     79     TALER_PQ_query_param_amount (
     80       pg->conn,
     81       &td->details.denominations.fees.withdraw),
     82     TALER_PQ_query_param_amount (
     83       pg->conn,
     84       &td->details.denominations.fees.deposit),
     85     TALER_PQ_query_param_amount (
     86       pg->conn,
     87       &td->details.denominations.fees.refresh),
     88     TALER_PQ_query_param_amount (
     89       pg->conn,
     90       &td->details.denominations.fees.refund),
     91     GNUNET_PQ_query_param_end
     92   };
     93 
     94   PREPARE (pg,
     95            "insert_records_by_table_into_table_denominations",
     96            "INSERT INTO denominations"
     97            "(denominations_serial"
     98            ",denom_pub_hash"
     99            ",denom_type"
    100            ",age_mask"
    101            ",denom_pub"
    102            ",master_sig"
    103            ",valid_from"
    104            ",expire_withdraw"
    105            ",expire_deposit"
    106            ",expire_legal"
    107            ",coin"
    108            ",fee_withdraw"
    109            ",fee_deposit"
    110            ",fee_refresh"
    111            ",fee_refund"
    112            ") VALUES "
    113            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
    114            " $11, $12, $13, $14, $15);");
    115 
    116   TALER_denom_pub_hash (
    117     &td->details.denominations.denom_pub,
    118     &denom_hash);
    119 
    120   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    121                                              "insert_records_by_table_into_table_denominations",
    122                                              params);
    123 }
    124 
    125 
    126 /**
    127  * Function called with denomination_revocations records to insert into table.
    128  *
    129  * @param pg plugin context
    130  * @param td record to insert
    131  */
    132 static enum GNUNET_DB_QueryStatus
    133 irbt_cb_table_denomination_revocations (
    134   struct TALER_EXCHANGEDB_PostgresContext *pg,
    135   const struct TALER_EXCHANGEDB_TableData *td)
    136 {
    137   struct GNUNET_PQ_QueryParam params[] = {
    138     GNUNET_PQ_query_param_uint64 (&td->serial),
    139     GNUNET_PQ_query_param_auto_from_type (
    140       &td->details.denomination_revocations.master_sig),
    141     GNUNET_PQ_query_param_uint64 (
    142       &td->details.denomination_revocations.denominations_serial),
    143     GNUNET_PQ_query_param_end
    144   };
    145 
    146   PREPARE (pg,
    147            "insert_records_by_table_into_table_denomination_revocations",
    148            "INSERT INTO denomination_revocations"
    149            "(denom_revocations_serial_id"
    150            ",master_sig"
    151            ",denominations_serial"
    152            ") VALUES "
    153            "($1, $2, $3);");
    154   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    155                                              "insert_records_by_table_into_table_denomination_revocations",
    156                                              params);
    157 }
    158 
    159 
    160 /**
    161  * Function called with wire target records to insert into table.
    162  *
    163  * @param pg plugin context
    164  * @param td record to insert
    165  */
    166 static enum GNUNET_DB_QueryStatus
    167 irbt_cb_table_wire_targets (struct TALER_EXCHANGEDB_PostgresContext *pg,
    168                             const struct TALER_EXCHANGEDB_TableData *td)
    169 {
    170   struct TALER_NormalizedPaytoHashP normalized_payto_hash;
    171   struct TALER_FullPaytoHashP full_payto_hash;
    172   struct GNUNET_PQ_QueryParam params[] = {
    173     GNUNET_PQ_query_param_uint64 (&td->serial),
    174     GNUNET_PQ_query_param_auto_from_type (&full_payto_hash),
    175     GNUNET_PQ_query_param_auto_from_type (&normalized_payto_hash),
    176     GNUNET_PQ_query_param_string (
    177       td->details.wire_targets.full_payto_uri.full_payto),
    178     GNUNET_PQ_query_param_end
    179   };
    180 
    181   TALER_full_payto_hash (
    182     td->details.wire_targets.full_payto_uri,
    183     &full_payto_hash);
    184   TALER_full_payto_normalize_and_hash (
    185     td->details.wire_targets.full_payto_uri,
    186     &normalized_payto_hash);
    187   PREPARE (pg,
    188            "insert_records_by_table_into_table_wire_targets",
    189            "INSERT INTO wire_targets"
    190            "(wire_target_serial_id"
    191            ",wire_target_h_payto"
    192            ",h_normalized_payto"
    193            ",payto_uri"
    194            ") VALUES "
    195            "($1, $2, $3, $4);");
    196   return GNUNET_PQ_eval_prepared_non_select (
    197     pg->conn,
    198     "insert_records_by_table_into_table_wire_targets",
    199     params);
    200 }
    201 
    202 
    203 /**
    204  * Function called with kyc target records to insert into table.
    205  *
    206  * @param pg plugin context
    207  * @param td record to insert
    208  */
    209 static enum GNUNET_DB_QueryStatus
    210 irbt_cb_table_kyc_targets (struct TALER_EXCHANGEDB_PostgresContext *pg,
    211                            const struct TALER_EXCHANGEDB_TableData *td)
    212 {
    213   struct GNUNET_PQ_QueryParam params[] = {
    214     GNUNET_PQ_query_param_uint64 (&td->serial),
    215     GNUNET_PQ_query_param_auto_from_type (
    216       &td->details.kyc_targets.h_normalized_payto),
    217     GNUNET_PQ_query_param_auto_from_type (
    218       &td->details.kyc_targets.access_token),
    219     td->details.kyc_targets.no_account
    220     ? GNUNET_PQ_query_param_null ()
    221     : GNUNET_PQ_query_param_auto_from_type (
    222       &td->details.kyc_targets.target_pub),
    223     GNUNET_PQ_query_param_bool (
    224       td->details.kyc_targets.is_wallet),
    225     GNUNET_PQ_query_param_end
    226   };
    227 
    228   PREPARE (pg,
    229            "insert_records_by_table_into_table_kyc_targets",
    230            "INSERT INTO kyc_targets"
    231            "(kyc_target_serial_id"
    232            ",h_normalized_payto"
    233            ",access_token"
    234            ",target_pub"
    235            ",is_wallet"
    236            ") VALUES "
    237            "($1, $2, $3, $4, $5);");
    238   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    239                                              "insert_records_by_table_into_table_kyc_targets",
    240                                              params);
    241 }
    242 
    243 
    244 /**
    245  * Function called with records to insert into table.
    246  *
    247  * @param pg plugin context
    248  * @param td record to insert
    249  */
    250 static enum GNUNET_DB_QueryStatus
    251 irbt_cb_table_legitimization_measures (
    252   struct TALER_EXCHANGEDB_PostgresContext *pg,
    253   const struct TALER_EXCHANGEDB_TableData *td)
    254 {
    255   struct GNUNET_PQ_QueryParam params[] = {
    256     GNUNET_PQ_query_param_uint64 (&td->serial),
    257     GNUNET_PQ_query_param_auto_from_type (
    258       &td->details.legitimization_measures.target_token),
    259     GNUNET_PQ_query_param_absolute_time (
    260       &td->details.legitimization_measures.start_time),
    261     TALER_PQ_query_param_json (
    262       td->details.legitimization_measures.measures),
    263     GNUNET_PQ_query_param_uint32 (
    264       &td->details.legitimization_measures.display_priority),
    265     GNUNET_PQ_query_param_end
    266   };
    267 
    268   PREPARE (pg,
    269            "insert_records_by_table_into_table_legitimization_measures",
    270            "INSERT INTO legitimization_measures"
    271            "(legitimization_measure_serial_id"
    272            ",access_token"
    273            ",start_time"
    274            ",jmeasures"
    275            ",display_priority"
    276            ") VALUES "
    277            "($1, $2, $3, $4::TEXT::JSONB, $5);");
    278   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    279                                              "insert_records_by_table_into_table_legitimization_measures",
    280                                              params);
    281 }
    282 
    283 
    284 /**
    285  * Function called with records to insert into table.
    286  *
    287  * @param pg plugin context
    288  * @param td record to insert
    289  */
    290 static enum GNUNET_DB_QueryStatus
    291 irbt_cb_table_legitimization_outcomes (
    292   struct TALER_EXCHANGEDB_PostgresContext *pg,
    293   const struct TALER_EXCHANGEDB_TableData *td)
    294 {
    295   struct GNUNET_PQ_QueryParam params[] = {
    296     GNUNET_PQ_query_param_uint64 (&td->serial),
    297     GNUNET_PQ_query_param_auto_from_type (
    298       &td->details.legitimization_outcomes.h_payto),
    299     GNUNET_PQ_query_param_timestamp (
    300       &td->details.legitimization_outcomes.decision_time),
    301     GNUNET_PQ_query_param_timestamp (
    302       &td->details.legitimization_outcomes.expiration_time),
    303     NULL == td->details.legitimization_outcomes.properties
    304     ? GNUNET_PQ_query_param_null ()
    305     : TALER_PQ_query_param_json (
    306       td->details.legitimization_outcomes.properties),
    307     GNUNET_PQ_query_param_bool (
    308       td->details.legitimization_outcomes.to_investigate),
    309     TALER_PQ_query_param_json (
    310       td->details.legitimization_outcomes.new_rules),
    311     GNUNET_PQ_query_param_end
    312   };
    313 
    314   PREPARE (pg,
    315            "insert_records_by_table_into_table_legitimization_outcomes",
    316            "INSERT INTO legitimization_outcomes"
    317            "(outcome_serial_id"
    318            ",h_payto"
    319            ",decision_time"
    320            ",expiration_time"
    321            ",jproperties"
    322            ",to_investigate"
    323            ",jnew_rules"
    324            ") VALUES "
    325            "($1, $2, $3, $4, $5::TEXT::JSONB, $6, $7::TEXT::JSONB);");
    326   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    327                                              "insert_records_by_table_into_table_legitimization_outcomes",
    328                                              params);
    329 }
    330 
    331 
    332 /**
    333  * Function called with records to insert into table.
    334  *
    335  * @param pg plugin context
    336  * @param td record to insert
    337  */
    338 static enum GNUNET_DB_QueryStatus
    339 irbt_cb_table_legitimization_processes (
    340   struct TALER_EXCHANGEDB_PostgresContext *pg,
    341   const struct TALER_EXCHANGEDB_TableData *td)
    342 {
    343   struct GNUNET_PQ_QueryParam params[] = {
    344     GNUNET_PQ_query_param_uint64 (&td->serial),
    345     GNUNET_PQ_query_param_auto_from_type (
    346       &td->details.legitimization_processes.h_payto),
    347     GNUNET_PQ_query_param_absolute_time (
    348       &td->details.legitimization_processes.start_time),
    349     GNUNET_PQ_query_param_timestamp (
    350       &td->details.legitimization_processes.expiration_time),
    351     GNUNET_PQ_query_param_uint64 (
    352       &td->details.legitimization_processes.legitimization_measure_serial_id),
    353     GNUNET_PQ_query_param_uint32 (
    354       &td->details.legitimization_processes.measure_index),
    355     GNUNET_PQ_query_param_string (
    356       td->details.legitimization_processes.provider_name),
    357     NULL == td->details.legitimization_processes.provider_user_id
    358     ? GNUNET_PQ_query_param_null ()
    359     : GNUNET_PQ_query_param_string (
    360       td->details.legitimization_processes.provider_user_id),
    361     NULL == td->details.legitimization_processes.provider_legitimization_id
    362     ? GNUNET_PQ_query_param_null ()
    363     : GNUNET_PQ_query_param_string (
    364       td->details.legitimization_processes.provider_legitimization_id),
    365     NULL == td->details.legitimization_processes.redirect_url
    366     ? GNUNET_PQ_query_param_null ()
    367     : GNUNET_PQ_query_param_string (
    368       td->details.legitimization_processes.redirect_url),
    369     GNUNET_PQ_query_param_end
    370   };
    371 
    372   PREPARE (pg,
    373            "insert_records_by_table_into_table_legitimization_processes",
    374            "INSERT INTO legitimization_processes"
    375            "(legitimization_process_serial_id"
    376            ",h_payto"
    377            ",start_time"
    378            ",expiration_time"
    379            ",legitimization_measure_serial_id"
    380            ",measure_index"
    381            ",provider_name"
    382            ",provider_user_id"
    383            ",provider_legitimization_id"
    384            ",redirect_url"
    385            ") VALUES "
    386            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
    387   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    388                                              "insert_records_by_table_into_table_legitimization_processes",
    389                                              params);
    390 }
    391 
    392 
    393 /**
    394  * Function called with reserves records to insert into table.
    395  *
    396  * @param pg plugin context
    397  * @param td record to insert
    398  */
    399 static enum GNUNET_DB_QueryStatus
    400 irbt_cb_table_reserves (struct TALER_EXCHANGEDB_PostgresContext *pg,
    401                         const struct TALER_EXCHANGEDB_TableData *td)
    402 {
    403   struct GNUNET_PQ_QueryParam params[] = {
    404     GNUNET_PQ_query_param_uint64 (&td->serial),
    405     GNUNET_PQ_query_param_auto_from_type (&td->details.reserves.reserve_pub),
    406     GNUNET_PQ_query_param_timestamp (&td->details.reserves.expiration_date),
    407     GNUNET_PQ_query_param_timestamp (&td->details.reserves.gc_date),
    408     GNUNET_PQ_query_param_end
    409   };
    410 
    411   PREPARE (pg,
    412            "insert_records_by_table_into_table_reserves",
    413            "INSERT INTO reserves"
    414            "(reserve_uuid"
    415            ",reserve_pub"
    416            ",expiration_date"
    417            ",gc_date"
    418            ") VALUES "
    419            "($1, $2, $3, $4);");
    420   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    421                                              "insert_records_by_table_into_table_reserves",
    422                                              params);
    423 }
    424 
    425 
    426 /**
    427  * Function called with reserves_in records to insert into table.
    428  *
    429  * @param pg plugin context
    430  * @param td record to insert
    431  */
    432 static enum GNUNET_DB_QueryStatus
    433 irbt_cb_table_reserves_in (struct TALER_EXCHANGEDB_PostgresContext *pg,
    434                            const struct TALER_EXCHANGEDB_TableData *td)
    435 {
    436   struct GNUNET_PQ_QueryParam params[] = {
    437     GNUNET_PQ_query_param_uint64 (&td->serial),
    438     GNUNET_PQ_query_param_uint64 (&td->details.reserves_in.wire_reference),
    439     TALER_PQ_query_param_amount (
    440       pg->conn,
    441       &td->details.reserves_in.credit),
    442     GNUNET_PQ_query_param_auto_from_type (
    443       &td->details.reserves_in.sender_account_h_payto),
    444     GNUNET_PQ_query_param_string (
    445       td->details.reserves_in.exchange_account_section),
    446     GNUNET_PQ_query_param_timestamp (
    447       &td->details.reserves_in.execution_date),
    448     GNUNET_PQ_query_param_auto_from_type (&td->details.reserves_in.reserve_pub),
    449     GNUNET_PQ_query_param_end
    450   };
    451 
    452   PREPARE (pg,
    453            "insert_records_by_table_into_table_reserves_in",
    454            "INSERT INTO reserves_in"
    455            "(reserve_in_serial_id"
    456            ",wire_reference"
    457            ",credit"
    458            ",wire_source_h_payto"
    459            ",exchange_account_section"
    460            ",execution_date"
    461            ",reserve_pub"
    462            ") VALUES "
    463            "($1, $2, $3, $4, $5, $6, $7);");
    464   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    465                                              "insert_records_by_table_into_table_reserves_in",
    466                                              params);
    467 }
    468 
    469 
    470 /**
    471  * Function called with kycauth_in records to insert into table.
    472  *
    473  * @param pg plugin context
    474  * @param td record to insert
    475  */
    476 static enum GNUNET_DB_QueryStatus
    477 irbt_cb_table_kycauths_in (struct TALER_EXCHANGEDB_PostgresContext *pg,
    478                            const struct TALER_EXCHANGEDB_TableData *td)
    479 {
    480   struct GNUNET_PQ_QueryParam params[] = {
    481     GNUNET_PQ_query_param_uint64 (&td->serial),
    482     GNUNET_PQ_query_param_uint64 (&td->details.kycauth_in.wire_reference),
    483     TALER_PQ_query_param_amount (
    484       pg->conn,
    485       &td->details.reserves_in.credit),
    486     GNUNET_PQ_query_param_auto_from_type (
    487       &td->details.reserves_in.sender_account_h_payto),
    488     GNUNET_PQ_query_param_string (
    489       td->details.reserves_in.exchange_account_section),
    490     GNUNET_PQ_query_param_timestamp (
    491       &td->details.reserves_in.execution_date),
    492     GNUNET_PQ_query_param_auto_from_type (&td->details.kycauth_in.account_pub),
    493     GNUNET_PQ_query_param_end
    494   };
    495 
    496   PREPARE (pg,
    497            "insert_records_by_table_into_table_kycauth_in",
    498            "INSERT INTO kycauths_in"
    499            "(kycauth_in_serial_id"
    500            ",wire_reference"
    501            ",credit"
    502            ",wire_source_h_payto"
    503            ",exchange_account_section"
    504            ",execution_date"
    505            ",account_pub"
    506            ") VALUES "
    507            "($1, $2, $3, $4, $5, $6, $7);");
    508   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    509                                              "insert_records_by_table_into_table_kycauth_in",
    510                                              params);
    511 }
    512 
    513 
    514 /**
    515  * Function called with reserves_open_requests records to insert into table.
    516  *
    517  * @param pg plugin context
    518  * @param td record to insert
    519  */
    520 static enum GNUNET_DB_QueryStatus
    521 irbt_cb_table_reserves_open_requests (
    522   struct TALER_EXCHANGEDB_PostgresContext *pg,
    523   const struct TALER_EXCHANGEDB_TableData *td)
    524 {
    525   struct GNUNET_PQ_QueryParam params[] = {
    526     GNUNET_PQ_query_param_uint64 (&td->serial),
    527     GNUNET_PQ_query_param_auto_from_type (
    528       &td->details.reserves_open_requests.reserve_pub),
    529     GNUNET_PQ_query_param_timestamp (
    530       &td->details.reserves_open_requests.request_timestamp),
    531     GNUNET_PQ_query_param_timestamp (
    532       &td->details.reserves_open_requests.expiration_date),
    533     GNUNET_PQ_query_param_auto_from_type (
    534       &td->details.reserves_open_requests.reserve_sig),
    535     TALER_PQ_query_param_amount (
    536       pg->conn,
    537       &td->details.reserves_open_requests.reserve_payment),
    538     GNUNET_PQ_query_param_uint32 (
    539       &td->details.reserves_open_requests.requested_purse_limit),
    540     GNUNET_PQ_query_param_end
    541   };
    542 
    543   PREPARE (pg,
    544            "insert_records_by_table_into_table_reserves_open_requests",
    545            "INSERT INTO reserves_open_requests"
    546            "(open_request_uuid"
    547            ",reserve_pub"
    548            ",request_timestamp"
    549            ",expiration_date"
    550            ",reserve_sig"
    551            ",reserve_payment"
    552            ",requested_purse_limit"
    553            ") VALUES "
    554            "($1, $2, $3, $4, $5, $6, $7);");
    555   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    556                                              "insert_records_by_table_into_table_reserves_open_requests",
    557                                              params);
    558 }
    559 
    560 
    561 /**
    562  * Function called with reserves_open_deposits records to insert into table.
    563  *
    564  * @param pg plugin context
    565  * @param td record to insert
    566  */
    567 static enum GNUNET_DB_QueryStatus
    568 irbt_cb_table_reserves_open_deposits (
    569   struct TALER_EXCHANGEDB_PostgresContext *pg,
    570   const struct TALER_EXCHANGEDB_TableData *td)
    571 {
    572   struct GNUNET_PQ_QueryParam params[] = {
    573     GNUNET_PQ_query_param_uint64 (&td->serial),
    574     GNUNET_PQ_query_param_auto_from_type (
    575       &td->details.reserves_open_deposits.reserve_sig),
    576     GNUNET_PQ_query_param_auto_from_type (
    577       &td->details.reserves_open_deposits.reserve_pub),
    578     GNUNET_PQ_query_param_auto_from_type (
    579       &td->details.reserves_open_deposits.coin_pub),
    580     GNUNET_PQ_query_param_auto_from_type (
    581       &td->details.reserves_open_deposits.coin_sig),
    582     TALER_PQ_query_param_amount (
    583       pg->conn,
    584       &td->details.reserves_open_deposits.contribution),
    585     GNUNET_PQ_query_param_end
    586   };
    587 
    588   PREPARE (pg,
    589            "insert_records_by_table_into_table_reserves_open_deposits",
    590            "INSERT INTO reserves_open_deposits"
    591            "(reserve_open_deposit_uuid"
    592            ",reserve_sig"
    593            ",reserve_pub"
    594            ",coin_pub"
    595            ",coin_sig"
    596            ",contribution"
    597            ") VALUES "
    598            "($1, $2, $3, $4, $5, $6);");
    599   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    600                                              "insert_records_by_table_into_table_reserves_open_deposits",
    601                                              params);
    602 }
    603 
    604 
    605 /**
    606  * Function called with reserves_close records to insert into table.
    607  *
    608  * @param pg plugin context
    609  * @param td record to insert
    610  */
    611 static enum GNUNET_DB_QueryStatus
    612 irbt_cb_table_reserves_close (struct TALER_EXCHANGEDB_PostgresContext *pg,
    613                               const struct TALER_EXCHANGEDB_TableData *td)
    614 {
    615   struct GNUNET_PQ_QueryParam params[] = {
    616     GNUNET_PQ_query_param_uint64 (&td->serial),
    617     GNUNET_PQ_query_param_timestamp (
    618       &td->details.reserves_close.execution_date),
    619     GNUNET_PQ_query_param_auto_from_type (
    620       &td->details.reserves_close.wtid),
    621     GNUNET_PQ_query_param_auto_from_type (
    622       &td->details.reserves_close.sender_account_h_payto),
    623     TALER_PQ_query_param_amount (
    624       pg->conn,
    625       &td->details.reserves_close.amount),
    626     TALER_PQ_query_param_amount (
    627       pg->conn,
    628       &td->details.reserves_close.closing_fee),
    629     GNUNET_PQ_query_param_auto_from_type (
    630       &td->details.reserves_close.reserve_pub),
    631     GNUNET_PQ_query_param_end
    632   };
    633 
    634   PREPARE (pg,
    635            "insert_records_by_table_into_table_reserves_close",
    636            "INSERT INTO reserves_close"
    637            "(close_uuid"
    638            ",execution_date"
    639            ",wtid"
    640            ",wire_target_h_payto"
    641            ",amount"
    642            ",closing_fee"
    643            ",reserve_pub"
    644            ") VALUES "
    645            "($1, $2, $3, $4, $5, $6, $7);");
    646   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    647                                              "insert_records_by_table_into_table_reserves_close",
    648                                              params);
    649 }
    650 
    651 
    652 /**
    653  * Function called with auditors records to insert into table.
    654  *
    655  * @param pg plugin context
    656  * @param td record to insert
    657  */
    658 static enum GNUNET_DB_QueryStatus
    659 irbt_cb_table_auditors (struct TALER_EXCHANGEDB_PostgresContext *pg,
    660                         const struct TALER_EXCHANGEDB_TableData *td)
    661 {
    662   struct GNUNET_PQ_QueryParam params[] = {
    663     GNUNET_PQ_query_param_uint64 (&td->serial),
    664     GNUNET_PQ_query_param_auto_from_type (&td->details.auditors.auditor_pub),
    665     GNUNET_PQ_query_param_string (td->details.auditors.auditor_name),
    666     GNUNET_PQ_query_param_string (td->details.auditors.auditor_url),
    667     GNUNET_PQ_query_param_bool (td->details.auditors.is_active),
    668     GNUNET_PQ_query_param_timestamp (&td->details.auditors.last_change),
    669     GNUNET_PQ_query_param_end
    670   };
    671 
    672   PREPARE (pg,
    673            "insert_records_by_table_into_table_auditors",
    674            "INSERT INTO auditors"
    675            "(auditor_uuid"
    676            ",auditor_pub"
    677            ",auditor_name"
    678            ",auditor_url"
    679            ",is_active"
    680            ",last_change"
    681            ") VALUES "
    682            "($1, $2, $3, $4, $5, $6);");
    683   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    684                                              "insert_records_by_table_into_table_auditors",
    685                                              params);
    686 }
    687 
    688 
    689 /**
    690  * Function called with auditor_denom_sigs records to insert into table.
    691  *
    692  * @param pg plugin context
    693  * @param td record to insert
    694  */
    695 static enum GNUNET_DB_QueryStatus
    696 irbt_cb_table_auditor_denom_sigs (struct TALER_EXCHANGEDB_PostgresContext *pg,
    697                                   const struct TALER_EXCHANGEDB_TableData *td)
    698 {
    699   struct GNUNET_PQ_QueryParam params[] = {
    700     GNUNET_PQ_query_param_uint64 (&td->serial),
    701     GNUNET_PQ_query_param_uint64 (&td->details.auditor_denom_sigs.auditor_uuid),
    702     GNUNET_PQ_query_param_uint64 (
    703       &td->details.auditor_denom_sigs.denominations_serial),
    704     GNUNET_PQ_query_param_auto_from_type (
    705       &td->details.auditor_denom_sigs.auditor_sig),
    706     GNUNET_PQ_query_param_end
    707   };
    708 
    709   PREPARE (pg,
    710            "insert_records_by_table_into_table_auditor_denom_sigs",
    711            "INSERT INTO auditor_denom_sigs"
    712            "(auditor_denom_serial"
    713            ",auditor_uuid"
    714            ",denominations_serial"
    715            ",auditor_sig"
    716            ") VALUES "
    717            "($1, $2, $3, $4);");
    718   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    719                                              "insert_records_by_table_into_table_auditor_denom_sigs",
    720                                              params);
    721 }
    722 
    723 
    724 /**
    725  * Function called with exchange_sign_keys records to insert into table.
    726  *
    727  * @param pg plugin context
    728  * @param td record to insert
    729  */
    730 static enum GNUNET_DB_QueryStatus
    731 irbt_cb_table_exchange_sign_keys (struct TALER_EXCHANGEDB_PostgresContext *pg,
    732                                   const struct TALER_EXCHANGEDB_TableData *td)
    733 {
    734   struct GNUNET_PQ_QueryParam params[] = {
    735     GNUNET_PQ_query_param_uint64 (&td->serial),
    736     GNUNET_PQ_query_param_auto_from_type (
    737       &td->details.exchange_sign_keys.exchange_pub),
    738     GNUNET_PQ_query_param_auto_from_type (
    739       &td->details.exchange_sign_keys.master_sig),
    740     GNUNET_PQ_query_param_timestamp (
    741       &td->details.exchange_sign_keys.meta.start),
    742     GNUNET_PQ_query_param_timestamp (
    743       &td->details.exchange_sign_keys.meta.expire_sign),
    744     GNUNET_PQ_query_param_timestamp (
    745       &td->details.exchange_sign_keys.meta.expire_legal),
    746     GNUNET_PQ_query_param_end
    747   };
    748 
    749   PREPARE (pg,
    750            "insert_records_by_table_into_table_exchange_sign_keys",
    751            "INSERT INTO exchange_sign_keys"
    752            "(esk_serial"
    753            ",exchange_pub"
    754            ",master_sig"
    755            ",valid_from"
    756            ",expire_sign"
    757            ",expire_legal"
    758            ") VALUES "
    759            "($1, $2, $3, $4, $5, $6);");
    760   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    761                                              "insert_records_by_table_into_table_exchange_sign_keys",
    762                                              params);
    763 }
    764 
    765 
    766 /**
    767  * Function called with signkey_revocations records to insert into table.
    768  *
    769  * @param pg plugin context
    770  * @param td record to insert
    771  */
    772 static enum GNUNET_DB_QueryStatus
    773 irbt_cb_table_signkey_revocations (struct TALER_EXCHANGEDB_PostgresContext *pg,
    774                                    const struct TALER_EXCHANGEDB_TableData *td)
    775 {
    776   struct GNUNET_PQ_QueryParam params[] = {
    777     GNUNET_PQ_query_param_uint64 (&td->serial),
    778     GNUNET_PQ_query_param_uint64 (&td->details.signkey_revocations.esk_serial),
    779     GNUNET_PQ_query_param_auto_from_type (
    780       &td->details.signkey_revocations.master_sig),
    781     GNUNET_PQ_query_param_end
    782   };
    783 
    784   PREPARE (pg,
    785            "insert_records_by_table_into_table_signkey_revocations",
    786            "INSERT INTO signkey_revocations"
    787            "(signkey_revocations_serial_id"
    788            ",esk_serial"
    789            ",master_sig"
    790            ") VALUES "
    791            "($1, $2, $3);");
    792   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    793                                              "insert_records_by_table_into_table_signkey_revocations",
    794                                              params);
    795 }
    796 
    797 
    798 /**
    799  * Function called with known_coins records to insert into table.
    800  *
    801  * @param pg plugin context
    802  * @param td record to insert
    803  */
    804 static enum GNUNET_DB_QueryStatus
    805 irbt_cb_table_known_coins (struct TALER_EXCHANGEDB_PostgresContext *pg,
    806                            const struct TALER_EXCHANGEDB_TableData *td)
    807 {
    808   struct GNUNET_PQ_QueryParam params[] = {
    809     GNUNET_PQ_query_param_uint64 (&td->serial),
    810     GNUNET_PQ_query_param_auto_from_type (
    811       &td->details.known_coins.coin_pub),
    812     TALER_PQ_query_param_denom_sig (
    813       &td->details.known_coins.denom_sig),
    814     GNUNET_PQ_query_param_uint64 (
    815       &td->details.known_coins.denominations_serial),
    816     GNUNET_PQ_query_param_end
    817   };
    818 
    819   PREPARE (pg,
    820            "insert_records_by_table_into_table_known_coins",
    821            "INSERT INTO known_coins"
    822            "(known_coin_id"
    823            ",coin_pub"
    824            ",denom_sig"
    825            ",denominations_serial"
    826            ") VALUES "
    827            "($1, $2, $3, $4);");
    828   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    829                                              "insert_records_by_table_into_table_known_coins",
    830                                              params);
    831 }
    832 
    833 
    834 /**
    835  * Function called with refresh records to insert into table.
    836  *
    837  * @param pg plugin context
    838  * @param td record to insert
    839  */
    840 static enum GNUNET_DB_QueryStatus
    841 irbt_cb_table_refresh (struct TALER_EXCHANGEDB_PostgresContext *pg,
    842                        const struct TALER_EXCHANGEDB_TableData *td)
    843 {
    844   struct GNUNET_PQ_QueryParam params[] = {
    845     GNUNET_PQ_query_param_uint64 (&td->serial),
    846     GNUNET_PQ_query_param_auto_from_type (&td->details.refresh.rc),
    847     GNUNET_PQ_query_param_auto_from_type (&td->details.refresh.execution_date),
    848     TALER_PQ_query_param_amount (
    849       pg->conn,
    850       &td->details.refresh.amount_with_fee),
    851     GNUNET_PQ_query_param_auto_from_type (
    852       &td->details.refresh.old_coin_pub),
    853     GNUNET_PQ_query_param_auto_from_type (
    854       &td->details.refresh.old_coin_sig),
    855     GNUNET_PQ_query_param_auto_from_type (
    856       &td->details.refresh.refresh_seed),
    857     GNUNET_PQ_query_param_uint32 (
    858       &td->details.refresh.noreveal_index),
    859     GNUNET_PQ_query_param_auto_from_type (
    860       &td->details.refresh.planchets_h),
    861     GNUNET_PQ_query_param_auto_from_type (
    862       &td->details.refresh.selected_h),
    863     td->details.refresh.no_blinding_seed
    864        ? GNUNET_PQ_query_param_null ()
    865        : GNUNET_PQ_query_param_auto_from_type (
    866       &td->details.refresh.blinding_seed),
    867     td->details.refresh.no_blinding_seed
    868        ? GNUNET_PQ_query_param_null ()
    869        : TALER_PQ_query_param_array_cs_r_pub (
    870       td->details.refresh.num_cs_r_values,
    871       td->details.refresh.cs_r_values,
    872       pg->conn),
    873     td->details.refresh.no_blinding_seed
    874        ? GNUNET_PQ_query_param_null ()
    875        : GNUNET_PQ_query_param_uint64 (
    876       &td->details.refresh.cs_r_choices),
    877     GNUNET_PQ_query_param_array_uint64 (
    878       td->details.refresh.num_coins,
    879       td->details.refresh.denom_serials,
    880       pg->conn),
    881     TALER_PQ_query_param_array_blinded_denom_sig (
    882       td->details.refresh.num_coins,
    883       td->details.refresh.denom_sigs,
    884       pg->conn),
    885     GNUNET_PQ_query_param_end
    886   };
    887   enum GNUNET_DB_QueryStatus qs;
    888 
    889   PREPARE (pg,
    890            "insert_records_by_table_into_table_refresh",
    891            "INSERT INTO refresh"
    892            "(refresh_id"
    893            ",rc"
    894            ",execution_date"
    895            ",amount_with_fee"
    896            ",old_coin_pub"
    897            ",old_coin_sig"
    898            ",refresh_seed"
    899            ",noreveal_index"
    900            ",planchets_h"
    901            ",selected_h"
    902            ",blinding_seed"
    903            ",cs_r_values"
    904            ",cs_r_choices"
    905            ",denom_serials"
    906            ",denom_sigs"
    907            ") VALUES "
    908            "($1, $2, $3, $4, $5, $6,$7,$8,$9,$10,$11,$12,$13,$14,$15);");
    909   qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
    910                                            "insert_records_by_table_into_table_refresh",
    911                                            params);
    912   GNUNET_PQ_cleanup_query_params_closures (params);
    913   return qs;
    914 }
    915 
    916 
    917 /**
    918  * Function called with batch deposits records to insert into table.
    919  *
    920  * @param pg plugin context
    921  * @param td record to insert
    922  */
    923 static enum GNUNET_DB_QueryStatus
    924 irbt_cb_table_batch_deposits (struct TALER_EXCHANGEDB_PostgresContext *pg,
    925                               const struct TALER_EXCHANGEDB_TableData *td)
    926 {
    927   struct GNUNET_PQ_QueryParam params[] = {
    928     GNUNET_PQ_query_param_uint64 (&td->serial),
    929     GNUNET_PQ_query_param_uint64 (&td->details.batch_deposits.shard),
    930     GNUNET_PQ_query_param_auto_from_type (
    931       &td->details.batch_deposits.merchant_pub),
    932     GNUNET_PQ_query_param_timestamp (
    933       &td->details.batch_deposits.wallet_timestamp),
    934     GNUNET_PQ_query_param_timestamp (
    935       &td->details.batch_deposits.exchange_timestamp),
    936     GNUNET_PQ_query_param_timestamp (
    937       &td->details.batch_deposits.refund_deadline),
    938     GNUNET_PQ_query_param_timestamp (&td->details.batch_deposits.wire_deadline),
    939     GNUNET_PQ_query_param_auto_from_type (
    940       &td->details.batch_deposits.h_contract_terms),
    941     td->details.batch_deposits.no_wallet_data_hash
    942     ? GNUNET_PQ_query_param_null ()
    943     : GNUNET_PQ_query_param_auto_from_type (
    944       &td->details.batch_deposits.wallet_data_hash),
    945     GNUNET_PQ_query_param_auto_from_type (
    946       &td->details.batch_deposits.wire_salt),
    947     GNUNET_PQ_query_param_auto_from_type (
    948       &td->details.batch_deposits.wire_target_h_payto),
    949     TALER_PQ_query_param_amount (
    950       pg->conn,
    951       &td->details.batch_deposits.total_amount),
    952     TALER_PQ_query_param_amount (
    953       pg->conn,
    954       &td->details.batch_deposits.total_without_fee),
    955     GNUNET_PQ_query_param_auto_from_type (
    956       &td->details.batch_deposits.merchant_sig),
    957     GNUNET_PQ_query_param_bool (td->details.batch_deposits.done),
    958     GNUNET_PQ_query_param_end
    959   };
    960 
    961   PREPARE (pg,
    962            "insert_records_by_table_into_table_batch_deposits",
    963            "INSERT INTO batch_deposits"
    964            "(batch_deposit_serial_id"
    965            ",shard"
    966            ",merchant_pub"
    967            ",wallet_timestamp"
    968            ",exchange_timestamp"
    969            ",refund_deadline"
    970            ",wire_deadline"
    971            ",h_contract_terms"
    972            ",wallet_data_hash"
    973            ",wire_salt"
    974            ",wire_target_h_payto"
    975            ",total_amount"
    976            ",total_without_fee"
    977            ",merchant_sig"
    978            ",done"
    979            ") VALUES "
    980            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
    981            " $11, $12, $13, $14, $15);");
    982   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
    983                                              "insert_records_by_table_into_table_batch_deposits",
    984                                              params);
    985 }
    986 
    987 
    988 /**
    989  * Function called with deposits records to insert into table.
    990  *
    991  * @param pg plugin context
    992  * @param td record to insert
    993  */
    994 static enum GNUNET_DB_QueryStatus
    995 irbt_cb_table_coin_deposits (struct TALER_EXCHANGEDB_PostgresContext *pg,
    996                              const struct TALER_EXCHANGEDB_TableData *td)
    997 {
    998   struct GNUNET_PQ_QueryParam params[] = {
    999     GNUNET_PQ_query_param_uint64 (&td->serial),
   1000     GNUNET_PQ_query_param_uint64 (
   1001       &td->details.coin_deposits.batch_deposit_serial_id),
   1002     GNUNET_PQ_query_param_auto_from_type (
   1003       &td->details.coin_deposits.coin_pub),
   1004     GNUNET_PQ_query_param_auto_from_type (
   1005       &td->details.coin_deposits.coin_sig),
   1006     TALER_PQ_query_param_amount (
   1007       pg->conn,
   1008       &td->details.coin_deposits.amount_with_fee),
   1009     GNUNET_PQ_query_param_end
   1010   };
   1011 
   1012   PREPARE (pg,
   1013            "insert_records_by_table_into_table_coin_deposits",
   1014            "INSERT INTO coin_deposits"
   1015            "(coin_deposit_serial_id"
   1016            ",batch_deposit_serial_id"
   1017            ",coin_pub"
   1018            ",coin_sig"
   1019            ",amount_with_fee"
   1020            ") VALUES "
   1021            "($1, $2, $3, $4, $5);");
   1022   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1023                                              "insert_records_by_table_into_table_coin_deposits",
   1024                                              params);
   1025 }
   1026 
   1027 
   1028 /**
   1029  * Function called with refunds records to insert into table.
   1030  *
   1031  * @param pg plugin context
   1032  * @param td record to insert
   1033  */
   1034 static enum GNUNET_DB_QueryStatus
   1035 irbt_cb_table_refunds (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1036                        const struct TALER_EXCHANGEDB_TableData *td)
   1037 {
   1038   struct GNUNET_PQ_QueryParam params[] = {
   1039     GNUNET_PQ_query_param_uint64 (&td->serial),
   1040     GNUNET_PQ_query_param_auto_from_type (&td->details.refunds.coin_pub),
   1041     GNUNET_PQ_query_param_auto_from_type (&td->details.refunds.merchant_sig),
   1042     GNUNET_PQ_query_param_uint64 (&td->details.refunds.rtransaction_id),
   1043     TALER_PQ_query_param_amount (
   1044       pg->conn,
   1045       &td->details.refunds.amount_with_fee),
   1046     GNUNET_PQ_query_param_uint64 (
   1047       &td->details.refunds.batch_deposit_serial_id),
   1048     GNUNET_PQ_query_param_end
   1049   };
   1050 
   1051   PREPARE (pg,
   1052            "insert_records_by_table_into_table_refunds",
   1053            "INSERT INTO refunds"
   1054            "(refund_serial_id"
   1055            ",coin_pub"
   1056            ",merchant_sig"
   1057            ",rtransaction_id"
   1058            ",amount_with_fee"
   1059            ",batch_deposit_serial_id"
   1060            ") VALUES "
   1061            "($1, $2, $3, $4, $5, $6);");
   1062   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1063                                              "insert_records_by_table_into_table_refunds",
   1064                                              params);
   1065 }
   1066 
   1067 
   1068 /**
   1069  * Function called with wire_out records to insert into table.
   1070  *
   1071  * @param pg plugin context
   1072  * @param td record to insert
   1073  */
   1074 static enum GNUNET_DB_QueryStatus
   1075 irbt_cb_table_wire_out (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1076                         const struct TALER_EXCHANGEDB_TableData *td)
   1077 {
   1078   struct GNUNET_PQ_QueryParam params[] = {
   1079     GNUNET_PQ_query_param_uint64 (&td->serial),
   1080     GNUNET_PQ_query_param_timestamp (&td->details.wire_out.execution_date),
   1081     GNUNET_PQ_query_param_auto_from_type (&td->details.wire_out.wtid_raw),
   1082     GNUNET_PQ_query_param_auto_from_type (
   1083       &td->details.wire_out.wire_target_h_payto),
   1084     GNUNET_PQ_query_param_string (
   1085       td->details.wire_out.exchange_account_section),
   1086     TALER_PQ_query_param_amount (
   1087       pg->conn,
   1088       &td->details.wire_out.amount),
   1089     GNUNET_PQ_query_param_end
   1090   };
   1091 
   1092   PREPARE (pg,
   1093            "insert_records_by_table_into_table_wire_out",
   1094            "INSERT INTO wire_out"
   1095            "(wireout_uuid"
   1096            ",execution_date"
   1097            ",wtid_raw"
   1098            ",wire_target_h_payto"
   1099            ",exchange_account_section"
   1100            ",amount"
   1101            ") VALUES "
   1102            "($1, $2, $3, $4, $5, $6);");
   1103   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1104                                              "insert_records_by_table_into_table_wire_out",
   1105                                              params);
   1106 }
   1107 
   1108 
   1109 /**
   1110  * Function called with aggregation_tracking records to insert into table.
   1111  *
   1112  * @param pg plugin context
   1113  * @param td record to insert
   1114  */
   1115 static enum GNUNET_DB_QueryStatus
   1116 irbt_cb_table_aggregation_tracking (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1117                                     const struct TALER_EXCHANGEDB_TableData *td)
   1118 {
   1119   struct GNUNET_PQ_QueryParam params[] = {
   1120     GNUNET_PQ_query_param_uint64 (&td->serial),
   1121     GNUNET_PQ_query_param_uint64 (
   1122       &td->details.aggregation_tracking.batch_deposit_serial_id),
   1123     GNUNET_PQ_query_param_auto_from_type (
   1124       &td->details.aggregation_tracking.wtid_raw),
   1125     GNUNET_PQ_query_param_end
   1126   };
   1127 
   1128   PREPARE (pg,
   1129            "insert_records_by_table_into_table_aggregation_tracking",
   1130            "INSERT INTO aggregation_tracking"
   1131            "(aggregation_serial_id"
   1132            ",batch_deposit_serial_id"
   1133            ",wtid_raw"
   1134            ") VALUES "
   1135            "($1, $2, $3);");
   1136   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1137                                              "insert_records_by_table_into_table_aggregation_tracking",
   1138                                              params);
   1139 }
   1140 
   1141 
   1142 /**
   1143  * Function called with aggregation_deferrals records to insert into table.
   1144  *
   1145  * @param pg plugin context
   1146  * @param td record to insert
   1147  */
   1148 static enum GNUNET_DB_QueryStatus
   1149 irbt_cb_table_aggregation_deferrals (
   1150   struct TALER_EXCHANGEDB_PostgresContext *pg,
   1151   const struct TALER_EXCHANGEDB_TableData *td)
   1152 {
   1153   struct GNUNET_PQ_QueryParam params[] = {
   1154     GNUNET_PQ_query_param_uint64 (&td->serial),
   1155     GNUNET_PQ_query_param_uint64 (
   1156       &td->details.aggregation_deferrals.batch_deposit_serial_id),
   1157     GNUNET_PQ_query_param_auto_from_type (
   1158       &td->details.aggregation_deferrals.wtid_raw),
   1159     GNUNET_PQ_query_param_auto_from_type (
   1160       &td->details.aggregation_deferrals.wire_target_h_payto),
   1161     TALER_PQ_query_param_amount (
   1162       pg->conn,
   1163       &td->details.aggregation_deferrals.amount),
   1164     GNUNET_PQ_query_param_uint32 (
   1165       &td->details.aggregation_deferrals.deferral_reason),
   1166     GNUNET_PQ_query_param_uint64 (
   1167       &td->details.aggregation_deferrals.legitimization_requirement_serial_id),
   1168     GNUNET_PQ_query_param_timestamp (
   1169       &td->details.aggregation_deferrals.deferral_time),
   1170     GNUNET_PQ_query_param_end
   1171   };
   1172 
   1173   PREPARE (pg,
   1174            "insert_records_by_table_into_table_aggregation_deferrals",
   1175            "INSERT INTO aggregation_deferrals"
   1176            "(aggregation_deferral_serial_id"
   1177            ",batch_deposit_serial_id"
   1178            ",wtid_raw"
   1179            ",wire_target_h_payto"
   1180            ",amount"
   1181            ",deferral_reason"
   1182            ",legitimization_requirement_serial_id"
   1183            ",deferral_time"
   1184            ") VALUES "
   1185            "($1, $2, $3, $4, $5, $6, $7, $8);");
   1186   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1187                                              "insert_records_by_table_into_table_aggregation_deferrals",
   1188                                              params);
   1189 }
   1190 
   1191 
   1192 /**
   1193  * Function called with wire_fee records to insert into table.
   1194  *
   1195  * @param pg plugin context
   1196  * @param td record to insert
   1197  */
   1198 static enum GNUNET_DB_QueryStatus
   1199 irbt_cb_table_wire_fee (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1200                         const struct TALER_EXCHANGEDB_TableData *td)
   1201 {
   1202   struct GNUNET_PQ_QueryParam params[] = {
   1203     GNUNET_PQ_query_param_uint64 (&td->serial),
   1204     GNUNET_PQ_query_param_string (td->details.wire_fee.wire_method),
   1205     GNUNET_PQ_query_param_timestamp (&td->details.wire_fee.start_date),
   1206     GNUNET_PQ_query_param_timestamp (&td->details.wire_fee.end_date),
   1207     TALER_PQ_query_param_amount (
   1208       pg->conn,
   1209       &td->details.wire_fee.fees.wire),
   1210     TALER_PQ_query_param_amount (
   1211       pg->conn,
   1212       &td->details.wire_fee.fees.closing),
   1213     GNUNET_PQ_query_param_auto_from_type (&td->details.wire_fee.master_sig),
   1214     GNUNET_PQ_query_param_end
   1215   };
   1216 
   1217   PREPARE (pg,
   1218            "insert_records_by_table_into_table_wire_fee",
   1219            "INSERT INTO wire_fee"
   1220            "(wire_fee_serial"
   1221            ",wire_method"
   1222            ",start_date"
   1223            ",end_date"
   1224            ",wire_fee"
   1225            ",closing_fee"
   1226            ",master_sig"
   1227            ") VALUES "
   1228            "($1, $2, $3, $4, $5, $6, $7);");
   1229   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1230                                              "insert_records_by_table_into_table_wire_fee",
   1231                                              params);
   1232 }
   1233 
   1234 
   1235 /**
   1236  * Function called with wire_fee records to insert into table.
   1237  *
   1238  * @param pg plugin context
   1239  * @param td record to insert
   1240  */
   1241 static enum GNUNET_DB_QueryStatus
   1242 irbt_cb_table_global_fee (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1243                           const struct TALER_EXCHANGEDB_TableData *td)
   1244 {
   1245   struct GNUNET_PQ_QueryParam params[] = {
   1246     GNUNET_PQ_query_param_uint64 (
   1247       &td->serial),
   1248     GNUNET_PQ_query_param_timestamp (
   1249       &td->details.global_fee.start_date),
   1250     GNUNET_PQ_query_param_timestamp (
   1251       &td->details.global_fee.end_date),
   1252     TALER_PQ_query_param_amount (
   1253       pg->conn,
   1254       &td->details.global_fee.fees.history),
   1255     TALER_PQ_query_param_amount (
   1256       pg->conn,
   1257       &td->details.global_fee.fees.account),
   1258     TALER_PQ_query_param_amount (
   1259       pg->conn,
   1260       &td->details.global_fee.fees.purse),
   1261     GNUNET_PQ_query_param_relative_time (
   1262       &td->details.global_fee.purse_timeout),
   1263     GNUNET_PQ_query_param_relative_time (
   1264       &td->details.global_fee.history_expiration),
   1265     GNUNET_PQ_query_param_uint32 (
   1266       &td->details.global_fee.purse_account_limit),
   1267     GNUNET_PQ_query_param_auto_from_type (
   1268       &td->details.global_fee.master_sig),
   1269     GNUNET_PQ_query_param_end
   1270   };
   1271 
   1272   PREPARE (pg,
   1273            "insert_records_by_table_into_table_global_fee",
   1274            "INSERT INTO global_fee"
   1275            "(global_fee_serial"
   1276            ",start_date"
   1277            ",end_date"
   1278            ",history_fee"
   1279            ",account_fee"
   1280            ",purse_fee"
   1281            ",purse_timeout"
   1282            ",history_expiration"
   1283            ",purse_account_limit"
   1284            ",master_sig"
   1285            ") VALUES "
   1286            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
   1287   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1288                                              "insert_records_by_table_into_table_global_fee",
   1289                                              params);
   1290 }
   1291 
   1292 
   1293 /**
   1294  * Function called with recoup records to insert into table.
   1295  *
   1296  * @param pg plugin context
   1297  * @param td record to insert
   1298  */
   1299 static enum GNUNET_DB_QueryStatus
   1300 irbt_cb_table_recoup (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1301                       const struct TALER_EXCHANGEDB_TableData *td)
   1302 {
   1303   struct GNUNET_PQ_QueryParam params[] = {
   1304     GNUNET_PQ_query_param_uint64 (&td->serial),
   1305     GNUNET_PQ_query_param_auto_from_type (&td->details.recoup.coin_sig),
   1306     GNUNET_PQ_query_param_auto_from_type (&td->details.recoup.coin_blind),
   1307     TALER_PQ_query_param_amount (
   1308       pg->conn,
   1309       &td->details.recoup.amount),
   1310     GNUNET_PQ_query_param_timestamp (&td->details.recoup.timestamp),
   1311     GNUNET_PQ_query_param_auto_from_type (
   1312       &td->details.recoup.coin_pub),
   1313     GNUNET_PQ_query_param_uint64 (&td->details.recoup.withdraw_serial_id),
   1314     GNUNET_PQ_query_param_end
   1315   };
   1316 
   1317   PREPARE (pg,
   1318            "insert_records_by_table_into_table_recoup",
   1319            "INSERT INTO recoup"
   1320            "(recoup_uuid"
   1321            ",coin_sig"
   1322            ",coin_blind"
   1323            ",amount"
   1324            ",recoup_timestamp"
   1325            ",coin_pub"
   1326            ",withdraw_id"
   1327            ") VALUES "
   1328            "($1, $2, $3, $4, $5, $6, $7);");
   1329   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1330                                              "insert_records_by_table_into_table_recoup",
   1331                                              params);
   1332 }
   1333 
   1334 
   1335 /**
   1336  * Function called with recoup_refresh records to insert into table.
   1337  *
   1338  * @param pg plugin context
   1339  * @param td record to insert
   1340  */
   1341 static enum GNUNET_DB_QueryStatus
   1342 irbt_cb_table_recoup_refresh (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1343                               const struct TALER_EXCHANGEDB_TableData *td)
   1344 {
   1345   struct GNUNET_PQ_QueryParam params[] = {
   1346     GNUNET_PQ_query_param_uint64 (
   1347       &td->serial),
   1348     GNUNET_PQ_query_param_auto_from_type (
   1349       &td->details.recoup_refresh.coin_sig),
   1350     GNUNET_PQ_query_param_auto_from_type (
   1351       &td->details.recoup_refresh.coin_blind),
   1352     TALER_PQ_query_param_amount (
   1353       pg->conn,
   1354       &td->details.recoup_refresh.amount),
   1355     GNUNET_PQ_query_param_timestamp (
   1356       &td->details.recoup_refresh.recoup_timestamp),
   1357     GNUNET_PQ_query_param_uint64 (
   1358       &td->details.recoup_refresh.known_coin_id),
   1359     GNUNET_PQ_query_param_auto_from_type (
   1360       &td->details.recoup_refresh.coin_pub),
   1361     GNUNET_PQ_query_param_uint64 (
   1362       &td->details.recoup_refresh.refresh_id),
   1363     GNUNET_PQ_query_param_end
   1364   };
   1365 
   1366   PREPARE (pg,
   1367            "insert_records_by_table_into_table_recoup_refresh",
   1368            "INSERT INTO recoup_refresh"
   1369            "(recoup_refresh_uuid"
   1370            ",coin_sig"
   1371            ",coin_blind"
   1372            ",amount"
   1373            ",recoup_timestamp"
   1374            ",known_coin_id"
   1375            ",coin_pub"
   1376            ",refresh_id"
   1377            ") VALUES "
   1378            "($1, $2, $3, $4, $5, $6, $7, $8);");
   1379   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1380                                              "insert_records_by_table_into_table_recoup_refresh",
   1381                                              params);
   1382 }
   1383 
   1384 
   1385 /**
   1386  * Function called with purse_requests records to insert into table.
   1387  *
   1388  * @param pg plugin context
   1389  * @param td record to insert
   1390  */
   1391 static enum GNUNET_DB_QueryStatus
   1392 irbt_cb_table_purse_requests (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1393                               const struct TALER_EXCHANGEDB_TableData *td)
   1394 {
   1395   struct GNUNET_PQ_QueryParam params[] = {
   1396     GNUNET_PQ_query_param_uint64 (&td->serial),
   1397     GNUNET_PQ_query_param_auto_from_type (
   1398       &td->details.purse_requests.purse_pub),
   1399     GNUNET_PQ_query_param_auto_from_type (
   1400       &td->details.purse_requests.merge_pub),
   1401     GNUNET_PQ_query_param_timestamp (
   1402       &td->details.purse_requests.purse_creation),
   1403     GNUNET_PQ_query_param_timestamp (
   1404       &td->details.purse_requests.purse_expiration),
   1405     GNUNET_PQ_query_param_auto_from_type (
   1406       &td->details.purse_requests.h_contract_terms),
   1407     GNUNET_PQ_query_param_uint32 (&td->details.purse_requests.age_limit),
   1408     GNUNET_PQ_query_param_uint32 (&td->details.purse_requests.flags),
   1409     TALER_PQ_query_param_amount (
   1410       pg->conn,
   1411       &td->details.purse_requests.amount_with_fee),
   1412     TALER_PQ_query_param_amount (
   1413       pg->conn,
   1414       &td->details.purse_requests.purse_fee),
   1415     GNUNET_PQ_query_param_auto_from_type (
   1416       &td->details.purse_requests.purse_sig),
   1417     GNUNET_PQ_query_param_end
   1418   };
   1419 
   1420   PREPARE (pg,
   1421            "insert_records_by_table_into_table_purse_requests",
   1422            "INSERT INTO purse_requests"
   1423            "(purse_requests_serial_id"
   1424            ",purse_pub"
   1425            ",merge_pub"
   1426            ",purse_creation"
   1427            ",purse_expiration"
   1428            ",h_contract_terms"
   1429            ",age_limit"
   1430            ",flags"
   1431            ",amount_with_fee"
   1432            ",purse_fee"
   1433            ",purse_sig"
   1434            ") VALUES "
   1435            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);");
   1436   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1437                                              "insert_records_by_table_into_table_purse_requests",
   1438                                              params);
   1439 }
   1440 
   1441 
   1442 /**
   1443  * Function called with purse_decision records to insert into table.
   1444  *
   1445  * @param pg plugin context
   1446  * @param td record to insert
   1447  */
   1448 static enum GNUNET_DB_QueryStatus
   1449 irbt_cb_table_purse_decision (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1450                               const struct TALER_EXCHANGEDB_TableData *td)
   1451 {
   1452   struct GNUNET_PQ_QueryParam params[] = {
   1453     GNUNET_PQ_query_param_uint64 (&td->serial),
   1454     GNUNET_PQ_query_param_auto_from_type (
   1455       &td->details.purse_decision.purse_pub),
   1456     GNUNET_PQ_query_param_timestamp (
   1457       &td->details.purse_decision.action_timestamp),
   1458     GNUNET_PQ_query_param_bool (
   1459       td->details.purse_decision.refunded),
   1460     GNUNET_PQ_query_param_end
   1461   };
   1462 
   1463   PREPARE (pg,
   1464            "insert_records_by_table_into_table_purse_decision",
   1465            "INSERT INTO purse_decision"
   1466            "(purse_decision_serial_id"
   1467            ",purse_pub"
   1468            ",action_timestamp"
   1469            ",refunded"
   1470            ") VALUES "
   1471            "($1, $2, $3, $4);");
   1472   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1473                                              "insert_records_by_table_into_table_purse_decision",
   1474                                              params);
   1475 }
   1476 
   1477 
   1478 /**
   1479  * Function called with purse_merges records to insert into table.
   1480  *
   1481  * @param pg plugin context
   1482  * @param td record to insert
   1483  */
   1484 static enum GNUNET_DB_QueryStatus
   1485 irbt_cb_table_purse_merges (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1486                             const struct TALER_EXCHANGEDB_TableData *td)
   1487 {
   1488   struct GNUNET_PQ_QueryParam params[] = {
   1489     GNUNET_PQ_query_param_uint64 (&td->serial),
   1490     GNUNET_PQ_query_param_uint64 (&td->details.purse_merges.partner_serial_id),
   1491     GNUNET_PQ_query_param_auto_from_type (
   1492       &td->details.purse_merges.reserve_pub),
   1493     GNUNET_PQ_query_param_auto_from_type (&td->details.purse_merges.purse_pub),
   1494     GNUNET_PQ_query_param_auto_from_type (&td->details.purse_merges.merge_sig),
   1495     GNUNET_PQ_query_param_timestamp (&td->details.purse_merges.merge_timestamp),
   1496     GNUNET_PQ_query_param_end
   1497   };
   1498 
   1499   PREPARE (pg,
   1500            "insert_records_by_table_into_table_purse_merges",
   1501            "INSERT INTO purse_merges"
   1502            "(purse_merge_request_serial_id"
   1503            ",partner_serial_id"
   1504            ",reserve_pub"
   1505            ",purse_pub"
   1506            ",merge_sig"
   1507            ",merge_timestamp"
   1508            ") VALUES "
   1509            "($1, $2, $3, $4, $5, $6);");
   1510   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1511                                              "insert_records_by_table_into_table_purse_merges",
   1512                                              params);
   1513 }
   1514 
   1515 
   1516 /**
   1517  * Function called with purse_deposits records to insert into table.
   1518  *
   1519  * @param pg plugin context
   1520  * @param td record to insert
   1521  */
   1522 static enum GNUNET_DB_QueryStatus
   1523 irbt_cb_table_purse_deposits (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1524                               const struct TALER_EXCHANGEDB_TableData *td)
   1525 {
   1526   struct GNUNET_PQ_QueryParam params[] = {
   1527     GNUNET_PQ_query_param_uint64 (&td->serial),
   1528     GNUNET_PQ_query_param_uint64 (
   1529       &td->details.purse_deposits.partner_serial_id),
   1530     GNUNET_PQ_query_param_auto_from_type (
   1531       &td->details.purse_deposits.purse_pub),
   1532     GNUNET_PQ_query_param_auto_from_type (&td->details.purse_deposits.coin_pub),
   1533     TALER_PQ_query_param_amount (
   1534       pg->conn,
   1535       &td->details.purse_deposits.amount_with_fee),
   1536     GNUNET_PQ_query_param_auto_from_type (&td->details.purse_deposits.coin_sig),
   1537     GNUNET_PQ_query_param_end
   1538   };
   1539 
   1540   PREPARE (pg,
   1541            "insert_records_by_table_into_table_purse_deposits",
   1542            "INSERT INTO purse_deposits"
   1543            "(purse_deposit_serial_id"
   1544            ",partner_serial_id"
   1545            ",purse_pub"
   1546            ",coin_pub"
   1547            ",amount_with_fee"
   1548            ",coin_sig"
   1549            ") VALUES "
   1550            "($1, $2, $3, $4, $5, $6);");
   1551   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1552                                              "insert_records_by_table_into_table_purse_deposits",
   1553                                              params);
   1554 }
   1555 
   1556 
   1557 /**
   1558 x * Function called with account_mergers records to insert into table.
   1559  *
   1560  * @param pg plugin context
   1561  * @param td record to insert
   1562  */
   1563 static enum GNUNET_DB_QueryStatus
   1564 irbt_cb_table_account_mergers (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1565                                const struct TALER_EXCHANGEDB_TableData *td)
   1566 {
   1567   struct GNUNET_PQ_QueryParam params[] = {
   1568     GNUNET_PQ_query_param_uint64 (&td->serial),
   1569     GNUNET_PQ_query_param_auto_from_type (
   1570       &td->details.account_merges.reserve_pub),
   1571     GNUNET_PQ_query_param_auto_from_type (
   1572       &td->details.account_merges.reserve_sig),
   1573     GNUNET_PQ_query_param_auto_from_type (
   1574       &td->details.account_merges.purse_pub),
   1575     GNUNET_PQ_query_param_auto_from_type (
   1576       &td->details.account_merges.wallet_h_payto),
   1577     GNUNET_PQ_query_param_end
   1578   };
   1579 
   1580   PREPARE (pg,
   1581            "insert_records_by_table_into_table_account_merges",
   1582            "INSERT INTO account_merges"
   1583            "(account_merge_request_serial_id"
   1584            ",reserve_pub"
   1585            ",reserve_sig"
   1586            ",purse_pub"
   1587            ",wallet_h_payto"
   1588            ") VALUES "
   1589            "($1, $2, $3, $4, $5);");
   1590   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1591                                              "insert_records_by_table_into_table_account_merges",
   1592                                              params);
   1593 }
   1594 
   1595 
   1596 /**
   1597  * Function called with history_requests records to insert into table.
   1598  *
   1599  * @param pg plugin context
   1600  * @param td record to insert
   1601  */
   1602 static enum GNUNET_DB_QueryStatus
   1603 irbt_cb_table_history_requests (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1604                                 const struct TALER_EXCHANGEDB_TableData *td)
   1605 {
   1606   struct GNUNET_PQ_QueryParam params[] = {
   1607     GNUNET_PQ_query_param_uint64 (&td->serial),
   1608     GNUNET_PQ_query_param_auto_from_type (
   1609       &td->details.history_requests.reserve_pub),
   1610     GNUNET_PQ_query_param_timestamp (
   1611       &td->details.history_requests.request_timestamp),
   1612     GNUNET_PQ_query_param_auto_from_type (
   1613       &td->details.history_requests.reserve_sig),
   1614     TALER_PQ_query_param_amount (
   1615       pg->conn,
   1616       &td->details.history_requests.history_fee),
   1617     GNUNET_PQ_query_param_end
   1618   };
   1619 
   1620   PREPARE (pg,
   1621            "insert_records_by_table_into_table_history_requests",
   1622            "INSERT INTO history_requests"
   1623            "(history_request_serial_id"
   1624            ",reserve_pub"
   1625            ",request_timestamp"
   1626            ",reserve_sig"
   1627            ",history_fee"
   1628            ") VALUES "
   1629            "($1, $2, $3, $4, $5);");
   1630   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1631                                              "insert_records_by_table_into_table_history_requests",
   1632                                              params);
   1633 }
   1634 
   1635 
   1636 /**
   1637  * Function called with close_requests records to insert into table.
   1638  *
   1639  * @param pg plugin context
   1640  * @param td record to insert
   1641  */
   1642 static enum GNUNET_DB_QueryStatus
   1643 irbt_cb_table_close_requests (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1644                               const struct TALER_EXCHANGEDB_TableData *td)
   1645 {
   1646   struct GNUNET_PQ_QueryParam params[] = {
   1647     GNUNET_PQ_query_param_uint64 (&td->serial),
   1648     GNUNET_PQ_query_param_auto_from_type (
   1649       &td->details.close_requests.reserve_pub),
   1650     GNUNET_PQ_query_param_timestamp (
   1651       &td->details.close_requests.close_timestamp),
   1652     GNUNET_PQ_query_param_auto_from_type (
   1653       &td->details.close_requests.reserve_sig),
   1654     TALER_PQ_query_param_amount (
   1655       pg->conn,
   1656       &td->details.close_requests.close),
   1657     TALER_PQ_query_param_amount (
   1658       pg->conn,
   1659       &td->details.close_requests.close_fee),
   1660     GNUNET_PQ_query_param_string (
   1661       td->details.close_requests.payto_uri.full_payto),
   1662     GNUNET_PQ_query_param_end
   1663   };
   1664 
   1665   PREPARE (pg,
   1666            "insert_records_by_table_into_table_close_requests",
   1667            "INSERT INTO close_requests"
   1668            "(close_request_serial_id"
   1669            ",reserve_pub"
   1670            ",close_timestamp"
   1671            ",reserve_sig"
   1672            ",close"
   1673            ",close_fee"
   1674            ",payto_uri"
   1675            ") VALUES "
   1676            "($1, $2, $3, $4, $5, $6, $7);");
   1677   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1678                                              "insert_records_by_table_into_table_close_requests",
   1679                                              params);
   1680 }
   1681 
   1682 
   1683 /**
   1684  * Function called with wads_out records to insert into table.
   1685  *
   1686  * @param pg plugin context
   1687  * @param td record to insert
   1688  */
   1689 static enum GNUNET_DB_QueryStatus
   1690 irbt_cb_table_wads_out (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1691                         const struct TALER_EXCHANGEDB_TableData *td)
   1692 {
   1693   struct GNUNET_PQ_QueryParam params[] = {
   1694     GNUNET_PQ_query_param_uint64 (&td->serial),
   1695     GNUNET_PQ_query_param_auto_from_type (&td->details.wads_out.wad_id),
   1696     GNUNET_PQ_query_param_uint64 (&td->details.wads_out.partner_serial_id),
   1697     TALER_PQ_query_param_amount (
   1698       pg->conn,
   1699       &td->details.wads_out.amount),
   1700     GNUNET_PQ_query_param_timestamp (&td->details.wads_out.execution_time),
   1701     GNUNET_PQ_query_param_end
   1702   };
   1703 
   1704   PREPARE (pg,
   1705            "insert_records_by_table_into_table_wads_out",
   1706            "INSERT INTO wads_out"
   1707            "(wad_out_serial_id"
   1708            ",wad_id"
   1709            ",partner_serial_id"
   1710            ",amount"
   1711            ",execution_time"
   1712            ") VALUES "
   1713            "($1, $2, $3, $4, $5);");
   1714   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1715                                              "insert_records_by_table_into_table_wads_out",
   1716                                              params);
   1717 }
   1718 
   1719 
   1720 /**
   1721  * Function called with wads_out_entries records to insert into table.
   1722  *
   1723  * @param pg plugin context
   1724  * @param td record to insert
   1725  */
   1726 static enum GNUNET_DB_QueryStatus
   1727 irbt_cb_table_wads_out_entries (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1728                                 const struct TALER_EXCHANGEDB_TableData *td)
   1729 {
   1730   struct GNUNET_PQ_QueryParam params[] = {
   1731     GNUNET_PQ_query_param_uint64 (&td->serial),
   1732     GNUNET_PQ_query_param_uint64 (
   1733       &td->details.wads_out_entries.wad_out_serial_id),
   1734     GNUNET_PQ_query_param_auto_from_type (
   1735       &td->details.wads_out_entries.reserve_pub),
   1736     GNUNET_PQ_query_param_auto_from_type (
   1737       &td->details.wads_out_entries.purse_pub),
   1738     GNUNET_PQ_query_param_auto_from_type (
   1739       &td->details.wads_out_entries.h_contract),
   1740     GNUNET_PQ_query_param_timestamp (
   1741       &td->details.wads_out_entries.purse_expiration),
   1742     GNUNET_PQ_query_param_timestamp (
   1743       &td->details.wads_out_entries.merge_timestamp),
   1744     TALER_PQ_query_param_amount (
   1745       pg->conn,
   1746       &td->details.wads_out_entries.amount_with_fee),
   1747     TALER_PQ_query_param_amount (
   1748       pg->conn,
   1749       &td->details.wads_out_entries.wad_fee),
   1750     TALER_PQ_query_param_amount (
   1751       pg->conn,
   1752       &td->details.wads_out_entries.deposit_fees),
   1753     GNUNET_PQ_query_param_auto_from_type (
   1754       &td->details.wads_out_entries.reserve_sig),
   1755     GNUNET_PQ_query_param_auto_from_type (
   1756       &td->details.wads_out_entries.purse_sig),
   1757     GNUNET_PQ_query_param_end
   1758   };
   1759 
   1760   PREPARE (pg,
   1761            "insert_records_by_table_into_table_wad_out_entries",
   1762            "INSERT INTO wad_out_entries"
   1763            "(wad_out_entry_serial_id"
   1764            ",wad_out_serial_id"
   1765            ",reserve_pub"
   1766            ",purse_pub"
   1767            ",h_contract"
   1768            ",purse_expiration"
   1769            ",merge_timestamp"
   1770            ",amount_with_fee"
   1771            ",wad_fee"
   1772            ",deposit_fees"
   1773            ",reserve_sig"
   1774            ",purse_sig"
   1775            ") VALUES "
   1776            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);");
   1777   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1778                                              "insert_records_by_table_into_table_wad_out_entries",
   1779                                              params);
   1780 }
   1781 
   1782 
   1783 /**
   1784  * Function called with wads_in records to insert into table.
   1785  *
   1786  * @param pg plugin context
   1787  * @param td record to insert
   1788  */
   1789 static enum GNUNET_DB_QueryStatus
   1790 irbt_cb_table_wads_in (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1791                        const struct TALER_EXCHANGEDB_TableData *td)
   1792 {
   1793   struct GNUNET_PQ_QueryParam params[] = {
   1794     GNUNET_PQ_query_param_uint64 (&td->serial),
   1795     GNUNET_PQ_query_param_auto_from_type (&td->details.wads_in.wad_id),
   1796     GNUNET_PQ_query_param_string (td->details.wads_in.origin_exchange_url),
   1797     TALER_PQ_query_param_amount (
   1798       pg->conn,
   1799       &td->details.wads_in.amount),
   1800     GNUNET_PQ_query_param_timestamp (&td->details.wads_in.arrival_time),
   1801     GNUNET_PQ_query_param_end
   1802   };
   1803 
   1804   PREPARE (pg,
   1805            "insert_records_by_table_into_table_wads_in",
   1806            "INSERT INTO wads_in"
   1807            "(wad_in_serial_id"
   1808            ",wad_id"
   1809            ",origin_exchange_url"
   1810            ",amount"
   1811            ",arrival_time"
   1812            ") VALUES "
   1813            "($1, $2, $3, $4, $5);");
   1814   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1815                                              "insert_records_by_table_into_table_wads_in",
   1816                                              params);
   1817 }
   1818 
   1819 
   1820 /**
   1821  * Function called with wads_in_entries records to insert into table.
   1822  *
   1823  * @param pg plugin context
   1824  * @param td record to insert
   1825  */
   1826 static enum GNUNET_DB_QueryStatus
   1827 irbt_cb_table_wads_in_entries (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1828                                const struct TALER_EXCHANGEDB_TableData *td)
   1829 {
   1830   struct GNUNET_PQ_QueryParam params[] = {
   1831     GNUNET_PQ_query_param_uint64 (&td->serial),
   1832     GNUNET_PQ_query_param_auto_from_type (
   1833       &td->details.wads_in_entries.reserve_pub),
   1834     GNUNET_PQ_query_param_auto_from_type (
   1835       &td->details.wads_in_entries.purse_pub),
   1836     GNUNET_PQ_query_param_auto_from_type (
   1837       &td->details.wads_in_entries.h_contract),
   1838     GNUNET_PQ_query_param_timestamp (
   1839       &td->details.wads_in_entries.purse_expiration),
   1840     GNUNET_PQ_query_param_timestamp (
   1841       &td->details.wads_in_entries.merge_timestamp),
   1842     TALER_PQ_query_param_amount (
   1843       pg->conn,
   1844       &td->details.wads_in_entries.amount_with_fee),
   1845     TALER_PQ_query_param_amount (
   1846       pg->conn,
   1847       &td->details.wads_in_entries.wad_fee),
   1848     TALER_PQ_query_param_amount (
   1849       pg->conn,
   1850       &td->details.wads_in_entries.deposit_fees),
   1851     GNUNET_PQ_query_param_auto_from_type (
   1852       &td->details.wads_in_entries.reserve_sig),
   1853     GNUNET_PQ_query_param_auto_from_type (
   1854       &td->details.wads_in_entries.purse_sig),
   1855     GNUNET_PQ_query_param_end
   1856   };
   1857 
   1858   PREPARE (pg,
   1859            "insert_records_by_table_into_table_wad_in_entries",
   1860            "INSERT INTO wad_in_entries"
   1861            "(wad_in_entry_serial_id"
   1862            ",wad_in_serial_id"
   1863            ",reserve_pub"
   1864            ",purse_pub"
   1865            ",h_contract"
   1866            ",purse_expiration"
   1867            ",merge_timestamp"
   1868            ",amount_with_fee"
   1869            ",wad_fee"
   1870            ",deposit_fees"
   1871            ",reserve_sig"
   1872            ",purse_sig"
   1873            ") VALUES "
   1874            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);");
   1875   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1876                                              "insert_records_by_table_into_table_wad_in_entries",
   1877                                              params);
   1878 }
   1879 
   1880 
   1881 /**
   1882  * Function called with profit_drains records to insert into table.
   1883  *
   1884  * @param pg plugin context
   1885  * @param td record to insert
   1886  */
   1887 static enum GNUNET_DB_QueryStatus
   1888 irbt_cb_table_profit_drains (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1889                              const struct TALER_EXCHANGEDB_TableData *td)
   1890 {
   1891   struct GNUNET_PQ_QueryParam params[] = {
   1892     GNUNET_PQ_query_param_uint64 (&td->serial),
   1893     GNUNET_PQ_query_param_auto_from_type (
   1894       &td->details.profit_drains.wtid),
   1895     GNUNET_PQ_query_param_string (
   1896       td->details.profit_drains.account_section),
   1897     GNUNET_PQ_query_param_string (
   1898       td->details.profit_drains.payto_uri.full_payto),
   1899     GNUNET_PQ_query_param_timestamp (
   1900       &td->details.profit_drains.trigger_date),
   1901     TALER_PQ_query_param_amount (
   1902       pg->conn,
   1903       &td->details.profit_drains.amount),
   1904     GNUNET_PQ_query_param_auto_from_type (
   1905       &td->details.profit_drains.master_sig),
   1906     GNUNET_PQ_query_param_end
   1907   };
   1908 
   1909   PREPARE (pg,
   1910            "insert_records_by_table_into_table_profit_drains",
   1911            "INSERT INTO profit_drains"
   1912            "(profit_drain_serial_id"
   1913            ",wtid"
   1914            ",account_section"
   1915            ",payto_uri"
   1916            ",trigger_date"
   1917            ",amount"
   1918            ",master_sig"
   1919            ") VALUES "
   1920            "($1, $2, $3, $4, $5, $6, $7);");
   1921   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1922                                              "insert_records_by_table_into_table_profit_drains",
   1923                                              params);
   1924 }
   1925 
   1926 
   1927 /**
   1928  * Function called with aml_staff records to insert into table.
   1929  *
   1930  * @param pg plugin context
   1931  * @param td record to insert
   1932  */
   1933 static enum GNUNET_DB_QueryStatus
   1934 irbt_cb_table_aml_staff (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1935                          const struct TALER_EXCHANGEDB_TableData *td)
   1936 {
   1937   struct GNUNET_PQ_QueryParam params[] = {
   1938     GNUNET_PQ_query_param_uint64 (&td->serial),
   1939     GNUNET_PQ_query_param_auto_from_type (
   1940       &td->details.aml_staff.decider_pub),
   1941     GNUNET_PQ_query_param_auto_from_type (
   1942       &td->details.aml_staff.master_sig),
   1943     GNUNET_PQ_query_param_string (
   1944       td->details.aml_staff.decider_name),
   1945     GNUNET_PQ_query_param_bool (
   1946       td->details.aml_staff.is_active),
   1947     GNUNET_PQ_query_param_bool (
   1948       td->details.aml_staff.read_only),
   1949     GNUNET_PQ_query_param_timestamp (
   1950       &td->details.aml_staff.last_change),
   1951     GNUNET_PQ_query_param_end
   1952   };
   1953 
   1954   PREPARE (pg,
   1955            "insert_records_by_table_into_table_aml_staff",
   1956            "INSERT INTO aml_staff"
   1957            "(aml_staff_uuid"
   1958            ",decider_pub"
   1959            ",master_sig"
   1960            ",decider_name"
   1961            ",is_active"
   1962            ",read_only"
   1963            ",last_change"
   1964            ") VALUES "
   1965            "($1, $2, $3, $4, $5, $6, $7);");
   1966   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   1967                                              "insert_records_by_table_into_table_aml_staff",
   1968                                              params);
   1969 }
   1970 
   1971 
   1972 /**
   1973  * Function called with kyc_attributes records to insert into table.
   1974  *
   1975  * @param pg plugin context
   1976  * @param td record to insert
   1977  */
   1978 static enum GNUNET_DB_QueryStatus
   1979 irbt_cb_table_kyc_attributes (struct TALER_EXCHANGEDB_PostgresContext *pg,
   1980                               const struct TALER_EXCHANGEDB_TableData *td)
   1981 {
   1982   struct GNUNET_PQ_QueryParam params[] = {
   1983     GNUNET_PQ_query_param_uint64 (&td->serial),
   1984     GNUNET_PQ_query_param_auto_from_type (
   1985       &td->details.kyc_attributes.h_payto),
   1986     GNUNET_PQ_query_param_uint64 (
   1987       &td->details.kyc_attributes.legitimization_serial),
   1988     GNUNET_PQ_query_param_timestamp (
   1989       &td->details.kyc_attributes.collection_time),
   1990     GNUNET_PQ_query_param_timestamp (
   1991       &td->details.kyc_attributes.expiration_time),
   1992     NULL == td->details.kyc_attributes.form_name
   1993     ? GNUNET_PQ_query_param_null ()
   1994     : GNUNET_PQ_query_param_string (
   1995       td->details.kyc_attributes.form_name),
   1996     GNUNET_PQ_query_param_bool (
   1997       td->details.kyc_attributes.by_aml_officer),
   1998     GNUNET_PQ_query_param_fixed_size (
   1999       td->details.kyc_attributes.encrypted_attributes,
   2000       td->details.kyc_attributes.encrypted_attributes_size),
   2001     GNUNET_PQ_query_param_end
   2002   };
   2003 
   2004   PREPARE (pg,
   2005            "insert_records_by_table_into_table_kyc_attributes",
   2006            "INSERT INTO kyc_attributes"
   2007            "(kyc_attributes_serial_id"
   2008            ",h_payto"
   2009            ",legitimization_serial"
   2010            ",collection_time"
   2011            ",expiration_time"
   2012            ",form_name"
   2013            ",by_aml_officer"
   2014            ",encrypted_attributes"
   2015            ") VALUES "
   2016            "($1, $2, $3, $4, $5, $6, $7, $8);");
   2017   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   2018                                              "insert_records_by_table_into_table_kyc_attributes",
   2019                                              params);
   2020 }
   2021 
   2022 
   2023 /**
   2024  * Function called with aml_history records to insert into table.
   2025  *
   2026  * @param pg plugin context
   2027  * @param td record to insert
   2028  */
   2029 static enum GNUNET_DB_QueryStatus
   2030 irbt_cb_table_aml_history (struct TALER_EXCHANGEDB_PostgresContext *pg,
   2031                            const struct TALER_EXCHANGEDB_TableData *td)
   2032 {
   2033   struct GNUNET_PQ_QueryParam params[] = {
   2034     GNUNET_PQ_query_param_uint64 (&td->serial),
   2035     GNUNET_PQ_query_param_auto_from_type (
   2036       &td->details.aml_history.h_payto),
   2037     GNUNET_PQ_query_param_uint64 (
   2038       &td->details.aml_history.outcome_serial_id),
   2039     GNUNET_PQ_query_param_string (
   2040       td->details.aml_history.justification),
   2041     GNUNET_PQ_query_param_auto_from_type (
   2042       &td->details.aml_history.decider_pub),
   2043     GNUNET_PQ_query_param_auto_from_type (
   2044       &td->details.aml_history.decider_sig),
   2045     td->details.aml_history.no_kyc_attributes_hash
   2046     ? GNUNET_PQ_query_param_null ()
   2047     : GNUNET_PQ_query_param_auto_from_type (
   2048       &td->details.aml_history.kyc_attributes_hash),
   2049     td->details.aml_history.no_kyc_attributes_serial_id
   2050     ? GNUNET_PQ_query_param_null ()
   2051     : GNUNET_PQ_query_param_uint64 (
   2052       &td->details.aml_history.kyc_attributes_serial_id),
   2053     GNUNET_PQ_query_param_end
   2054   };
   2055 
   2056   PREPARE (pg,
   2057            "insert_records_by_table_into_table_aml_history",
   2058            "INSERT INTO aml_history"
   2059            "(aml_history_serial_id"
   2060            ",h_payto"
   2061            ",outcome_serial_id"
   2062            ",justification"
   2063            ",decider_pub"
   2064            ",decider_sig"
   2065            ",kyc_attributes_hash"
   2066            ",kyc_attributes_serial_id"
   2067            ") VALUES "
   2068            "($1, $2, $3, $4, $5, $6, $7, $8);");
   2069   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   2070                                              "insert_records_by_table_into_table_aml_history",
   2071                                              params);
   2072 }
   2073 
   2074 
   2075 /**
   2076  * Function called with kyc_event records to insert into table.
   2077  *
   2078  * @param pg plugin context
   2079  * @param td record to insert
   2080  */
   2081 static enum GNUNET_DB_QueryStatus
   2082 irbt_cb_table_kyc_events (struct TALER_EXCHANGEDB_PostgresContext *pg,
   2083                           const struct TALER_EXCHANGEDB_TableData *td)
   2084 {
   2085   struct GNUNET_PQ_QueryParam params[] = {
   2086     GNUNET_PQ_query_param_uint64 (&td->serial),
   2087     GNUNET_PQ_query_param_timestamp (
   2088       &td->details.kyc_events.event_timestamp),
   2089     GNUNET_PQ_query_param_string (
   2090       td->details.kyc_events.event_type),
   2091     GNUNET_PQ_query_param_end
   2092   };
   2093 
   2094   PREPARE (pg,
   2095            "insert_records_by_table_into_table_kyc_events",
   2096            "INSERT INTO kyc_events"
   2097            "(kyc_event_serial_id"
   2098            ",event_timestamp"
   2099            ",event_type"
   2100            ") VALUES "
   2101            "($1, $2, $3);");
   2102   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   2103                                              "insert_records_by_table_into_table_kyc_events",
   2104                                              params);
   2105 }
   2106 
   2107 
   2108 /**
   2109  * Function called with purse_deletion records to insert into table.
   2110  *
   2111  * @param pg plugin context
   2112  * @param td record to insert
   2113  */
   2114 static enum GNUNET_DB_QueryStatus
   2115 irbt_cb_table_purse_deletion (struct TALER_EXCHANGEDB_PostgresContext *pg,
   2116                               const struct TALER_EXCHANGEDB_TableData *td)
   2117 {
   2118   struct GNUNET_PQ_QueryParam params[] = {
   2119     GNUNET_PQ_query_param_uint64 (&td->serial),
   2120     GNUNET_PQ_query_param_auto_from_type (
   2121       &td->details.purse_deletion.purse_pub),
   2122     GNUNET_PQ_query_param_auto_from_type (
   2123       &td->details.purse_deletion.purse_sig),
   2124     GNUNET_PQ_query_param_end
   2125   };
   2126 
   2127   PREPARE (pg,
   2128            "insert_records_by_table_into_table_purse_deletion",
   2129            "INSERT INTO purse_deletion"
   2130            "(purse_deletion_serial_id"
   2131            ",purse_pub"
   2132            ",purse_sig"
   2133            ") VALUES "
   2134            "($1, $2, $3);");
   2135   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
   2136                                              "insert_records_by_table_into_table_purse_deletion",
   2137                                              params);
   2138 }
   2139 
   2140 
   2141 /**
   2142  * Function called with withdraw records to insert into table.
   2143  *
   2144  * @param pg plugin context
   2145  * @param td record to insert
   2146  */
   2147 static enum GNUNET_DB_QueryStatus
   2148 irbt_cb_table_withdraw (
   2149   struct TALER_EXCHANGEDB_PostgresContext *pg,
   2150   const struct TALER_EXCHANGEDB_TableData *td)
   2151 {
   2152   struct GNUNET_PQ_QueryParam params[] = {
   2153     GNUNET_PQ_query_param_uint64 (&td->serial),
   2154     GNUNET_PQ_query_param_auto_from_type (
   2155       &td->details.withdraw.planchets_h),
   2156     GNUNET_PQ_query_param_timestamp (
   2157       &td->details.withdraw.execution_date),
   2158     TALER_PQ_query_param_amount (
   2159       pg->conn,
   2160       &td->details.withdraw.amount_with_fee),
   2161     GNUNET_PQ_query_param_auto_from_type (
   2162       &td->details.withdraw.reserve_pub),
   2163     GNUNET_PQ_query_param_auto_from_type (
   2164       &td->details.withdraw.reserve_sig),
   2165     td->details.withdraw.age_proof_required
   2166     ? GNUNET_PQ_query_param_uint16 (
   2167       &td->details.withdraw.max_age)
   2168     : GNUNET_PQ_query_param_null (),
   2169     td->details.withdraw.age_proof_required
   2170     ? GNUNET_PQ_query_param_uint16 (
   2171       &td->details.withdraw.noreveal_index)
   2172     : GNUNET_PQ_query_param_null (),
   2173     td->details.withdraw.age_proof_required
   2174     ? GNUNET_PQ_query_param_auto_from_type (
   2175       &td->details.withdraw.selected_h)
   2176     : GNUNET_PQ_query_param_null (),
   2177     td->details.withdraw.no_blinding_seed
   2178     ? GNUNET_PQ_query_param_null ()
   2179     : GNUNET_PQ_query_param_auto_from_type (
   2180       &td->details.withdraw.blinding_seed),
   2181     (0 < td->details.withdraw.num_cs_r_values)
   2182     ? TALER_PQ_query_param_array_cs_r_pub (
   2183       td->details.withdraw.num_cs_r_values,
   2184       td->details.withdraw.cs_r_values,
   2185       pg->conn)
   2186     : GNUNET_PQ_query_param_null (),
   2187     (0 < td->details.withdraw.num_cs_r_values)
   2188     ? GNUNET_PQ_query_param_uint64 (
   2189       &td->details.withdraw.cs_r_choices)
   2190     : GNUNET_PQ_query_param_null (),
   2191     GNUNET_PQ_query_param_array_uint64 (
   2192       td->details.withdraw.num_coins,
   2193       td->details.withdraw.denom_serials,
   2194       pg->conn),
   2195     TALER_PQ_query_param_array_blinded_denom_sig (
   2196       td->details.withdraw.num_coins,
   2197       td->details.withdraw.denom_sigs,
   2198       pg->conn),
   2199     GNUNET_PQ_query_param_end
   2200   };
   2201   enum GNUNET_DB_QueryStatus qs;
   2202 
   2203   PREPARE (pg,
   2204            "insert_records_by_table_into_table_withdraw",
   2205            "INSERT INTO withdraw"
   2206            "(withdraw_id"
   2207            ",planchets_h"
   2208            ",execution_date"
   2209            ",amount_with_fee"
   2210            ",reserve_pub"
   2211            ",reserve_sig"
   2212            ",max_age"
   2213            ",noreveal_index"
   2214            ",selected_h"
   2215            ",blinding_seed"
   2216            ",cs_r_values"
   2217            ",cs_r_choices"
   2218            ",denom_serials"
   2219            ",denom_sigs"
   2220            ") VALUES "
   2221            "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14);");
   2222   qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
   2223                                            "insert_records_by_table_into_table_withdraw",
   2224                                            params);
   2225   GNUNET_PQ_cleanup_query_params_closures (params);
   2226   return qs;
   2227 }
   2228 
   2229 
   2230 enum GNUNET_DB_QueryStatus
   2231 TALER_EXCHANGEDB_insert_records_by_table (
   2232   struct TALER_EXCHANGEDB_PostgresContext *pg,
   2233   const struct TALER_EXCHANGEDB_TableData *td)
   2234 {
   2235   InsertRecordCallback rh = NULL;
   2236 
   2237   switch (td->table)
   2238   {
   2239   case TALER_EXCHANGEDB_RT_DENOMINATIONS:
   2240     rh = &irbt_cb_table_denominations;
   2241     break;
   2242   case TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS:
   2243     rh = &irbt_cb_table_denomination_revocations;
   2244     break;
   2245   case TALER_EXCHANGEDB_RT_WIRE_TARGETS:
   2246     rh = &irbt_cb_table_wire_targets;
   2247     break;
   2248   case TALER_EXCHANGEDB_RT_KYC_TARGETS:
   2249     rh = &irbt_cb_table_kyc_targets;
   2250     break;
   2251   case TALER_EXCHANGEDB_RT_RESERVES:
   2252     rh = &irbt_cb_table_reserves;
   2253     break;
   2254   case TALER_EXCHANGEDB_RT_RESERVES_IN:
   2255     rh = &irbt_cb_table_reserves_in;
   2256     break;
   2257   case TALER_EXCHANGEDB_RT_KYCAUTHS_IN:
   2258     rh = &irbt_cb_table_kycauths_in;
   2259     break;
   2260   case TALER_EXCHANGEDB_RT_RESERVES_CLOSE:
   2261     rh = &irbt_cb_table_reserves_close;
   2262     break;
   2263   case TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS:
   2264     rh = &irbt_cb_table_reserves_open_requests;
   2265     break;
   2266   case TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS:
   2267     rh = &irbt_cb_table_reserves_open_deposits;
   2268     break;
   2269   case TALER_EXCHANGEDB_RT_AUDITORS:
   2270     rh = &irbt_cb_table_auditors;
   2271     break;
   2272   case TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS:
   2273     rh = &irbt_cb_table_auditor_denom_sigs;
   2274     break;
   2275   case TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS:
   2276     rh = &irbt_cb_table_exchange_sign_keys;
   2277     break;
   2278   case TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS:
   2279     rh = &irbt_cb_table_signkey_revocations;
   2280     break;
   2281   case TALER_EXCHANGEDB_RT_KNOWN_COINS:
   2282     rh = &irbt_cb_table_known_coins;
   2283     break;
   2284   case TALER_EXCHANGEDB_RT_REFRESH:
   2285     rh = &irbt_cb_table_refresh;
   2286     break;
   2287   case TALER_EXCHANGEDB_RT_BATCH_DEPOSITS:
   2288     rh = &irbt_cb_table_batch_deposits;
   2289     break;
   2290   case TALER_EXCHANGEDB_RT_COIN_DEPOSITS:
   2291     rh = &irbt_cb_table_coin_deposits;
   2292     break;
   2293   case TALER_EXCHANGEDB_RT_REFUNDS:
   2294     rh = &irbt_cb_table_refunds;
   2295     break;
   2296   case TALER_EXCHANGEDB_RT_WIRE_OUT:
   2297     rh = &irbt_cb_table_wire_out;
   2298     break;
   2299   case TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING:
   2300     rh = &irbt_cb_table_aggregation_tracking;
   2301     break;
   2302   case TALER_EXCHANGEDB_RT_AGGREGATION_DEFERRALS:
   2303     rh = &irbt_cb_table_aggregation_deferrals;
   2304     break;
   2305   case TALER_EXCHANGEDB_RT_WIRE_FEE:
   2306     rh = &irbt_cb_table_wire_fee;
   2307     break;
   2308   case TALER_EXCHANGEDB_RT_GLOBAL_FEE:
   2309     rh = &irbt_cb_table_global_fee;
   2310     break;
   2311   case TALER_EXCHANGEDB_RT_RECOUP:
   2312     rh = &irbt_cb_table_recoup;
   2313     break;
   2314   case TALER_EXCHANGEDB_RT_RECOUP_REFRESH:
   2315     rh = &irbt_cb_table_recoup_refresh;
   2316     break;
   2317   case TALER_EXCHANGEDB_RT_PURSE_REQUESTS:
   2318     rh = &irbt_cb_table_purse_requests;
   2319     break;
   2320   case TALER_EXCHANGEDB_RT_PURSE_DECISION:
   2321     rh = &irbt_cb_table_purse_decision;
   2322     break;
   2323   case TALER_EXCHANGEDB_RT_PURSE_MERGES:
   2324     rh = &irbt_cb_table_purse_merges;
   2325     break;
   2326   case TALER_EXCHANGEDB_RT_PURSE_DEPOSITS:
   2327     rh = &irbt_cb_table_purse_deposits;
   2328     break;
   2329   case TALER_EXCHANGEDB_RT_ACCOUNT_MERGES:
   2330     rh = &irbt_cb_table_account_mergers;
   2331     break;
   2332   case TALER_EXCHANGEDB_RT_HISTORY_REQUESTS:
   2333     rh = &irbt_cb_table_history_requests;
   2334     break;
   2335   case TALER_EXCHANGEDB_RT_CLOSE_REQUESTS:
   2336     rh = &irbt_cb_table_close_requests;
   2337     break;
   2338   case TALER_EXCHANGEDB_RT_WADS_OUT:
   2339     rh = &irbt_cb_table_wads_out;
   2340     break;
   2341   case TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES:
   2342     rh = &irbt_cb_table_wads_out_entries;
   2343     break;
   2344   case TALER_EXCHANGEDB_RT_WADS_IN:
   2345     rh = &irbt_cb_table_wads_in;
   2346     break;
   2347   case TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES:
   2348     rh = &irbt_cb_table_wads_in_entries;
   2349     break;
   2350   case TALER_EXCHANGEDB_RT_PROFIT_DRAINS:
   2351     rh = &irbt_cb_table_profit_drains;
   2352     break;
   2353   case TALER_EXCHANGEDB_RT_AML_STAFF:
   2354     rh = &irbt_cb_table_aml_staff;
   2355     break;
   2356   case TALER_EXCHANGEDB_RT_PURSE_DELETION:
   2357     rh = &irbt_cb_table_purse_deletion;
   2358     break;
   2359   case TALER_EXCHANGEDB_RT_WITHDRAW:
   2360     rh = &irbt_cb_table_withdraw;
   2361     break;
   2362   case TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES:
   2363     rh = &irbt_cb_table_legitimization_measures;
   2364     break;
   2365   case TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES:
   2366     rh = &irbt_cb_table_legitimization_outcomes;
   2367     break;
   2368   case TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES:
   2369     rh = &irbt_cb_table_legitimization_processes;
   2370     break;
   2371   case TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES:
   2372     rh = &irbt_cb_table_kyc_attributes;
   2373     break;
   2374   case TALER_EXCHANGEDB_RT_AML_HISTORY:
   2375     rh = &irbt_cb_table_aml_history;
   2376     break;
   2377   case TALER_EXCHANGEDB_RT_KYC_EVENTS:
   2378     rh = &irbt_cb_table_kyc_events;
   2379     break;
   2380   }
   2381   if (NULL == rh)
   2382   {
   2383     GNUNET_break (0);
   2384     return GNUNET_DB_STATUS_HARD_ERROR;
   2385   }
   2386   return rh (pg,
   2387              td);
   2388 }
   2389 
   2390 
   2391 /* end of insert_records_by_table.c */