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_unlock_inventory.h" 92 : #include "pg_insert_order_lock.h" 93 : #include "pg_lookup_contract_terms3.h" 94 : #include "pg_lookup_contract_terms2.h" 95 : #include "pg_lookup_contract_terms.h" 96 : #include "pg_insert_contract_terms.h" 97 : #include "pg_update_contract_terms.h" 98 : #include "pg_delete_contract_terms.h" 99 : #include "pg_delete_template.h" 100 : #include "pg_insert_template.h" 101 : #include "pg_update_template.h" 102 : #include "pg_lookup_templates.h" 103 : #include "pg_lookup_template.h" 104 : #include "pg_lookup_deposits.h" 105 : #include "pg_insert_exchange_signkey.h" 106 : #include "pg_insert_deposit.h" 107 : #include "pg_insert_deposit_confirmation.h" 108 : #include "pg_lookup_refunds.h" 109 : #include "pg_mark_contract_paid.h" 110 : #include "pg_select_account_by_uri.h" 111 : #include "pg_refund_coin.h" 112 : #include "pg_lookup_order_status.h" 113 : #include "pg_lookup_order_status_by_serial.h" 114 : #include "pg_lookup_deposits_by_order.h" 115 : #include "pg_lookup_transfer_details_by_order.h" 116 : #include "pg_mark_order_wired.h" 117 : #include "pg_lookup_refunds_detailed.h" 118 : #include "pg_insert_refund_proof.h" 119 : #include "pg_lookup_refund_proof.h" 120 : #include "pg_lookup_order_by_fulfillment.h" 121 : #include "pg_delete_transfer.h" 122 : #include "pg_check_transfer_exists.h" 123 : #include "pg_lookup_account.h" 124 : #include "pg_lookup_expected_transfers.h" 125 : #include "pg_lookup_deposits_by_contract_and_coin.h" 126 : #include "pg_lookup_transfer_summary.h" 127 : #include "pg_lookup_transfer_details.h" 128 : #include "pg_lookup_webhooks.h" 129 : #include "pg_lookup_webhook.h" 130 : #include "pg_lookup_wire_fee.h" 131 : #include "pg_delete_webhook.h" 132 : #include "pg_insert_webhook.h" 133 : #include "pg_update_webhook.h" 134 : #include "pg_lookup_webhook_by_event.h" 135 : #include "pg_delete_pending_webhook.h" 136 : #include "pg_insert_pending_webhook.h" 137 : #include "pg_update_pending_webhook.h" 138 : #include "pg_lookup_pending_webhooks.h" 139 : #include "pg_update_deposit_confirmation_status.h" 140 : #include "pg_insert_exchange_keys.h" 141 : #include "pg_select_exchange_keys.h" 142 : #include "pg_insert_deposit_to_transfer.h" 143 : #include "pg_increase_refund.h" 144 : #include "pg_select_account.h" 145 : #include "pg_select_accounts.h" 146 : #include "pg_insert_transfer.h" 147 : #include "pg_insert_transfer_details.h" 148 : #include "pg_store_wire_fee_by_exchange.h" 149 : #include "pg_insert_token_family.h" 150 : #include "pg_lookup_token_family.h" 151 : #include "pg_lookup_token_families.h" 152 : #include "pg_delete_token_family.h" 153 : #include "pg_update_token_family.h" 154 : #include "pg_insert_token_family_key.h" 155 : #include "pg_lookup_token_family_key.h" 156 : #include "pg_insert_spent_token.h" 157 : #include "pg_insert_issued_token.h" 158 : #include "pg_lookup_spent_tokens_by_order.h" 159 : #include "pg_lookup_statistics_amount_by_bucket.h" 160 : #include "pg_lookup_statistics_amount_by_interval.h" 161 : #include "pg_lookup_statistics_counter_by_bucket.h" 162 : #include "pg_lookup_statistics_counter_by_interval.h" 163 : 164 : 165 : /** 166 : * How often do we re-try if we run into a DB serialization error? 167 : */ 168 : #define MAX_RETRIES 3 169 : 170 : 171 : /** 172 : * Drop all Taler tables. This should only be used by testcases. 173 : * 174 : * @param cls the `struct PostgresClosure` with the plugin-specific state 175 : * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 176 : */ 177 : static enum GNUNET_GenericReturnValue 178 15 : postgres_drop_tables (void *cls) 179 : { 180 15 : struct PostgresClosure *pc = cls; 181 : struct GNUNET_PQ_Context *conn; 182 : enum GNUNET_GenericReturnValue ret; 183 : 184 15 : conn = GNUNET_PQ_connect_with_cfg (pc->cfg, 185 : "merchantdb-postgres", 186 : NULL, 187 : NULL, 188 : NULL); 189 15 : if (NULL == conn) 190 0 : return GNUNET_SYSERR; 191 15 : ret = GNUNET_PQ_exec_sql (conn, 192 : "drop"); 193 15 : GNUNET_PQ_disconnect (conn); 194 15 : return ret; 195 : } 196 : 197 : 198 : /** 199 : * Initialize tables. 200 : * 201 : * @param cls the `struct PostgresClosure` with the plugin-specific state 202 : * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 203 : */ 204 : static enum GNUNET_GenericReturnValue 205 15 : postgres_create_tables (void *cls) 206 : { 207 15 : struct PostgresClosure *pc = cls; 208 : struct GNUNET_PQ_Context *conn; 209 15 : struct GNUNET_PQ_ExecuteStatement es[] = { 210 15 : GNUNET_PQ_make_try_execute ("SET search_path TO merchant;"), 211 : GNUNET_PQ_EXECUTE_STATEMENT_END 212 : }; 213 : enum GNUNET_GenericReturnValue ret; 214 : 215 15 : conn = GNUNET_PQ_connect_with_cfg (pc->cfg, 216 : "merchantdb-postgres", 217 : "merchant-", 218 : es, 219 : NULL); 220 15 : if (NULL == conn) 221 1 : return GNUNET_SYSERR; 222 14 : ret = GNUNET_PQ_exec_sql (conn, 223 : "procedures"); 224 14 : GNUNET_PQ_disconnect (conn); 225 14 : return ret; 226 : } 227 : 228 : 229 : /** 230 : * Register callback to be invoked on events of type @a es. 231 : * 232 : * @param cls database context to use 233 : * @param es specification of the event to listen for 234 : * @param timeout how long to wait for the event 235 : * @param cb function to call when the event happens, possibly 236 : * multiple times (until cancel is invoked) 237 : * @param cb_cls closure for @a cb 238 : * @return handle useful to cancel the listener 239 : */ 240 : static struct GNUNET_DB_EventHandler * 241 174 : postgres_event_listen (void *cls, 242 : const struct GNUNET_DB_EventHeaderP *es, 243 : struct GNUNET_TIME_Relative timeout, 244 : GNUNET_DB_EventCallback cb, 245 : void *cb_cls) 246 : { 247 174 : struct PostgresClosure *pg = cls; 248 : 249 174 : return GNUNET_PQ_event_listen (pg->conn, 250 : es, 251 : timeout, 252 : cb, 253 : cb_cls); 254 : } 255 : 256 : 257 : /** 258 : * Stop notifications. 259 : * 260 : * @param eh handle to unregister. 261 : */ 262 : static void 263 174 : postgres_event_listen_cancel (struct GNUNET_DB_EventHandler *eh) 264 : { 265 174 : GNUNET_PQ_event_listen_cancel (eh); 266 174 : } 267 : 268 : 269 : /** 270 : * Notify all that listen on @a es of an event. 271 : * 272 : * @param cls database context to use 273 : * @param es specification of the event to generate 274 : * @param extra additional event data provided 275 : * @param extra_size number of bytes in @a extra 276 : */ 277 : static void 278 386 : postgres_event_notify (void *cls, 279 : const struct GNUNET_DB_EventHeaderP *es, 280 : const void *extra, 281 : size_t extra_size) 282 : { 283 386 : struct PostgresClosure *pg = cls; 284 : 285 386 : return GNUNET_PQ_event_notify (pg->conn, 286 : es, 287 : extra, 288 : extra_size); 289 : } 290 : 291 : 292 : void 293 1465 : postgres_preflight (void *cls) 294 : { 295 1465 : struct PostgresClosure *pg = cls; 296 : 297 1465 : if (NULL == pg->transaction_name) 298 1465 : return; /* all good */ 299 0 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 300 : "BUG: Preflight check detected running transaction `%s'!\n", 301 : pg->transaction_name); 302 0 : GNUNET_assert (0); 303 : } 304 : 305 : 306 : void 307 2976 : check_connection (struct PostgresClosure *pg) 308 : { 309 2976 : if (NULL != pg->transaction_name) 310 1258 : return; 311 1718 : GNUNET_PQ_reconnect_if_down (pg->conn); 312 : } 313 : 314 : 315 : /** 316 : * Establish connection to the database. 317 : * 318 : * @param cls plugin context 319 : * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 320 : */ 321 : static enum GNUNET_GenericReturnValue 322 83 : postgres_connect (void *cls) 323 : { 324 83 : struct PostgresClosure *pg = cls; 325 83 : struct GNUNET_PQ_ExecuteStatement es[] = { 326 83 : GNUNET_PQ_make_try_execute ("SET search_path TO merchant;"), 327 : GNUNET_PQ_EXECUTE_STATEMENT_END 328 : }; 329 : 330 83 : pg->conn = GNUNET_PQ_connect_with_cfg2 (pg->cfg, 331 : "merchantdb-postgres", 332 : "merchant-", 333 : es, 334 : NULL, /* prepared statemetns */ 335 : GNUNET_PQ_FLAG_CHECK_CURRENT); 336 83 : pg->prep_gen++; 337 83 : if (NULL == pg->conn) 338 0 : return GNUNET_SYSERR; 339 83 : return GNUNET_OK; 340 : }; 341 : 342 : 343 : /** 344 : * Initialize Postgres database subsystem. 345 : * 346 : * @param cls a configuration instance 347 : * @return NULL on error, otherwise a `struct TALER_MERCHANTDB_Plugin` 348 : */ 349 : void * 350 : libtaler_plugin_merchantdb_postgres_init (void *cls); 351 : 352 : /* declaration to avoid compiler warning */ 353 : void * 354 98 : libtaler_plugin_merchantdb_postgres_init (void *cls) 355 : { 356 98 : const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 357 : struct PostgresClosure *pg; 358 : struct TALER_MERCHANTDB_Plugin *plugin; 359 : 360 98 : pg = GNUNET_new (struct PostgresClosure); 361 98 : pg->cfg = cfg; 362 98 : if (GNUNET_OK != 363 98 : GNUNET_CONFIGURATION_get_value_filename (cfg, 364 : "merchantdb-postgres", 365 : "SQL_DIR", 366 : &pg->sql_dir)) 367 : { 368 0 : GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 369 : "merchantdb-postgres", 370 : "SQL_DIR"); 371 0 : GNUNET_free (pg); 372 0 : return NULL; 373 : } 374 98 : plugin = GNUNET_new (struct TALER_MERCHANTDB_Plugin); 375 98 : plugin->cls = pg; 376 98 : plugin->connect = &postgres_connect; 377 98 : plugin->create_tables = &postgres_create_tables; 378 98 : plugin->drop_tables = &postgres_drop_tables; 379 98 : plugin->event_listen = &postgres_event_listen; 380 98 : plugin->event_listen_cancel = &postgres_event_listen_cancel; 381 98 : plugin->event_notify = &postgres_event_notify; 382 98 : plugin->preflight = &postgres_preflight; 383 98 : plugin->start = &TMH_PG_start; 384 98 : plugin->start_read_committed = &TMH_PG_start_read_committed; 385 98 : plugin->rollback = &TMH_PG_rollback; 386 98 : plugin->commit = &TMH_PG_commit; 387 : plugin->insert_login_token 388 98 : = &TMH_PG_insert_login_token; 389 : plugin->delete_login_token 390 98 : = &TMH_PG_delete_login_token; 391 : plugin->delete_login_token_serial 392 98 : = &TMH_PG_delete_login_token_serial; 393 : plugin->select_login_token 394 98 : = &TMH_PG_select_login_token; 395 : plugin->lookup_login_tokens 396 98 : = &TMH_PG_lookup_login_tokens; 397 : plugin->select_account_by_uri 398 98 : = &TMH_PG_select_account_by_uri; 399 : plugin->lookup_instance_auth 400 98 : = &TMH_PG_lookup_instance_auth; 401 : plugin->insert_instance 402 98 : = &TMH_PG_insert_instance; 403 : plugin->insert_account 404 98 : = &TMH_PG_insert_account; 405 : plugin->lookup_otp_devices 406 98 : = &TMH_PG_lookup_otp_devices; 407 : plugin->delete_template 408 98 : = &TMH_PG_delete_template; 409 : plugin->insert_template 410 98 : = &TMH_PG_insert_template; 411 : plugin->update_template 412 98 : = &TMH_PG_update_template; 413 : plugin->lookup_templates 414 98 : = &TMH_PG_lookup_templates; 415 : plugin->lookup_template 416 98 : = &TMH_PG_lookup_template; 417 : plugin->update_account 418 98 : = &TMH_PG_update_account; 419 : plugin->account_kyc_set_status 420 98 : = &TMH_PG_account_kyc_set_status; 421 : plugin->account_kyc_get_status 422 98 : = &TMH_PG_account_kyc_get_status; 423 : plugin->delete_instance_private_key 424 98 : = &TMH_PG_delete_instance_private_key; 425 : plugin->purge_instance 426 98 : = &TMH_PG_purge_instance; 427 : plugin->update_instance 428 98 : = &TMH_PG_update_instance; 429 : plugin->update_instance_auth 430 98 : = &TMH_PG_update_instance_auth; 431 : plugin->activate_account 432 98 : = &TMH_PG_activate_account; 433 : plugin->inactivate_account 434 98 : = &TMH_PG_inactivate_account; 435 : plugin->update_transfer_status 436 98 : = &TMH_PG_update_transfer_status; 437 : plugin->finalize_transfer_status 438 98 : = &TMH_PG_finalize_transfer_status; 439 : plugin->lookup_products 440 98 : = &TMH_PG_lookup_products; 441 : plugin->lookup_all_products 442 98 : = &TMH_PG_lookup_all_products; 443 : plugin->lookup_product 444 98 : = &TMH_PG_lookup_product; 445 : plugin->delete_product 446 98 : = &TMH_PG_delete_product; 447 : plugin->insert_product 448 98 : = &TMH_PG_insert_product; 449 : plugin->update_product 450 98 : = &TMH_PG_update_product; 451 : plugin->insert_otp 452 98 : = &TMH_PG_insert_otp; 453 : plugin->delete_otp 454 98 : = &TMH_PG_delete_otp; 455 : plugin->update_otp 456 98 : = &TMH_PG_update_otp; 457 : plugin->select_otp 458 98 : = &TMH_PG_select_otp; 459 : plugin->select_otp_serial 460 98 : = &TMH_PG_select_otp_serial; 461 : plugin->lock_product 462 98 : = &TMH_PG_lock_product; 463 : plugin->expire_locks 464 98 : = &TMH_PG_expire_locks; 465 : plugin->delete_order 466 98 : = &TMH_PG_delete_order; 467 : plugin->lookup_order 468 98 : = &TMH_PG_lookup_order; 469 : plugin->lookup_order_summary 470 98 : = &TMH_PG_lookup_order_summary; 471 : plugin->lookup_orders 472 98 : = &TMH_PG_lookup_orders; 473 : plugin->insert_order 474 98 : = &TMH_PG_insert_order; 475 : plugin->unlock_inventory 476 98 : = &TMH_PG_unlock_inventory; 477 : plugin->insert_order_lock 478 98 : = &TMH_PG_insert_order_lock; 479 : plugin->lookup_contract_terms 480 98 : = &TMH_PG_lookup_contract_terms; 481 : plugin->lookup_contract_terms2 482 98 : = &TMH_PG_lookup_contract_terms2; 483 : plugin->lookup_contract_terms3 484 98 : = &TMH_PG_lookup_contract_terms3; 485 : plugin->insert_contract_terms 486 98 : = &TMH_PG_insert_contract_terms; 487 : plugin->update_contract_terms 488 98 : = &TMH_PG_update_contract_terms; 489 : plugin->delete_contract_terms 490 98 : = &TMH_PG_delete_contract_terms; 491 : plugin->lookup_deposits 492 98 : = &TMH_PG_lookup_deposits; 493 : plugin->insert_exchange_signkey 494 98 : = &TMH_PG_insert_exchange_signkey; 495 : plugin->insert_deposit_confirmation 496 98 : = &TMH_PG_insert_deposit_confirmation; 497 : plugin->insert_deposit 498 98 : = &TMH_PG_insert_deposit; 499 : plugin->lookup_refunds 500 98 : = &TMH_PG_lookup_refunds; 501 : plugin->mark_contract_paid 502 98 : = &TMH_PG_mark_contract_paid; 503 : plugin->refund_coin 504 98 : = &TMH_PG_refund_coin; 505 : plugin->lookup_order_status 506 98 : = &TMH_PG_lookup_order_status; 507 : plugin->lookup_order_status_by_serial 508 98 : = &TMH_PG_lookup_order_status_by_serial; 509 : plugin->lookup_deposits_by_order 510 98 : = &TMH_PG_lookup_deposits_by_order; 511 : plugin->lookup_transfer_details_by_order 512 98 : = &TMH_PG_lookup_transfer_details_by_order; 513 : plugin->mark_order_wired 514 98 : = &TMH_PG_mark_order_wired; 515 : plugin->increase_refund 516 98 : = &TMH_PG_increase_refund; 517 : plugin->lookup_refunds_detailed 518 98 : = &TMH_PG_lookup_refunds_detailed; 519 : plugin->insert_refund_proof 520 98 : = &TMH_PG_insert_refund_proof; 521 : plugin->lookup_refund_proof 522 98 : = &TMH_PG_lookup_refund_proof; 523 : plugin->lookup_order_by_fulfillment 524 98 : = &TMH_PG_lookup_order_by_fulfillment; 525 : plugin->delete_transfer 526 98 : = &TMH_PG_delete_transfer; 527 : plugin->check_transfer_exists 528 98 : = &TMH_PG_check_transfer_exists; 529 : plugin->lookup_account 530 98 : = &TMH_PG_lookup_account; 531 : plugin->lookup_wire_fee 532 98 : = &TMH_PG_lookup_wire_fee; 533 : plugin->lookup_deposits_by_contract_and_coin 534 98 : = &TMH_PG_lookup_deposits_by_contract_and_coin; 535 : plugin->lookup_transfer_summary 536 98 : = &TMH_PG_lookup_transfer_summary; 537 : plugin->lookup_transfer_details 538 98 : = &TMH_PG_lookup_transfer_details; 539 : plugin->lookup_instances 540 98 : = &TMH_PG_lookup_instances; 541 : plugin->lookup_instance 542 98 : = &TMH_PG_lookup_instance; 543 : plugin->lookup_transfers 544 98 : = &TMH_PG_lookup_transfers; 545 : plugin->update_wirewatch_progress 546 98 : = &TMH_PG_update_wirewatch_progress; 547 : plugin->select_wirewatch_accounts 548 98 : = &TMH_PG_select_wirewatch_accounts; 549 : plugin->select_account 550 98 : = &TMH_PG_select_account; 551 : plugin->select_accounts 552 98 : = &TMH_PG_select_accounts; 553 : plugin->select_open_transfers 554 98 : = &TMH_PG_select_open_transfers; 555 : plugin->insert_exchange_keys 556 98 : = &TMH_PG_insert_exchange_keys; 557 : plugin->select_exchange_keys 558 98 : = &TMH_PG_select_exchange_keys; 559 : plugin->insert_deposit_to_transfer 560 98 : = &TMH_PG_insert_deposit_to_transfer; 561 : plugin->insert_transfer 562 98 : = &TMH_PG_insert_transfer; 563 : plugin->lookup_token_family_keys 564 98 : = &TMH_PG_lookup_token_family_keys; 565 : plugin->insert_transfer_details 566 98 : = &TMH_PG_insert_transfer_details; 567 : plugin->store_wire_fee_by_exchange 568 98 : = &TMH_PG_store_wire_fee_by_exchange; 569 : plugin->lookup_webhooks 570 98 : = &TMH_PG_lookup_webhooks; 571 : plugin->lookup_webhook 572 98 : = &TMH_PG_lookup_webhook; 573 : plugin->delete_webhook 574 98 : = &TMH_PG_delete_webhook; 575 : plugin->insert_webhook 576 98 : = &TMH_PG_insert_webhook; 577 : plugin->update_webhook 578 98 : = &TMH_PG_update_webhook; 579 : plugin->lookup_pending_deposits 580 98 : = &TMH_PG_lookup_pending_deposits; 581 : plugin->lookup_webhook_by_event 582 98 : = &TMH_PG_lookup_webhook_by_event; 583 : plugin->lookup_all_webhooks 584 98 : = &TMH_PG_lookup_all_webhooks; 585 : plugin->lookup_future_webhook 586 98 : = &TMH_PG_lookup_future_webhook; 587 : plugin->lookup_pending_webhooks 588 98 : = &TMH_PG_lookup_pending_webhooks; 589 : plugin->delete_pending_webhook 590 98 : = &TMH_PG_delete_pending_webhook; 591 : plugin->insert_pending_webhook 592 98 : = &TMH_PG_insert_pending_webhook; 593 : plugin->update_pending_webhook 594 98 : = &TMH_PG_update_pending_webhook; 595 : plugin->lookup_categories 596 98 : = &TMH_PG_lookup_categories; 597 : plugin->select_category_by_name 598 98 : = &TMH_PG_select_category_by_name; 599 : plugin->get_kyc_status 600 98 : = &TMH_PG_get_kyc_status; 601 : plugin->account_kyc_set_failed 602 98 : = &TMH_PG_account_kyc_set_failed; 603 : plugin->get_kyc_limits 604 98 : = &TMH_PG_get_kyc_limits; 605 : plugin->select_category 606 98 : = &TMH_PG_select_category; 607 : plugin->update_category 608 98 : = &TMH_PG_update_category; 609 : plugin->insert_category 610 98 : = &TMH_PG_insert_category; 611 : plugin->delete_category 612 98 : = &TMH_PG_delete_category; 613 : plugin->delete_exchange_accounts 614 98 : = &TMH_PG_delete_exchange_accounts; 615 : plugin->select_accounts_by_exchange 616 98 : = &TMH_PG_select_accounts_by_exchange; 617 : plugin->insert_exchange_account 618 98 : = &TMH_PG_insert_exchange_account; 619 : plugin->insert_token_family 620 98 : = &TMH_PG_insert_token_family; 621 : plugin->lookup_expected_transfers 622 98 : = &TMH_PG_lookup_expected_transfers; 623 : plugin->lookup_token_family 624 98 : = &TMH_PG_lookup_token_family; 625 : plugin->lookup_token_families 626 98 : = &TMH_PG_lookup_token_families; 627 : plugin->delete_token_family 628 98 : = &TMH_PG_delete_token_family; 629 : plugin->update_token_family 630 98 : = &TMH_PG_update_token_family; 631 : plugin->insert_token_family_key 632 98 : = &TMH_PG_insert_token_family_key; 633 : plugin->lookup_token_family_key 634 98 : = &TMH_PG_lookup_token_family_key; 635 : plugin->update_deposit_confirmation_status 636 98 : = &TMH_PG_update_deposit_confirmation_status; 637 : plugin->insert_spent_token 638 98 : = &TMH_PG_insert_spent_token; 639 : plugin->insert_issued_token 640 98 : = &TMH_PG_insert_issued_token; 641 : plugin->lookup_spent_tokens_by_order 642 98 : = &TMH_PG_lookup_spent_tokens_by_order; 643 : plugin->lookup_statistics_amount_by_bucket 644 98 : = &TMH_PG_lookup_statistics_amount_by_bucket; 645 : plugin->lookup_statistics_counter_by_bucket 646 98 : = &TMH_PG_lookup_statistics_counter_by_bucket; 647 : plugin->lookup_statistics_counter_by_interval 648 98 : = &TMH_PG_lookup_statistics_counter_by_interval; 649 : plugin->lookup_statistics_amount_by_interval 650 98 : = &TMH_PG_lookup_statistics_amount_by_interval; 651 : plugin->gc 652 98 : = &TMH_PG_gc; 653 : 654 98 : return plugin; 655 : } 656 : 657 : 658 : /** 659 : * Shutdown Postgres database subsystem. 660 : * 661 : * @param cls a `struct TALER_MERCHANTDB_Plugin` 662 : * @return NULL (always) 663 : */ 664 : void * 665 : libtaler_plugin_merchantdb_postgres_done (void *cls); 666 : 667 : /* declaration to avoid compiler warning */ 668 : void * 669 97 : libtaler_plugin_merchantdb_postgres_done (void *cls) 670 : { 671 97 : struct TALER_MERCHANTDB_Plugin *plugin = cls; 672 97 : struct PostgresClosure *pg = plugin->cls; 673 : 674 97 : if (NULL != pg->conn) 675 : { 676 83 : GNUNET_PQ_disconnect (pg->conn); 677 83 : pg->conn = NULL; 678 : } 679 97 : GNUNET_free (pg->sql_dir); 680 97 : GNUNET_free (pg); 681 97 : GNUNET_free (plugin); 682 97 : return NULL; 683 : } 684 : 685 : 686 : /* end of plugin_merchantdb_postgres.c */