Line data Source code
1 : /* 2 : This file is part of TALER 3 : Copyright (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 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 : /** 18 : * @file plugin_exchangedb_postgres.c 19 : * @brief Low-level (statement-level) Postgres database access for the exchange 20 : * @author Florian Dold 21 : * @author Christian Grothoff 22 : * @author Sree Harsha Totakura 23 : * @author Marcello Stanisci 24 : * @author Özgür Kesim 25 : */ 26 : #include "taler/platform.h" 27 : #include <poll.h> 28 : #include <pthread.h> 29 : #include <libpq-fe.h> 30 : #include "pg_abort_shard.h" 31 : #include "pg_activate_signing_key.h" 32 : #include "pg_add_denomination_key.h" 33 : #include "pg_add_policy_fulfillment_proof.h" 34 : #include "pg_aggregate.h" 35 : #include "pg_batch_ensure_coin_known.h" 36 : #include "pg_begin_revolving_shard.h" 37 : #include "pg_begin_shard.h" 38 : #include "pg_clear_aml_lock.h" 39 : #include "pg_commit.h" 40 : #include "pg_complete_shard.h" 41 : #include "pg_compute_shard.h" 42 : #include "pg_count_known_coins.h" 43 : #include "pg_create_aggregation_transient.h" 44 : #include "pg_create_tables.h" 45 : #include "pg_delete_aggregation_transient.h" 46 : #include "pg_delete_shard_locks.h" 47 : #include "pg_disable_rules.h" 48 : #include "pg_do_withdraw.h" 49 : #include "pg_do_check_deposit_idempotent.h" 50 : #include "pg_do_deposit.h" 51 : #include "pg_do_melt.h" 52 : #include "pg_do_purse_delete.h" 53 : #include "pg_do_purse_deposit.h" 54 : #include "pg_do_purse_merge.h" 55 : #include "pg_do_recoup.h" 56 : #include "pg_do_recoup_refresh.h" 57 : #include "pg_do_refresh.h" 58 : #include "pg_do_refund.h" 59 : #include "pg_do_reserve_open.h" 60 : #include "pg_do_reserve_purse.h" 61 : #include "pg_drain_kyc_alert.h" 62 : #include "pg_drop_tables.h" 63 : #include "pg_enable_rules.h" 64 : #include "pg_ensure_coin_known.h" 65 : #include "pg_event_listen.h" 66 : #include "pg_event_listen_cancel.h" 67 : #include "pg_event_notify.h" 68 : #include "pg_expire_purse.h" 69 : #include "pg_find_aggregation_transient.h" 70 : #include "pg_gc.h" 71 : #include "pg_get_withdraw.h" 72 : #include "pg_get_coin_denomination.h" 73 : #include "pg_get_coin_transactions.h" 74 : #include "pg_get_denomination_info.h" 75 : #include "pg_get_denomination_by_serial.h" 76 : #include "pg_get_denomination_revocation.h" 77 : #include "pg_get_drain_profit.h" 78 : #include "pg_get_expired_reserves.h" 79 : #include "pg_get_extension_manifest.h" 80 : #include "pg_get_global_fee.h" 81 : #include "pg_get_global_fees.h" 82 : #include "pg_get_known_coin.h" 83 : #include "pg_get_kyc_rules.h" 84 : #include "pg_get_old_coin_by_h_blind.h" 85 : #include "pg_get_pending_kyc_requirement_process.h" 86 : #include "pg_get_policy_details.h" 87 : #include "pg_get_purse_deposit.h" 88 : #include "pg_get_purse_request.h" 89 : #include "pg_get_ready_deposit.h" 90 : #include "pg_get_refresh.h" 91 : #include "pg_get_refresh_reveal.h" 92 : #include "pg_get_reserve_balance.h" 93 : #include "pg_get_reserve_by_h_planchets.h" 94 : #include "pg_get_reserve_history.h" 95 : #include "pg_get_signature_for_known_coin.h" 96 : #include "pg_get_unfinished_close_requests.h" 97 : #include "pg_get_wire_accounts.h" 98 : #include "pg_get_wire_fee.h" 99 : #include "pg_get_wire_fees.h" 100 : #include "pg_get_wire_hash_for_contract.h" 101 : #include "pg_have_deposit2.h" 102 : #include "pg_helper.h" 103 : #include "pg_inject_auditor_triggers.h" 104 : #include "pg_insert_active_legitimization_measure.h" 105 : #include "pg_insert_aml_decision.h" 106 : #include "pg_insert_aml_officer.h" 107 : #include "pg_insert_aml_program_failure.h" 108 : #include "pg_insert_auditor.h" 109 : #include "pg_insert_auditor_denom_sig.h" 110 : #include "pg_insert_close_request.h" 111 : #include "pg_insert_contract.h" 112 : #include "pg_insert_denomination_info.h" 113 : #include "pg_insert_denomination_revocation.h" 114 : #include "pg_insert_drain_profit.h" 115 : #include "pg_insert_global_fee.h" 116 : #include "pg_insert_kyc_failure.h" 117 : #include "pg_insert_kyc_requirement_process.h" 118 : #include "pg_insert_partner.h" 119 : #include "pg_insert_purse_request.h" 120 : #include "pg_insert_records_by_table.h" 121 : #include "pg_insert_refund.h" 122 : #include "pg_insert_reserve_closed.h" 123 : #include "pg_insert_reserve_open_deposit.h" 124 : #include "pg_insert_sanction_list_hit.h" 125 : #include "pg_insert_signkey_revocation.h" 126 : #include "pg_insert_successor_measure.h" 127 : #include "pg_insert_wire.h" 128 : #include "pg_insert_wire_fee.h" 129 : #include "pg_iterate_active_auditors.h" 130 : #include "pg_iterate_active_signkeys.h" 131 : #include "pg_iterate_auditor_denominations.h" 132 : #include "pg_iterate_denomination_info.h" 133 : #include "pg_iterate_denominations.h" 134 : #include "pg_iterate_kyc_reference.h" 135 : #include "pg_iterate_reserve_close_info.h" 136 : #include "pg_kyc_provider_account_lookup.h" 137 : #include "pg_kycauth_in_insert.h" 138 : #include "pg_lookup_active_legitimization.h" 139 : #include "pg_lookup_aml_history.h" 140 : #include "pg_lookup_aml_officer.h" 141 : #include "pg_lookup_auditor_status.h" 142 : #include "pg_lookup_auditor_timestamp.h" 143 : #include "pg_lookup_completed_legitimization.h" 144 : #include "pg_lookup_denomination_key.h" 145 : #include "pg_lookup_global_fee_by_time.h" 146 : #include "pg_lookup_h_payto_by_access_token.h" 147 : #include "pg_lookup_kyc_history.h" 148 : #include "pg_lookup_kyc_process_by_account.h" 149 : #include "pg_lookup_kyc_requirement_by_row.h" 150 : #include "pg_lookup_kyc_status_by_token.h" 151 : #include "pg_lookup_pending_legitimization.h" 152 : #include "pg_lookup_records_by_table.h" 153 : #include "pg_lookup_rules_by_access_token.h" 154 : #include "pg_lookup_serial_by_table.h" 155 : #include "pg_lookup_signing_key.h" 156 : #include "pg_lookup_signkey_revocation.h" 157 : #include "pg_lookup_transfer_by_deposit.h" 158 : #include "pg_lookup_wire_fee_by_time.h" 159 : #include "pg_lookup_wire_timestamp.h" 160 : #include "pg_lookup_wire_transfer.h" 161 : #include "pg_persist_kyc_attributes.h" 162 : #include "pg_persist_policy_details.h" 163 : #include "pg_preflight.h" 164 : #include "pg_profit_drains_get_pending.h" 165 : #include "pg_profit_drains_set_finished.h" 166 : #include "pg_release_revolving_shard.h" 167 : #include "pg_reserves_get.h" 168 : #include "pg_reserves_get_origin.h" 169 : #include "pg_reserves_in_insert.h" 170 : #include "pg_reserves_update.h" 171 : #include "pg_rollback.h" 172 : #include "pg_select_account_merges_above_serial_id.h" 173 : #include "pg_select_aggregation_amounts_for_kyc_check.h" 174 : #include "pg_select_aggregation_transient.h" 175 : #include "pg_select_aggregations_above_serial.h" 176 : #include "pg_select_all_kyc_attributes.h" 177 : #include "pg_select_all_purse_decisions_above_serial_id.h" 178 : #include "pg_select_all_purse_deletions_above_serial_id.h" 179 : #include "pg_select_aml_attributes.h" 180 : #include "pg_select_aml_decisions.h" 181 : #include "pg_select_aml_measures.h" 182 : #include "pg_select_aml_statistics.h" 183 : #include "pg_select_auditor_denom_sig.h" 184 : #include "pg_select_batch_deposits_missing_wire.h" 185 : #include "pg_select_coin_deposits_above_serial_id.h" 186 : #include "pg_select_contract.h" 187 : #include "pg_select_contract_by_purse.h" 188 : #include "pg_select_deposit_amounts_for_kyc_check.h" 189 : #include "pg_select_exchange_credit_transfers.h" 190 : #include "pg_select_exchange_debit_transfers.h" 191 : #include "pg_select_exchange_kycauth_transfers.h" 192 : #include "pg_select_kyc_attributes.h" 193 : #include "pg_select_merge_amounts_for_kyc_check.h" 194 : #include "pg_select_purse.h" 195 : #include "pg_select_purse_by_merge_pub.h" 196 : #include "pg_select_purse_decisions_above_serial_id.h" 197 : #include "pg_select_purse_deposits_above_serial_id.h" 198 : #include "pg_select_purse_deposits_by_purse.h" 199 : #include "pg_select_purse_merge.h" 200 : #include "pg_select_purse_merges_above_serial_id.h" 201 : #include "pg_select_purse_requests_above_serial_id.h" 202 : #include "pg_select_recoup_above_serial_id.h" 203 : #include "pg_select_recoup_refresh_above_serial_id.h" 204 : #include "pg_select_refreshes_above_serial_id.h" 205 : #include "pg_select_refunds_above_serial_id.h" 206 : #include "pg_select_refunds_by_coin.h" 207 : #include "pg_select_reserve_close_info.h" 208 : #include "pg_select_reserve_closed_above_serial_id.h" 209 : #include "pg_select_reserve_open_above_serial_id.h" 210 : #include "pg_select_reserves_in_above_serial_id.h" 211 : #include "pg_select_reserves_in_above_serial_id_by_account.h" 212 : #include "pg_select_wire_out_above_serial_id.h" 213 : #include "pg_select_wire_out_above_serial_id_by_account.h" 214 : #include "pg_select_withdraw_amounts_for_kyc_check.h" 215 : #include "pg_select_withdrawals_above_serial_id.h" 216 : #include "pg_set_aml_lock.h" 217 : #include "pg_set_extension_manifest.h" 218 : #include "pg_set_purse_balance.h" 219 : #include "pg_start.h" 220 : #include "pg_start_deferred_wire_out.h" 221 : #include "pg_start_read_committed.h" 222 : #include "pg_start_read_only.h" 223 : #include "pg_store_wire_transfer_out.h" 224 : #include "pg_test_aml_officer.h" 225 : #include "pg_trigger_kyc_rule_for_account.h" 226 : #include "pg_update_aggregation_transient.h" 227 : #include "pg_update_auditor.h" 228 : #include "pg_update_kyc_process_by_row.h" 229 : #include "pg_update_wire.h" 230 : #include "pg_wad_in_insert.h" 231 : #include "pg_wire_prepare_data_get.h" 232 : #include "pg_wire_prepare_data_insert.h" 233 : #include "pg_wire_prepare_data_mark_failed.h" 234 : #include "pg_wire_prepare_data_mark_finished.h" 235 : #include "plugin_exchangedb_common.h" 236 : #include "plugin_exchangedb_postgres.h" 237 : #include "taler/taler_dbevents.h" 238 : #include "taler/taler_error_codes.h" 239 : #include "taler/taler_exchangedb_plugin.h" 240 : #include "taler/taler_json_lib.h" 241 : #include "taler/taler_pq_lib.h" 242 : #include "taler/taler_util.h" 243 : 244 : /** 245 : * Set to 1 to enable Postgres auto_explain module. This will 246 : * slow down things a _lot_, but also provide extensive logging 247 : * in the Postgres database logger for performance analysis. 248 : */ 249 : #define AUTO_EXPLAIN 0 250 : 251 : 252 : /** 253 : * Log a really unexpected PQ error with all the details we can get hold of. 254 : * 255 : * @param result PQ result object of the PQ operation that failed 256 : * @param conn SQL connection that was used 257 : */ 258 : #define BREAK_DB_ERR(result,conn) do { \ 259 : GNUNET_break (0); \ 260 : GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ 261 : "Database failure: %s/%s/%s/%s/%s", \ 262 : PQresultErrorField (result, PG_DIAG_MESSAGE_PRIMARY), \ 263 : PQresultErrorField (result, PG_DIAG_MESSAGE_DETAIL), \ 264 : PQresultErrorMessage (result), \ 265 : PQresStatus (PQresultStatus (result)), \ 266 : PQerrorMessage (conn)); \ 267 : } while (0) 268 : 269 : 270 : /** 271 : * Initialize Postgres database subsystem. 272 : * 273 : * @param cls a configuration instance 274 : * @return NULL on error, otherwise a `struct 275 : * TALER_EXCHANGEDB_Plugin` 276 : */ 277 : void * 278 : libtaler_plugin_exchangedb_postgres_init (void *cls); 279 : 280 : /* Declaration used to squash compiler warning */ 281 : void * 282 895 : libtaler_plugin_exchangedb_postgres_init (void *cls) 283 : { 284 895 : const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 285 : struct PostgresClosure *pg; 286 : struct TALER_EXCHANGEDB_Plugin *plugin; 287 : unsigned long long dpl; 288 : 289 895 : pg = GNUNET_new (struct PostgresClosure); 290 895 : plugin = GNUNET_new (struct TALER_EXCHANGEDB_Plugin); 291 895 : pg->cfg = cfg; 292 895 : if (GNUNET_OK != 293 895 : GNUNET_CONFIGURATION_get_value_filename (cfg, 294 : "exchangedb-postgres", 295 : "SQL_DIR", 296 : &pg->sql_dir)) 297 : { 298 0 : GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 299 : "exchangedb-postgres", 300 : "SQL_DIR"); 301 0 : goto fail; 302 : } 303 895 : if (GNUNET_OK != 304 895 : GNUNET_CONFIGURATION_get_value_string (cfg, 305 : "exchange", 306 : "BASE_URL", 307 : &pg->exchange_url)) 308 : { 309 0 : GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 310 : "exchange", 311 : "BASE_URL"); 312 0 : goto fail; 313 : } 314 895 : if (GNUNET_OK != 315 895 : GNUNET_CONFIGURATION_get_value_time (cfg, 316 : "exchangedb", 317 : "IDLE_RESERVE_EXPIRATION_TIME", 318 : &pg->idle_reserve_expiration_time)) 319 : { 320 0 : GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 321 : "exchangedb", 322 : "IDLE_RESERVE_EXPIRATION_TIME"); 323 0 : goto fail; 324 : } 325 895 : if (GNUNET_OK != 326 895 : GNUNET_CONFIGURATION_get_value_time (cfg, 327 : "exchangedb", 328 : "MAX_AML_PROGRAM_RUNTIME", 329 : &plugin->max_aml_program_runtime)) 330 : { 331 0 : GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 332 : "exchangedb", 333 : "MAX_AML_PROGRAM_RUNTIME"); 334 0 : goto fail; 335 : } 336 895 : if (GNUNET_OK != 337 895 : GNUNET_CONFIGURATION_get_value_time (cfg, 338 : "exchangedb", 339 : "LEGAL_RESERVE_EXPIRATION_TIME", 340 : &pg->legal_reserve_expiration_time)) 341 : { 342 0 : GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 343 : "exchangedb", 344 : "LEGAL_RESERVE_EXPIRATION_TIME"); 345 0 : goto fail; 346 : } 347 895 : if (GNUNET_OK != 348 895 : GNUNET_CONFIGURATION_get_value_time (cfg, 349 : "exchangedb", 350 : "AGGREGATOR_SHIFT", 351 : &pg->aggregator_shift)) 352 : { 353 0 : GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, 354 : "exchangedb", 355 : "AGGREGATOR_SHIFT"); 356 : } 357 895 : if (GNUNET_OK != 358 895 : GNUNET_CONFIGURATION_get_value_number (cfg, 359 : "exchangedb", 360 : "DEFAULT_PURSE_LIMIT", 361 : &dpl)) 362 : { 363 0 : GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, 364 : "exchangedb", 365 : "DEFAULT_PURSE_LIMIT"); 366 0 : pg->def_purse_limit = 1; 367 : } 368 : else 369 : { 370 895 : pg->def_purse_limit = (uint32_t) dpl; 371 : } 372 : 373 895 : if (GNUNET_OK != 374 895 : TALER_config_get_currency (cfg, 375 : "exchange", 376 : &pg->currency)) 377 : { 378 0 : goto fail; 379 : } 380 895 : plugin->cls = pg; 381 : plugin->do_reserve_open 382 895 : = &TEH_PG_do_reserve_open; 383 : plugin->drop_tables 384 895 : = &TEH_PG_drop_tables; 385 : plugin->free_coin_transaction_list 386 895 : = &TEH_COMMON_free_coin_transaction_list; 387 : plugin->free_reserve_history 388 895 : = &TEH_COMMON_free_reserve_history; 389 : plugin->get_coin_transactions 390 895 : = &TEH_PG_get_coin_transactions; 391 : plugin->get_expired_reserves 392 895 : = &TEH_PG_get_expired_reserves; 393 : plugin->get_purse_request 394 895 : = &TEH_PG_get_purse_request; 395 : plugin->get_reserve_history 396 895 : = &TEH_PG_get_reserve_history; 397 : plugin->get_unfinished_close_requests 398 895 : = &TEH_PG_get_unfinished_close_requests; 399 : plugin->insert_records_by_table 400 895 : = &TEH_PG_insert_records_by_table; 401 : plugin->insert_reserve_open_deposit 402 895 : = &TEH_PG_insert_reserve_open_deposit; 403 : plugin->insert_close_request 404 895 : = &TEH_PG_insert_close_request; 405 : plugin->delete_aggregation_transient 406 895 : = &TEH_PG_delete_aggregation_transient; 407 : plugin->iterate_reserve_close_info 408 895 : = &TEH_PG_iterate_reserve_close_info; 409 : plugin->iterate_kyc_reference 410 895 : = &TEH_PG_iterate_kyc_reference; 411 : plugin->lookup_records_by_table 412 895 : = &TEH_PG_lookup_records_by_table; 413 : plugin->lookup_serial_by_table 414 895 : = &TEH_PG_lookup_serial_by_table; 415 : plugin->select_account_merges_above_serial_id 416 895 : = &TEH_PG_select_account_merges_above_serial_id; 417 : plugin->select_all_purse_decisions_above_serial_id 418 895 : = &TEH_PG_select_all_purse_decisions_above_serial_id; 419 : plugin->select_all_purse_deletions_above_serial_id 420 895 : = &TEH_PG_select_all_purse_deletions_above_serial_id; 421 : plugin->select_purse 422 895 : = &TEH_PG_select_purse; 423 : plugin->select_purse_deposits_above_serial_id 424 895 : = &TEH_PG_select_purse_deposits_above_serial_id; 425 : plugin->select_purse_merges_above_serial_id 426 895 : = &TEH_PG_select_purse_merges_above_serial_id; 427 : plugin->select_purse_requests_above_serial_id 428 895 : = &TEH_PG_select_purse_requests_above_serial_id; 429 : plugin->select_reserve_close_info 430 895 : = &TEH_PG_select_reserve_close_info; 431 : plugin->select_reserve_closed_above_serial_id 432 895 : = &TEH_PG_select_reserve_closed_above_serial_id; 433 : plugin->select_reserve_open_above_serial_id 434 895 : = &TEH_PG_select_reserve_open_above_serial_id; 435 : plugin->insert_purse_request 436 895 : = &TEH_PG_insert_purse_request; 437 : plugin->iterate_active_signkeys 438 895 : = &TEH_PG_iterate_active_signkeys; 439 : plugin->commit 440 895 : = &TEH_PG_commit; 441 : plugin->preflight 442 895 : = &TEH_PG_preflight; 443 : plugin->select_aggregation_amounts_for_kyc_check 444 895 : = &TEH_PG_select_aggregation_amounts_for_kyc_check; 445 : plugin->get_kyc_rules 446 895 : = &TEH_PG_get_kyc_rules; 447 : plugin->get_kyc_rules2 448 895 : = &TEH_PG_get_kyc_rules2; 449 : plugin->kyc_provider_account_lookup 450 895 : = &TEH_PG_kyc_provider_account_lookup; 451 : plugin->lookup_kyc_process_by_account 452 895 : = &TEH_PG_lookup_kyc_process_by_account; 453 : plugin->update_kyc_process_by_row 454 895 : = &TEH_PG_update_kyc_process_by_row; 455 : plugin->insert_kyc_requirement_process 456 895 : = &TEH_PG_insert_kyc_requirement_process; 457 : plugin->select_withdraw_amounts_for_kyc_check 458 895 : = &TEH_PG_select_withdraw_amounts_for_kyc_check; 459 : plugin->select_merge_amounts_for_kyc_check 460 895 : = &TEH_PG_select_merge_amounts_for_kyc_check; 461 : plugin->profit_drains_set_finished 462 895 : = &TEH_PG_profit_drains_set_finished; 463 : plugin->profit_drains_get_pending 464 895 : = &TEH_PG_profit_drains_get_pending; 465 : plugin->get_drain_profit 466 895 : = &TEH_PG_get_drain_profit; 467 : plugin->get_purse_deposit 468 895 : = &TEH_PG_get_purse_deposit; 469 : plugin->insert_contract 470 895 : = &TEH_PG_insert_contract; 471 : plugin->select_contract 472 895 : = &TEH_PG_select_contract; 473 : plugin->select_purse_merge 474 895 : = &TEH_PG_select_purse_merge; 475 : plugin->select_contract_by_purse 476 895 : = &TEH_PG_select_contract_by_purse; 477 : plugin->insert_drain_profit 478 895 : = &TEH_PG_insert_drain_profit; 479 : plugin->do_reserve_purse 480 895 : = &TEH_PG_do_reserve_purse; 481 : plugin->lookup_global_fee_by_time 482 895 : = &TEH_PG_lookup_global_fee_by_time; 483 : plugin->do_purse_deposit 484 895 : = &TEH_PG_do_purse_deposit; 485 : plugin->activate_signing_key 486 895 : = &TEH_PG_activate_signing_key; 487 : plugin->update_auditor 488 895 : = &TEH_PG_update_auditor; 489 : plugin->begin_revolving_shard 490 895 : = &TEH_PG_begin_revolving_shard; 491 : plugin->get_extension_manifest 492 895 : = &TEH_PG_get_extension_manifest; 493 : plugin->do_purse_merge 494 895 : = &TEH_PG_do_purse_merge; 495 : plugin->do_purse_delete 496 895 : = &TEH_PG_do_purse_delete; 497 : plugin->start_read_committed 498 895 : = &TEH_PG_start_read_committed; 499 : plugin->start_read_only 500 895 : = &TEH_PG_start_read_only; 501 : plugin->insert_denomination_info 502 895 : = &TEH_PG_insert_denomination_info; 503 : plugin->lookup_wire_fee_by_time 504 895 : = &TEH_PG_lookup_wire_fee_by_time; 505 : plugin->start 506 895 : = &TEH_PG_start; 507 : plugin->rollback 508 895 : = &TEH_PG_rollback; 509 : plugin->create_tables 510 895 : = &TEH_PG_create_tables; 511 : plugin->event_listen 512 895 : = &TEH_PG_event_listen; 513 : plugin->event_listen_cancel 514 895 : = &TEH_PG_event_listen_cancel; 515 : plugin->event_notify 516 895 : = &TEH_PG_event_notify; 517 : plugin->get_denomination_info 518 895 : = &TEH_PG_get_denomination_info; 519 : plugin->get_denomination_by_serial 520 895 : = &TEH_PG_get_denomination_by_serial; 521 : plugin->iterate_denomination_info 522 895 : = &TEH_PG_iterate_denomination_info; 523 : plugin->iterate_denominations 524 895 : = &TEH_PG_iterate_denominations; 525 : plugin->iterate_active_auditors 526 895 : = &TEH_PG_iterate_active_auditors; 527 : plugin->iterate_auditor_denominations 528 895 : = &TEH_PG_iterate_auditor_denominations; 529 : plugin->lookup_rules_by_access_token 530 895 : = &TEH_PG_lookup_rules_by_access_token; 531 : plugin->reserves_get 532 895 : = &TEH_PG_reserves_get; 533 : plugin->reserves_get_origin 534 895 : = &TEH_PG_reserves_get_origin; 535 : plugin->drain_kyc_alert 536 895 : = &TEH_PG_drain_kyc_alert; 537 : plugin->reserves_in_insert 538 895 : = &TEH_PG_reserves_in_insert; 539 : plugin->do_withdraw 540 895 : = &TEH_PG_do_withdraw; 541 : plugin->get_withdraw 542 895 : = &TEH_PG_get_withdraw; 543 : plugin->wad_in_insert 544 895 : = &TEH_PG_wad_in_insert; 545 : plugin->kycauth_in_insert 546 895 : = &TEH_PG_kycauth_in_insert; 547 : plugin->get_policy_details 548 895 : = &TEH_PG_get_policy_details; 549 : plugin->persist_policy_details 550 895 : = &TEH_PG_persist_policy_details; 551 : plugin->do_deposit 552 895 : = &TEH_PG_do_deposit; 553 : plugin->get_wire_hash_for_contract 554 895 : = &TEH_PG_get_wire_hash_for_contract; 555 : plugin->add_policy_fulfillment_proof 556 895 : = &TEH_PG_add_policy_fulfillment_proof; 557 : plugin->do_refresh 558 895 : = &TEH_PG_do_refresh; 559 : plugin->do_refund 560 895 : = &TEH_PG_do_refund; 561 : plugin->do_recoup 562 895 : = &TEH_PG_do_recoup; 563 : plugin->do_recoup_refresh 564 895 : = &TEH_PG_do_recoup_refresh; 565 : plugin->get_reserve_balance 566 895 : = &TEH_PG_get_reserve_balance; 567 : plugin->count_known_coins 568 895 : = &TEH_PG_count_known_coins; 569 : plugin->ensure_coin_known 570 895 : = &TEH_PG_ensure_coin_known; 571 : plugin->get_known_coin 572 895 : = &TEH_PG_get_known_coin; 573 : plugin->get_signature_for_known_coin 574 895 : = &TEH_PG_get_signature_for_known_coin; 575 : plugin->get_coin_denomination 576 895 : = &TEH_PG_get_coin_denomination; 577 : plugin->have_deposit2 578 895 : = &TEH_PG_have_deposit2; 579 : plugin->aggregate 580 895 : = &TEH_PG_aggregate; 581 : plugin->create_aggregation_transient 582 895 : = &TEH_PG_create_aggregation_transient; 583 : plugin->select_aggregation_transient 584 895 : = &TEH_PG_select_aggregation_transient; 585 : plugin->find_aggregation_transient 586 895 : = &TEH_PG_find_aggregation_transient; 587 : plugin->update_aggregation_transient 588 895 : = &TEH_PG_update_aggregation_transient; 589 : plugin->get_ready_deposit 590 895 : = &TEH_PG_get_ready_deposit; 591 : plugin->insert_refund 592 895 : = &TEH_PG_insert_refund; 593 : plugin->select_refunds_by_coin 594 895 : = &TEH_PG_select_refunds_by_coin; 595 : plugin->select_aml_measures 596 895 : = &TEH_PG_select_aml_measures; 597 : plugin->get_refresh 598 895 : = &TEH_PG_get_refresh; 599 : plugin->lookup_wire_transfer 600 895 : = &TEH_PG_lookup_wire_transfer; 601 : plugin->lookup_transfer_by_deposit 602 895 : = &TEH_PG_lookup_transfer_by_deposit; 603 : plugin->insert_wire_fee 604 895 : = &TEH_PG_insert_wire_fee; 605 : plugin->insert_global_fee 606 895 : = &TEH_PG_insert_global_fee; 607 : plugin->get_wire_fee 608 895 : = &TEH_PG_get_wire_fee; 609 : plugin->get_global_fee 610 895 : = &TEH_PG_get_global_fee; 611 : plugin->get_global_fees 612 895 : = &TEH_PG_get_global_fees; 613 : plugin->insert_reserve_closed 614 895 : = &TEH_PG_insert_reserve_closed; 615 : plugin->wire_prepare_data_insert 616 895 : = &TEH_PG_wire_prepare_data_insert; 617 : plugin->wire_prepare_data_mark_finished 618 895 : = &TEH_PG_wire_prepare_data_mark_finished; 619 : plugin->wire_prepare_data_mark_failed 620 895 : = &TEH_PG_wire_prepare_data_mark_failed; 621 : plugin->wire_prepare_data_get 622 895 : = &TEH_PG_wire_prepare_data_get; 623 : plugin->start_deferred_wire_out 624 895 : = &TEH_PG_start_deferred_wire_out; 625 : plugin->store_wire_transfer_out 626 895 : = &TEH_PG_store_wire_transfer_out; 627 : plugin->gc 628 895 : = &TEH_PG_gc; 629 : plugin->select_coin_deposits_above_serial_id 630 895 : = &TEH_PG_select_coin_deposits_above_serial_id; 631 : plugin->lookup_aml_history 632 895 : = &TEH_PG_lookup_aml_history; 633 : plugin->lookup_kyc_history 634 895 : = &TEH_PG_lookup_kyc_history; 635 : plugin->select_purse_decisions_above_serial_id 636 895 : = &TEH_PG_select_purse_decisions_above_serial_id; 637 : plugin->select_purse_deposits_by_purse 638 895 : = &TEH_PG_select_purse_deposits_by_purse; 639 : plugin->select_refreshes_above_serial_id 640 895 : = &TEH_PG_select_refreshes_above_serial_id; 641 : plugin->select_refunds_above_serial_id 642 895 : = &TEH_PG_select_refunds_above_serial_id; 643 : plugin->select_reserves_in_above_serial_id 644 895 : = &TEH_PG_select_reserves_in_above_serial_id; 645 : plugin->select_reserves_in_above_serial_id_by_account 646 895 : = &TEH_PG_select_reserves_in_above_serial_id_by_account; 647 : plugin->select_withdrawals_above_serial_id 648 895 : = &TEH_PG_select_withdrawals_above_serial_id; 649 : plugin->select_wire_out_above_serial_id 650 895 : = &TEH_PG_select_wire_out_above_serial_id; 651 : plugin->select_wire_out_above_serial_id_by_account 652 895 : = &TEH_PG_select_wire_out_above_serial_id_by_account; 653 : plugin->select_recoup_above_serial_id 654 895 : = &TEH_PG_select_recoup_above_serial_id; 655 : plugin->select_recoup_refresh_above_serial_id 656 895 : = &TEH_PG_select_recoup_refresh_above_serial_id; 657 : plugin->get_reserve_by_h_planchets 658 895 : = &TEH_PG_get_reserve_by_h_planchets; 659 : plugin->get_old_coin_by_h_blind 660 895 : = &TEH_PG_get_old_coin_by_h_blind; 661 : plugin->insert_denomination_revocation 662 895 : = &TEH_PG_insert_denomination_revocation; 663 : plugin->get_denomination_revocation 664 895 : = &TEH_PG_get_denomination_revocation; 665 : plugin->select_batch_deposits_missing_wire 666 895 : = &TEH_PG_select_batch_deposits_missing_wire; 667 : plugin->select_aggregations_above_serial 668 895 : = &TEH_PG_select_aggregations_above_serial; 669 : plugin->lookup_auditor_timestamp 670 895 : = &TEH_PG_lookup_auditor_timestamp; 671 : plugin->lookup_auditor_status 672 895 : = &TEH_PG_lookup_auditor_status; 673 : plugin->insert_auditor 674 895 : = &TEH_PG_insert_auditor; 675 : plugin->lookup_wire_timestamp 676 895 : = &TEH_PG_lookup_wire_timestamp; 677 : plugin->insert_wire 678 895 : = &TEH_PG_insert_wire; 679 : plugin->update_wire 680 895 : = &TEH_PG_update_wire; 681 : plugin->get_wire_accounts 682 895 : = &TEH_PG_get_wire_accounts; 683 : plugin->get_wire_fees 684 895 : = &TEH_PG_get_wire_fees; 685 : plugin->select_aml_decisions 686 895 : = &TEH_PG_select_aml_decisions; 687 : plugin->select_deposit_amounts_for_kyc_check 688 895 : = &TEH_PG_select_deposit_amounts_for_kyc_check; 689 : plugin->do_check_deposit_idempotent 690 895 : = &TEH_PG_do_check_deposit_idempotent; 691 : plugin->insert_signkey_revocation 692 895 : = &TEH_PG_insert_signkey_revocation; 693 : plugin->select_aml_attributes 694 895 : = &TEH_PG_select_aml_attributes; 695 : plugin->select_aml_statistics 696 895 : = &TEH_PG_select_aml_statistics; 697 : plugin->lookup_signkey_revocation 698 895 : = &TEH_PG_lookup_signkey_revocation; 699 : plugin->lookup_denomination_key 700 895 : = &TEH_PG_lookup_denomination_key; 701 : plugin->lookup_completed_legitimization 702 895 : = &TEH_PG_lookup_completed_legitimization; 703 : plugin->lookup_pending_legitimization 704 895 : = &TEH_PG_lookup_pending_legitimization; 705 : plugin->lookup_active_legitimization 706 895 : = &TEH_PG_lookup_active_legitimization; 707 : plugin->insert_auditor_denom_sig 708 895 : = &TEH_PG_insert_auditor_denom_sig; 709 : plugin->select_auditor_denom_sig 710 895 : = &TEH_PG_select_auditor_denom_sig; 711 : plugin->add_denomination_key 712 895 : = &TEH_PG_add_denomination_key; 713 : plugin->lookup_signing_key 714 895 : = &TEH_PG_lookup_signing_key; 715 : plugin->lookup_h_payto_by_access_token 716 895 : = &TEH_PG_lookup_h_payto_by_access_token; 717 : plugin->insert_sanction_list_hit 718 895 : = &TEH_PG_insert_sanction_list_hit; 719 : plugin->select_exchange_debit_transfers 720 895 : = &TEH_PG_select_exchange_debit_transfers; 721 : plugin->select_exchange_credit_transfers 722 895 : = &TEH_PG_select_exchange_credit_transfers; 723 : plugin->select_exchange_kycauth_transfers 724 895 : = &TEH_PG_select_exchange_kycauth_transfers; 725 : plugin->select_all_kyc_attributes 726 895 : = &TEH_PG_select_all_kyc_attributes; 727 : plugin->begin_shard 728 895 : = &TEH_PG_begin_shard; 729 : plugin->abort_shard 730 895 : = &TEH_PG_abort_shard; 731 : plugin->insert_kyc_failure 732 895 : = &TEH_PG_insert_kyc_failure; 733 : plugin->complete_shard 734 895 : = &TEH_PG_complete_shard; 735 : plugin->release_revolving_shard 736 895 : = &TEH_PG_release_revolving_shard; 737 : plugin->delete_shard_locks 738 895 : = &TEH_PG_delete_shard_locks; 739 : plugin->set_extension_manifest 740 895 : = &TEH_PG_set_extension_manifest; 741 : plugin->insert_partner 742 895 : = &TEH_PG_insert_partner; 743 : plugin->expire_purse 744 895 : = &TEH_PG_expire_purse; 745 : plugin->select_purse_by_merge_pub 746 895 : = &TEH_PG_select_purse_by_merge_pub; 747 : plugin->set_purse_balance 748 895 : = &TEH_PG_set_purse_balance; 749 : plugin->get_pending_kyc_requirement_process 750 895 : = &TEH_PG_get_pending_kyc_requirement_process; 751 : plugin->select_kyc_attributes 752 895 : = &TEH_PG_select_kyc_attributes; 753 : plugin->insert_aml_officer 754 895 : = &TEH_PG_insert_aml_officer; 755 : plugin->enable_rules 756 895 : = &TEH_PG_enable_rules; 757 : plugin->disable_rules 758 895 : = &TEH_PG_disable_rules; 759 : plugin->test_aml_officer 760 895 : = &TEH_PG_test_aml_officer; 761 : plugin->lookup_aml_officer 762 895 : = &TEH_PG_lookup_aml_officer; 763 : plugin->insert_active_legitimization_measure 764 895 : = &TEH_PG_insert_active_legitimization_measure; 765 : plugin->insert_aml_decision 766 895 : = &TEH_PG_insert_aml_decision; 767 : plugin->lookup_kyc_requirement_by_row 768 895 : = &TEH_PG_lookup_kyc_requirement_by_row; 769 : plugin->trigger_kyc_rule_for_account 770 895 : = &TEH_PG_trigger_kyc_rule_for_account; 771 : plugin->lookup_kyc_status_by_token 772 895 : = &TEH_PG_lookup_kyc_status_by_token; 773 : plugin->batch_ensure_coin_known 774 895 : = &TEH_PG_batch_ensure_coin_known; 775 : plugin->inject_auditor_triggers 776 895 : = &TEH_PG_inject_auditor_triggers; 777 : plugin->insert_successor_measure 778 895 : = &TEH_PG_insert_successor_measure; 779 : plugin->insert_aml_program_failure 780 895 : = &TEH_PG_insert_aml_program_failure; 781 : plugin->persist_kyc_attributes 782 895 : = &TEH_PG_persist_kyc_attributes; 783 : plugin->clear_aml_lock 784 895 : = &TEH_PG_clear_aml_lock; 785 : plugin->set_aml_lock 786 895 : = &TEH_PG_set_aml_lock; 787 : 788 895 : return plugin; 789 : 790 0 : fail: 791 0 : GNUNET_free (pg->exchange_url); 792 0 : GNUNET_free (pg->sql_dir); 793 0 : GNUNET_free (pg); 794 0 : GNUNET_free (plugin); 795 0 : return NULL; 796 : } 797 : 798 : 799 : /** 800 : * Shutdown Postgres database subsystem. 801 : * 802 : * @param cls a `struct TALER_EXCHANGEDB_Plugin` 803 : * @return NULL (always) 804 : */ 805 : void * 806 : libtaler_plugin_exchangedb_postgres_done (void *cls); 807 : 808 : /* Declaration used to squash compiler warning */ 809 : void * 810 895 : libtaler_plugin_exchangedb_postgres_done (void *cls) 811 : { 812 895 : struct TALER_EXCHANGEDB_Plugin *plugin = cls; 813 895 : struct PostgresClosure *pg = plugin->cls; 814 : 815 895 : if (NULL != pg->conn) 816 : { 817 871 : GNUNET_PQ_disconnect (pg->conn); 818 871 : pg->conn = NULL; 819 : } 820 895 : GNUNET_free (pg->exchange_url); 821 895 : GNUNET_free (pg->sql_dir); 822 895 : GNUNET_free (pg->currency); 823 895 : GNUNET_free (pg); 824 895 : GNUNET_free (plugin); 825 895 : return NULL; 826 : } 827 : 828 : 829 : /* end of plugin_exchangedb_postgres.c */