plugin_merchantdb_postgres.c (27679B)
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 "taler/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/taler_merchantdb_plugin.h" 33 #include "pg_helper.h" 34 #include "pg_gc.h" 35 #include "pg_insert_otp.h" 36 #include "pg_account_kyc_get_outdated.h" 37 #include "pg_get_kyc_status.h" 38 #include "pg_get_kyc_limits.h" 39 #include "pg_delete_otp.h" 40 #include "pg_update_otp.h" 41 #include "pg_account_kyc_set_failed.h" 42 #include "pg_select_otp.h" 43 #include "pg_select_otp_serial.h" 44 #include "pg_insert_login_token.h" 45 #include "pg_delete_login_token.h" 46 #include "pg_select_login_token.h" 47 #include "pg_lookup_login_tokens.h" 48 #include "pg_insert_account.h" 49 #include "pg_update_account.h" 50 #include "pg_lookup_instances.h" 51 #include "pg_lookup_transfers.h" 52 #include "pg_lookup_pending_deposits.h" 53 #include "pg_lookup_categories.h" 54 #include "pg_insert_unclaim_signature.h" 55 #include "pg_lookup_reconciliation_details.h" 56 #include "pg_lookup_expected_transfer.h" 57 #include "pg_lookup_categories_by_ids.h" 58 #include "pg_lookup_units.h" 59 #include "pg_lookup_custom_units_by_names.h" 60 #include "pg_select_category.h" 61 #include "pg_update_category.h" 62 #include "pg_insert_category.h" 63 #include "pg_delete_category.h" 64 #include "pg_select_unit.h" 65 #include "pg_insert_unit.h" 66 #include "pg_update_unit.h" 67 #include "pg_delete_unit.h" 68 #include "pg_insert_report.h" 69 #include "pg_delete_report.h" 70 #include "pg_update_report.h" 71 #include "pg_check_report.h" 72 #include "pg_select_reports.h" 73 #include "pg_lookup_reports_pending.h" 74 #include "pg_update_report_status.h" 75 #include "pg_select_report.h" 76 #include "pg_insert_product_group.h" 77 #include "pg_delete_product_group.h" 78 #include "pg_update_product_group.h" 79 #include "pg_select_product_groups.h" 80 #include "pg_insert_money_pot.h" 81 #include "pg_delete_money_pot.h" 82 #include "pg_update_money_pot.h" 83 #include "pg_check_money_pots.h" 84 #include "pg_select_money_pots.h" 85 #include "pg_select_money_pot.h" 86 #include "pg_update_wirewatch_progress.h" 87 #include "pg_select_wirewatch_accounts.h" 88 #include "pg_select_open_transfers.h" 89 #include "pg_delete_exchange_accounts.h" 90 #include "pg_select_exchanges.h" 91 #include "pg_select_accounts_by_exchange.h" 92 #include "pg_insert_exchange_account.h" 93 #include "pg_lookup_instance_auth.h" 94 #include "pg_lookup_otp_devices.h" 95 #include "pg_update_transfer_status.h" 96 #include "pg_lookup_mfa_challenge.h" 97 #include "pg_solve_mfa_challenge.h" 98 #include "pg_update_mfa_challenge.h" 99 #include "pg_create_mfa_challenge.h" 100 #include "pg_finalize_transfer_status.h" 101 #include "pg_insert_instance.h" 102 #include "pg_account_kyc_set_status.h" 103 #include "pg_account_kyc_get_status.h" 104 #include "pg_delete_instance_private_key.h" 105 #include "pg_select_category_by_name.h" 106 #include "pg_purge_instance.h" 107 #include "pg_update_instance.h" 108 #include "pg_update_instance_auth.h" 109 #include "pg_inactivate_account.h" 110 #include "pg_activate_account.h" 111 #include "pg_lookup_products.h" 112 #include "pg_lookup_all_products.h" 113 #include "pg_lookup_inventory_products.h" 114 #include "pg_lookup_inventory_products_filtered.h" 115 #include "pg_lookup_product.h" 116 #include "pg_lookup_product_image.h" 117 #include "pg_lookup_statistics_amount_by_bucket2.h" 118 #include "pg_lookup_statistics_counter_by_bucket2.h" 119 #include "pg_delete_product.h" 120 #include "pg_insert_product.h" 121 #include "pg_update_product.h" 122 #include "pg_lookup_token_family_keys.h" 123 #include "pg_lock_product.h" 124 #include "pg_expire_locks.h" 125 #include "pg_delete_order.h" 126 #include "pg_lookup_order.h" 127 #include "pg_lookup_order_summary.h" 128 #include "pg_lookup_orders.h" 129 #include "pg_insert_order.h" 130 #include "pg_insert_order_blinded_sigs.h" 131 #include "pg_increment_money_pots.h" 132 #include "pg_unlock_inventory.h" 133 #include "pg_insert_order_lock.h" 134 #include "pg_select_order_blinded_sigs.h" 135 #include "pg_lookup_contract_terms3.h" 136 #include "pg_lookup_contract_terms2.h" 137 #include "pg_lookup_contract_terms.h" 138 #include "pg_insert_contract_terms.h" 139 #include "pg_update_contract_terms.h" 140 #include "pg_delete_contract_terms.h" 141 #include "pg_delete_template.h" 142 #include "pg_insert_template.h" 143 #include "pg_update_template.h" 144 #include "pg_lookup_templates.h" 145 #include "pg_lookup_template.h" 146 #include "pg_lookup_deposits.h" 147 #include "pg_insert_exchange_signkey.h" 148 #include "pg_insert_deposit.h" 149 #include "pg_insert_deposit_confirmation.h" 150 #include "pg_lookup_refunds.h" 151 #include "pg_mark_contract_paid.h" 152 #include "pg_select_account_by_uri.h" 153 #include "pg_refund_coin.h" 154 #include "pg_lookup_order_status.h" 155 #include "pg_lookup_order_status_by_serial.h" 156 #include "pg_lookup_deposits_by_order.h" 157 #include "pg_lookup_transfer_details_by_order.h" 158 #include "pg_mark_order_wired.h" 159 #include "pg_lookup_refunds_detailed.h" 160 #include "pg_insert_refund_proof.h" 161 #include "pg_lookup_refund_proof.h" 162 #include "pg_lookup_order_by_fulfillment.h" 163 #include "pg_delete_transfer.h" 164 #include "pg_check_transfer_exists.h" 165 #include "pg_lookup_account.h" 166 #include "pg_lookup_expected_transfers.h" 167 #include "pg_lookup_deposits_by_contract_and_coin.h" 168 #include "pg_lookup_transfer_summary.h" 169 #include "pg_lookup_transfer_details.h" 170 #include "pg_lookup_webhooks.h" 171 #include "pg_lookup_webhook.h" 172 #include "pg_lookup_wire_fee.h" 173 #include "pg_delete_webhook.h" 174 #include "pg_insert_webhook.h" 175 #include "pg_update_webhook.h" 176 #include "pg_lookup_webhook_by_event.h" 177 #include "pg_delete_pending_webhook.h" 178 #include "pg_insert_pending_webhook.h" 179 #include "pg_update_pending_webhook.h" 180 #include "pg_lookup_pending_webhooks.h" 181 #include "pg_update_deposit_confirmation_status.h" 182 #include "pg_insert_exchange_keys.h" 183 #include "pg_select_exchange_keys.h" 184 #include "pg_insert_deposit_to_transfer.h" 185 #include "pg_increase_refund.h" 186 #include "pg_select_account.h" 187 #include "pg_select_accounts.h" 188 #include "pg_insert_transfer.h" 189 #include "pg_insert_transfer_details.h" 190 #include "pg_store_wire_fee_by_exchange.h" 191 #include "pg_insert_token_family.h" 192 #include "pg_lookup_token_family.h" 193 #include "pg_lookup_token_families.h" 194 #include "pg_delete_token_family.h" 195 #include "pg_update_token_family.h" 196 #include "pg_insert_token_family_key.h" 197 #include "pg_lookup_token_family_key.h" 198 #include "pg_insert_spent_token.h" 199 #include "pg_insert_issued_token.h" 200 #include "pg_lookup_spent_tokens_by_order.h" 201 #include "pg_lookup_statistics_amount_by_bucket.h" 202 #include "pg_lookup_statistics_amount_by_interval.h" 203 #include "pg_lookup_statistics_counter_by_bucket.h" 204 #include "pg_lookup_statistics_counter_by_interval.h" 205 #include "pg_update_donau_instance_receipts_amount.h" 206 #include "pg_delete_donau_instance.h" 207 #include "pg_update_contract_session.h" 208 209 #ifdef HAVE_DONAU_DONAU_SERVICE_H 210 #include "donau/donau_service.h" 211 #include "pg_insert_donau_instance.h" 212 #include "pg_check_donau_instance.h" 213 #include "pg_select_donau_instance_by_serial.h" 214 #include "pg_select_all_donau_instances.h" 215 #include "pg_select_donau_instances.h" 216 #include "pg_select_donau_instances_filtered.h" 217 #include "pg_lookup_donau_keys.h" 218 #include "pg_lookup_order_charity.h" 219 #include "pg_upsert_donau_keys.h" 220 #include "pg_update_donau_instance.h" 221 #endif 222 223 /** 224 * How often do we re-try if we run into a DB serialization error? 225 */ 226 #define MAX_RETRIES 3 227 228 229 /** 230 * Drop all Taler tables. This should only be used by testcases. 231 * 232 * @param cls the `struct PostgresClosure` with the plugin-specific state 233 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 234 */ 235 static enum GNUNET_GenericReturnValue 236 postgres_drop_tables (void *cls) 237 { 238 struct PostgresClosure *pc = cls; 239 struct GNUNET_PQ_Context *conn; 240 enum GNUNET_GenericReturnValue ret; 241 242 conn = GNUNET_PQ_connect_with_cfg (pc->cfg, 243 "merchantdb-postgres", 244 NULL, 245 NULL, 246 NULL); 247 if (NULL == conn) 248 return GNUNET_SYSERR; 249 ret = GNUNET_PQ_exec_sql (conn, 250 "drop"); 251 GNUNET_PQ_disconnect (conn); 252 return ret; 253 } 254 255 256 /** 257 * Initialize tables. 258 * 259 * @param cls the `struct PostgresClosure` with the plugin-specific state 260 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 261 */ 262 static enum GNUNET_GenericReturnValue 263 postgres_create_tables (void *cls) 264 { 265 struct PostgresClosure *pc = cls; 266 struct GNUNET_PQ_Context *conn; 267 struct GNUNET_PQ_ExecuteStatement es[] = { 268 GNUNET_PQ_make_try_execute ("SET search_path TO merchant;"), 269 GNUNET_PQ_EXECUTE_STATEMENT_END 270 }; 271 enum GNUNET_GenericReturnValue ret; 272 273 conn = GNUNET_PQ_connect_with_cfg (pc->cfg, 274 "merchantdb-postgres", 275 "merchant-", 276 es, 277 NULL); 278 if (NULL == conn) 279 return GNUNET_SYSERR; 280 ret = GNUNET_PQ_exec_sql (conn, 281 "procedures"); 282 GNUNET_PQ_disconnect (conn); 283 return ret; 284 } 285 286 287 /** 288 * Register callback to be invoked on events of type @a es. 289 * 290 * @param cls database context to use 291 * @param es specification of the event to listen for 292 * @param timeout how long to wait for the event 293 * @param cb function to call when the event happens, possibly 294 * multiple times (until cancel is invoked) 295 * @param cb_cls closure for @a cb 296 * @return handle useful to cancel the listener 297 */ 298 static struct GNUNET_DB_EventHandler * 299 postgres_event_listen (void *cls, 300 const struct GNUNET_DB_EventHeaderP *es, 301 struct GNUNET_TIME_Relative timeout, 302 GNUNET_DB_EventCallback cb, 303 void *cb_cls) 304 { 305 struct PostgresClosure *pg = cls; 306 307 return GNUNET_PQ_event_listen (pg->conn, 308 es, 309 timeout, 310 cb, 311 cb_cls); 312 } 313 314 315 /** 316 * Stop notifications. 317 * 318 * @param eh handle to unregister. 319 */ 320 static void 321 postgres_event_listen_cancel (struct GNUNET_DB_EventHandler *eh) 322 { 323 GNUNET_PQ_event_listen_cancel (eh); 324 } 325 326 327 /** 328 * Notify all that listen on @a es of an event. 329 * 330 * @param cls database context to use 331 * @param es specification of the event to generate 332 * @param extra additional event data provided 333 * @param extra_size number of bytes in @a extra 334 */ 335 static void 336 postgres_event_notify (void *cls, 337 const struct GNUNET_DB_EventHeaderP *es, 338 const void *extra, 339 size_t extra_size) 340 { 341 struct PostgresClosure *pg = cls; 342 343 return GNUNET_PQ_event_notify (pg->conn, 344 es, 345 extra, 346 extra_size); 347 } 348 349 350 void 351 postgres_preflight (void *cls) 352 { 353 struct PostgresClosure *pg = cls; 354 355 if (NULL == pg->transaction_name) 356 return; /* all good */ 357 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 358 "BUG: Preflight check detected running transaction `%s'!\n", 359 pg->transaction_name); 360 GNUNET_assert (0); 361 } 362 363 364 void 365 check_connection (struct PostgresClosure *pg) 366 { 367 if (NULL != pg->transaction_name) 368 return; 369 GNUNET_PQ_reconnect_if_down (pg->conn); 370 } 371 372 373 /** 374 * Establish connection to the database. 375 * 376 * @param cls plugin context 377 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 378 */ 379 static enum GNUNET_GenericReturnValue 380 postgres_connect (void *cls) 381 { 382 struct PostgresClosure *pg = cls; 383 struct GNUNET_PQ_ExecuteStatement es[] = { 384 GNUNET_PQ_make_try_execute ("SET search_path TO merchant;"), 385 GNUNET_PQ_EXECUTE_STATEMENT_END 386 }; 387 388 pg->conn = GNUNET_PQ_connect_with_cfg2 (pg->cfg, 389 "merchantdb-postgres", 390 "merchant-", 391 es, 392 NULL, /* prepared statemetns */ 393 GNUNET_PQ_FLAG_CHECK_CURRENT); 394 pg->prep_gen++; 395 if (NULL == pg->conn) 396 return GNUNET_SYSERR; 397 return GNUNET_OK; 398 }; 399 400 401 /** 402 * Initialize Postgres database subsystem. 403 * 404 * @param cls a configuration instance 405 * @return NULL on error, otherwise a `struct TALER_MERCHANTDB_Plugin` 406 */ 407 void * 408 libtaler_plugin_merchantdb_postgres_init (void *cls); 409 410 /* declaration to avoid compiler warning */ 411 void * 412 libtaler_plugin_merchantdb_postgres_init (void *cls) 413 { 414 const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 415 struct PostgresClosure *pg; 416 struct TALER_MERCHANTDB_Plugin *plugin; 417 418 pg = GNUNET_new (struct PostgresClosure); 419 pg->cfg = cfg; 420 if (GNUNET_OK != 421 GNUNET_CONFIGURATION_get_value_filename (cfg, 422 "merchantdb-postgres", 423 "SQL_DIR", 424 &pg->sql_dir)) 425 { 426 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 427 "merchantdb-postgres", 428 "SQL_DIR"); 429 GNUNET_free (pg); 430 return NULL; 431 } 432 plugin = GNUNET_new (struct TALER_MERCHANTDB_Plugin); 433 plugin->cls = pg; 434 plugin->connect = &postgres_connect; 435 plugin->create_tables = &postgres_create_tables; 436 plugin->drop_tables = &postgres_drop_tables; 437 plugin->event_listen = &postgres_event_listen; 438 plugin->event_listen_cancel = &postgres_event_listen_cancel; 439 plugin->event_notify = &postgres_event_notify; 440 plugin->preflight = &postgres_preflight; 441 plugin->start = &TMH_PG_start; 442 plugin->start_read_committed = &TMH_PG_start_read_committed; 443 plugin->rollback = &TMH_PG_rollback; 444 plugin->commit = &TMH_PG_commit; 445 plugin->insert_login_token 446 = &TMH_PG_insert_login_token; 447 plugin->delete_login_token 448 = &TMH_PG_delete_login_token; 449 plugin->delete_login_token_serial 450 = &TMH_PG_delete_login_token_serial; 451 plugin->select_login_token 452 = &TMH_PG_select_login_token; 453 plugin->lookup_login_tokens 454 = &TMH_PG_lookup_login_tokens; 455 plugin->select_account_by_uri 456 = &TMH_PG_select_account_by_uri; 457 plugin->lookup_instance_auth 458 = &TMH_PG_lookup_instance_auth; 459 plugin->insert_instance 460 = &TMH_PG_insert_instance; 461 plugin->insert_account 462 = &TMH_PG_insert_account; 463 plugin->lookup_otp_devices 464 = &TMH_PG_lookup_otp_devices; 465 plugin->delete_template 466 = &TMH_PG_delete_template; 467 plugin->insert_template 468 = &TMH_PG_insert_template; 469 plugin->update_template 470 = &TMH_PG_update_template; 471 plugin->lookup_templates 472 = &TMH_PG_lookup_templates; 473 plugin->lookup_template 474 = &TMH_PG_lookup_template; 475 plugin->update_account 476 = &TMH_PG_update_account; 477 plugin->account_kyc_set_status 478 = &TMH_PG_account_kyc_set_status; 479 plugin->account_kyc_get_status 480 = &TMH_PG_account_kyc_get_status; 481 plugin->delete_instance_private_key 482 = &TMH_PG_delete_instance_private_key; 483 plugin->purge_instance 484 = &TMH_PG_purge_instance; 485 plugin->update_instance 486 = &TMH_PG_update_instance; 487 plugin->update_instance_auth 488 = &TMH_PG_update_instance_auth; 489 plugin->activate_account 490 = &TMH_PG_activate_account; 491 plugin->inactivate_account 492 = &TMH_PG_inactivate_account; 493 plugin->update_transfer_status 494 = &TMH_PG_update_transfer_status; 495 plugin->finalize_transfer_status 496 = &TMH_PG_finalize_transfer_status; 497 plugin->lookup_products 498 = &TMH_PG_lookup_products; 499 plugin->lookup_all_products 500 = &TMH_PG_lookup_all_products; 501 plugin->lookup_inventory_products 502 = &TMH_PG_lookup_inventory_products; 503 plugin->lookup_inventory_products_filtered 504 = &TMH_PG_lookup_inventory_products_filtered; 505 plugin->lookup_product 506 = &TMH_PG_lookup_product; 507 plugin->lookup_product_image_by_hash 508 = &TMH_PG_lookup_product_image_by_hash; 509 plugin->delete_product 510 = &TMH_PG_delete_product; 511 plugin->insert_product 512 = &TMH_PG_insert_product; 513 plugin->update_product 514 = &TMH_PG_update_product; 515 plugin->insert_otp 516 = &TMH_PG_insert_otp; 517 plugin->delete_otp 518 = &TMH_PG_delete_otp; 519 plugin->update_otp 520 = &TMH_PG_update_otp; 521 plugin->select_otp 522 = &TMH_PG_select_otp; 523 plugin->select_otp_serial 524 = &TMH_PG_select_otp_serial; 525 plugin->insert_unclaim_signature 526 = &TMH_PG_insert_unclaim_signature; 527 plugin->lookup_reconciliation_details 528 = &TMH_PG_lookup_reconciliation_details; 529 plugin->lookup_expected_transfer 530 = &TMH_PG_lookup_expected_transfer; 531 plugin->lock_product 532 = &TMH_PG_lock_product; 533 plugin->expire_locks 534 = &TMH_PG_expire_locks; 535 plugin->delete_order 536 = &TMH_PG_delete_order; 537 plugin->lookup_order 538 = &TMH_PG_lookup_order; 539 plugin->lookup_order_summary 540 = &TMH_PG_lookup_order_summary; 541 plugin->lookup_orders 542 = &TMH_PG_lookup_orders; 543 plugin->insert_order 544 = &TMH_PG_insert_order; 545 plugin->insert_order_blinded_sigs 546 = &TMH_PG_insert_order_blinded_sigs; 547 plugin->unlock_inventory 548 = &TMH_PG_unlock_inventory; 549 plugin->insert_order_lock 550 = &TMH_PG_insert_order_lock; 551 plugin->select_order_blinded_sigs 552 = &TMH_PG_select_order_blinded_sigs; 553 plugin->lookup_contract_terms 554 = &TMH_PG_lookup_contract_terms; 555 plugin->lookup_contract_terms2 556 = &TMH_PG_lookup_contract_terms2; 557 plugin->lookup_contract_terms3 558 = &TMH_PG_lookup_contract_terms3; 559 plugin->insert_contract_terms 560 = &TMH_PG_insert_contract_terms; 561 plugin->update_contract_terms 562 = &TMH_PG_update_contract_terms; 563 plugin->delete_contract_terms 564 = &TMH_PG_delete_contract_terms; 565 plugin->lookup_deposits 566 = &TMH_PG_lookup_deposits; 567 plugin->insert_exchange_signkey 568 = &TMH_PG_insert_exchange_signkey; 569 plugin->insert_deposit_confirmation 570 = &TMH_PG_insert_deposit_confirmation; 571 plugin->insert_deposit 572 = &TMH_PG_insert_deposit; 573 plugin->lookup_refunds 574 = &TMH_PG_lookup_refunds; 575 plugin->mark_contract_paid 576 = &TMH_PG_mark_contract_paid; 577 plugin->refund_coin 578 = &TMH_PG_refund_coin; 579 plugin->lookup_order_status 580 = &TMH_PG_lookup_order_status; 581 plugin->lookup_order_status_by_serial 582 = &TMH_PG_lookup_order_status_by_serial; 583 plugin->lookup_deposits_by_order 584 = &TMH_PG_lookup_deposits_by_order; 585 plugin->lookup_transfer_details_by_order 586 = &TMH_PG_lookup_transfer_details_by_order; 587 plugin->mark_order_wired 588 = &TMH_PG_mark_order_wired; 589 plugin->increase_refund 590 = &TMH_PG_increase_refund; 591 plugin->lookup_refunds_detailed 592 = &TMH_PG_lookup_refunds_detailed; 593 plugin->insert_refund_proof 594 = &TMH_PG_insert_refund_proof; 595 plugin->lookup_refund_proof 596 = &TMH_PG_lookup_refund_proof; 597 plugin->lookup_order_by_fulfillment 598 = &TMH_PG_lookup_order_by_fulfillment; 599 plugin->delete_transfer 600 = &TMH_PG_delete_transfer; 601 plugin->check_transfer_exists 602 = &TMH_PG_check_transfer_exists; 603 plugin->lookup_account 604 = &TMH_PG_lookup_account; 605 plugin->lookup_wire_fee 606 = &TMH_PG_lookup_wire_fee; 607 plugin->lookup_deposits_by_contract_and_coin 608 = &TMH_PG_lookup_deposits_by_contract_and_coin; 609 plugin->lookup_transfer_summary 610 = &TMH_PG_lookup_transfer_summary; 611 plugin->lookup_transfer_details 612 = &TMH_PG_lookup_transfer_details; 613 plugin->lookup_instances 614 = &TMH_PG_lookup_instances; 615 plugin->lookup_instance 616 = &TMH_PG_lookup_instance; 617 plugin->lookup_transfers 618 = &TMH_PG_lookup_transfers; 619 plugin->update_wirewatch_progress 620 = &TMH_PG_update_wirewatch_progress; 621 plugin->select_wirewatch_accounts 622 = &TMH_PG_select_wirewatch_accounts; 623 plugin->select_account 624 = &TMH_PG_select_account; 625 plugin->select_accounts 626 = &TMH_PG_select_accounts; 627 plugin->select_open_transfers 628 = &TMH_PG_select_open_transfers; 629 plugin->insert_exchange_keys 630 = &TMH_PG_insert_exchange_keys; 631 plugin->select_exchange_keys 632 = &TMH_PG_select_exchange_keys; 633 plugin->insert_deposit_to_transfer 634 = &TMH_PG_insert_deposit_to_transfer; 635 plugin->insert_transfer 636 = &TMH_PG_insert_transfer; 637 plugin->lookup_token_family_keys 638 = &TMH_PG_lookup_token_family_keys; 639 plugin->insert_transfer_details 640 = &TMH_PG_insert_transfer_details; 641 plugin->store_wire_fee_by_exchange 642 = &TMH_PG_store_wire_fee_by_exchange; 643 plugin->lookup_webhooks 644 = &TMH_PG_lookup_webhooks; 645 plugin->lookup_webhook 646 = &TMH_PG_lookup_webhook; 647 plugin->delete_webhook 648 = &TMH_PG_delete_webhook; 649 plugin->insert_webhook 650 = &TMH_PG_insert_webhook; 651 plugin->update_webhook 652 = &TMH_PG_update_webhook; 653 plugin->lookup_pending_deposits 654 = &TMH_PG_lookup_pending_deposits; 655 plugin->lookup_webhook_by_event 656 = &TMH_PG_lookup_webhook_by_event; 657 plugin->lookup_all_webhooks 658 = &TMH_PG_lookup_all_webhooks; 659 plugin->lookup_future_webhook 660 = &TMH_PG_lookup_future_webhook; 661 plugin->lookup_pending_webhooks 662 = &TMH_PG_lookup_pending_webhooks; 663 plugin->delete_pending_webhook 664 = &TMH_PG_delete_pending_webhook; 665 plugin->insert_pending_webhook 666 = &TMH_PG_insert_pending_webhook; 667 plugin->update_pending_webhook 668 = &TMH_PG_update_pending_webhook; 669 plugin->lookup_categories 670 = &TMH_PG_lookup_categories; 671 plugin->lookup_categories_by_ids 672 = &TMH_PG_lookup_categories_by_ids; 673 plugin->lookup_units 674 = &TMH_PG_lookup_units; 675 plugin->lookup_custom_units_by_names 676 = &TMH_PG_lookup_custom_units_by_names; 677 plugin->select_category_by_name 678 = &TMH_PG_select_category_by_name; 679 plugin->get_kyc_status 680 = &TMH_PG_get_kyc_status; 681 plugin->account_kyc_set_failed 682 = &TMH_PG_account_kyc_set_failed; 683 plugin->get_kyc_limits 684 = &TMH_PG_get_kyc_limits; 685 plugin->select_category 686 = &TMH_PG_select_category; 687 plugin->select_unit 688 = &TMH_PG_select_unit; 689 plugin->update_category 690 = &TMH_PG_update_category; 691 plugin->update_unit 692 = &TMH_PG_update_unit; 693 plugin->insert_category 694 = &TMH_PG_insert_category; 695 plugin->insert_unit 696 = &TMH_PG_insert_unit; 697 plugin->delete_category 698 = &TMH_PG_delete_category; 699 plugin->delete_unit 700 = &TMH_PG_delete_unit; 701 plugin->delete_exchange_accounts 702 = &TMH_PG_delete_exchange_accounts; 703 plugin->select_accounts_by_exchange 704 = &TMH_PG_select_accounts_by_exchange; 705 plugin->insert_exchange_account 706 = &TMH_PG_insert_exchange_account; 707 plugin->insert_token_family 708 = &TMH_PG_insert_token_family; 709 plugin->lookup_expected_transfers 710 = &TMH_PG_lookup_expected_transfers; 711 plugin->lookup_token_family 712 = &TMH_PG_lookup_token_family; 713 plugin->lookup_token_families 714 = &TMH_PG_lookup_token_families; 715 plugin->delete_token_family 716 = &TMH_PG_delete_token_family; 717 plugin->update_token_family 718 = &TMH_PG_update_token_family; 719 plugin->insert_report 720 = &TMH_PG_insert_report; 721 plugin->delete_report 722 = &TMH_PG_delete_report; 723 plugin->update_report 724 = &TMH_PG_update_report; 725 plugin->check_report 726 = &TMH_PG_check_report; 727 plugin->select_reports 728 = &TMH_PG_select_reports; 729 plugin->lookup_reports_pending 730 = &TMH_PG_lookup_reports_pending; 731 plugin->update_report_status 732 = &TMH_PG_update_report_status; 733 plugin->lookup_statistics_amount_by_bucket2 734 = &TMH_PG_lookup_statistics_amount_by_bucket2; 735 plugin->lookup_statistics_counter_by_bucket2 736 = &TMH_PG_lookup_statistics_counter_by_bucket2; 737 plugin->account_kyc_get_outdated 738 = &TMH_PG_account_kyc_get_outdated; 739 plugin->select_report 740 = &TMH_PG_select_report; 741 plugin->insert_product_group 742 = &TMH_PG_insert_product_group; 743 plugin->delete_product_group 744 = &TMH_PG_delete_product_group; 745 plugin->select_exchanges 746 = &TMH_PG_select_exchanges; 747 plugin->update_product_group 748 = &TMH_PG_update_product_group; 749 plugin->select_product_groups 750 = &TMH_PG_select_product_groups; 751 plugin->insert_money_pot 752 = &TMH_PG_insert_money_pot; 753 plugin->delete_money_pot 754 = &TMH_PG_delete_money_pot; 755 plugin->update_money_pot 756 = &TMH_PG_update_money_pot; 757 plugin->check_money_pots 758 = &TMH_PG_check_money_pots; 759 plugin->select_money_pots 760 = &TMH_PG_select_money_pots; 761 plugin->select_money_pot 762 = &TMH_PG_select_money_pot; 763 plugin->insert_token_family_key 764 = &TMH_PG_insert_token_family_key; 765 plugin->update_contract_session 766 = &TMH_PG_update_contract_session; 767 plugin->lookup_token_family_key 768 = &TMH_PG_lookup_token_family_key; 769 plugin->update_deposit_confirmation_status 770 = &TMH_PG_update_deposit_confirmation_status; 771 plugin->update_donau_instance_receipts_amount 772 = &TMH_PG_update_donau_instance_receipts_amount; 773 plugin->insert_spent_token 774 = &TMH_PG_insert_spent_token; 775 plugin->insert_issued_token 776 = &TMH_PG_insert_issued_token; 777 plugin->lookup_spent_tokens_by_order 778 = &TMH_PG_lookup_spent_tokens_by_order; 779 plugin->lookup_statistics_amount_by_bucket 780 = &TMH_PG_lookup_statistics_amount_by_bucket; 781 plugin->lookup_statistics_counter_by_bucket 782 = &TMH_PG_lookup_statistics_counter_by_bucket; 783 plugin->lookup_statistics_counter_by_interval 784 = &TMH_PG_lookup_statistics_counter_by_interval; 785 plugin->lookup_statistics_amount_by_interval 786 = &TMH_PG_lookup_statistics_amount_by_interval; 787 plugin->lookup_mfa_challenge 788 = &TMH_PG_lookup_mfa_challenge; 789 plugin->solve_mfa_challenge 790 = &TMH_PG_solve_mfa_challenge; 791 plugin->update_mfa_challenge 792 = &TMH_PG_update_mfa_challenge; 793 plugin->create_mfa_challenge 794 = &TMH_PG_create_mfa_challenge; 795 plugin->gc 796 = &TMH_PG_gc; 797 #ifdef HAVE_DONAU_DONAU_SERVICE_H 798 plugin->insert_donau_instance 799 = &TMH_PG_insert_donau_instance; 800 plugin->check_donau_instance 801 = &TMH_PG_check_donau_instance; 802 plugin->select_donau_instance_by_serial 803 = &TMH_PG_select_donau_instance_by_serial; 804 plugin->select_all_donau_instances 805 = &TMH_PG_select_all_donau_instances; 806 plugin->select_donau_instances 807 = &TMH_PG_select_donau_instances; 808 plugin->select_donau_instances_filtered 809 = &TMH_PG_select_donau_instances_filtered; 810 plugin->delete_donau_instance 811 = &TMH_PG_delete_donau_instance; 812 plugin->lookup_donau_keys 813 = &TMH_PG_lookup_donau_keys; 814 plugin->lookup_order_charity 815 = &TMH_PG_lookup_order_charity; 816 plugin->increment_money_pots 817 = &TMH_PG_increment_money_pots; 818 plugin->upsert_donau_keys 819 = &TMH_PG_upsert_donau_keys; 820 plugin->update_donau_instance 821 = &TMH_PG_update_donau_instance; 822 #endif 823 return plugin; 824 } 825 826 827 /** 828 * Shutdown Postgres database subsystem. 829 * 830 * @param cls a `struct TALER_MERCHANTDB_Plugin` 831 * @return NULL (always) 832 */ 833 void * 834 libtaler_plugin_merchantdb_postgres_done (void *cls); 835 836 /* declaration to avoid compiler warning */ 837 void * 838 libtaler_plugin_merchantdb_postgres_done (void *cls) 839 { 840 struct TALER_MERCHANTDB_Plugin *plugin = cls; 841 struct PostgresClosure *pg = plugin->cls; 842 843 if (NULL != pg->conn) 844 { 845 GNUNET_PQ_disconnect (pg->conn); 846 pg->conn = NULL; 847 } 848 GNUNET_free (pg->sql_dir); 849 GNUNET_free (pg); 850 GNUNET_free (plugin); 851 return NULL; 852 } 853 854 855 /* end of plugin_merchantdb_postgres.c */