lookup_records_by_table.h (18425B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2022 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 * @file lookup_records_by_table.h 18 * @brief implementation of the lookup_records_by_table function 19 * @author Christian Grothoff 20 */ 21 #ifndef EXCHANGE_DATABASE_LOOKUP_RECORDS_BY_TABLE_H 22 #define EXCHANGE_DATABASE_LOOKUP_RECORDS_BY_TABLE_H 23 24 #include "taler/taler_json_lib.h" 25 #include "exchangedb_lib.h" 26 27 28 /** 29 * Enumeration of all of the tables replicated by exchange-auditor 30 * database replication. 31 * 32 * Note: wire_accounts is not replicated. So far not needed by the auditor. 33 */ 34 enum TALER_EXCHANGEDB_ReplicatedTable 35 { 36 TALER_EXCHANGEDB_RT_DENOMINATIONS, 37 TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS, 38 TALER_EXCHANGEDB_RT_KYC_TARGETS, 39 TALER_EXCHANGEDB_RT_WIRE_TARGETS, 40 TALER_EXCHANGEDB_RT_RESERVES, 41 TALER_EXCHANGEDB_RT_RESERVES_IN, 42 TALER_EXCHANGEDB_RT_RESERVES_CLOSE, 43 TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS, 44 TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS, 45 TALER_EXCHANGEDB_RT_AUDITORS, 46 TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS, 47 TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS, 48 TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS, 49 TALER_EXCHANGEDB_RT_KNOWN_COINS, 50 TALER_EXCHANGEDB_RT_REFRESH, 51 TALER_EXCHANGEDB_RT_BATCH_DEPOSITS, 52 TALER_EXCHANGEDB_RT_COIN_DEPOSITS, 53 TALER_EXCHANGEDB_RT_REFUNDS, 54 TALER_EXCHANGEDB_RT_WIRE_OUT, 55 TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING, 56 TALER_EXCHANGEDB_RT_WIRE_FEE, 57 TALER_EXCHANGEDB_RT_GLOBAL_FEE, 58 TALER_EXCHANGEDB_RT_RECOUP, 59 TALER_EXCHANGEDB_RT_RECOUP_REFRESH, 60 TALER_EXCHANGEDB_RT_PURSE_REQUESTS, 61 TALER_EXCHANGEDB_RT_PURSE_DECISION, 62 TALER_EXCHANGEDB_RT_PURSE_MERGES, 63 TALER_EXCHANGEDB_RT_PURSE_DEPOSITS, 64 TALER_EXCHANGEDB_RT_ACCOUNT_MERGES, 65 TALER_EXCHANGEDB_RT_HISTORY_REQUESTS, 66 TALER_EXCHANGEDB_RT_CLOSE_REQUESTS, 67 TALER_EXCHANGEDB_RT_WADS_OUT, 68 TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES, 69 TALER_EXCHANGEDB_RT_WADS_IN, 70 TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES, 71 TALER_EXCHANGEDB_RT_PROFIT_DRAINS, 72 TALER_EXCHANGEDB_RT_AML_STAFF, 73 TALER_EXCHANGEDB_RT_PURSE_DELETION, 74 TALER_EXCHANGEDB_RT_WITHDRAW, 75 TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES, 76 TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES, 77 TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES, 78 TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES, 79 TALER_EXCHANGEDB_RT_AML_HISTORY, 80 TALER_EXCHANGEDB_RT_KYC_EVENTS, 81 TALER_EXCHANGEDB_RT_KYCAUTHS_IN 82 }; 83 84 85 /** 86 * Record of a single entry in a replicated table. 87 */ 88 struct TALER_EXCHANGEDB_TableData 89 { 90 /** 91 * Data of which table is returned here? 92 */ 93 enum TALER_EXCHANGEDB_ReplicatedTable table; 94 95 /** 96 * Serial number of the record. 97 */ 98 uint64_t serial; 99 100 /** 101 * Table-specific details. 102 */ 103 union 104 { 105 106 /** 107 * Details from the 'denominations' table. 108 */ 109 struct 110 { 111 uint32_t denom_type; 112 uint32_t age_mask; 113 struct TALER_DenominationPublicKey denom_pub; 114 struct TALER_MasterSignatureP master_sig; 115 struct GNUNET_TIME_Timestamp valid_from; 116 struct GNUNET_TIME_Timestamp expire_withdraw; 117 struct GNUNET_TIME_Timestamp expire_deposit; 118 struct GNUNET_TIME_Timestamp expire_legal; 119 struct TALER_Amount coin; 120 struct TALER_DenomFeeSet fees; 121 } denominations; 122 123 struct 124 { 125 struct TALER_MasterSignatureP master_sig; 126 uint64_t denominations_serial; 127 } denomination_revocations; 128 129 struct 130 { 131 struct TALER_FullPayto full_payto_uri; 132 } wire_targets; 133 134 struct 135 { 136 struct TALER_NormalizedPaytoHashP h_normalized_payto; 137 struct TALER_AccountAccessTokenP access_token; 138 union TALER_AccountPublicKeyP target_pub; 139 bool no_account; 140 bool is_wallet; 141 } kyc_targets; 142 143 struct 144 { 145 struct TALER_AccountAccessTokenP target_token; 146 struct GNUNET_TIME_Timestamp start_time; 147 json_t *measures; 148 uint32_t display_priority; 149 } legitimization_measures; 150 151 struct 152 { 153 struct TALER_NormalizedPaytoHashP h_payto; 154 struct GNUNET_TIME_Timestamp decision_time; 155 struct GNUNET_TIME_Timestamp expiration_time; 156 json_t *properties; 157 bool to_investigate; 158 json_t *new_rules; 159 } legitimization_outcomes; 160 161 struct 162 { 163 struct TALER_NormalizedPaytoHashP h_payto; 164 struct GNUNET_TIME_Timestamp start_time; 165 struct GNUNET_TIME_Timestamp expiration_time; 166 uint64_t legitimization_measure_serial_id; 167 uint32_t measure_index; 168 char *provider_name; 169 char *provider_user_id; 170 char *provider_legitimization_id; 171 char *redirect_url; 172 } legitimization_processes; 173 174 struct 175 { 176 struct TALER_NormalizedPaytoHashP h_payto; 177 uint64_t legitimization_serial; 178 struct GNUNET_TIME_Timestamp collection_time; 179 struct GNUNET_TIME_Timestamp expiration_time; 180 uint64_t trigger_outcome_serial; 181 void *encrypted_attributes; 182 size_t encrypted_attributes_size; 183 } kyc_attributes; 184 185 struct 186 { 187 struct TALER_NormalizedPaytoHashP h_payto; 188 uint64_t outcome_serial_id; 189 char *justification; 190 struct TALER_AmlOfficerPublicKeyP decider_pub; 191 struct TALER_AmlOfficerSignatureP decider_sig; 192 } aml_history; 193 194 struct 195 { 196 struct GNUNET_TIME_Timestamp event_timestamp; 197 char *event_type; 198 } kyc_events; 199 200 struct 201 { 202 struct TALER_AmlOfficerPublicKeyP decider_pub; 203 struct TALER_MasterSignatureP master_sig; 204 char *decider_name; 205 bool is_active; 206 bool read_only; 207 struct GNUNET_TIME_Timestamp last_change; 208 } aml_staff; 209 210 struct 211 { 212 struct TALER_ReservePublicKeyP reserve_pub; 213 struct GNUNET_TIME_Timestamp expiration_date; 214 struct GNUNET_TIME_Timestamp gc_date; 215 } reserves; 216 217 struct 218 { 219 uint64_t wire_reference; 220 struct TALER_Amount credit; 221 struct TALER_FullPaytoHashP sender_account_h_payto; 222 char *exchange_account_section; 223 struct GNUNET_TIME_Timestamp execution_date; 224 struct TALER_ReservePublicKeyP reserve_pub; 225 } reserves_in; 226 227 struct 228 { 229 uint64_t wire_reference; 230 struct TALER_Amount credit; 231 struct TALER_FullPaytoHashP sender_account_h_payto; 232 char *exchange_account_section; 233 struct GNUNET_TIME_Timestamp execution_date; 234 union TALER_AccountPublicKeyP account_pub; 235 } kycauth_in; 236 237 struct 238 { 239 struct TALER_ReservePublicKeyP reserve_pub; 240 struct GNUNET_TIME_Timestamp request_timestamp; 241 struct GNUNET_TIME_Timestamp expiration_date; 242 struct TALER_ReserveSignatureP reserve_sig; 243 struct TALER_Amount reserve_payment; 244 uint32_t requested_purse_limit; 245 } reserves_open_requests; 246 247 struct 248 { 249 struct TALER_ReservePublicKeyP reserve_pub; 250 struct TALER_CoinSpendPublicKeyP coin_pub; 251 struct TALER_CoinSpendSignatureP coin_sig; 252 struct TALER_ReserveSignatureP reserve_sig; 253 struct TALER_Amount contribution; 254 } reserves_open_deposits; 255 256 struct 257 { 258 struct TALER_ReservePublicKeyP reserve_pub; 259 struct GNUNET_TIME_Timestamp execution_date; 260 struct TALER_WireTransferIdentifierRawP wtid; 261 struct TALER_FullPaytoHashP sender_account_h_payto; 262 struct TALER_Amount amount; 263 struct TALER_Amount closing_fee; 264 } reserves_close; 265 266 struct 267 { 268 struct TALER_AuditorPublicKeyP auditor_pub; 269 char *auditor_url; 270 char *auditor_name; 271 bool is_active; 272 struct GNUNET_TIME_Timestamp last_change; 273 } auditors; 274 275 struct 276 { 277 uint64_t auditor_uuid; 278 uint64_t denominations_serial; 279 struct TALER_AuditorSignatureP auditor_sig; 280 } auditor_denom_sigs; 281 282 struct 283 { 284 struct TALER_ExchangePublicKeyP exchange_pub; 285 struct TALER_MasterSignatureP master_sig; 286 struct TALER_EXCHANGEDB_SignkeyMetaData meta; 287 } exchange_sign_keys; 288 289 struct 290 { 291 uint64_t esk_serial; 292 struct TALER_MasterSignatureP master_sig; 293 } signkey_revocations; 294 295 struct 296 { 297 struct TALER_CoinSpendPublicKeyP coin_pub; 298 struct TALER_AgeCommitmentHashP age_hash; 299 uint64_t denominations_serial; 300 struct TALER_DenominationSignature denom_sig; 301 } known_coins; 302 303 struct 304 { 305 struct TALER_RefreshCommitmentP rc; 306 struct GNUNET_TIME_Timestamp execution_date; 307 struct TALER_Amount amount_with_fee; 308 struct TALER_CoinSpendPublicKeyP old_coin_pub; 309 struct TALER_CoinSpendSignatureP old_coin_sig; 310 struct TALER_PublicRefreshMasterSeedP refresh_seed; 311 uint32_t noreveal_index; 312 struct TALER_HashBlindedPlanchetsP planchets_h; 313 struct TALER_HashBlindedPlanchetsP selected_h; 314 bool no_blinding_seed; 315 struct TALER_BlindingMasterSeedP blinding_seed; 316 size_t num_cs_r_values; 317 struct GNUNET_CRYPTO_CSPublicRPairP *cs_r_values; 318 uint64_t cs_r_choices; 319 size_t num_coins; 320 uint64_t *denom_serials; 321 struct TALER_BlindedDenominationSignature *denom_sigs; 322 } refresh; 323 324 struct 325 { 326 uint64_t shard; 327 struct TALER_MerchantPublicKeyP merchant_pub; 328 struct GNUNET_TIME_Timestamp wallet_timestamp; 329 struct GNUNET_TIME_Timestamp exchange_timestamp; 330 struct GNUNET_TIME_Timestamp refund_deadline; 331 struct GNUNET_TIME_Timestamp wire_deadline; 332 struct TALER_PrivateContractHashP h_contract_terms; 333 bool no_wallet_data_hash; 334 struct GNUNET_HashCode wallet_data_hash; 335 struct TALER_WireSaltP wire_salt; 336 struct TALER_FullPaytoHashP wire_target_h_payto; 337 struct TALER_Amount total_amount; 338 struct TALER_Amount total_without_fee; 339 struct TALER_MerchantSignatureP merchant_sig; 340 bool done; 341 } batch_deposits; 342 343 struct 344 { 345 uint64_t batch_deposit_serial_id; 346 struct TALER_CoinSpendPublicKeyP coin_pub; 347 struct TALER_CoinSpendSignatureP coin_sig; 348 struct TALER_Amount amount_with_fee; 349 } coin_deposits; 350 351 struct 352 { 353 struct TALER_CoinSpendPublicKeyP coin_pub; 354 uint64_t batch_deposit_serial_id; 355 struct TALER_MerchantSignatureP merchant_sig; 356 uint64_t rtransaction_id; 357 struct TALER_Amount amount_with_fee; 358 } refunds; 359 360 struct 361 { 362 struct GNUNET_TIME_Timestamp execution_date; 363 struct TALER_WireTransferIdentifierRawP wtid_raw; 364 struct TALER_FullPaytoHashP wire_target_h_payto; 365 char *exchange_account_section; 366 struct TALER_Amount amount; 367 } wire_out; 368 369 struct 370 { 371 uint64_t batch_deposit_serial_id; 372 struct TALER_WireTransferIdentifierRawP wtid_raw; 373 } aggregation_tracking; 374 375 struct 376 { 377 char *wire_method; 378 struct GNUNET_TIME_Timestamp start_date; 379 struct GNUNET_TIME_Timestamp end_date; 380 struct TALER_WireFeeSet fees; 381 struct TALER_MasterSignatureP master_sig; 382 } wire_fee; 383 384 struct 385 { 386 struct GNUNET_TIME_Timestamp start_date; 387 struct GNUNET_TIME_Timestamp end_date; 388 struct TALER_GlobalFeeSet fees; 389 struct GNUNET_TIME_Relative purse_timeout; 390 struct GNUNET_TIME_Relative history_expiration; 391 uint32_t purse_account_limit; 392 struct TALER_MasterSignatureP master_sig; 393 } global_fee; 394 395 struct 396 { 397 struct TALER_CoinSpendPublicKeyP coin_pub; 398 struct TALER_CoinSpendSignatureP coin_sig; 399 union GNUNET_CRYPTO_BlindingSecretP coin_blind; 400 struct TALER_Amount amount; 401 struct GNUNET_TIME_Timestamp timestamp; 402 uint64_t withdraw_serial_id; 403 } recoup; 404 405 struct 406 { 407 uint64_t known_coin_id; 408 struct TALER_CoinSpendPublicKeyP coin_pub; 409 struct TALER_CoinSpendSignatureP coin_sig; 410 union GNUNET_CRYPTO_BlindingSecretP coin_blind; 411 struct TALER_Amount amount; 412 struct GNUNET_TIME_Timestamp recoup_timestamp; 413 uint64_t refresh_id; 414 } recoup_refresh; 415 416 struct 417 { 418 struct TALER_PurseContractPublicKeyP purse_pub; 419 struct TALER_PurseMergePublicKeyP merge_pub; 420 struct GNUNET_TIME_Timestamp purse_creation; 421 struct GNUNET_TIME_Timestamp purse_expiration; 422 struct TALER_PrivateContractHashP h_contract_terms; 423 uint32_t age_limit; 424 uint32_t flags; 425 struct TALER_Amount amount_with_fee; 426 struct TALER_Amount purse_fee; 427 struct TALER_PurseContractSignatureP purse_sig; 428 } purse_requests; 429 430 struct 431 { 432 struct TALER_PurseContractPublicKeyP purse_pub; 433 struct GNUNET_TIME_Timestamp action_timestamp; 434 bool refunded; 435 } purse_decision; 436 437 struct 438 { 439 uint64_t partner_serial_id; 440 struct TALER_ReservePublicKeyP reserve_pub; 441 struct TALER_PurseContractPublicKeyP purse_pub; 442 struct TALER_PurseMergeSignatureP merge_sig; 443 struct GNUNET_TIME_Timestamp merge_timestamp; 444 } purse_merges; 445 446 struct 447 { 448 uint64_t partner_serial_id; 449 struct TALER_PurseContractPublicKeyP purse_pub; 450 struct TALER_CoinSpendPublicKeyP coin_pub; 451 struct TALER_Amount amount_with_fee; 452 struct TALER_CoinSpendSignatureP coin_sig; 453 } purse_deposits; 454 455 struct 456 { 457 struct TALER_ReservePublicKeyP reserve_pub; 458 struct TALER_ReserveSignatureP reserve_sig; 459 struct TALER_PurseContractPublicKeyP purse_pub; 460 struct TALER_NormalizedPaytoHashP wallet_h_payto; 461 } account_merges; 462 463 struct 464 { 465 struct TALER_ReservePublicKeyP reserve_pub; 466 struct TALER_ReserveSignatureP reserve_sig; 467 struct GNUNET_TIME_Timestamp request_timestamp; 468 struct TALER_Amount history_fee; 469 } history_requests; 470 471 struct 472 { 473 struct TALER_ReservePublicKeyP reserve_pub; 474 struct GNUNET_TIME_Timestamp close_timestamp; 475 struct TALER_ReserveSignatureP reserve_sig; 476 struct TALER_Amount close; 477 struct TALER_Amount close_fee; 478 struct TALER_FullPayto payto_uri; 479 } close_requests; 480 481 struct 482 { 483 struct TALER_WadIdentifierP wad_id; 484 uint64_t partner_serial_id; 485 struct TALER_Amount amount; 486 struct GNUNET_TIME_Timestamp execution_time; 487 } wads_out; 488 489 struct 490 { 491 uint64_t wad_out_serial_id; 492 struct TALER_ReservePublicKeyP reserve_pub; 493 struct TALER_PurseContractPublicKeyP purse_pub; 494 struct TALER_PrivateContractHashP h_contract; 495 struct GNUNET_TIME_Timestamp purse_expiration; 496 struct GNUNET_TIME_Timestamp merge_timestamp; 497 struct TALER_Amount amount_with_fee; 498 struct TALER_Amount wad_fee; 499 struct TALER_Amount deposit_fees; 500 struct TALER_ReserveSignatureP reserve_sig; 501 struct TALER_PurseContractSignatureP purse_sig; 502 } wads_out_entries; 503 504 struct 505 { 506 struct TALER_WadIdentifierP wad_id; 507 char *origin_exchange_url; 508 struct TALER_Amount amount; 509 struct GNUNET_TIME_Timestamp arrival_time; 510 } wads_in; 511 512 struct 513 { 514 uint64_t wad_in_serial_id; 515 struct TALER_ReservePublicKeyP reserve_pub; 516 struct TALER_PurseContractPublicKeyP purse_pub; 517 struct TALER_PrivateContractHashP h_contract; 518 struct GNUNET_TIME_Timestamp purse_expiration; 519 struct GNUNET_TIME_Timestamp merge_timestamp; 520 struct TALER_Amount amount_with_fee; 521 struct TALER_Amount wad_fee; 522 struct TALER_Amount deposit_fees; 523 struct TALER_ReserveSignatureP reserve_sig; 524 struct TALER_PurseContractSignatureP purse_sig; 525 } wads_in_entries; 526 527 struct 528 { 529 struct TALER_WireTransferIdentifierRawP wtid; 530 char *account_section; 531 struct TALER_FullPayto payto_uri; 532 struct GNUNET_TIME_Timestamp trigger_date; 533 struct TALER_Amount amount; 534 struct TALER_MasterSignatureP master_sig; 535 } profit_drains; 536 537 struct 538 { 539 struct TALER_PurseContractPublicKeyP purse_pub; 540 struct TALER_PurseContractSignatureP purse_sig; 541 } purse_deletion; 542 543 struct 544 { 545 struct TALER_HashBlindedPlanchetsP planchets_h; 546 struct GNUNET_TIME_Timestamp execution_date; 547 struct TALER_Amount amount_with_fee; 548 struct TALER_ReservePublicKeyP reserve_pub; 549 struct TALER_ReserveSignatureP reserve_sig; 550 bool age_proof_required; 551 uint16_t max_age; 552 uint16_t noreveal_index; 553 struct TALER_HashBlindedPlanchetsP selected_h; 554 bool no_blinding_seed; 555 struct TALER_BlindingMasterSeedP blinding_seed; 556 size_t num_cs_r_values; 557 struct GNUNET_CRYPTO_CSPublicRPairP *cs_r_values; 558 uint64_t cs_r_choices; 559 size_t num_coins; 560 uint64_t *denom_serials; 561 struct TALER_BlindedDenominationSignature *denom_sigs; 562 } withdraw; 563 564 } details; 565 566 }; 567 568 569 /** 570 * Function called on data to replicate in the auditor's database. 571 * 572 * @param cls closure 573 * @param td record from an exchange table 574 * @return #GNUNET_OK to continue to iterate, 575 * #GNUNET_SYSERR to fail with an error 576 */ 577 typedef int 578 (*TALER_EXCHANGEDB_ReplicationCallback)( 579 void *cls, 580 const struct TALER_EXCHANGEDB_TableData *td); 581 582 583 /** 584 * Function called on data to replicate in the auditor's database. 585 * 586 * @param cls closure 587 * @param td record from an exchange table 588 * @return #GNUNET_OK to continue to iterate, 589 * #GNUNET_SYSERR to fail with an error 590 */ 591 typedef int 592 (*TALER_EXCHANGEDB_ReplicationCallback)( 593 void *cls, 594 const struct TALER_EXCHANGEDB_TableData *td); 595 596 597 /** 598 * Lookup records above @a serial number in @a table. Used in 599 * exchange-auditor database replication. 600 * 601 * @param pg the database context 602 * @param table table for which we should return the serial 603 * @param serial largest serial number to exclude 604 * @param cb function to call on the records 605 * @param cb_cls closure for @a cb 606 * @return transaction status code, GNUNET_DB_STATUS_HARD_ERROR if 607 * @a table does not have a serial number 608 */ 609 enum GNUNET_DB_QueryStatus 610 TALER_EXCHANGEDB_lookup_records_by_table ( 611 struct TALER_EXCHANGEDB_PostgresContext *pg, 612 enum TALER_EXCHANGEDB_ReplicatedTable table, 613 uint64_t serial, 614 TALER_EXCHANGEDB_ReplicationCallback cb, 615 void *cb_cls); 616 617 618 #endif