LCOV - code coverage report
Current view: top level - backenddb - plugin_merchantdb_postgres.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 208 215 96.7 %
Date: 2025-08-28 06:06:54 Functions: 10 10 100.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   (C) 2014--2025 Taler Systems SA
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify it under the
       6             :   terms of the GNU Lesser General Public License as published by the Free Software
       7             :   Foundation; either version 3, or (at your option) any later version.
       8             : 
       9             :   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
      10             :   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
      11             :   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
      12             : 
      13             :   You should have received a copy of the GNU General Public License along with
      14             :   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
      15             : */
      16             : /**
      17             :  * @file plugin_merchantdb_postgres.c
      18             :  * @brief database helper functions for postgres used by the merchant
      19             :  * @author Sree Harsha Totakura <sreeharsha@totakura.in>
      20             :  * @author Christian Grothoff
      21             :  * @author Marcello Stanisci
      22             :  * @author Priscilla Huang
      23             :  * @author Iván Ávalos
      24             :  */
      25             : #include "platform.h"
      26             : #include <gnunet/gnunet_util_lib.h>
      27             : #include <gnunet/gnunet_pq_lib.h>
      28             : #include <taler/taler_util.h>
      29             : #include <taler/taler_pq_lib.h>
      30             : #include <taler/taler_json_lib.h>
      31             : #include <taler/taler_mhd_lib.h>
      32             : #include "taler_merchantdb_plugin.h"
      33             : #include "pg_helper.h"
      34             : #include "pg_gc.h"
      35             : #include "pg_insert_otp.h"
      36             : #include "pg_get_kyc_status.h"
      37             : #include "pg_get_kyc_limits.h"
      38             : #include "pg_delete_otp.h"
      39             : #include "pg_update_otp.h"
      40             : #include "pg_account_kyc_set_failed.h"
      41             : #include "pg_select_otp.h"
      42             : #include "pg_select_otp_serial.h"
      43             : #include "pg_insert_login_token.h"
      44             : #include "pg_delete_login_token.h"
      45             : #include "pg_select_login_token.h"
      46             : #include "pg_lookup_login_tokens.h"
      47             : #include "pg_insert_account.h"
      48             : #include "pg_update_account.h"
      49             : #include "pg_lookup_instances.h"
      50             : #include "pg_lookup_transfers.h"
      51             : #include "pg_lookup_pending_deposits.h"
      52             : #include "pg_lookup_categories.h"
      53             : #include "pg_select_category.h"
      54             : #include "pg_update_category.h"
      55             : #include "pg_insert_category.h"
      56             : #include "pg_delete_category.h"
      57             : #include "pg_update_wirewatch_progress.h"
      58             : #include "pg_select_wirewatch_accounts.h"
      59             : #include "pg_select_open_transfers.h"
      60             : #include "pg_delete_exchange_accounts.h"
      61             : #include "pg_select_accounts_by_exchange.h"
      62             : #include "pg_insert_exchange_account.h"
      63             : #include "pg_lookup_instance_auth.h"
      64             : #include "pg_lookup_otp_devices.h"
      65             : #include "pg_update_transfer_status.h"
      66             : #include "pg_finalize_transfer_status.h"
      67             : #include "pg_insert_instance.h"
      68             : #include "pg_account_kyc_set_status.h"
      69             : #include "pg_account_kyc_get_status.h"
      70             : #include "pg_delete_instance_private_key.h"
      71             : #include "pg_select_category_by_name.h"
      72             : #include "pg_purge_instance.h"
      73             : #include "pg_update_instance.h"
      74             : #include "pg_update_instance_auth.h"
      75             : #include "pg_inactivate_account.h"
      76             : #include "pg_activate_account.h"
      77             : #include "pg_lookup_products.h"
      78             : #include "pg_lookup_all_products.h"
      79             : #include "pg_lookup_product.h"
      80             : #include "pg_delete_product.h"
      81             : #include "pg_insert_product.h"
      82             : #include "pg_update_product.h"
      83             : #include "pg_lookup_token_family_keys.h"
      84             : #include "pg_lock_product.h"
      85             : #include "pg_expire_locks.h"
      86             : #include "pg_delete_order.h"
      87             : #include "pg_lookup_order.h"
      88             : #include "pg_lookup_order_summary.h"
      89             : #include "pg_lookup_orders.h"
      90             : #include "pg_insert_order.h"
      91             : #include "pg_insert_order_blinded_sigs.h"
      92             : #include "pg_unlock_inventory.h"
      93             : #include "pg_insert_order_lock.h"
      94             : #include "pg_select_order_blinded_sigs.h"
      95             : #include "pg_lookup_contract_terms3.h"
      96             : #include "pg_lookup_contract_terms2.h"
      97             : #include "pg_lookup_contract_terms.h"
      98             : #include "pg_insert_contract_terms.h"
      99             : #include "pg_update_contract_terms.h"
     100             : #include "pg_delete_contract_terms.h"
     101             : #include "pg_delete_template.h"
     102             : #include "pg_insert_template.h"
     103             : #include "pg_update_template.h"
     104             : #include "pg_lookup_templates.h"
     105             : #include "pg_lookup_template.h"
     106             : #include "pg_lookup_deposits.h"
     107             : #include "pg_insert_exchange_signkey.h"
     108             : #include "pg_insert_deposit.h"
     109             : #include "pg_insert_deposit_confirmation.h"
     110             : #include "pg_lookup_refunds.h"
     111             : #include "pg_mark_contract_paid.h"
     112             : #include "pg_select_account_by_uri.h"
     113             : #include "pg_refund_coin.h"
     114             : #include "pg_lookup_order_status.h"
     115             : #include "pg_lookup_order_status_by_serial.h"
     116             : #include "pg_lookup_deposits_by_order.h"
     117             : #include "pg_lookup_transfer_details_by_order.h"
     118             : #include "pg_mark_order_wired.h"
     119             : #include "pg_lookup_refunds_detailed.h"
     120             : #include "pg_insert_refund_proof.h"
     121             : #include "pg_lookup_refund_proof.h"
     122             : #include "pg_lookup_order_by_fulfillment.h"
     123             : #include "pg_delete_transfer.h"
     124             : #include "pg_check_transfer_exists.h"
     125             : #include "pg_lookup_account.h"
     126             : #include "pg_lookup_expected_transfers.h"
     127             : #include "pg_lookup_deposits_by_contract_and_coin.h"
     128             : #include "pg_lookup_transfer_summary.h"
     129             : #include "pg_lookup_transfer_details.h"
     130             : #include "pg_lookup_webhooks.h"
     131             : #include "pg_lookup_webhook.h"
     132             : #include "pg_lookup_wire_fee.h"
     133             : #include "pg_delete_webhook.h"
     134             : #include "pg_insert_webhook.h"
     135             : #include "pg_update_webhook.h"
     136             : #include "pg_lookup_webhook_by_event.h"
     137             : #include "pg_delete_pending_webhook.h"
     138             : #include "pg_insert_pending_webhook.h"
     139             : #include "pg_update_pending_webhook.h"
     140             : #include "pg_lookup_pending_webhooks.h"
     141             : #include "pg_update_deposit_confirmation_status.h"
     142             : #include "pg_insert_exchange_keys.h"
     143             : #include "pg_select_exchange_keys.h"
     144             : #include "pg_insert_deposit_to_transfer.h"
     145             : #include "pg_increase_refund.h"
     146             : #include "pg_select_account.h"
     147             : #include "pg_select_accounts.h"
     148             : #include "pg_insert_transfer.h"
     149             : #include "pg_insert_transfer_details.h"
     150             : #include "pg_store_wire_fee_by_exchange.h"
     151             : #include "pg_insert_token_family.h"
     152             : #include "pg_lookup_token_family.h"
     153             : #include "pg_lookup_token_families.h"
     154             : #include "pg_delete_token_family.h"
     155             : #include "pg_update_token_family.h"
     156             : #include "pg_insert_token_family_key.h"
     157             : #include "pg_lookup_token_family_key.h"
     158             : #include "pg_insert_spent_token.h"
     159             : #include "pg_insert_issued_token.h"
     160             : #include "pg_lookup_spent_tokens_by_order.h"
     161             : #include "pg_lookup_statistics_amount_by_bucket.h"
     162             : #include "pg_lookup_statistics_amount_by_interval.h"
     163             : #include "pg_lookup_statistics_counter_by_bucket.h"
     164             : #include "pg_lookup_statistics_counter_by_interval.h"
     165             : #include "pg_update_donau_instance_receipts_amount.h"
     166             : #include "pg_delete_donau_instance.h"
     167             : 
     168             : #ifdef HAVE_DONAU_DONAU_SERVICE_H
     169             : #include "donau/donau_service.h"
     170             : #include "pg_insert_donau_instance.h"
     171             : #include "pg_select_donau_instance_by_serial.h"
     172             : #include "pg_select_donau_instances.h"
     173             : #include "pg_select_donau_instances_filtered.h"
     174             : #include "pg_lookup_donau_keys.h"
     175             : #include "pg_lookup_order_charity.h"
     176             : #include "pg_upsert_donau_keys.h"
     177             : #include "pg_update_donau_instance.h"
     178             : #endif
     179             : 
     180             : /**
     181             :  * How often do we re-try if we run into a DB serialization error?
     182             :  */
     183             : #define MAX_RETRIES 3
     184             : 
     185             : 
     186             : /**
     187             :  * Drop all Taler tables.  This should only be used by testcases.
     188             :  *
     189             :  * @param cls the `struct PostgresClosure` with the plugin-specific state
     190             :  * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
     191             :  */
     192             : static enum GNUNET_GenericReturnValue
     193          16 : postgres_drop_tables (void *cls)
     194             : {
     195          16 :   struct PostgresClosure *pc = cls;
     196             :   struct GNUNET_PQ_Context *conn;
     197             :   enum GNUNET_GenericReturnValue ret;
     198             : 
     199          16 :   conn = GNUNET_PQ_connect_with_cfg (pc->cfg,
     200             :                                      "merchantdb-postgres",
     201             :                                      NULL,
     202             :                                      NULL,
     203             :                                      NULL);
     204          16 :   if (NULL == conn)
     205           0 :     return GNUNET_SYSERR;
     206          16 :   ret = GNUNET_PQ_exec_sql (conn,
     207             :                             "drop");
     208          16 :   GNUNET_PQ_disconnect (conn);
     209          16 :   return ret;
     210             : }
     211             : 
     212             : 
     213             : /**
     214             :  * Initialize tables.
     215             :  *
     216             :  * @param cls the `struct PostgresClosure` with the plugin-specific state
     217             :  * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
     218             :  */
     219             : static enum GNUNET_GenericReturnValue
     220          16 : postgres_create_tables (void *cls)
     221             : {
     222          16 :   struct PostgresClosure *pc = cls;
     223             :   struct GNUNET_PQ_Context *conn;
     224          16 :   struct GNUNET_PQ_ExecuteStatement es[] = {
     225          16 :     GNUNET_PQ_make_try_execute ("SET search_path TO merchant;"),
     226             :     GNUNET_PQ_EXECUTE_STATEMENT_END
     227             :   };
     228             :   enum GNUNET_GenericReturnValue ret;
     229             : 
     230          16 :   conn = GNUNET_PQ_connect_with_cfg (pc->cfg,
     231             :                                      "merchantdb-postgres",
     232             :                                      "merchant-",
     233             :                                      es,
     234             :                                      NULL);
     235          16 :   if (NULL == conn)
     236           1 :     return GNUNET_SYSERR;
     237          15 :   ret = GNUNET_PQ_exec_sql (conn,
     238             :                             "procedures");
     239          15 :   GNUNET_PQ_disconnect (conn);
     240          15 :   return ret;
     241             : }
     242             : 
     243             : 
     244             : /**
     245             :  * Register callback to be invoked on events of type @a es.
     246             :  *
     247             :  * @param cls database context to use
     248             :  * @param es specification of the event to listen for
     249             :  * @param timeout how long to wait for the event
     250             :  * @param cb function to call when the event happens, possibly
     251             :  *         multiple times (until cancel is invoked)
     252             :  * @param cb_cls closure for @a cb
     253             :  * @return handle useful to cancel the listener
     254             :  */
     255             : static struct GNUNET_DB_EventHandler *
     256         181 : postgres_event_listen (void *cls,
     257             :                        const struct GNUNET_DB_EventHeaderP *es,
     258             :                        struct GNUNET_TIME_Relative timeout,
     259             :                        GNUNET_DB_EventCallback cb,
     260             :                        void *cb_cls)
     261             : {
     262         181 :   struct PostgresClosure *pg = cls;
     263             : 
     264         181 :   return GNUNET_PQ_event_listen (pg->conn,
     265             :                                  es,
     266             :                                  timeout,
     267             :                                  cb,
     268             :                                  cb_cls);
     269             : }
     270             : 
     271             : 
     272             : /**
     273             :  * Stop notifications.
     274             :  *
     275             :  * @param eh handle to unregister.
     276             :  */
     277             : static void
     278         181 : postgres_event_listen_cancel (struct GNUNET_DB_EventHandler *eh)
     279             : {
     280         181 :   GNUNET_PQ_event_listen_cancel (eh);
     281         181 : }
     282             : 
     283             : 
     284             : /**
     285             :  * Notify all that listen on @a es of an event.
     286             :  *
     287             :  * @param cls database context to use
     288             :  * @param es specification of the event to generate
     289             :  * @param extra additional event data provided
     290             :  * @param extra_size number of bytes in @a extra
     291             :  */
     292             : static void
     293         375 : postgres_event_notify (void *cls,
     294             :                        const struct GNUNET_DB_EventHeaderP *es,
     295             :                        const void *extra,
     296             :                        size_t extra_size)
     297             : {
     298         375 :   struct PostgresClosure *pg = cls;
     299             : 
     300         375 :   return GNUNET_PQ_event_notify (pg->conn,
     301             :                                  es,
     302             :                                  extra,
     303             :                                  extra_size);
     304             : }
     305             : 
     306             : 
     307             : void
     308        1490 : postgres_preflight (void *cls)
     309             : {
     310        1490 :   struct PostgresClosure *pg = cls;
     311             : 
     312        1490 :   if (NULL == pg->transaction_name)
     313        1490 :     return; /* all good */
     314           0 :   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     315             :               "BUG: Preflight check detected running transaction `%s'!\n",
     316             :               pg->transaction_name);
     317           0 :   GNUNET_assert (0);
     318             : }
     319             : 
     320             : 
     321             : void
     322        2894 : check_connection (struct PostgresClosure *pg)
     323             : {
     324        2894 :   if (NULL != pg->transaction_name)
     325        1181 :     return;
     326        1713 :   GNUNET_PQ_reconnect_if_down (pg->conn);
     327             : }
     328             : 
     329             : 
     330             : /**
     331             :  * Establish connection to the database.
     332             :  *
     333             :  * @param cls plugin context
     334             :  * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
     335             :  */
     336             : static enum GNUNET_GenericReturnValue
     337          87 : postgres_connect (void *cls)
     338             : {
     339          87 :   struct PostgresClosure *pg = cls;
     340          87 :   struct GNUNET_PQ_ExecuteStatement es[] = {
     341          87 :     GNUNET_PQ_make_try_execute ("SET search_path TO merchant;"),
     342             :     GNUNET_PQ_EXECUTE_STATEMENT_END
     343             :   };
     344             : 
     345          87 :   pg->conn = GNUNET_PQ_connect_with_cfg2 (pg->cfg,
     346             :                                           "merchantdb-postgres",
     347             :                                           "merchant-",
     348             :                                           es,
     349             :                                           NULL, /* prepared statemetns */
     350             :                                           GNUNET_PQ_FLAG_CHECK_CURRENT);
     351          87 :   pg->prep_gen++;
     352          87 :   if (NULL == pg->conn)
     353           0 :     return GNUNET_SYSERR;
     354          87 :   return GNUNET_OK;
     355             : };
     356             : 
     357             : 
     358             : /**
     359             :  * Initialize Postgres database subsystem.
     360             :  *
     361             :  * @param cls a configuration instance
     362             :  * @return NULL on error, otherwise a `struct TALER_MERCHANTDB_Plugin`
     363             :  */
     364             : void *
     365             : libtaler_plugin_merchantdb_postgres_init (void *cls);
     366             : 
     367             : /* declaration to avoid compiler warning */
     368             : void *
     369         103 : libtaler_plugin_merchantdb_postgres_init (void *cls)
     370             : {
     371         103 :   const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
     372             :   struct PostgresClosure *pg;
     373             :   struct TALER_MERCHANTDB_Plugin *plugin;
     374             : 
     375         103 :   pg = GNUNET_new (struct PostgresClosure);
     376         103 :   pg->cfg = cfg;
     377         103 :   if (GNUNET_OK !=
     378         103 :       GNUNET_CONFIGURATION_get_value_filename (cfg,
     379             :                                                "merchantdb-postgres",
     380             :                                                "SQL_DIR",
     381             :                                                &pg->sql_dir))
     382             :   {
     383           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     384             :                                "merchantdb-postgres",
     385             :                                "SQL_DIR");
     386           0 :     GNUNET_free (pg);
     387           0 :     return NULL;
     388             :   }
     389         103 :   plugin = GNUNET_new (struct TALER_MERCHANTDB_Plugin);
     390         103 :   plugin->cls = pg;
     391         103 :   plugin->connect = &postgres_connect;
     392         103 :   plugin->create_tables = &postgres_create_tables;
     393         103 :   plugin->drop_tables = &postgres_drop_tables;
     394         103 :   plugin->event_listen = &postgres_event_listen;
     395         103 :   plugin->event_listen_cancel = &postgres_event_listen_cancel;
     396         103 :   plugin->event_notify = &postgres_event_notify;
     397         103 :   plugin->preflight = &postgres_preflight;
     398         103 :   plugin->start = &TMH_PG_start;
     399         103 :   plugin->start_read_committed = &TMH_PG_start_read_committed;
     400         103 :   plugin->rollback = &TMH_PG_rollback;
     401         103 :   plugin->commit = &TMH_PG_commit;
     402             :   plugin->insert_login_token
     403         103 :     = &TMH_PG_insert_login_token;
     404             :   plugin->delete_login_token
     405         103 :     = &TMH_PG_delete_login_token;
     406             :   plugin->delete_login_token_serial
     407         103 :     = &TMH_PG_delete_login_token_serial;
     408             :   plugin->select_login_token
     409         103 :     = &TMH_PG_select_login_token;
     410             :   plugin->lookup_login_tokens
     411         103 :     = &TMH_PG_lookup_login_tokens;
     412             :   plugin->select_account_by_uri
     413         103 :     = &TMH_PG_select_account_by_uri;
     414             :   plugin->lookup_instance_auth
     415         103 :     = &TMH_PG_lookup_instance_auth;
     416             :   plugin->insert_instance
     417         103 :     = &TMH_PG_insert_instance;
     418             :   plugin->insert_account
     419         103 :     = &TMH_PG_insert_account;
     420             :   plugin->lookup_otp_devices
     421         103 :     = &TMH_PG_lookup_otp_devices;
     422             :   plugin->delete_template
     423         103 :     = &TMH_PG_delete_template;
     424             :   plugin->insert_template
     425         103 :     = &TMH_PG_insert_template;
     426             :   plugin->update_template
     427         103 :     = &TMH_PG_update_template;
     428             :   plugin->lookup_templates
     429         103 :     = &TMH_PG_lookup_templates;
     430             :   plugin->lookup_template
     431         103 :     = &TMH_PG_lookup_template;
     432             :   plugin->update_account
     433         103 :     = &TMH_PG_update_account;
     434             :   plugin->account_kyc_set_status
     435         103 :     = &TMH_PG_account_kyc_set_status;
     436             :   plugin->account_kyc_get_status
     437         103 :     = &TMH_PG_account_kyc_get_status;
     438             :   plugin->delete_instance_private_key
     439         103 :     = &TMH_PG_delete_instance_private_key;
     440             :   plugin->purge_instance
     441         103 :     = &TMH_PG_purge_instance;
     442             :   plugin->update_instance
     443         103 :     = &TMH_PG_update_instance;
     444             :   plugin->update_instance_auth
     445         103 :     = &TMH_PG_update_instance_auth;
     446             :   plugin->activate_account
     447         103 :     = &TMH_PG_activate_account;
     448             :   plugin->inactivate_account
     449         103 :     = &TMH_PG_inactivate_account;
     450             :   plugin->update_transfer_status
     451         103 :     = &TMH_PG_update_transfer_status;
     452             :   plugin->finalize_transfer_status
     453         103 :     = &TMH_PG_finalize_transfer_status;
     454             :   plugin->lookup_products
     455         103 :     = &TMH_PG_lookup_products;
     456             :   plugin->lookup_all_products
     457         103 :     = &TMH_PG_lookup_all_products;
     458             :   plugin->lookup_product
     459         103 :     = &TMH_PG_lookup_product;
     460             :   plugin->delete_product
     461         103 :     = &TMH_PG_delete_product;
     462             :   plugin->insert_product
     463         103 :     = &TMH_PG_insert_product;
     464             :   plugin->update_product
     465         103 :     = &TMH_PG_update_product;
     466             :   plugin->insert_otp
     467         103 :     = &TMH_PG_insert_otp;
     468             :   plugin->delete_otp
     469         103 :     = &TMH_PG_delete_otp;
     470             :   plugin->update_otp
     471         103 :     = &TMH_PG_update_otp;
     472             :   plugin->select_otp
     473         103 :     = &TMH_PG_select_otp;
     474             :   plugin->select_otp_serial
     475         103 :     = &TMH_PG_select_otp_serial;
     476             :   plugin->lock_product
     477         103 :     = &TMH_PG_lock_product;
     478             :   plugin->expire_locks
     479         103 :     = &TMH_PG_expire_locks;
     480             :   plugin->delete_order
     481         103 :     = &TMH_PG_delete_order;
     482             :   plugin->lookup_order
     483         103 :     = &TMH_PG_lookup_order;
     484             :   plugin->lookup_order_summary
     485         103 :     = &TMH_PG_lookup_order_summary;
     486             :   plugin->lookup_orders
     487         103 :     = &TMH_PG_lookup_orders;
     488             :   plugin->insert_order
     489         103 :     = &TMH_PG_insert_order;
     490             :   plugin->insert_order_blinded_sigs
     491         103 :     = &TMH_PG_insert_order_blinded_sigs;
     492             :   plugin->unlock_inventory
     493         103 :     = &TMH_PG_unlock_inventory;
     494             :   plugin->insert_order_lock
     495         103 :     = &TMH_PG_insert_order_lock;
     496             :   plugin->select_order_blinded_sigs
     497         103 :     = &TMH_PG_select_order_blinded_sigs;
     498             :   plugin->lookup_contract_terms
     499         103 :     = &TMH_PG_lookup_contract_terms;
     500             :   plugin->lookup_contract_terms2
     501         103 :     = &TMH_PG_lookup_contract_terms2;
     502             :   plugin->lookup_contract_terms3
     503         103 :     = &TMH_PG_lookup_contract_terms3;
     504             :   plugin->insert_contract_terms
     505         103 :     = &TMH_PG_insert_contract_terms;
     506             :   plugin->update_contract_terms
     507         103 :     = &TMH_PG_update_contract_terms;
     508             :   plugin->delete_contract_terms
     509         103 :     = &TMH_PG_delete_contract_terms;
     510             :   plugin->lookup_deposits
     511         103 :     = &TMH_PG_lookup_deposits;
     512             :   plugin->insert_exchange_signkey
     513         103 :     = &TMH_PG_insert_exchange_signkey;
     514             :   plugin->insert_deposit_confirmation
     515         103 :     = &TMH_PG_insert_deposit_confirmation;
     516             :   plugin->insert_deposit
     517         103 :     = &TMH_PG_insert_deposit;
     518             :   plugin->lookup_refunds
     519         103 :     = &TMH_PG_lookup_refunds;
     520             :   plugin->mark_contract_paid
     521         103 :     = &TMH_PG_mark_contract_paid;
     522             :   plugin->refund_coin
     523         103 :     = &TMH_PG_refund_coin;
     524             :   plugin->lookup_order_status
     525         103 :     = &TMH_PG_lookup_order_status;
     526             :   plugin->lookup_order_status_by_serial
     527         103 :     = &TMH_PG_lookup_order_status_by_serial;
     528             :   plugin->lookup_deposits_by_order
     529         103 :     = &TMH_PG_lookup_deposits_by_order;
     530             :   plugin->lookup_transfer_details_by_order
     531         103 :     = &TMH_PG_lookup_transfer_details_by_order;
     532             :   plugin->mark_order_wired
     533         103 :     = &TMH_PG_mark_order_wired;
     534             :   plugin->increase_refund
     535         103 :     = &TMH_PG_increase_refund;
     536             :   plugin->lookup_refunds_detailed
     537         103 :     = &TMH_PG_lookup_refunds_detailed;
     538             :   plugin->insert_refund_proof
     539         103 :     = &TMH_PG_insert_refund_proof;
     540             :   plugin->lookup_refund_proof
     541         103 :     = &TMH_PG_lookup_refund_proof;
     542             :   plugin->lookup_order_by_fulfillment
     543         103 :     = &TMH_PG_lookup_order_by_fulfillment;
     544             :   plugin->delete_transfer
     545         103 :     = &TMH_PG_delete_transfer;
     546             :   plugin->check_transfer_exists
     547         103 :     = &TMH_PG_check_transfer_exists;
     548             :   plugin->lookup_account
     549         103 :     = &TMH_PG_lookup_account;
     550             :   plugin->lookup_wire_fee
     551         103 :     = &TMH_PG_lookup_wire_fee;
     552             :   plugin->lookup_deposits_by_contract_and_coin
     553         103 :     = &TMH_PG_lookup_deposits_by_contract_and_coin;
     554             :   plugin->lookup_transfer_summary
     555         103 :     = &TMH_PG_lookup_transfer_summary;
     556             :   plugin->lookup_transfer_details
     557         103 :     = &TMH_PG_lookup_transfer_details;
     558             :   plugin->lookup_instances
     559         103 :     = &TMH_PG_lookup_instances;
     560             :   plugin->lookup_instance
     561         103 :     = &TMH_PG_lookup_instance;
     562             :   plugin->lookup_transfers
     563         103 :     = &TMH_PG_lookup_transfers;
     564             :   plugin->update_wirewatch_progress
     565         103 :     = &TMH_PG_update_wirewatch_progress;
     566             :   plugin->select_wirewatch_accounts
     567         103 :     = &TMH_PG_select_wirewatch_accounts;
     568             :   plugin->select_account
     569         103 :     = &TMH_PG_select_account;
     570             :   plugin->select_accounts
     571         103 :     = &TMH_PG_select_accounts;
     572             :   plugin->select_open_transfers
     573         103 :     = &TMH_PG_select_open_transfers;
     574             :   plugin->insert_exchange_keys
     575         103 :     = &TMH_PG_insert_exchange_keys;
     576             :   plugin->select_exchange_keys
     577         103 :     = &TMH_PG_select_exchange_keys;
     578             :   plugin->insert_deposit_to_transfer
     579         103 :     = &TMH_PG_insert_deposit_to_transfer;
     580             :   plugin->insert_transfer
     581         103 :     = &TMH_PG_insert_transfer;
     582             :   plugin->lookup_token_family_keys
     583         103 :     = &TMH_PG_lookup_token_family_keys;
     584             :   plugin->insert_transfer_details
     585         103 :     = &TMH_PG_insert_transfer_details;
     586             :   plugin->store_wire_fee_by_exchange
     587         103 :     = &TMH_PG_store_wire_fee_by_exchange;
     588             :   plugin->lookup_webhooks
     589         103 :     = &TMH_PG_lookup_webhooks;
     590             :   plugin->lookup_webhook
     591         103 :     = &TMH_PG_lookup_webhook;
     592             :   plugin->delete_webhook
     593         103 :     = &TMH_PG_delete_webhook;
     594             :   plugin->insert_webhook
     595         103 :     = &TMH_PG_insert_webhook;
     596             :   plugin->update_webhook
     597         103 :     = &TMH_PG_update_webhook;
     598             :   plugin->lookup_pending_deposits
     599         103 :     = &TMH_PG_lookup_pending_deposits;
     600             :   plugin->lookup_webhook_by_event
     601         103 :     = &TMH_PG_lookup_webhook_by_event;
     602             :   plugin->lookup_all_webhooks
     603         103 :     = &TMH_PG_lookup_all_webhooks;
     604             :   plugin->lookup_future_webhook
     605         103 :     = &TMH_PG_lookup_future_webhook;
     606             :   plugin->lookup_pending_webhooks
     607         103 :     = &TMH_PG_lookup_pending_webhooks;
     608             :   plugin->delete_pending_webhook
     609         103 :     = &TMH_PG_delete_pending_webhook;
     610             :   plugin->insert_pending_webhook
     611         103 :     = &TMH_PG_insert_pending_webhook;
     612             :   plugin->update_pending_webhook
     613         103 :     = &TMH_PG_update_pending_webhook;
     614             :   plugin->lookup_categories
     615         103 :     = &TMH_PG_lookup_categories;
     616             :   plugin->select_category_by_name
     617         103 :     = &TMH_PG_select_category_by_name;
     618             :   plugin->get_kyc_status
     619         103 :     = &TMH_PG_get_kyc_status;
     620             :   plugin->account_kyc_set_failed
     621         103 :     = &TMH_PG_account_kyc_set_failed;
     622             :   plugin->get_kyc_limits
     623         103 :     = &TMH_PG_get_kyc_limits;
     624             :   plugin->select_category
     625         103 :     = &TMH_PG_select_category;
     626             :   plugin->update_category
     627         103 :     = &TMH_PG_update_category;
     628             :   plugin->insert_category
     629         103 :     = &TMH_PG_insert_category;
     630             :   plugin->delete_category
     631         103 :     = &TMH_PG_delete_category;
     632             :   plugin->delete_exchange_accounts
     633         103 :     = &TMH_PG_delete_exchange_accounts;
     634             :   plugin->select_accounts_by_exchange
     635         103 :     = &TMH_PG_select_accounts_by_exchange;
     636             :   plugin->insert_exchange_account
     637         103 :     = &TMH_PG_insert_exchange_account;
     638             :   plugin->insert_token_family
     639         103 :     = &TMH_PG_insert_token_family;
     640             :   plugin->lookup_expected_transfers
     641         103 :     = &TMH_PG_lookup_expected_transfers;
     642             :   plugin->lookup_token_family
     643         103 :     = &TMH_PG_lookup_token_family;
     644             :   plugin->lookup_token_families
     645         103 :     = &TMH_PG_lookup_token_families;
     646             :   plugin->delete_token_family
     647         103 :     = &TMH_PG_delete_token_family;
     648             :   plugin->update_token_family
     649         103 :     = &TMH_PG_update_token_family;
     650             :   plugin->insert_token_family_key
     651         103 :     = &TMH_PG_insert_token_family_key;
     652             :   plugin->lookup_token_family_key
     653         103 :     = &TMH_PG_lookup_token_family_key;
     654             :   plugin->update_deposit_confirmation_status
     655         103 :     = &TMH_PG_update_deposit_confirmation_status;
     656             :   plugin->update_donau_instance_receipts_amount
     657         103 :     = &TMH_PG_update_donau_instance_receipts_amount;
     658             :   plugin->insert_spent_token
     659         103 :     = &TMH_PG_insert_spent_token;
     660             :   plugin->insert_issued_token
     661         103 :     = &TMH_PG_insert_issued_token;
     662             :   plugin->lookup_spent_tokens_by_order
     663         103 :     = &TMH_PG_lookup_spent_tokens_by_order;
     664             :   plugin->lookup_statistics_amount_by_bucket
     665         103 :     = &TMH_PG_lookup_statistics_amount_by_bucket;
     666             :   plugin->lookup_statistics_counter_by_bucket
     667         103 :     = &TMH_PG_lookup_statistics_counter_by_bucket;
     668             :   plugin->lookup_statistics_counter_by_interval
     669         103 :     = &TMH_PG_lookup_statistics_counter_by_interval;
     670             :   plugin->lookup_statistics_amount_by_interval
     671         103 :     = &TMH_PG_lookup_statistics_amount_by_interval;
     672             :   plugin->gc
     673         103 :     = &TMH_PG_gc;
     674             : #ifdef HAVE_DONAU_DONAU_SERVICE_H
     675             :   plugin->insert_donau_instance
     676             :     = &TMH_PG_insert_donau_instance;
     677             :   plugin->select_donau_instance_by_serial
     678             :     = &TMH_PG_select_donau_instance_by_serial;
     679             :   plugin->select_donau_instances
     680             :     = &TMH_PG_select_donau_instances;
     681             :   plugin->select_donau_instances_filtered
     682             :     = &TMH_PG_select_donau_instances_filtered;
     683             :   plugin->delete_donau_instance
     684             :     = &TMH_PG_delete_donau_instance;
     685             :   plugin->lookup_donau_keys
     686             :     = &TMH_PG_lookup_donau_keys;
     687             :   plugin->lookup_order_charity
     688             :     = &TMH_PG_lookup_order_charity;
     689             :   plugin->upsert_donau_keys
     690             :     = &TMH_PG_upsert_donau_keys;
     691             :   plugin->update_donau_instance
     692             :     = &TMH_PG_update_donau_instance;
     693             : #endif
     694         103 :   return plugin;
     695             : }
     696             : 
     697             : 
     698             : /**
     699             :  * Shutdown Postgres database subsystem.
     700             :  *
     701             :  * @param cls a `struct TALER_MERCHANTDB_Plugin`
     702             :  * @return NULL (always)
     703             :  */
     704             : void *
     705             : libtaler_plugin_merchantdb_postgres_done (void *cls);
     706             : 
     707             : /* declaration to avoid compiler warning */
     708             : void *
     709         102 : libtaler_plugin_merchantdb_postgres_done (void *cls)
     710             : {
     711         102 :   struct TALER_MERCHANTDB_Plugin *plugin = cls;
     712         102 :   struct PostgresClosure *pg = plugin->cls;
     713             : 
     714         102 :   if (NULL != pg->conn)
     715             :   {
     716          87 :     GNUNET_PQ_disconnect (pg->conn);
     717          87 :     pg->conn = NULL;
     718             :   }
     719         102 :   GNUNET_free (pg->sql_dir);
     720         102 :   GNUNET_free (pg);
     721         102 :   GNUNET_free (plugin);
     722         102 :   return NULL;
     723             : }
     724             : 
     725             : 
     726             : /* end of plugin_merchantdb_postgres.c */

Generated by: LCOV version 1.16