taler_exchangedb_plugin.h (270004B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2014-2024 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 include/taler/taler_exchangedb_plugin.h 18 * @brief Low-level (statement-level) database access for the exchange 19 * @author Florian Dold 20 * @author Christian Grothoff 21 * @author Özgür Kesim 22 */ 23 #ifndef TALER_EXCHANGEDB_PLUGIN_H 24 #define TALER_EXCHANGEDB_PLUGIN_H 25 #include <jansson.h> 26 #include <gnunet/gnunet_util_lib.h> 27 #include <gnunet/gnunet_db_lib.h> 28 #include <taler/taler_util.h> 29 #include <taler/taler_signatures.h> 30 #include <taler/taler_extensions_policy.h> 31 32 /** 33 * The conflict that can occur for the age restriction 34 */ 35 enum TALER_EXCHANGEDB_AgeCommitmentHash_Conflict 36 { 37 /** 38 * Value OK, no conflict 39 */ 40 TALER_AgeCommitmentHashP_NoConflict = 0, 41 42 /** 43 * Given hash had a value, but NULL (or zero) was expected 44 */ 45 TALER_AgeCommitmentHashP_NullExpected = 1, 46 47 /** 48 * Given hash was NULL, but value was expected 49 */ 50 TALER_AgeCommitmentHashP_ValueExpected = 2, 51 52 /** 53 * Given hash differs from value in the known coin 54 */ 55 TALER_AgeCommitmentHashP_ValueDiffers = 3, 56 }; 57 58 /** 59 * Per-coin information returned when doing a batch insert. 60 */ 61 struct TALER_EXCHANGEDB_CoinInfo 62 { 63 /** 64 * Row of the coin in the known_coins table. 65 */ 66 uint64_t known_coin_id; 67 68 /** 69 * Hash of the denomination, relevant on @e denom_conflict. 70 */ 71 struct TALER_DenominationHashP denom_hash; 72 73 /** 74 * Hash of the age commitment, relevant on @e age_conflict. 75 */ 76 struct TALER_AgeCommitmentHashP h_age_commitment; 77 78 /** 79 * True if the coin was known previously. 80 */ 81 bool existed; 82 83 /** 84 * True if the known coin has a different denomination; 85 * application will find denomination of the already 86 * known coin in @e denom_hash. 87 */ 88 bool denom_conflict; 89 90 /** 91 * Indicates if and what kind of conflict with the age 92 * restriction of the known coin was present; 93 * application will find age commitment of the already 94 * known coin in @e h_age_commitment. 95 */ 96 enum TALER_EXCHANGEDB_AgeCommitmentHash_Conflict age_conflict; 97 }; 98 99 100 /** 101 * Information about a denomination key. 102 */ 103 struct TALER_EXCHANGEDB_DenominationKeyInformation 104 { 105 106 /** 107 * Signature over this struct to affirm the validity of the key. 108 */ 109 struct TALER_MasterSignatureP signature; 110 111 /** 112 * Start time of the validity period for this key. 113 */ 114 struct GNUNET_TIME_Timestamp start; 115 116 /** 117 * The exchange will sign fresh coins between @e start and this time. 118 * @e expire_withdraw will be somewhat larger than @e start to 119 * ensure a sufficiently large anonymity set, while also allowing 120 * the Exchange to limit the financial damage in case of a key being 121 * compromised. Thus, exchanges with low volume are expected to have a 122 * longer withdraw period (@e expire_withdraw - @e start) than exchanges 123 * with high transaction volume. The period may also differ between 124 * types of coins. A exchange may also have a few denomination keys 125 * with the same value with overlapping validity periods, to address 126 * issues such as clock skew. 127 */ 128 struct GNUNET_TIME_Timestamp expire_withdraw; 129 130 /** 131 * Coins signed with the denomination key must be spent or refreshed 132 * between @e start and this expiration time. After this time, the 133 * exchange will refuse transactions involving this key as it will 134 * "drop" the table with double-spending information (shortly after) 135 * this time. Note that wallets should refresh coins significantly 136 * before this time to be on the safe side. @e expire_deposit must be 137 * significantly larger than @e expire_withdraw (by months or even 138 * years). 139 */ 140 struct GNUNET_TIME_Timestamp expire_deposit; 141 142 /** 143 * When do signatures with this denomination key become invalid? 144 * After this point, these signatures cannot be used in (legal) 145 * disputes anymore, as the Exchange is then allowed to destroy its side 146 * of the evidence. @e expire_legal is expected to be significantly 147 * larger than @e expire_deposit (by a year or more). 148 */ 149 struct GNUNET_TIME_Timestamp expire_legal; 150 151 /** 152 * The value of the coins signed with this denomination key. 153 */ 154 struct TALER_Amount value; 155 156 /** 157 * Fees for the coin. 158 */ 159 struct TALER_DenomFeeSet fees; 160 161 /** 162 * Hash code of the denomination public key. (Used to avoid having 163 * the variable-size RSA key in this struct.) 164 */ 165 struct TALER_DenominationHashP denom_hash; 166 167 /** 168 * If denomination was setup for age restriction, non-zero age mask. 169 * Note that the mask is not part of the signature. 170 */ 171 struct TALER_AgeMask age_mask; 172 }; 173 174 175 GNUNET_NETWORK_STRUCT_BEGIN 176 177 /** 178 * Events signalling that a coin deposit status 179 * changed. 180 */ 181 struct TALER_CoinDepositEventP 182 { 183 /** 184 * Of type #TALER_DBEVENT_EXCHANGE_DEPOSIT_STATUS_CHANGED. 185 */ 186 struct GNUNET_DB_EventHeaderP header; 187 188 /** 189 * Public key of the merchant. 190 */ 191 struct TALER_MerchantPublicKeyP merchant_pub; 192 193 }; 194 195 /** 196 * Events signalling a reserve got funding. 197 */ 198 struct TALER_ReserveEventP 199 { 200 /** 201 * Of type #TALER_DBEVENT_EXCHANGE_RESERVE_INCOMING. 202 */ 203 struct GNUNET_DB_EventHeaderP header; 204 205 /** 206 * Public key of the reserve the event is about. 207 */ 208 struct TALER_ReservePublicKeyP reserve_pub; 209 }; 210 211 212 /** 213 * Signature of events signalling a purse changed its status. 214 */ 215 struct TALER_PurseEventP 216 { 217 /** 218 * Of type #TALER_DBEVENT_EXCHANGE_PURSE_MERGED or 219 * #TALER_DBEVENT_EXCHANGE_PURSE_DEPOSITED. 220 */ 221 struct GNUNET_DB_EventHeaderP header; 222 223 /** 224 * Public key of the purse the event is about. 225 */ 226 struct TALER_PurseContractPublicKeyP purse_pub; 227 }; 228 229 230 /** 231 * Signature of events signalling a KYC process was completed. 232 */ 233 struct TALER_KycCompletedEventP 234 { 235 /** 236 * Of type #TALER_DBEVENT_EXCHANGE_KYC_COMPLETED. 237 */ 238 struct GNUNET_DB_EventHeaderP header; 239 240 /** 241 * Hash of payto://-URI for which the KYC state changed. 242 */ 243 struct TALER_NormalizedPaytoHashP h_payto; 244 }; 245 246 247 GNUNET_NETWORK_STRUCT_END 248 249 /** 250 * Meta data about an exchange online signing key. 251 */ 252 struct TALER_EXCHANGEDB_SignkeyMetaData 253 { 254 /** 255 * Start time of the validity period for this key. 256 */ 257 struct GNUNET_TIME_Timestamp start; 258 259 /** 260 * The exchange will sign messages with this key between @e start and this time. 261 */ 262 struct GNUNET_TIME_Timestamp expire_sign; 263 264 /** 265 * When do signatures with this sign key become invalid? 266 * After this point, these signatures cannot be used in (legal) 267 * disputes anymore, as the Exchange is then allowed to destroy its side 268 * of the evidence. @e expire_legal is expected to be significantly 269 * larger than @e expire_sign (by a year or more). 270 */ 271 struct GNUNET_TIME_Timestamp expire_legal; 272 273 }; 274 275 276 /** 277 * Enumeration of all of the tables replicated by exchange-auditor 278 * database replication. 279 * 280 * Note: wire_accounts is not replicated. So far not needed by the auditor. 281 */ 282 enum TALER_EXCHANGEDB_ReplicatedTable 283 { 284 TALER_EXCHANGEDB_RT_DENOMINATIONS, 285 TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS, 286 TALER_EXCHANGEDB_RT_KYC_TARGETS, 287 TALER_EXCHANGEDB_RT_WIRE_TARGETS, 288 TALER_EXCHANGEDB_RT_RESERVES, 289 TALER_EXCHANGEDB_RT_RESERVES_IN, 290 TALER_EXCHANGEDB_RT_RESERVES_CLOSE, 291 TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS, 292 TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS, 293 TALER_EXCHANGEDB_RT_AUDITORS, 294 TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS, 295 TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS, 296 TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS, 297 TALER_EXCHANGEDB_RT_KNOWN_COINS, 298 TALER_EXCHANGEDB_RT_REFRESH, 299 TALER_EXCHANGEDB_RT_BATCH_DEPOSITS, 300 TALER_EXCHANGEDB_RT_COIN_DEPOSITS, 301 TALER_EXCHANGEDB_RT_REFUNDS, 302 TALER_EXCHANGEDB_RT_WIRE_OUT, 303 TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING, 304 TALER_EXCHANGEDB_RT_WIRE_FEE, 305 TALER_EXCHANGEDB_RT_GLOBAL_FEE, 306 TALER_EXCHANGEDB_RT_RECOUP, 307 TALER_EXCHANGEDB_RT_RECOUP_REFRESH, 308 TALER_EXCHANGEDB_RT_EXTENSIONS, 309 TALER_EXCHANGEDB_RT_POLICY_DETAILS, 310 TALER_EXCHANGEDB_RT_POLICY_FULFILLMENTS, 311 TALER_EXCHANGEDB_RT_PURSE_REQUESTS, 312 TALER_EXCHANGEDB_RT_PURSE_DECISION, 313 TALER_EXCHANGEDB_RT_PURSE_MERGES, 314 TALER_EXCHANGEDB_RT_PURSE_DEPOSITS, 315 TALER_EXCHANGEDB_RT_ACCOUNT_MERGES, 316 TALER_EXCHANGEDB_RT_HISTORY_REQUESTS, 317 TALER_EXCHANGEDB_RT_CLOSE_REQUESTS, 318 TALER_EXCHANGEDB_RT_WADS_OUT, 319 TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES, 320 TALER_EXCHANGEDB_RT_WADS_IN, 321 TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES, 322 TALER_EXCHANGEDB_RT_PROFIT_DRAINS, 323 TALER_EXCHANGEDB_RT_AML_STAFF, 324 TALER_EXCHANGEDB_RT_PURSE_DELETION, 325 TALER_EXCHANGEDB_RT_WITHDRAW, 326 TALER_EXCHANGEDB_RT_LEGITIMIZATION_MEASURES, 327 TALER_EXCHANGEDB_RT_LEGITIMIZATION_OUTCOMES, 328 TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES, 329 TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES, 330 TALER_EXCHANGEDB_RT_AML_HISTORY, 331 TALER_EXCHANGEDB_RT_KYC_EVENTS, 332 TALER_EXCHANGEDB_RT_KYCAUTHS_IN 333 }; 334 335 336 /** 337 * Record of a single entry in a replicated table. 338 */ 339 struct TALER_EXCHANGEDB_TableData 340 { 341 /** 342 * Data of which table is returned here? 343 */ 344 enum TALER_EXCHANGEDB_ReplicatedTable table; 345 346 /** 347 * Serial number of the record. 348 */ 349 uint64_t serial; 350 351 /** 352 * Table-specific details. 353 */ 354 union 355 { 356 357 /** 358 * Details from the 'denominations' table. 359 */ 360 struct 361 { 362 uint32_t denom_type; 363 uint32_t age_mask; 364 struct TALER_DenominationPublicKey denom_pub; 365 struct TALER_MasterSignatureP master_sig; 366 struct GNUNET_TIME_Timestamp valid_from; 367 struct GNUNET_TIME_Timestamp expire_withdraw; 368 struct GNUNET_TIME_Timestamp expire_deposit; 369 struct GNUNET_TIME_Timestamp expire_legal; 370 struct TALER_Amount coin; 371 struct TALER_DenomFeeSet fees; 372 } denominations; 373 374 struct 375 { 376 struct TALER_MasterSignatureP master_sig; 377 uint64_t denominations_serial; 378 } denomination_revocations; 379 380 struct 381 { 382 struct TALER_FullPayto full_payto_uri; 383 } wire_targets; 384 385 struct 386 { 387 struct TALER_NormalizedPaytoHashP h_normalized_payto; 388 struct TALER_AccountAccessTokenP access_token; 389 union TALER_AccountPublicKeyP target_pub; 390 bool no_account; 391 bool is_wallet; 392 } kyc_targets; 393 394 struct 395 { 396 struct TALER_AccountAccessTokenP target_token; 397 struct GNUNET_TIME_Timestamp start_time; 398 json_t *measures; 399 uint32_t display_priority; 400 } legitimization_measures; 401 402 struct 403 { 404 struct TALER_NormalizedPaytoHashP h_payto; 405 struct GNUNET_TIME_Timestamp decision_time; 406 struct GNUNET_TIME_Timestamp expiration_time; 407 json_t *properties; 408 bool to_investigate; 409 json_t *new_rules; 410 } legitimization_outcomes; 411 412 struct 413 { 414 struct TALER_NormalizedPaytoHashP h_payto; 415 struct GNUNET_TIME_Timestamp start_time; 416 struct GNUNET_TIME_Timestamp expiration_time; 417 uint64_t legitimization_measure_serial_id; 418 uint32_t measure_index; 419 char *provider_name; 420 char *provider_user_id; 421 char *provider_legitimization_id; 422 char *redirect_url; 423 } legitimization_processes; 424 425 struct 426 { 427 struct TALER_NormalizedPaytoHashP h_payto; 428 uint64_t legitimization_serial; 429 struct GNUNET_TIME_Timestamp collection_time; 430 struct GNUNET_TIME_Timestamp expiration_time; 431 uint64_t trigger_outcome_serial; 432 void *encrypted_attributes; 433 size_t encrypted_attributes_size; 434 } kyc_attributes; 435 436 struct 437 { 438 struct TALER_NormalizedPaytoHashP h_payto; 439 uint64_t outcome_serial_id; 440 char *justification; 441 struct TALER_AmlOfficerPublicKeyP decider_pub; 442 struct TALER_AmlOfficerSignatureP decider_sig; 443 } aml_history; 444 445 struct 446 { 447 struct GNUNET_TIME_Timestamp event_timestamp; 448 char *event_type; 449 } kyc_events; 450 451 struct 452 { 453 struct TALER_AmlOfficerPublicKeyP decider_pub; 454 struct TALER_MasterSignatureP master_sig; 455 char *decider_name; 456 bool is_active; 457 bool read_only; 458 struct GNUNET_TIME_Timestamp last_change; 459 } aml_staff; 460 461 struct 462 { 463 struct TALER_ReservePublicKeyP reserve_pub; 464 struct GNUNET_TIME_Timestamp expiration_date; 465 struct GNUNET_TIME_Timestamp gc_date; 466 } reserves; 467 468 struct 469 { 470 uint64_t wire_reference; 471 struct TALER_Amount credit; 472 struct TALER_FullPaytoHashP sender_account_h_payto; 473 char *exchange_account_section; 474 struct GNUNET_TIME_Timestamp execution_date; 475 struct TALER_ReservePublicKeyP reserve_pub; 476 } reserves_in; 477 478 struct 479 { 480 uint64_t wire_reference; 481 struct TALER_Amount credit; 482 struct TALER_FullPaytoHashP sender_account_h_payto; 483 char *exchange_account_section; 484 struct GNUNET_TIME_Timestamp execution_date; 485 union TALER_AccountPublicKeyP account_pub; 486 } kycauth_in; 487 488 struct 489 { 490 struct TALER_ReservePublicKeyP reserve_pub; 491 struct GNUNET_TIME_Timestamp request_timestamp; 492 struct GNUNET_TIME_Timestamp expiration_date; 493 struct TALER_ReserveSignatureP reserve_sig; 494 struct TALER_Amount reserve_payment; 495 uint32_t requested_purse_limit; 496 } reserves_open_requests; 497 498 struct 499 { 500 struct TALER_ReservePublicKeyP reserve_pub; 501 struct TALER_CoinSpendPublicKeyP coin_pub; 502 struct TALER_CoinSpendSignatureP coin_sig; 503 struct TALER_ReserveSignatureP reserve_sig; 504 struct TALER_Amount contribution; 505 } reserves_open_deposits; 506 507 struct 508 { 509 struct TALER_ReservePublicKeyP reserve_pub; 510 struct GNUNET_TIME_Timestamp execution_date; 511 struct TALER_WireTransferIdentifierRawP wtid; 512 struct TALER_FullPaytoHashP sender_account_h_payto; 513 struct TALER_Amount amount; 514 struct TALER_Amount closing_fee; 515 } reserves_close; 516 517 struct 518 { 519 struct TALER_AuditorPublicKeyP auditor_pub; 520 char *auditor_url; 521 char *auditor_name; 522 bool is_active; 523 struct GNUNET_TIME_Timestamp last_change; 524 } auditors; 525 526 struct 527 { 528 uint64_t auditor_uuid; 529 uint64_t denominations_serial; 530 struct TALER_AuditorSignatureP auditor_sig; 531 } auditor_denom_sigs; 532 533 struct 534 { 535 struct TALER_ExchangePublicKeyP exchange_pub; 536 struct TALER_MasterSignatureP master_sig; 537 struct TALER_EXCHANGEDB_SignkeyMetaData meta; 538 } exchange_sign_keys; 539 540 struct 541 { 542 uint64_t esk_serial; 543 struct TALER_MasterSignatureP master_sig; 544 } signkey_revocations; 545 546 struct 547 { 548 struct TALER_CoinSpendPublicKeyP coin_pub; 549 struct TALER_AgeCommitmentHashP age_hash; 550 uint64_t denominations_serial; 551 struct TALER_DenominationSignature denom_sig; 552 } known_coins; 553 554 struct 555 { 556 struct TALER_RefreshCommitmentP rc; 557 struct GNUNET_TIME_Timestamp execution_date; 558 struct TALER_Amount amount_with_fee; 559 struct TALER_CoinSpendPublicKeyP old_coin_pub; 560 struct TALER_CoinSpendSignatureP old_coin_sig; 561 struct TALER_PublicRefreshMasterSeedP refresh_seed; 562 uint32_t noreveal_index; 563 struct TALER_HashBlindedPlanchetsP planchets_h; 564 struct TALER_HashBlindedPlanchetsP selected_h; 565 bool no_blinding_seed; 566 struct TALER_BlindingMasterSeedP blinding_seed; 567 size_t num_cs_r_values; 568 struct GNUNET_CRYPTO_CSPublicRPairP *cs_r_values; 569 uint64_t cs_r_choices; 570 size_t num_coins; 571 uint64_t *denom_serials; 572 struct TALER_BlindedDenominationSignature *denom_sigs; 573 } refresh; 574 575 struct 576 { 577 uint64_t shard; 578 struct TALER_MerchantPublicKeyP merchant_pub; 579 struct GNUNET_TIME_Timestamp wallet_timestamp; 580 struct GNUNET_TIME_Timestamp exchange_timestamp; 581 struct GNUNET_TIME_Timestamp refund_deadline; 582 struct GNUNET_TIME_Timestamp wire_deadline; 583 struct TALER_PrivateContractHashP h_contract_terms; 584 bool no_wallet_data_hash; 585 struct GNUNET_HashCode wallet_data_hash; 586 struct TALER_WireSaltP wire_salt; 587 struct TALER_FullPaytoHashP wire_target_h_payto; 588 bool no_policy_details; 589 uint64_t policy_details_serial_id; 590 bool policy_blocked; 591 struct TALER_Amount total_amount; 592 struct TALER_Amount total_without_fee; 593 struct TALER_MerchantSignatureP merchant_sig; 594 bool done; 595 } batch_deposits; 596 597 struct 598 { 599 uint64_t batch_deposit_serial_id; 600 struct TALER_CoinSpendPublicKeyP coin_pub; 601 struct TALER_CoinSpendSignatureP coin_sig; 602 struct TALER_Amount amount_with_fee; 603 } coin_deposits; 604 605 struct 606 { 607 struct TALER_CoinSpendPublicKeyP coin_pub; 608 uint64_t batch_deposit_serial_id; 609 struct TALER_MerchantSignatureP merchant_sig; 610 uint64_t rtransaction_id; 611 struct TALER_Amount amount_with_fee; 612 } refunds; 613 614 struct 615 { 616 struct GNUNET_TIME_Timestamp execution_date; 617 struct TALER_WireTransferIdentifierRawP wtid_raw; 618 struct TALER_FullPaytoHashP wire_target_h_payto; 619 char *exchange_account_section; 620 struct TALER_Amount amount; 621 } wire_out; 622 623 struct 624 { 625 uint64_t batch_deposit_serial_id; 626 struct TALER_WireTransferIdentifierRawP wtid_raw; 627 } aggregation_tracking; 628 629 struct 630 { 631 char *wire_method; 632 struct GNUNET_TIME_Timestamp start_date; 633 struct GNUNET_TIME_Timestamp end_date; 634 struct TALER_WireFeeSet fees; 635 struct TALER_MasterSignatureP master_sig; 636 } wire_fee; 637 638 struct 639 { 640 struct GNUNET_TIME_Timestamp start_date; 641 struct GNUNET_TIME_Timestamp end_date; 642 struct TALER_GlobalFeeSet fees; 643 struct GNUNET_TIME_Relative purse_timeout; 644 struct GNUNET_TIME_Relative history_expiration; 645 uint32_t purse_account_limit; 646 struct TALER_MasterSignatureP master_sig; 647 } global_fee; 648 649 struct 650 { 651 struct TALER_CoinSpendPublicKeyP coin_pub; 652 struct TALER_CoinSpendSignatureP coin_sig; 653 union GNUNET_CRYPTO_BlindingSecretP coin_blind; 654 struct TALER_Amount amount; 655 struct GNUNET_TIME_Timestamp timestamp; 656 uint64_t withdraw_serial_id; 657 } recoup; 658 659 struct 660 { 661 uint64_t known_coin_id; 662 struct TALER_CoinSpendPublicKeyP coin_pub; 663 struct TALER_CoinSpendSignatureP coin_sig; 664 union GNUNET_CRYPTO_BlindingSecretP coin_blind; 665 struct TALER_Amount amount; 666 struct GNUNET_TIME_Timestamp timestamp; 667 uint64_t rrc_serial; 668 } recoup_refresh; 669 670 struct 671 { 672 char *name; 673 char *manifest; 674 } extensions; 675 676 struct 677 { 678 struct GNUNET_HashCode hash_code; 679 json_t *policy_json; 680 bool no_policy_json; 681 struct GNUNET_TIME_Timestamp deadline; 682 struct TALER_Amount commitment; 683 struct TALER_Amount accumulated_total; 684 struct TALER_Amount fee; 685 struct TALER_Amount transferable; 686 uint16_t fulfillment_state; /* will also be recomputed */ 687 uint64_t fulfillment_id; 688 bool no_fulfillment_id; 689 } policy_details; 690 691 struct 692 { 693 struct GNUNET_TIME_Timestamp fulfillment_timestamp; 694 char *fulfillment_proof; 695 struct GNUNET_HashCode h_fulfillment_proof; 696 struct GNUNET_HashCode *policy_hash_codes; 697 size_t policy_hash_codes_count; 698 } policy_fulfillments; 699 700 struct 701 { 702 struct TALER_PurseContractPublicKeyP purse_pub; 703 struct TALER_PurseMergePublicKeyP merge_pub; 704 struct GNUNET_TIME_Timestamp purse_creation; 705 struct GNUNET_TIME_Timestamp purse_expiration; 706 struct TALER_PrivateContractHashP h_contract_terms; 707 uint32_t age_limit; 708 uint32_t flags; 709 struct TALER_Amount amount_with_fee; 710 struct TALER_Amount purse_fee; 711 struct TALER_PurseContractSignatureP purse_sig; 712 } purse_requests; 713 714 struct 715 { 716 struct TALER_PurseContractPublicKeyP purse_pub; 717 struct GNUNET_TIME_Timestamp action_timestamp; 718 bool refunded; 719 } purse_decision; 720 721 struct 722 { 723 uint64_t partner_serial_id; 724 struct TALER_ReservePublicKeyP reserve_pub; 725 struct TALER_PurseContractPublicKeyP purse_pub; 726 struct TALER_PurseMergeSignatureP merge_sig; 727 struct GNUNET_TIME_Timestamp merge_timestamp; 728 } purse_merges; 729 730 struct 731 { 732 uint64_t partner_serial_id; 733 struct TALER_PurseContractPublicKeyP purse_pub; 734 struct TALER_CoinSpendPublicKeyP coin_pub; 735 struct TALER_Amount amount_with_fee; 736 struct TALER_CoinSpendSignatureP coin_sig; 737 } purse_deposits; 738 739 struct 740 { 741 struct TALER_ReservePublicKeyP reserve_pub; 742 struct TALER_ReserveSignatureP reserve_sig; 743 struct TALER_PurseContractPublicKeyP purse_pub; 744 struct TALER_NormalizedPaytoHashP wallet_h_payto; 745 } account_merges; 746 747 struct 748 { 749 struct TALER_ReservePublicKeyP reserve_pub; 750 struct TALER_ReserveSignatureP reserve_sig; 751 struct GNUNET_TIME_Timestamp request_timestamp; 752 struct TALER_Amount history_fee; 753 } history_requests; 754 755 struct 756 { 757 struct TALER_ReservePublicKeyP reserve_pub; 758 struct GNUNET_TIME_Timestamp close_timestamp; 759 struct TALER_ReserveSignatureP reserve_sig; 760 struct TALER_Amount close; 761 struct TALER_Amount close_fee; 762 struct TALER_FullPayto payto_uri; 763 } close_requests; 764 765 struct 766 { 767 struct TALER_WadIdentifierP wad_id; 768 uint64_t partner_serial_id; 769 struct TALER_Amount amount; 770 struct GNUNET_TIME_Timestamp execution_time; 771 } wads_out; 772 773 struct 774 { 775 uint64_t wad_out_serial_id; 776 struct TALER_ReservePublicKeyP reserve_pub; 777 struct TALER_PurseContractPublicKeyP purse_pub; 778 struct TALER_PrivateContractHashP h_contract; 779 struct GNUNET_TIME_Timestamp purse_expiration; 780 struct GNUNET_TIME_Timestamp merge_timestamp; 781 struct TALER_Amount amount_with_fee; 782 struct TALER_Amount wad_fee; 783 struct TALER_Amount deposit_fees; 784 struct TALER_ReserveSignatureP reserve_sig; 785 struct TALER_PurseContractSignatureP purse_sig; 786 } wads_out_entries; 787 788 struct 789 { 790 struct TALER_WadIdentifierP wad_id; 791 char *origin_exchange_url; 792 struct TALER_Amount amount; 793 struct GNUNET_TIME_Timestamp arrival_time; 794 } wads_in; 795 796 struct 797 { 798 uint64_t wad_in_serial_id; 799 struct TALER_ReservePublicKeyP reserve_pub; 800 struct TALER_PurseContractPublicKeyP purse_pub; 801 struct TALER_PrivateContractHashP h_contract; 802 struct GNUNET_TIME_Timestamp purse_expiration; 803 struct GNUNET_TIME_Timestamp merge_timestamp; 804 struct TALER_Amount amount_with_fee; 805 struct TALER_Amount wad_fee; 806 struct TALER_Amount deposit_fees; 807 struct TALER_ReserveSignatureP reserve_sig; 808 struct TALER_PurseContractSignatureP purse_sig; 809 } wads_in_entries; 810 811 struct 812 { 813 struct TALER_WireTransferIdentifierRawP wtid; 814 char *account_section; 815 struct TALER_FullPayto payto_uri; 816 struct GNUNET_TIME_Timestamp trigger_date; 817 struct TALER_Amount amount; 818 struct TALER_MasterSignatureP master_sig; 819 } profit_drains; 820 821 struct 822 { 823 struct TALER_PurseContractPublicKeyP purse_pub; 824 struct TALER_PurseContractSignatureP purse_sig; 825 } purse_deletion; 826 827 struct 828 { 829 struct TALER_HashBlindedPlanchetsP planchets_h; 830 struct GNUNET_TIME_Timestamp execution_date; 831 struct TALER_Amount amount_with_fee; 832 struct TALER_ReservePublicKeyP reserve_pub; 833 struct TALER_ReserveSignatureP reserve_sig; 834 bool age_proof_required; 835 uint16_t max_age; 836 uint16_t noreveal_index; 837 struct TALER_HashBlindedPlanchetsP selected_h; 838 bool no_blinding_seed; 839 struct TALER_BlindingMasterSeedP blinding_seed; 840 size_t num_cs_r_values; 841 struct GNUNET_CRYPTO_CSPublicRPairP *cs_r_values; 842 uint64_t cs_r_choices; 843 size_t num_coins; 844 uint64_t *denom_serials; 845 struct TALER_BlindedDenominationSignature *denom_sigs; 846 } withdraw; 847 848 } details; 849 850 }; 851 852 853 /** 854 * Function called on data to replicate in the auditor's database. 855 * 856 * @param cls closure 857 * @param td record from an exchange table 858 * @return #GNUNET_OK to continue to iterate, 859 * #GNUNET_SYSERR to fail with an error 860 */ 861 typedef int 862 (*TALER_EXCHANGEDB_ReplicationCallback)( 863 void *cls, 864 const struct TALER_EXCHANGEDB_TableData *td); 865 866 867 /** 868 * @brief All information about a denomination key (which is used to 869 * sign coins into existence). 870 */ 871 struct TALER_EXCHANGEDB_DenominationKey 872 { 873 /** 874 * The private key of the denomination. Will be NULL if the private 875 * key is not available (this is the case after the key has expired 876 * for signing coins, but is still valid for depositing coins). 877 */ 878 struct TALER_DenominationPrivateKey denom_priv; 879 880 /** 881 * Decoded denomination public key (the hash of it is in 882 * @e issue, but we sometimes need the full public key as well). 883 */ 884 struct TALER_DenominationPublicKey denom_pub; 885 886 /** 887 * Signed public information about a denomination key. 888 */ 889 struct TALER_EXCHANGEDB_DenominationKeyInformation issue; 890 }; 891 892 893 /** 894 * @brief Information we keep on bank transfer(s) that established a reserve. 895 */ 896 struct TALER_EXCHANGEDB_BankTransfer 897 { 898 899 /** 900 * Public key of the reserve that was filled. 901 */ 902 struct TALER_ReservePublicKeyP reserve_pub; 903 904 /** 905 * Amount that was transferred to the exchange. 906 */ 907 struct TALER_Amount amount; 908 909 /** 910 * When did the exchange receive the incoming transaction? 911 * (This is the execution date of the exchange's database, 912 * the execution date of the bank should be in @e wire). 913 */ 914 struct GNUNET_TIME_Timestamp execution_date; 915 916 /** 917 * Detailed wire information about the sending account 918 * in "payto://" format. 919 */ 920 struct TALER_FullPayto sender_account_details; 921 922 /** 923 * Data uniquely identifying the wire transfer (wire transfer-type specific) 924 */ 925 uint64_t wire_reference; 926 927 }; 928 929 930 /** 931 * @brief Information we keep on bank transfer(s) that 932 * closed a reserve. 933 */ 934 struct TALER_EXCHANGEDB_ClosingTransfer 935 { 936 937 /** 938 * Public key of the reserve that was depleted. 939 */ 940 struct TALER_ReservePublicKeyP reserve_pub; 941 942 /** 943 * Amount that was transferred from the exchange. 944 */ 945 struct TALER_Amount amount; 946 947 /** 948 * Amount that was charged by the exchange. 949 */ 950 struct TALER_Amount closing_fee; 951 952 /** 953 * When did the exchange execute the transaction? 954 */ 955 struct GNUNET_TIME_Timestamp execution_date; 956 957 /** 958 * Detailed wire information about the receiving account 959 * in payto://-format. 960 */ 961 struct TALER_FullPayto receiver_account_details; 962 963 /** 964 * Detailed wire transfer information that uniquely identifies the 965 * wire transfer. 966 */ 967 struct TALER_WireTransferIdentifierRawP wtid; 968 969 }; 970 971 972 /** 973 * @brief A summary of a Reserve 974 */ 975 struct TALER_EXCHANGEDB_Reserve 976 { 977 /** 978 * The reserve's public key. This uniquely identifies the reserve 979 */ 980 struct TALER_ReservePublicKeyP pub; 981 982 /** 983 * The balance amount existing in the reserve 984 */ 985 struct TALER_Amount balance; 986 987 /** 988 * The expiration date of this reserve; funds will be wired back 989 * at this time. 990 */ 991 struct GNUNET_TIME_Timestamp expiry; 992 993 /** 994 * The legal expiration date of this reserve; we will forget about 995 * it at this time. 996 */ 997 struct GNUNET_TIME_Timestamp gc; 998 }; 999 1000 1001 /** 1002 * Meta data about a denomination public key. 1003 * If this is changed, you must also adjust 1004 * taler-exchange-httpd-post-management-keys.c::denomination_meta_cmp(). 1005 */ 1006 struct TALER_EXCHANGEDB_DenominationKeyMetaData 1007 { 1008 /** 1009 * Serial of the denomination key as in the DB. 1010 * Can be used calls to stored procedures in order to spare 1011 * additional lookups. 1012 */ 1013 uint64_t serial; 1014 1015 /** 1016 * Start time of the validity period for this key. 1017 */ 1018 struct GNUNET_TIME_Timestamp start; 1019 1020 /** 1021 * The exchange will sign fresh coins between @e start and this time. 1022 * @e expire_withdraw will be somewhat larger than @e start to 1023 * ensure a sufficiently large anonymity set, while also allowing 1024 * the Exchange to limit the financial damage in case of a key being 1025 * compromised. Thus, exchanges with low volume are expected to have a 1026 * longer withdraw period (@e expire_withdraw - @e start) than exchanges 1027 * with high transaction volume. The period may also differ between 1028 * types of coins. A exchange may also have a few denomination keys 1029 * with the same value with overlapping validity periods, to address 1030 * issues such as clock skew. 1031 */ 1032 struct GNUNET_TIME_Timestamp expire_withdraw; 1033 1034 /** 1035 * Coins signed with the denomination key must be spent or refreshed 1036 * between @e start and this expiration time. After this time, the 1037 * exchange will refuse transactions involving this key as it will 1038 * "drop" the table with double-spending information (shortly after) 1039 * this time. Note that wallets should refresh coins significantly 1040 * before this time to be on the safe side. @e expire_deposit must be 1041 * significantly larger than @e expire_withdraw (by months or even 1042 * years). 1043 */ 1044 struct GNUNET_TIME_Timestamp expire_deposit; 1045 1046 /** 1047 * When do signatures with this denomination key become invalid? 1048 * After this point, these signatures cannot be used in (legal) 1049 * disputes anymore, as the Exchange is then allowed to destroy its side 1050 * of the evidence. @e expire_legal is expected to be significantly 1051 * larger than @e expire_deposit (by a year or more). 1052 */ 1053 struct GNUNET_TIME_Timestamp expire_legal; 1054 1055 /** 1056 * The value of the coins signed with this denomination key. 1057 */ 1058 struct TALER_Amount value; 1059 1060 /** 1061 * The fees the exchange charges for operations with 1062 * coins of this denomination. 1063 */ 1064 struct TALER_DenomFeeSet fees; 1065 1066 /** 1067 * Age restriction for the denomination. (can be zero). If not zero, the bits 1068 * set in the mask mark the edges at the beginning of a next age group. F.e. 1069 * for the age groups 1070 * 0-7, 8-9, 10-11, 12-14, 14-15, 16-17, 18-21, 21-* 1071 * the following bits are set: 1072 * 1073 * 31 24 16 8 0 1074 * | | | | | 1075 * oooooooo oo1oo1o1 o1o1o1o1 ooooooo1 1076 * 1077 * A value of 0 means that the denomination does not support the extension for 1078 * age-restriction. 1079 */ 1080 struct TALER_AgeMask age_mask; 1081 }; 1082 1083 1084 /** 1085 * Signature of a function called with information about the exchange's 1086 * denomination keys. 1087 * 1088 * @param cls closure with a `struct TEH_KeyStateHandle *` 1089 * @param denom_pub public key of the denomination 1090 * @param h_denom_pub hash of @a denom_pub 1091 * @param meta meta data information about the denomination type (value, expirations, fees) 1092 * @param master_sig master signature affirming the validity of this denomination 1093 * @param recoup_possible true if the key was revoked and clients can currently recoup 1094 * coins of this denomination 1095 */ 1096 typedef void 1097 (*TALER_EXCHANGEDB_DenominationsCallback)( 1098 void *cls, 1099 const struct TALER_DenominationPublicKey *denom_pub, 1100 const struct TALER_DenominationHashP *h_denom_pub, 1101 const struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta, 1102 const struct TALER_MasterSignatureP *master_sig, 1103 bool recoup_possible); 1104 1105 1106 /** 1107 * Signature of a function called with information about the exchange's 1108 * online signing keys. 1109 * 1110 * @param cls closure with a `struct TEH_KeyStateHandle *` 1111 * @param exchange_pub public key of the exchange 1112 * @param meta meta data information about the signing type (expirations) 1113 * @param master_sig master signature affirming the validity of this denomination 1114 */ 1115 typedef void 1116 (*TALER_EXCHANGEDB_ActiveSignkeysCallback)( 1117 void *cls, 1118 const struct TALER_ExchangePublicKeyP *exchange_pub, 1119 const struct TALER_EXCHANGEDB_SignkeyMetaData *meta, 1120 const struct TALER_MasterSignatureP *master_sig); 1121 1122 1123 /** 1124 * Function called on all legitimization operations 1125 * we have performed for the given account so far 1126 * (and that have not yet expired). 1127 * 1128 * @param cls closure 1129 * @param kyc_provider_name name of the provider 1130 * of the respective KYC process 1131 * @param provider_user_id UID at a provider (can be NULL) 1132 * @param legi_id legitimization process ID (can be NULL) 1133 */ 1134 typedef void 1135 (*TALER_EXCHANGEDB_LegitimizationProcessCallback)( 1136 void *cls, 1137 const char *kyc_provider_name, 1138 const char *provider_user_id, 1139 const char *legi_id); 1140 1141 1142 /** 1143 * Function called with information about the exchange's auditors. 1144 * 1145 * @param cls closure with a `struct TEH_KeyStateHandle *` 1146 * @param auditor_pub the public key of the auditor 1147 * @param auditor_url URL of the REST API of the auditor 1148 * @param auditor_name human readable official name of the auditor 1149 */ 1150 typedef void 1151 (*TALER_EXCHANGEDB_AuditorsCallback)( 1152 void *cls, 1153 const struct TALER_AuditorPublicKeyP *auditor_pub, 1154 const char *auditor_url, 1155 const char *auditor_name); 1156 1157 1158 /** 1159 * Function called with information about the denominations 1160 * audited by the exchange's auditors. 1161 * 1162 * @param cls closure with a `struct TEH_KeyStateHandle *` 1163 * @param auditor_pub the public key of an auditor 1164 * @param h_denom_pub hash of a denomination key audited by this auditor 1165 * @param auditor_sig signature from the auditor affirming this 1166 */ 1167 typedef void 1168 (*TALER_EXCHANGEDB_AuditorDenominationsCallback)( 1169 void *cls, 1170 const struct TALER_AuditorPublicKeyP *auditor_pub, 1171 const struct TALER_DenominationHashP *h_denom_pub, 1172 const struct TALER_AuditorSignatureP *auditor_sig); 1173 1174 1175 /** 1176 * @brief Information we keep for a withdrawn coin to reproduce 1177 * the /batch-withdraw operation if needed, and to have proof 1178 * that a reserve was drained by this amount. 1179 * 1180 * @note This structure will be removed at some point after v24 of the protocol 1181 * FIXME: to be deleted. 1182 */ 1183 struct TALER_EXCHANGEDB_CollectableBlindcoin 1184 { 1185 1186 /** 1187 * Our (blinded) signature over the (blinded) coin. 1188 */ 1189 struct TALER_BlindedDenominationSignature sig; 1190 1191 /** 1192 * Hash of the denomination key (which coin was generated). 1193 */ 1194 struct TALER_DenominationHashP denom_pub_hash; 1195 1196 /** 1197 * Value of the coin being exchangeed (matching the denomination key) 1198 * plus the transaction fee. We include this in what is being 1199 * signed so that we can verify a reserve's remaining total balance 1200 * without needing to access the respective denomination key 1201 * information each time. 1202 */ 1203 struct TALER_Amount amount_with_fee; 1204 1205 /** 1206 * Withdrawal fee charged by the exchange. This must match the Exchange's 1207 * denomination key's withdrawal fee. If the client puts in an 1208 * invalid withdrawal fee (too high or too low) that does not match 1209 * the Exchange's denomination key, the withdraw operation is invalid 1210 * and will be rejected by the exchange. The @e amount_with_fee minus 1211 * the @e withdraw_fee is must match the value of the generated 1212 * coin. We include this in what is being signed so that we can 1213 * verify a exchange's accounting without needing to access the 1214 * respective denomination key information each time. 1215 */ 1216 struct TALER_Amount withdraw_fee; 1217 1218 /** 1219 * Public key of the reserve that was drained. 1220 */ 1221 struct TALER_ReservePublicKeyP reserve_pub; 1222 1223 /** 1224 * Hash over the blinded message, needed to verify 1225 * the @e reserve_sig. 1226 */ 1227 struct TALER_BlindedCoinHashP h_coin_envelope; 1228 1229 /** 1230 * Signature confirming the withdrawal, matching @e reserve_pub, 1231 * @e denom_pub and @e h_coin_envelope. 1232 */ 1233 struct TALER_ReserveSignatureP reserve_sig; 1234 }; 1235 1236 /** 1237 * @brief Information we keep for a withdraw request 1238 * to reproduce the /withdraw operation if needed, and to have proof 1239 * that a reserve was drained by this amount. 1240 */ 1241 struct TALER_EXCHANGEDB_Withdraw 1242 { 1243 /** 1244 * Total amount (with fee) committed to withdraw 1245 */ 1246 struct TALER_Amount amount_with_fee; 1247 1248 /** 1249 * true, if a proof of age was required following this withdraw, 1250 * in a subsequent call to /reveal-withdraw. 1251 * In this case, @e max_age, @e h_commitment and 1252 * @e noreveal_index are to be taken into account 1253 */ 1254 bool age_proof_required; 1255 1256 /** 1257 * Maximum age (in years) that the coins are restricted to, 1258 * if ``age_proof_required`` is true. 1259 */ 1260 uint16_t max_age; 1261 1262 /** 1263 * If ``age_proof_required`` is true, index (smaller #TALER_CNC_KAPPA) 1264 * which the exchange has chosen to keep unrevealed 1265 * during the next cut and choose (aka /reveal-age) step. 1266 * This value applies to all n coins in the commitment. 1267 */ 1268 uint16_t noreveal_index; 1269 1270 /** 1271 * If @e age_proof_required is true, the running hash over all blinded coin 1272 * envelope's TALER_BlindedCoinHashP values. 1273 * It runs over ``kappa*num_coins``, starting with the hashes for the coins 1274 * for kappa index=0, then index=1 etc., 1275 * i.e. h[0][0]...h[0][n-1]h[1][0]...h[1][n-1]...h[κ-1][0]...h[κ-1][n-1] 1276 */ 1277 struct TALER_HashBlindedPlanchetsP planchets_h; 1278 1279 /** 1280 * Public key of the reserve that was drained. 1281 */ 1282 struct TALER_ReservePublicKeyP reserve_pub; 1283 1284 /** 1285 * Signature confirming the withdrawal commitment 1286 */ 1287 struct TALER_ReserveSignatureP reserve_sig; 1288 1289 /** 1290 * Number of coins to be withdrawn. 1291 */ 1292 size_t num_coins; 1293 1294 /** 1295 * The hash of the blinded coin envelopes which are signed by the exchange. 1296 * In case of @e age_proof_required = true, this is the hash over the chosen coins' 1297 * envelopes (according to @e noreveal_index) from the request, which contained 1298 * kappa*num_coins blinded coins envelopes. 1299 */ 1300 struct TALER_HashBlindedPlanchetsP selected_h; 1301 1302 /** 1303 * Array of @a num_coins denomination signatures of the blinded coins @a 1304 * h_coin_evs. 1305 */ 1306 struct TALER_BlindedDenominationSignature *denom_sigs; 1307 1308 /** 1309 * Array of @a num_coins serial id's of the denominations, corresponding to 1310 * the coins in @a h_coin_evs. 1311 * If @e age_proof_required is true, the denominations MUST support age restriction. 1312 */ 1313 uint64_t *denom_serials; 1314 1315 /** 1316 * If true, no @e blinding_seed is set and @e num_cs_r_values is 0. 1317 */ 1318 bool no_blinding_seed; 1319 1320 /** 1321 * If @e no_blinding_seed is false, the blinding seed for the nonces needed for 1322 * blind CS signatures. 1323 */ 1324 struct TALER_BlindingMasterSeedP blinding_seed; 1325 1326 /** 1327 * Number of elements in @e cs_r_values. 1328 * Only non-zero IF @e age_proof_required is true AND any of the denomination 1329 * has a cipher of type CS. 1330 */ 1331 size_t num_cs_r_values; 1332 1333 /** 1334 * Array @e num_r_pubs of public R-value pairs for CS that were generated from the 1335 * @e blinding_seed, a coin's index and the denomination's private key during the 1336 * the /withdraw request, to ensure idempotency in case of expiration of a denomination. 1337 * NULL if @e num_r_pub is 0 (or @e age_proof_required is false). 1338 */ 1339 struct GNUNET_CRYPTO_CSPublicRPairP *cs_r_values; 1340 1341 /** 1342 * The bitvector encoding the choices per coin, made by the exchange, 1343 * for the R-values in @e cs_r_values. The value is encoded in NBO 1344 * and the lowest bit corresponds to the pair at index 0 in @e cs_r_values. 1345 */ 1346 uint64_t cs_r_choices; 1347 1348 /** 1349 * [out]-Array of @a num_coins hashes of the public keys of the denominations 1350 * identified by @e denom_serials. This field is only set when calling 1351 * get_reserve_history(). 1352 */ 1353 struct TALER_DenominationHashP *denom_pub_hashes; 1354 }; 1355 1356 1357 /** 1358 * Information the exchange records about a recoup request 1359 * in a reserve history. 1360 */ 1361 struct TALER_EXCHANGEDB_Recoup 1362 { 1363 1364 /** 1365 * Information about the coin that was paid back. 1366 */ 1367 struct TALER_CoinPublicInfo coin; 1368 1369 /** 1370 * Blinding factor supplied to prove to the exchange that 1371 * the coin came from this reserve. 1372 */ 1373 union GNUNET_CRYPTO_BlindingSecretP coin_blind; 1374 1375 /** 1376 * Signature of the coin of type 1377 * #TALER_SIGNATURE_WALLET_COIN_RECOUP. 1378 */ 1379 struct TALER_CoinSpendSignatureP coin_sig; 1380 1381 /** 1382 * Public key of the reserve the coin was paid back into. 1383 */ 1384 struct TALER_ReservePublicKeyP reserve_pub; 1385 1386 /** 1387 * How much was the coin still worth at this time? 1388 */ 1389 struct TALER_Amount value; 1390 1391 /** 1392 * When did the recoup operation happen? 1393 */ 1394 struct GNUNET_TIME_Timestamp timestamp; 1395 1396 }; 1397 1398 1399 /** 1400 * Public key to which a nonce is locked. 1401 */ 1402 union TALER_EXCHANGEDB_NonceLockTargetP 1403 { 1404 /** 1405 * Nonce is locked to this coin key. 1406 */ 1407 struct TALER_CoinSpendPublicKeyP coin; 1408 1409 /** 1410 * Nonce is locked to this reserve key. 1411 */ 1412 struct TALER_ReservePublicKeyP reserve; 1413 }; 1414 1415 1416 /** 1417 * Information the exchange records about a recoup request 1418 * in a coin history. 1419 */ 1420 struct TALER_EXCHANGEDB_RecoupListEntry 1421 { 1422 1423 /** 1424 * Blinding factor supplied to prove to the exchange that 1425 * the coin came from this reserve. 1426 */ 1427 union GNUNET_CRYPTO_BlindingSecretP coin_blind; 1428 1429 /** 1430 * Signature of the coin of type 1431 * #TALER_SIGNATURE_WALLET_COIN_RECOUP. 1432 */ 1433 struct TALER_CoinSpendSignatureP coin_sig; 1434 1435 /** 1436 * Hash of the public denomination key used to sign the coin. 1437 */ 1438 struct TALER_DenominationHashP h_denom_pub; 1439 1440 /** 1441 * Public key of the reserve the coin was paid back into. 1442 */ 1443 struct TALER_ReservePublicKeyP reserve_pub; 1444 1445 /** 1446 * How much was the coin still worth at this time? 1447 */ 1448 struct TALER_Amount value; 1449 1450 /** 1451 * When did the /recoup operation happen? 1452 */ 1453 struct GNUNET_TIME_Timestamp timestamp; 1454 1455 }; 1456 1457 1458 /** 1459 * Information the exchange records about a recoup-refresh request in 1460 * a coin transaction history. 1461 */ 1462 struct TALER_EXCHANGEDB_RecoupRefreshListEntry 1463 { 1464 1465 /** 1466 * Information about the coin that was paid back 1467 * (NOT the coin we are considering the history of!) 1468 */ 1469 struct TALER_CoinPublicInfo coin; 1470 1471 /** 1472 * Blinding factor supplied to prove to the exchange that 1473 * the coin came from this @e old_coin_pub. 1474 */ 1475 union GNUNET_CRYPTO_BlindingSecretP coin_blind; 1476 1477 /** 1478 * Signature of the coin of type 1479 * #TALER_SIGNATURE_WALLET_COIN_RECOUP. 1480 */ 1481 struct TALER_CoinSpendSignatureP coin_sig; 1482 1483 /** 1484 * Public key of the old coin that the refreshed coin was paid back to. 1485 */ 1486 struct TALER_CoinSpendPublicKeyP old_coin_pub; 1487 1488 /** 1489 * How much was the coin still worth at this time? 1490 */ 1491 struct TALER_Amount value; 1492 1493 /** 1494 * When did the recoup operation happen? 1495 */ 1496 struct GNUNET_TIME_Timestamp timestamp; 1497 1498 }; 1499 1500 1501 /** 1502 * Details about a purse merge operation. 1503 */ 1504 struct TALER_EXCHANGEDB_PurseMerge 1505 { 1506 1507 /** 1508 * Public key of the reserve the coin was merged into. 1509 */ 1510 struct TALER_ReservePublicKeyP reserve_pub; 1511 1512 /** 1513 * Amount in the purse, with fees. 1514 */ 1515 struct TALER_Amount amount_with_fee; 1516 1517 /** 1518 * Fee paid for the purse. 1519 */ 1520 struct TALER_Amount purse_fee; 1521 1522 /** 1523 * Hash over the contract. 1524 */ 1525 struct TALER_PrivateContractHashP h_contract_terms; 1526 1527 /** 1528 * Merge capability key. 1529 */ 1530 struct TALER_PurseMergePublicKeyP merge_pub; 1531 1532 /** 1533 * Purse public key. 1534 */ 1535 struct TALER_PurseContractPublicKeyP purse_pub; 1536 1537 /** 1538 * Signature by the reserve approving the merge. 1539 */ 1540 struct TALER_ReserveSignatureP reserve_sig; 1541 1542 /** 1543 * When was the merge made. 1544 */ 1545 struct GNUNET_TIME_Timestamp merge_timestamp; 1546 1547 /** 1548 * When was the purse set to expire. 1549 */ 1550 struct GNUNET_TIME_Timestamp purse_expiration; 1551 1552 /** 1553 * Minimum age required for depositing into the purse. 1554 */ 1555 uint32_t min_age; 1556 1557 /** 1558 * Flags of the purse. 1559 */ 1560 enum TALER_WalletAccountMergeFlags flags; 1561 1562 /** 1563 * true if the purse was actually successfully merged, 1564 * false if the @e purse_fee was charged but the 1565 * @e amount was not credited to the reserve. 1566 */ 1567 bool merged; 1568 }; 1569 1570 1571 /** 1572 * Details about a (paid for) reserve history request. 1573 */ 1574 struct TALER_EXCHANGEDB_HistoryRequest 1575 { 1576 /** 1577 * Public key of the reserve the history request was for. 1578 */ 1579 struct TALER_ReservePublicKeyP reserve_pub; 1580 1581 /** 1582 * Fee paid for the request. 1583 */ 1584 struct TALER_Amount history_fee; 1585 1586 /** 1587 * When was the request made. 1588 */ 1589 struct GNUNET_TIME_Timestamp request_timestamp; 1590 1591 /** 1592 * Signature by the reserve approving the history request. 1593 */ 1594 struct TALER_ReserveSignatureP reserve_sig; 1595 }; 1596 1597 1598 /** 1599 * Details about a (paid for) reserve open request. 1600 */ 1601 struct TALER_EXCHANGEDB_OpenRequest 1602 { 1603 /** 1604 * Public key of the reserve the open request was for. 1605 */ 1606 struct TALER_ReservePublicKeyP reserve_pub; 1607 1608 /** 1609 * Fee paid for the request from the reserve. 1610 */ 1611 struct TALER_Amount open_fee; 1612 1613 /** 1614 * When was the request made. 1615 */ 1616 struct GNUNET_TIME_Timestamp request_timestamp; 1617 1618 /** 1619 * How long was the reserve supposed to be open. 1620 */ 1621 struct GNUNET_TIME_Timestamp reserve_expiration; 1622 1623 /** 1624 * Signature by the reserve approving the open request, 1625 * with purpose #TALER_SIGNATURE_WALLET_RESERVE_OPEN. 1626 */ 1627 struct TALER_ReserveSignatureP reserve_sig; 1628 1629 /** 1630 * How many open purses should be included with the 1631 * open reserve? 1632 */ 1633 uint32_t purse_limit; 1634 1635 }; 1636 1637 1638 /** 1639 * Details about an (explicit) reserve close request. 1640 */ 1641 struct TALER_EXCHANGEDB_CloseRequest 1642 { 1643 /** 1644 * Public key of the reserve the history request was for. 1645 */ 1646 struct TALER_ReservePublicKeyP reserve_pub; 1647 1648 /** 1649 * When was the request made. 1650 */ 1651 struct GNUNET_TIME_Timestamp request_timestamp; 1652 1653 /** 1654 * Hash of the payto://-URI of the target account 1655 * for the closure, or all zeros for the reserve 1656 * origin account. 1657 */ 1658 struct TALER_FullPaytoHashP target_account_h_payto; 1659 1660 /** 1661 * Signature by the reserve approving the history request. 1662 */ 1663 struct TALER_ReserveSignatureP reserve_sig; 1664 1665 }; 1666 1667 1668 /** 1669 * @brief Types of operations on a reserve. 1670 */ 1671 enum TALER_EXCHANGEDB_ReserveOperation 1672 { 1673 /** 1674 * Money was deposited into the reserve via a bank transfer. 1675 * This is how customers establish a reserve at the exchange. 1676 */ 1677 TALER_EXCHANGEDB_RO_BANK_TO_EXCHANGE = 0, 1678 1679 /** 1680 * A batch of coins was withdrawn from the reserve using /withdraw. 1681 */ 1682 TALER_EXCHANGEDB_RO_WITHDRAW_COINS = 1, 1683 1684 /** 1685 * A coin was returned to the reserve using /recoup. 1686 */ 1687 TALER_EXCHANGEDB_RO_RECOUP_COIN = 2, 1688 1689 /** 1690 * The exchange send inactive funds back from the reserve to the 1691 * customer's bank account. This happens when the exchange 1692 * closes a reserve with a non-zero amount left in it. 1693 */ 1694 TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK = 3, 1695 1696 /** 1697 * Event where a purse was merged into a reserve. 1698 */ 1699 TALER_EXCHANGEDB_RO_PURSE_MERGE = 4, 1700 1701 /** 1702 * Event where a wallet paid for a full reserve history. 1703 */ 1704 TALER_EXCHANGEDB_RO_HISTORY_REQUEST = 5, 1705 1706 /** 1707 * Event where a wallet paid to open a reserve for longer. 1708 */ 1709 TALER_EXCHANGEDB_RO_OPEN_REQUEST = 6, 1710 1711 /** 1712 * Event where a wallet requested a reserve to be closed. 1713 */ 1714 TALER_EXCHANGEDB_RO_CLOSE_REQUEST = 7, 1715 1716 }; 1717 1718 1719 /** 1720 * @brief Reserve history as a linked list. Lists all of the transactions 1721 * associated with this reserve (such as the bank transfers that 1722 * established the reserve and all /withdraw operations we have done 1723 * since). 1724 */ 1725 struct TALER_EXCHANGEDB_ReserveHistory 1726 { 1727 1728 /** 1729 * Next entry in the reserve history. 1730 */ 1731 struct TALER_EXCHANGEDB_ReserveHistory *next; 1732 1733 /** 1734 * Offset of this entry in the reserve history. 1735 * Corresponds to the reserve_history_serial_id in the database. 1736 */ 1737 uint64_t history_offset; 1738 1739 /** 1740 * Type of the event, determines @e details. 1741 */ 1742 enum TALER_EXCHANGEDB_ReserveOperation type; 1743 1744 /** 1745 * Details of the operation, depending on @e type. 1746 */ 1747 union 1748 { 1749 1750 /** 1751 * Details about a bank transfer to the exchange (reserve 1752 * was established). 1753 */ 1754 struct TALER_EXCHANGEDB_BankTransfer *bank; 1755 1756 /** 1757 * Details about a /withdraw operation. 1758 */ 1759 struct TALER_EXCHANGEDB_Withdraw *withdraw; 1760 1761 /** 1762 * Details about a /recoup operation. 1763 */ 1764 struct TALER_EXCHANGEDB_Recoup *recoup; 1765 1766 /** 1767 * Details about a bank transfer from the exchange (reserve 1768 * was closed). 1769 */ 1770 struct TALER_EXCHANGEDB_ClosingTransfer *closing; 1771 1772 /** 1773 * Details about a purse merge operation. 1774 */ 1775 struct TALER_EXCHANGEDB_PurseMerge *merge; 1776 1777 /** 1778 * Details about a (paid for) reserve history request. 1779 */ 1780 struct TALER_EXCHANGEDB_HistoryRequest *history; 1781 1782 /** 1783 * Details about a (paid for) open reserve request. 1784 */ 1785 struct TALER_EXCHANGEDB_OpenRequest *open_request; 1786 1787 /** 1788 * Details about an (explicit) reserve close request. 1789 */ 1790 struct TALER_EXCHANGEDB_CloseRequest *close_request; 1791 1792 } details; 1793 1794 }; 1795 1796 1797 /** 1798 * @brief Data about a coin for a deposit operation. 1799 */ 1800 struct TALER_EXCHANGEDB_CoinDepositInformation 1801 { 1802 /** 1803 * Information about the coin that is being deposited. 1804 */ 1805 struct TALER_CoinPublicInfo coin; 1806 1807 /** 1808 * ECDSA signature affirming that the customer intends 1809 * this coin to be deposited at the merchant identified 1810 * by @e h_wire in relation to the proposal data identified 1811 * by @e h_contract_terms. 1812 */ 1813 struct TALER_CoinSpendSignatureP csig; 1814 1815 /** 1816 * Fraction of the coin's remaining value to be deposited, including 1817 * depositing fee (if any). The coin is identified by @e coin_pub. 1818 */ 1819 struct TALER_Amount amount_with_fee; 1820 1821 }; 1822 1823 1824 /** 1825 * @brief Data from a batch deposit operation. 1826 */ 1827 struct TALER_EXCHANGEDB_BatchDeposit 1828 { 1829 1830 /** 1831 * Public key of the merchant. Enables later identification 1832 * of the merchant in case of a need to rollback transactions. 1833 */ 1834 struct TALER_MerchantPublicKeyP merchant_pub; 1835 1836 /** 1837 * Signature of the merchant over the contract, of purpose 1838 * #TALER_SIGNATURE_MERCHANT_CONTRACT. 1839 */ 1840 struct TALER_MerchantSignatureP merchant_sig; 1841 1842 /** 1843 * Hash over the proposal data between merchant and customer 1844 * (remains unknown to the Exchange). 1845 */ 1846 struct TALER_PrivateContractHashP h_contract_terms; 1847 1848 /** 1849 * Hash over additional inputs by the wallet. 1850 */ 1851 struct GNUNET_HashCode wallet_data_hash; 1852 1853 /** 1854 * Unsalted hash over @e receiver_wire_account. 1855 */ 1856 struct TALER_FullPaytoHashP wire_target_h_payto; 1857 1858 /** 1859 * Salt used by the merchant to compute "h_wire". 1860 */ 1861 struct TALER_WireSaltP wire_salt; 1862 1863 /** 1864 * Time when this request was generated. Used, for example, to 1865 * assess when (roughly) the income was achieved for tax purposes. 1866 * Note that the Exchange will only check that the timestamp is not "too 1867 * far" into the future (i.e. several days). The fact that the 1868 * timestamp falls within the validity period of the coin's 1869 * denomination key is irrelevant for the validity of the deposit 1870 * request, as obviously the customer and merchant could conspire to 1871 * set any timestamp. Also, the Exchange must accept very old deposit 1872 * requests, as the merchant might have been unable to transmit the 1873 * deposit request in a timely fashion (so back-dating is not 1874 * prevented). 1875 */ 1876 struct GNUNET_TIME_Timestamp wallet_timestamp; 1877 1878 /** 1879 * How much time does the merchant have to issue a refund request? 1880 * Zero if refunds are not allowed. After this time, the coin 1881 * cannot be refunded. 1882 */ 1883 struct GNUNET_TIME_Timestamp refund_deadline; 1884 1885 /** 1886 * How much time does the merchant have to execute the wire transfer? 1887 * This time is advisory for aggregating transactions, not a hard 1888 * constraint (as the merchant can theoretically pick any time, 1889 * including one in the past). 1890 */ 1891 struct GNUNET_TIME_Timestamp wire_deadline; 1892 1893 /** 1894 * Row ID of the policy details; 0 if no policy applies. 1895 */ 1896 uint64_t policy_details_serial_id; 1897 1898 /** 1899 * Information about the receiver for executing the transaction. URI in 1900 * payto://-format. 1901 */ 1902 struct TALER_FullPayto receiver_wire_account; 1903 1904 /** 1905 * Optional extra information to include in the wire transfer 1906 * subject. 1907 */ 1908 const char *extra_wire_subject_metadata; 1909 1910 /** 1911 * Array about the coins that are being deposited. 1912 */ 1913 const struct TALER_EXCHANGEDB_CoinDepositInformation *cdis; 1914 1915 /** 1916 * Length of the @e cdis array. 1917 */ 1918 unsigned int num_cdis; 1919 1920 /** 1921 * False if @e wallet_data_hash was provided 1922 */ 1923 bool no_wallet_data_hash; 1924 1925 /** 1926 * True if further processing is blocked by policy. 1927 */ 1928 bool policy_blocked; 1929 1930 }; 1931 1932 1933 /** 1934 * @brief Data from a deposit operation. The combination of 1935 * the coin's public key, the merchant's public key and the 1936 * transaction ID must be unique. While a coin can (theoretically) be 1937 * deposited at the same merchant twice (with partial spending), the 1938 * merchant must either use a different public key or a different 1939 * transaction ID for the two transactions. The same coin must not 1940 * be used twice at the same merchant for the same transaction 1941 * (as determined by transaction ID). 1942 */ 1943 struct TALER_EXCHANGEDB_Deposit 1944 { 1945 /** 1946 * Information about the coin that is being deposited. 1947 */ 1948 struct TALER_CoinPublicInfo coin; 1949 1950 /** 1951 * ECDSA signature affirming that the customer intends 1952 * this coin to be deposited at the merchant identified 1953 * by @e h_wire in relation to the proposal data identified 1954 * by @e h_contract_terms. 1955 */ 1956 struct TALER_CoinSpendSignatureP csig; 1957 1958 /** 1959 * Public key of the merchant. Enables later identification 1960 * of the merchant in case of a need to rollback transactions. 1961 */ 1962 struct TALER_MerchantPublicKeyP merchant_pub; 1963 1964 /** 1965 * Hash over the proposal data between merchant and customer 1966 * (remains unknown to the Exchange). 1967 */ 1968 struct TALER_PrivateContractHashP h_contract_terms; 1969 1970 /** 1971 * Salt used by the merchant to compute "h_wire". 1972 */ 1973 struct TALER_WireSaltP wire_salt; 1974 1975 /** 1976 * Hash over inputs from the wallet to customize the contract. 1977 */ 1978 struct GNUNET_HashCode wallet_data_hash; 1979 1980 /** 1981 * Hash over the policy data for this deposit (remains unknown to the 1982 * Exchange). Needed for the verification of the deposit's signature 1983 */ 1984 struct TALER_ExtensionPolicyHashP h_policy; 1985 1986 /** 1987 * Time when this request was generated. Used, for example, to 1988 * assess when (roughly) the income was achieved for tax purposes. 1989 * Note that the Exchange will only check that the timestamp is not "too 1990 * far" into the future (i.e. several days). The fact that the 1991 * timestamp falls within the validity period of the coin's 1992 * denomination key is irrelevant for the validity of the deposit 1993 * request, as obviously the customer and merchant could conspire to 1994 * set any timestamp. Also, the Exchange must accept very old deposit 1995 * requests, as the merchant might have been unable to transmit the 1996 * deposit request in a timely fashion (so back-dating is not 1997 * prevented). 1998 */ 1999 struct GNUNET_TIME_Timestamp timestamp; 2000 2001 /** 2002 * How much time does the merchant have to issue a refund request? 2003 * Zero if refunds are not allowed. After this time, the coin 2004 * cannot be refunded. 2005 */ 2006 struct GNUNET_TIME_Timestamp refund_deadline; 2007 2008 /** 2009 * How much time does the merchant have to execute the wire transfer? 2010 * This time is advisory for aggregating transactions, not a hard 2011 * constraint (as the merchant can theoretically pick any time, 2012 * including one in the past). 2013 */ 2014 struct GNUNET_TIME_Timestamp wire_deadline; 2015 2016 /** 2017 * Fraction of the coin's remaining value to be deposited, including 2018 * depositing fee (if any). The coin is identified by @e coin_pub. 2019 */ 2020 struct TALER_Amount amount_with_fee; 2021 2022 /** 2023 * Depositing fee. 2024 */ 2025 struct TALER_Amount deposit_fee; 2026 2027 /** 2028 * Information about the receiver for executing the transaction. URI in 2029 * payto://-format. 2030 */ 2031 struct TALER_FullPayto receiver_wire_account; 2032 2033 /** 2034 * True if @e policy_json was provided 2035 */ 2036 bool has_policy; 2037 2038 /** 2039 * True if @e wallet_data_hash is not in use. 2040 */ 2041 bool no_wallet_data_hash; 2042 2043 }; 2044 2045 2046 /** 2047 * @brief Specification for a deposit operation in the 2048 * `struct TALER_EXCHANGEDB_TransactionList`. 2049 */ 2050 struct TALER_EXCHANGEDB_DepositListEntry 2051 { 2052 2053 /** 2054 * ECDSA signature affirming that the customer intends 2055 * this coin to be deposited at the merchant identified 2056 * by @e h_wire in relation to the proposal data identified 2057 * by @e h_contract_terms. 2058 */ 2059 struct TALER_CoinSpendSignatureP csig; 2060 2061 /** 2062 * Public key of the merchant. Enables later identification 2063 * of the merchant in case of a need to rollback transactions. 2064 */ 2065 struct TALER_MerchantPublicKeyP merchant_pub; 2066 2067 /** 2068 * Hash over the proposa data between merchant and customer 2069 * (remains unknown to the Exchange). 2070 */ 2071 struct TALER_PrivateContractHashP h_contract_terms; 2072 2073 /** 2074 * Hash over inputs from the wallet to customize the contract. 2075 */ 2076 struct GNUNET_HashCode wallet_data_hash; 2077 2078 /** 2079 * Hash of the public denomination key used to sign the coin. 2080 */ 2081 struct TALER_DenominationHashP h_denom_pub; 2082 2083 /** 2084 * Age commitment hash, if applicable to the denomination. Should be all 2085 * zeroes if age commitment is not applicable to the denonimation. 2086 */ 2087 struct TALER_AgeCommitmentHashP h_age_commitment; 2088 2089 /** 2090 * Salt used to compute h_wire from the @e receiver_wire_account. 2091 */ 2092 struct TALER_WireSaltP wire_salt; 2093 2094 /** 2095 * Hash over the policy data for this deposit (remains unknown to the 2096 * Exchange). Needed for the verification of the deposit's signature 2097 */ 2098 struct TALER_ExtensionPolicyHashP h_policy; 2099 2100 /** 2101 * Fraction of the coin's remaining value to be deposited, including 2102 * depositing fee (if any). The coin is identified by @e coin_pub. 2103 */ 2104 struct TALER_Amount amount_with_fee; 2105 2106 /** 2107 * Depositing fee. 2108 */ 2109 struct TALER_Amount deposit_fee; 2110 2111 /** 2112 * Time when this request was generated. Used, for example, to 2113 * assess when (roughly) the income was achieved for tax purposes. 2114 * Note that the Exchange will only check that the timestamp is not "too 2115 * far" into the future (i.e. several days). The fact that the 2116 * timestamp falls within the validity period of the coin's 2117 * denomination key is irrelevant for the validity of the deposit 2118 * request, as obviously the customer and merchant could conspire to 2119 * set any timestamp. Also, the Exchange must accept very old deposit 2120 * requests, as the merchant might have been unable to transmit the 2121 * deposit request in a timely fashion (so back-dating is not 2122 * prevented). 2123 */ 2124 struct GNUNET_TIME_Timestamp timestamp; 2125 2126 /** 2127 * How much time does the merchant have to issue a refund request? 2128 * Zero if refunds are not allowed. After this time, the coin 2129 * cannot be refunded. 2130 */ 2131 struct GNUNET_TIME_Timestamp refund_deadline; 2132 2133 /** 2134 * How much time does the merchant have to execute the wire transfer? 2135 * This time is advisory for aggregating transactions, not a hard 2136 * constraint (as the merchant can theoretically pick any time, 2137 * including one in the past). 2138 */ 2139 struct GNUNET_TIME_Timestamp wire_deadline; 2140 2141 /** 2142 * Detailed information about the receiver for executing the transaction. 2143 * URL in payto://-format. 2144 */ 2145 struct TALER_FullPayto receiver_wire_account; 2146 2147 /** 2148 * true, if age commitment is not applicable 2149 */ 2150 bool no_age_commitment; 2151 2152 /** 2153 * true, if wallet data hash is not present 2154 */ 2155 bool no_wallet_data_hash; 2156 2157 /** 2158 * True if a policy was provided with the deposit request 2159 */ 2160 bool has_policy; 2161 2162 /** 2163 * Has the deposit been wired? 2164 */ 2165 bool done; 2166 2167 }; 2168 2169 2170 /** 2171 * @brief Specification for a refund operation in a coin's transaction list. 2172 */ 2173 struct TALER_EXCHANGEDB_RefundListEntry 2174 { 2175 2176 /** 2177 * Public key of the merchant. 2178 */ 2179 struct TALER_MerchantPublicKeyP merchant_pub; 2180 2181 /** 2182 * Signature from the merchant affirming the refund. 2183 */ 2184 struct TALER_MerchantSignatureP merchant_sig; 2185 2186 /** 2187 * Hash over the proposal data between merchant and customer 2188 * (remains unknown to the Exchange). 2189 */ 2190 struct TALER_PrivateContractHashP h_contract_terms; 2191 2192 /** 2193 * Merchant-generated REFUND transaction ID to detect duplicate 2194 * refunds. 2195 */ 2196 uint64_t rtransaction_id; 2197 2198 /** 2199 * Fraction of the original deposit's value to be refunded, including 2200 * refund fee (if any). The coin is identified by @e coin_pub. 2201 */ 2202 struct TALER_Amount refund_amount; 2203 2204 /** 2205 * Refund fee to be covered by the customer. 2206 */ 2207 struct TALER_Amount refund_fee; 2208 2209 }; 2210 2211 2212 /** 2213 * @brief Specification for a refund operation. The combination of 2214 * the coin's public key, the merchant's public key and the 2215 * transaction ID must be unique. While a coin can (theoretically) be 2216 * deposited at the same merchant twice (with partial spending), the 2217 * merchant must either use a different public key or a different 2218 * transaction ID for the two transactions. The same goes for 2219 * refunds, hence we also have a "rtransaction" ID which is disjoint 2220 * from the transaction ID. The same coin must not be used twice at 2221 * the same merchant for the same transaction or rtransaction ID. 2222 */ 2223 struct TALER_EXCHANGEDB_Refund 2224 { 2225 /** 2226 * Information about the coin that is being refunded. 2227 */ 2228 struct TALER_CoinPublicInfo coin; 2229 2230 /** 2231 * Details about the refund. 2232 */ 2233 struct TALER_EXCHANGEDB_RefundListEntry details; 2234 2235 }; 2236 2237 2238 /** 2239 * @brief Specification for coin in a melt operation. 2240 */ 2241 struct TALER_EXCHANGEDB_Refresh 2242 { 2243 /** 2244 * Information about the coin that is being melted. 2245 */ 2246 struct TALER_CoinPublicInfo coin; 2247 2248 /** 2249 * Signature over the melting operation. 2250 */ 2251 struct TALER_CoinSpendSignatureP coin_sig; 2252 2253 /** 2254 * Refresh commitment this coin is melted into. 2255 */ 2256 struct TALER_RefreshCommitmentP rc; 2257 2258 /** 2259 * How much value is being melted? This amount includes the fees, 2260 * so the final amount contributed to the melt is this value minus 2261 * the fee for melting the coin. We include the fee in what is 2262 * being signed so that we can verify a reserve's remaining total 2263 * balance without needing to access the respective denomination key 2264 * information each time. 2265 */ 2266 struct TALER_Amount amount_with_fee; 2267 2268 /** 2269 * Index (smaller #TALER_CNC_KAPPA) which the exchange has chosen to not 2270 * have revealed during cut and choose. 2271 */ 2272 uint32_t noreveal_index; 2273 2274 }; 2275 2276 2277 /** 2278 * Information about a /coins/$COIN_PUB/melt operation in a coin transaction history. 2279 */ 2280 struct TALER_EXCHANGEDB_MeltListEntry 2281 { 2282 2283 /** 2284 * Signature over the melting operation. 2285 */ 2286 struct TALER_CoinSpendSignatureP coin_sig; 2287 2288 /** 2289 * Refresh commitment this coin is melted into. 2290 */ 2291 struct TALER_RefreshCommitmentP rc; 2292 2293 /** 2294 * Hash of the public denomination key used to sign the coin. 2295 */ 2296 struct TALER_DenominationHashP h_denom_pub; 2297 2298 /** 2299 * Hash of the age commitment used to sign the coin, if age restriction was 2300 * applicable to the denomination. May be all zeroes if no age restriction 2301 * applies. 2302 */ 2303 struct TALER_AgeCommitmentHashP h_age_commitment; 2304 2305 /** 2306 * true, if no @e h_age_commitment is applicable 2307 */ 2308 bool no_age_commitment; 2309 2310 /** 2311 * How much value is being melted? This amount includes the fees, 2312 * so the final amount contributed to the melt is this value minus 2313 * the fee for melting the coin. We include the fee in what is 2314 * being signed so that we can verify a reserve's remaining total 2315 * balance without needing to access the respective denomination key 2316 * information each time. 2317 */ 2318 struct TALER_Amount amount_with_fee; 2319 2320 /** 2321 * Melt fee the exchange charged. 2322 */ 2323 struct TALER_Amount melt_fee; 2324 2325 /** 2326 * Index (smaller #TALER_CNC_KAPPA) which the exchange has chosen to not 2327 * have revealed during cut and choose. 2328 */ 2329 uint32_t noreveal_index; 2330 2331 /** 2332 * The refresh seed that was used for the melt operation 2333 */ 2334 struct TALER_PublicRefreshMasterSeedP refresh_seed; 2335 2336 /** 2337 * If false, @e blinding_seed is present 2338 */ 2339 bool no_blinding_seed; 2340 2341 /** 2342 * If @e no_blinding_seed it false, the blinding seed that was used 2343 * for the melt operation, in case of CS denominations. 2344 */ 2345 struct TALER_BlindingMasterSeedP blinding_seed; 2346 2347 }; 2348 2349 2350 /** 2351 * Information about a /purses/$PID/deposit operation in a coin transaction history. 2352 */ 2353 struct TALER_EXCHANGEDB_PurseDepositListEntry 2354 { 2355 2356 /** 2357 * Exchange hosting the purse, NULL for this exchange. 2358 */ 2359 char *exchange_base_url; 2360 2361 /** 2362 * Public key of the purse. 2363 */ 2364 struct TALER_PurseContractPublicKeyP purse_pub; 2365 2366 /** 2367 * Contribution of the coin to the purse, including 2368 * deposit fee. 2369 */ 2370 struct TALER_Amount amount; 2371 2372 /** 2373 * Depositing fee. 2374 */ 2375 struct TALER_Amount deposit_fee; 2376 2377 /** 2378 * Signature by the coin affirming the deposit. 2379 */ 2380 struct TALER_CoinSpendSignatureP coin_sig; 2381 2382 /** 2383 * Hash of the age commitment used to sign the coin, if age restriction was 2384 * applicable to the denomination. 2385 */ 2386 struct TALER_AgeCommitmentHashP h_age_commitment; 2387 2388 /** 2389 * Hash of the public denomination key used to sign the coin. 2390 */ 2391 struct TALER_DenominationHashP h_denom_pub; 2392 2393 /** 2394 * Set to true if the coin was refunded. 2395 */ 2396 bool refunded; 2397 2398 /** 2399 * Set to true if there was no age commitment. 2400 */ 2401 bool no_age_commitment; 2402 2403 }; 2404 2405 2406 /** 2407 * @brief Specification for a purse refund operation in a coin's transaction list. 2408 */ 2409 struct TALER_EXCHANGEDB_PurseRefundListEntry 2410 { 2411 2412 /** 2413 * Public key of the purse. 2414 */ 2415 struct TALER_PurseContractPublicKeyP purse_pub; 2416 2417 /** 2418 * Fraction of the original deposit's value to be refunded, including 2419 * refund fee (if any). The coin is identified by @e coin_pub. 2420 */ 2421 struct TALER_Amount refund_amount; 2422 2423 /** 2424 * Refund fee to be covered by the customer. 2425 */ 2426 struct TALER_Amount refund_fee; 2427 2428 }; 2429 2430 2431 /** 2432 * Information about a /reserves/$RID/open operation in a coin transaction history. 2433 */ 2434 struct TALER_EXCHANGEDB_ReserveOpenListEntry 2435 { 2436 2437 /** 2438 * Signature of the reserve. 2439 */ 2440 struct TALER_ReserveSignatureP reserve_sig; 2441 2442 /** 2443 * Contribution of the coin to the open fee, including 2444 * deposit fee. 2445 */ 2446 struct TALER_Amount coin_contribution; 2447 2448 /** 2449 * Signature by the coin affirming the open deposit. 2450 */ 2451 struct TALER_CoinSpendSignatureP coin_sig; 2452 2453 }; 2454 2455 2456 /** 2457 * Information about a /purses/$PID/deposit operation. 2458 */ 2459 struct TALER_EXCHANGEDB_PurseDeposit 2460 { 2461 2462 /** 2463 * Exchange hosting the purse, NULL for this exchange. 2464 */ 2465 char *exchange_base_url; 2466 2467 /** 2468 * Public key of the purse. 2469 */ 2470 struct TALER_PurseContractPublicKeyP purse_pub; 2471 2472 /** 2473 * Contribution of the coin to the purse, including 2474 * deposit fee. 2475 */ 2476 struct TALER_Amount amount; 2477 2478 /** 2479 * Depositing fee. 2480 */ 2481 struct TALER_Amount deposit_fee; 2482 2483 /** 2484 * Signature by the coin affirming the deposit. 2485 */ 2486 struct TALER_CoinSpendSignatureP coin_sig; 2487 2488 /** 2489 * Public key of the coin. 2490 */ 2491 struct TALER_CoinSpendPublicKeyP coin_pub; 2492 2493 /** 2494 * Hash of the age commitment used to sign the coin, if age restriction was 2495 * applicable to the denomination. May be all zeroes if no age restriction 2496 * applies. 2497 */ 2498 struct TALER_AgeCommitmentHashP h_age_commitment; 2499 2500 /** 2501 * Set to true if @e h_age_commitment is not available. 2502 */ 2503 bool no_age_commitment; 2504 2505 }; 2506 2507 /** 2508 * Information about a melt operation. 2509 */ 2510 struct TALER_EXCHANGEDB_Melt 2511 { 2512 2513 /** 2514 * Overall session data. 2515 */ 2516 struct TALER_EXCHANGEDB_Refresh session; 2517 2518 /** 2519 * Melt fee the exchange charged. 2520 */ 2521 struct TALER_Amount melt_fee; 2522 2523 }; 2524 2525 2526 /** 2527 * Information about a melt operation since vDOLDPLUS of the protocol. 2528 * This also includes the information for the reveal phase. 2529 */ 2530 struct TALER_EXCHANGEDB_Refresh_vDOLDPLUS 2531 { 2532 /** 2533 * Information about the coin that is being melted. 2534 */ 2535 struct TALER_CoinPublicInfo coin; 2536 2537 /** 2538 * Signature over the melting operation. 2539 */ 2540 struct TALER_CoinSpendSignatureP coin_sig; 2541 2542 /** 2543 * Refresh commitment this coin is melted into. 2544 */ 2545 struct TALER_RefreshCommitmentP rc; 2546 2547 /** 2548 * True if the client has successfully performed the reveal part 2549 * of the refresh protocol, after the melt. 2550 */ 2551 bool is_revealed; 2552 2553 /** 2554 * @since vDOLDPLUS 2555 * Mark if we have a v27 Refresh object. 2556 * That is, the @a refresh_seed refers to the vDOLDPLUS master_refresh_seed 2557 * from the original request, AND the client has provided transfer public keys, 2558 * see below, @a transfer_public_keys 2559 */ 2560 bool is_v27_refresh; 2561 2562 /** 2563 * Public seed from which the refresh nonces (v27) or transfer secrets (vDOLDPLUS) 2564 * per coin candidate were derived from. 2565 */ 2566 struct TALER_PublicRefreshMasterSeedP refresh_seed; 2567 2568 /** 2569 * How much value is being melted? This amount includes the fees, 2570 * so the final amount contributed to the melt is this value minus 2571 * the fee for melting the coin. We include the fee in what is 2572 * being signed so that we can verify a reserve's remaining total 2573 * balance without needing to access the respective denomination key 2574 * information each time. 2575 */ 2576 struct TALER_Amount amount_with_fee; 2577 2578 /** 2579 * Number of coins to be refreshed into 2580 */ 2581 size_t num_coins; 2582 2583 /** 2584 * The running hash over all kappa * @a num_coins blinded coin envelopes, provided by 2585 * the client. 2586 */ 2587 struct TALER_HashBlindedPlanchetsP planchets_h; 2588 2589 /** 2590 * The running hash over all chosen (noreveal_index) @a num_coins blinded coin envelopes. 2591 */ 2592 struct TALER_HashBlindedPlanchetsP selected_h; 2593 2594 /** 2595 * Array of @a num_coins denomination signatures of the blinded coins. 2596 */ 2597 struct TALER_BlindedDenominationSignature *denom_sigs; 2598 2599 /** 2600 * If @a is_v27_refresh is false, the client performed a vDOLDPLUS refresh, 2601 * and has provided @a num_coins * kappa transfer public keys. 2602 * This is the chosen (at index @a noreveal_index) array of @a num_coins transfer public keys. 2603 */ 2604 struct TALER_TransferPublicKeyP *transfer_pubs; 2605 2606 /** 2607 * Array of @a num_coins serial id's of the denominations. 2608 * If @e coin.no_age_commitment is false, the denominations 2609 * MUST support age restriction. 2610 */ 2611 uint64_t *denom_serials; 2612 2613 /** 2614 * Index (smaller #TALER_CNC_KAPPA) which the exchange chose to not 2615 * to be revealed during cut and choose. 2616 */ 2617 uint32_t noreveal_index; 2618 2619 /** 2620 * True, if the client has successfully performed the reveal step 2621 */ 2622 bool revealed; 2623 2624 /** 2625 * If true, no @e blinding_seed is set and @e num_cs_r_values is 0. 2626 */ 2627 bool no_blinding_seed; 2628 2629 /** 2630 * If @e no_blinding_seed is false, the blinding seed for the nonces needed for 2631 * blind CS signatures. 2632 */ 2633 struct TALER_BlindingMasterSeedP blinding_seed; 2634 2635 /** 2636 * Number of elements in @e cs_r_values. 2637 */ 2638 size_t num_cs_r_values; 2639 2640 /** 2641 * Array @e num_cs_r_values of public R-values for CS that were generated from the 2642 * @e blinding_seed, a coin's index and the denomination's private key during the 2643 * the /melt request, to ensure idempotency in case of expiration of a denomination. 2644 * NULL if @e num_cs_r_values is 0. 2645 */ 2646 struct GNUNET_CRYPTO_CSPublicRPairP *cs_r_values; 2647 2648 /** 2649 * If @e num_cs_r_values is not 0, the bitvector of choices for the pairs 2650 * in @e cs_r_values that was made by the exchange. The vector is in NBO 2651 * and the lowest bit represents the choice for the pair at index 0 into @e cs_r_values; 2652 */ 2653 uint64_t cs_r_choices; 2654 2655 /** 2656 * [out]-Array of @a num_coins hashes of the public keys of the denominations 2657 * identified by @e denom_serials. This field is set when calling 2658 * get_refresh 2659 */ 2660 struct TALER_DenominationHashP *denom_pub_hashes; 2661 }; 2662 2663 2664 /** 2665 * @brief Linked list of refresh information linked to a coin. 2666 */ 2667 struct TALER_EXCHANGEDB_LinkList 2668 { 2669 /** 2670 * Information is stored in a NULL-terminated linked list. 2671 */ 2672 struct TALER_EXCHANGEDB_LinkList *next; 2673 2674 /** 2675 * Denomination public key, determines the value of the coin. 2676 */ 2677 struct TALER_DenominationPublicKey denom_pub; 2678 2679 /** 2680 * Signature over the blinded envelope. 2681 */ 2682 struct TALER_BlindedDenominationSignature ev_sig; 2683 2684 /** 2685 * Exchange-provided values during the coin generation. 2686 */ 2687 struct TALER_ExchangeBlindingValues alg_values; 2688 2689 /** 2690 * Signature of the original coin being refreshed over the 2691 * link data, of type #TALER_SIGNATURE_WALLET_COIN_LINK 2692 */ 2693 struct TALER_CoinSpendSignatureP orig_coin_link_sig; 2694 2695 /** 2696 * Session nonce, if cipher has one. 2697 */ 2698 union GNUNET_CRYPTO_BlindSessionNonce nonce; 2699 2700 /** 2701 * Offset that generated this coin in the refresh 2702 * operation. 2703 */ 2704 uint32_t coin_refresh_offset; 2705 2706 /** 2707 * Set to true if @e nonce was initialized. 2708 */ 2709 bool have_nonce; 2710 }; 2711 2712 2713 /** 2714 * @brief Enumeration to classify the different types of transactions 2715 * that can be done with a coin. 2716 */ 2717 enum TALER_EXCHANGEDB_TransactionType 2718 { 2719 2720 /** 2721 * Deposit operation. 2722 */ 2723 TALER_EXCHANGEDB_TT_DEPOSIT = 0, 2724 2725 /** 2726 * Melt operation. 2727 */ 2728 TALER_EXCHANGEDB_TT_MELT = 1, 2729 2730 /** 2731 * Refund operation. 2732 */ 2733 TALER_EXCHANGEDB_TT_REFUND = 2, 2734 2735 /** 2736 * Recoup-refresh operation (on the old coin, adding to the old coin's value) 2737 */ 2738 TALER_EXCHANGEDB_TT_RECOUP_REFRESH_RECEIVER = 3, 2739 2740 /** 2741 * Recoup operation. 2742 */ 2743 TALER_EXCHANGEDB_TT_RECOUP_WITHDRAW = 4, 2744 2745 /** 2746 * Recoup-refresh operation (on the new coin, eliminating its value) 2747 */ 2748 TALER_EXCHANGEDB_TT_RECOUP_REFRESH = 5, 2749 2750 /** 2751 * Purse deposit operation. 2752 */ 2753 TALER_EXCHANGEDB_TT_PURSE_DEPOSIT = 6, 2754 2755 /** 2756 * Purse deposit operation. 2757 */ 2758 TALER_EXCHANGEDB_TT_PURSE_REFUND = 7, 2759 2760 /** 2761 * Reserve open deposit operation. 2762 */ 2763 TALER_EXCHANGEDB_TT_RESERVE_OPEN = 8 2764 2765 }; 2766 2767 2768 /** 2769 * @brief List of transactions we performed for a particular coin. 2770 */ 2771 struct TALER_EXCHANGEDB_TransactionList 2772 { 2773 2774 /** 2775 * Next pointer in the NULL-terminated linked list. 2776 */ 2777 struct TALER_EXCHANGEDB_TransactionList *next; 2778 2779 /** 2780 * Type of the transaction, determines what is stored in @e details. 2781 */ 2782 enum TALER_EXCHANGEDB_TransactionType type; 2783 2784 /** 2785 * Serial ID of this entry in the @e type-specific table. 2786 */ 2787 uint64_t serial_id; 2788 2789 /** 2790 * Serial ID of this entry in the coin history table. 2791 */ 2792 uint64_t coin_history_id; 2793 2794 /** 2795 * Details about the transaction, depending on @e type. 2796 */ 2797 union 2798 { 2799 2800 /** 2801 * Details if transaction was a deposit operation. 2802 * (#TALER_EXCHANGEDB_TT_DEPOSIT) 2803 */ 2804 struct TALER_EXCHANGEDB_DepositListEntry *deposit; 2805 2806 /** 2807 * Details if transaction was a melt operation. 2808 * (#TALER_EXCHANGEDB_TT_MELT) 2809 */ 2810 struct TALER_EXCHANGEDB_MeltListEntry *melt; 2811 2812 /** 2813 * Details if transaction was a refund operation. 2814 * (#TALER_EXCHANGEDB_TT_REFUND) 2815 */ 2816 struct TALER_EXCHANGEDB_RefundListEntry *refund; 2817 2818 /** 2819 * Details if transaction was a recoup-refund operation where 2820 * this coin was the OLD coin. 2821 * (#TALER_EXCHANGEDB_TT_RECOUP_REFRESH_RECEIVER). 2822 */ 2823 struct TALER_EXCHANGEDB_RecoupRefreshListEntry *old_coin_recoup; 2824 2825 /** 2826 * Details if transaction was a recoup operation. 2827 * (#TALER_EXCHANGEDB_TT_RECOUP_WITHDRAW) 2828 */ 2829 struct TALER_EXCHANGEDB_RecoupListEntry *recoup; 2830 2831 /** 2832 * Details if transaction was a recoup-refund operation where 2833 * this coin was the REFRESHED coin. 2834 * (#TALER_EXCHANGEDB_TT_RECOUP_REFRESH) 2835 */ 2836 struct TALER_EXCHANGEDB_RecoupRefreshListEntry *recoup_refresh; 2837 2838 /** 2839 * Coin was deposited into a purse. 2840 * (#TALER_EXCHANGEDB_TT_PURSE_DEPOSIT) 2841 */ 2842 struct TALER_EXCHANGEDB_PurseDepositListEntry *purse_deposit; 2843 2844 /** 2845 * Coin was refunded upon purse expiration 2846 * (#TALER_EXCHANGEDB_TT_PURSE_REFUND) 2847 */ 2848 struct TALER_EXCHANGEDB_PurseRefundListEntry *purse_refund; 2849 2850 /** 2851 * Coin was used to pay to open a reserve. 2852 * (#TALER_EXCHANGEDB_TT_RESERVE_OPEN) 2853 */ 2854 struct TALER_EXCHANGEDB_ReserveOpenListEntry *reserve_open; 2855 2856 } details; 2857 2858 }; 2859 2860 2861 /** 2862 * Callback with data about a prepared wire transfer. 2863 * 2864 * @param cls closure 2865 * @param rowid row identifier used to mark prepared transaction as done 2866 * @param wire_method which wire method is this preparation data for 2867 * @param buf transaction data that was persisted, NULL on error 2868 * @param buf_size number of bytes in @a buf, 0 on error 2869 */ 2870 typedef void 2871 (*TALER_EXCHANGEDB_WirePreparationIterator) (void *cls, 2872 uint64_t rowid, 2873 const char *wire_method, 2874 const char *buf, 2875 size_t buf_size); 2876 2877 2878 /** 2879 * Callback with KYC attributes about a particular user. 2880 * 2881 * @param cls closure 2882 * @param h_payto account for which the attribute data is stored 2883 * @param provider_name provider that must be checked 2884 * @param collection_time when was the data collected 2885 * @param expiration_time when does the data expire 2886 * @param enc_attributes_size number of bytes in @a enc_attributes 2887 * @param enc_attributes encrypted attribute data 2888 */ 2889 typedef void 2890 (*TALER_EXCHANGEDB_AttributeCallback)( 2891 void *cls, 2892 const struct TALER_NormalizedPaytoHashP *h_payto, 2893 const char *provider_name, 2894 struct GNUNET_TIME_Timestamp collection_time, 2895 struct GNUNET_TIME_Timestamp expiration_time, 2896 size_t enc_attributes_size, 2897 const void *enc_attributes); 2898 2899 2900 /** 2901 * Function called with details about deposits that have been made, 2902 * with the goal of auditing the deposit's execution. 2903 * 2904 * @param cls closure 2905 * @param rowid unique serial ID for the deposit in our DB 2906 * @param exchange_timestamp when did the deposit happen 2907 * @param deposit deposit details 2908 * @param denom_pub denomination public key of @a coin_pub 2909 * @param done flag set if the deposit was already executed (or not) 2910 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 2911 */ 2912 typedef enum GNUNET_GenericReturnValue 2913 (*TALER_EXCHANGEDB_DepositCallback)( 2914 void *cls, 2915 uint64_t rowid, 2916 struct GNUNET_TIME_Timestamp exchange_timestamp, 2917 const struct TALER_EXCHANGEDB_Deposit *deposit, 2918 const struct TALER_DenominationPublicKey *denom_pub, 2919 bool done); 2920 2921 2922 /** 2923 * Function called with details about purse deposits that have been made, with 2924 * the goal of auditing the deposit's execution. 2925 * 2926 * @param cls closure 2927 * @param rowid unique serial ID for the deposit in our DB 2928 * @param deposit deposit details 2929 * @param reserve_pub which reserve is the purse merged into, NULL if unknown 2930 * @param flags purse flags 2931 * @param auditor_balance purse balance (according to the 2932 * auditor during auditing) 2933 * @param purse_total target amount the purse should reach 2934 * @param denom_pub denomination public key of @a coin_pub 2935 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 2936 */ 2937 typedef enum GNUNET_GenericReturnValue 2938 (*TALER_EXCHANGEDB_PurseDepositCallback)( 2939 void *cls, 2940 uint64_t rowid, 2941 const struct TALER_EXCHANGEDB_PurseDeposit *deposit, 2942 const struct TALER_ReservePublicKeyP *reserve_pub, 2943 enum TALER_WalletAccountMergeFlags flags, 2944 const struct TALER_Amount *auditor_balance, 2945 const struct TALER_Amount *purse_total, 2946 const struct TALER_DenominationPublicKey *denom_pub); 2947 2948 2949 /** 2950 * Function called with details about 2951 * account merge requests that have been made, with 2952 * the goal of auditing the account merge execution. 2953 * 2954 * @param cls closure 2955 * @param rowid unique serial ID for the deposit in our DB 2956 * @param reserve_pub reserve affected by the merge 2957 * @param purse_pub purse being merged 2958 * @param h_contract_terms hash over contract of the purse 2959 * @param purse_expiration when would the purse expire 2960 * @param amount total amount in the purse 2961 * @param min_age minimum age of all coins deposited into the purse 2962 * @param flags how was the purse created 2963 * @param purse_fee if a purse fee was paid, how high is it 2964 * @param merge_timestamp when was the merge approved 2965 * @param reserve_sig signature by reserve approving the merge 2966 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 2967 */ 2968 typedef enum GNUNET_GenericReturnValue 2969 (*TALER_EXCHANGEDB_AccountMergeCallback)( 2970 void *cls, 2971 uint64_t rowid, 2972 const struct TALER_ReservePublicKeyP *reserve_pub, 2973 const struct TALER_PurseContractPublicKeyP *purse_pub, 2974 const struct TALER_PrivateContractHashP *h_contract_terms, 2975 struct GNUNET_TIME_Timestamp purse_expiration, 2976 const struct TALER_Amount *amount, 2977 uint32_t min_age, 2978 enum TALER_WalletAccountMergeFlags flags, 2979 const struct TALER_Amount *purse_fee, 2980 struct GNUNET_TIME_Timestamp merge_timestamp, 2981 const struct TALER_ReserveSignatureP *reserve_sig); 2982 2983 2984 /** 2985 * Function called with details about purse 2986 * merges that have been made, with 2987 * the goal of auditing the purse merge execution. 2988 * 2989 * @param cls closure 2990 * @param rowid unique serial ID for the deposit in our DB 2991 * @param partner_base_url where is the reserve, NULL for this exchange 2992 * @param amount total amount expected in the purse 2993 * @param balance current balance in the purse (according to the auditor) 2994 * @param flags purse flags 2995 * @param merge_pub merge capability key 2996 * @param reserve_pub reserve the merge affects 2997 * @param merge_sig signature affirming the merge 2998 * @param purse_pub purse key 2999 * @param merge_timestamp when did the merge happen 3000 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 3001 */ 3002 typedef enum GNUNET_GenericReturnValue 3003 (*TALER_EXCHANGEDB_PurseMergeCallback)( 3004 void *cls, 3005 uint64_t rowid, 3006 const char *partner_base_url, 3007 const struct TALER_Amount *amount, 3008 const struct TALER_Amount *balance, 3009 enum TALER_WalletAccountMergeFlags flags, 3010 const struct TALER_PurseMergePublicKeyP *merge_pub, 3011 const struct TALER_ReservePublicKeyP *reserve_pub, 3012 const struct TALER_PurseMergeSignatureP *merge_sig, 3013 const struct TALER_PurseContractPublicKeyP *purse_pub, 3014 struct GNUNET_TIME_Timestamp merge_timestamp); 3015 3016 3017 /** 3018 * Function called with details about purse decisions that have been made, with 3019 * the goal of auditing the purse's execution. 3020 * 3021 * @param cls closure 3022 * @param rowid unique serial ID for the deposit in our DB 3023 * @param purse_pub public key of the purse 3024 * @param reserve_pub public key of the target reserve, NULL if not known / refunded 3025 * @param purse_value what is the (target) value of the purse 3026 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 3027 */ 3028 typedef enum GNUNET_GenericReturnValue 3029 (*TALER_EXCHANGEDB_PurseDecisionCallback)( 3030 void *cls, 3031 uint64_t rowid, 3032 const struct TALER_PurseContractPublicKeyP *purse_pub, 3033 const struct TALER_ReservePublicKeyP *reserve_pub, 3034 const struct TALER_Amount *purse_value); 3035 3036 3037 /** 3038 * Function called with details about purse decisions that have been made, with 3039 * the goal of auditing the purse's execution. 3040 * 3041 * @param cls closure 3042 * @param rowid unique serial ID for the deposit in our DB 3043 * @param purse_pub public key of the purse 3044 * @param refunded true if decision was to refund 3045 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 3046 */ 3047 typedef enum GNUNET_GenericReturnValue 3048 (*TALER_EXCHANGEDB_AllPurseDecisionCallback)( 3049 void *cls, 3050 uint64_t rowid, 3051 const struct TALER_PurseContractPublicKeyP *purse_pub, 3052 bool refunded); 3053 3054 3055 /** 3056 * Function called with details about purse deletions that have been made, with 3057 * the goal of auditing the purse's execution. 3058 * 3059 * @param cls closure 3060 * @param rowid unique serial ID for the deposit in our DB 3061 * @param purse_pub public key of the purse 3062 * @param purse_sig signature affirming deletion of the purse 3063 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 3064 */ 3065 typedef enum GNUNET_GenericReturnValue 3066 (*TALER_EXCHANGEDB_AllPurseDeletionsCallback)( 3067 void *cls, 3068 uint64_t rowid, 3069 const struct TALER_PurseContractPublicKeyP *purse_pub, 3070 const struct TALER_PurseContractSignatureP *purse_sig); 3071 3072 3073 /** 3074 * Function called with details about purse refunds that have been made, with 3075 * the goal of auditing the purse refund's execution. 3076 * 3077 * @param cls closure 3078 * @param rowid row of the refund event 3079 * @param amount_with_fee amount of the deposit into the purse 3080 * @param coin_pub coin that is to be refunded the @a given amount_with_fee 3081 * @param denom_pub denomination of @a coin_pub 3082 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 3083 */ 3084 typedef enum GNUNET_GenericReturnValue 3085 (*TALER_EXCHANGEDB_PurseRefundCoinCallback)( 3086 void *cls, 3087 uint64_t rowid, 3088 const struct TALER_Amount *amount_with_fee, 3089 const struct TALER_CoinSpendPublicKeyP *coin_pub, 3090 const struct TALER_DenominationPublicKey *denom_pub); 3091 3092 3093 /** 3094 * Function called with details about coins that were melted, 3095 * with the goal of auditing the refresh's execution. 3096 * 3097 * @param cls closure 3098 * @param rowid unique serial ID for the refresh session in our DB 3099 * @param old_denom_pub denomination public key of @a coin_pub 3100 * @param coin_pub public key of the coin 3101 * @param coin_sig signature from the coin 3102 * @param h_age_commitment hash of the age commitment for the coin 3103 * @param amount_with_fee amount that was deposited including fee 3104 * @param num_nds length of the @a new_denom_serials array 3105 * @param new_denom_serials array of denomination serials of fresh coins 3106 * @param rc what the refresh commitment 3107 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 3108 */ 3109 typedef enum GNUNET_GenericReturnValue 3110 (*TALER_EXCHANGEDB_RefreshesCallback)( 3111 void *cls, 3112 uint64_t rowid, 3113 const struct TALER_DenominationPublicKey *old_denom_pub, 3114 const struct TALER_CoinSpendPublicKeyP *coin_pub, 3115 const struct TALER_CoinSpendSignatureP *coin_sig, 3116 const struct TALER_AgeCommitmentHashP *h_age_commitment, 3117 const struct TALER_Amount *amount_with_fee, 3118 size_t num_nds, 3119 uint64_t new_denom_serials[static num_nds], 3120 const struct TALER_RefreshCommitmentP *rc); 3121 3122 3123 /** 3124 * Callback invoked with information about refunds applicable 3125 * to a particular coin and contract. 3126 * 3127 * @param cls closure 3128 * @param amount_with_fee amount being refunded 3129 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 3130 */ 3131 typedef enum GNUNET_GenericReturnValue 3132 (*TALER_EXCHANGEDB_RefundCoinCallback)( 3133 void *cls, 3134 const struct TALER_Amount *amount_with_fee); 3135 3136 3137 /** 3138 * Information per Clause-Schnorr (CS) fresh coin to 3139 * be persisted for idempotency during refreshes-reveal. 3140 */ 3141 struct TALER_EXCHANGEDB_CsRevealFreshCoinData 3142 { 3143 /** 3144 * Denomination of the fresh coin. 3145 */ 3146 struct TALER_DenominationHashP new_denom_pub_hash; 3147 3148 /** 3149 * Blind signature of the fresh coin (possibly updated 3150 * in case if a replay!). 3151 */ 3152 struct TALER_BlindedDenominationSignature bsig; 3153 3154 /** 3155 * Offset of the fresh coin in the reveal operation. 3156 * (May not match the array offset as we may have 3157 * a mixture of RSA and CS coins being created, and 3158 * this request is only made for the CS subset). 3159 */ 3160 uint32_t coin_off; 3161 }; 3162 3163 3164 /** 3165 * Generic KYC status for some operation. 3166 */ 3167 struct TALER_EXCHANGEDB_KycStatus 3168 { 3169 3170 /** 3171 * Account public key that is currently associated 3172 * with the account. Only set if @e have_account_pub 3173 * is true. 3174 */ 3175 union TALER_AccountPublicKeyP account_pub; 3176 3177 /** 3178 * Number that identifies the KYC requirement the operation 3179 * was about. 3180 */ 3181 uint64_t requirement_row; 3182 3183 /** 3184 * True if @e account_pub is set. 3185 */ 3186 bool have_account_pub; 3187 3188 /** 3189 * True if the KYC status is "satisfied". 3190 */ 3191 bool ok; 3192 3193 }; 3194 3195 3196 struct TALER_EXCHANGEDB_ReserveInInfo 3197 { 3198 const struct TALER_ReservePublicKeyP *reserve_pub; 3199 const struct TALER_Amount *balance; 3200 struct GNUNET_TIME_Timestamp execution_time; 3201 struct TALER_FullPayto sender_account_details; 3202 const char *exchange_account_name; 3203 uint64_t wire_reference; 3204 }; 3205 3206 3207 /** 3208 * Function called on each @a amount that was found to 3209 * be relevant for a KYC check. 3210 * 3211 * @param cls closure to allow the KYC module to 3212 * total up amounts and evaluate rules 3213 * @param amount encountered transaction amount 3214 * @param date when was the amount encountered 3215 * @return #GNUNET_OK to continue to iterate, 3216 * #GNUNET_NO to abort iteration 3217 * #GNUNET_SYSERR on internal error (also abort itaration) 3218 */ 3219 typedef enum GNUNET_GenericReturnValue 3220 (*TALER_EXCHANGEDB_KycAmountCallback)( 3221 void *cls, 3222 const struct TALER_Amount *amount, 3223 struct GNUNET_TIME_Absolute date); 3224 3225 3226 /** 3227 * Function called with details about coins that were refunding, 3228 * with the goal of auditing the refund's execution. 3229 * 3230 * @param cls closure 3231 * @param rowid unique serial ID for the refund in our DB 3232 * @param denom_pub denomination public key of @a coin_pub 3233 * @param coin_pub public key of the coin 3234 * @param merchant_pub public key of the merchant 3235 * @param merchant_sig signature of the merchant 3236 * @param h_contract_terms hash of the proposal data known to merchant and customer 3237 * @param rtransaction_id refund transaction ID chosen by the merchant 3238 * @param full_refund true if the refunds total up to the entire value of the deposit 3239 * @param amount_with_fee amount that was deposited including fee 3240 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 3241 */ 3242 typedef enum GNUNET_GenericReturnValue 3243 (*TALER_EXCHANGEDB_RefundCallback)( 3244 void *cls, 3245 uint64_t rowid, 3246 const struct TALER_DenominationPublicKey *denom_pub, 3247 const struct TALER_CoinSpendPublicKeyP *coin_pub, 3248 const struct TALER_MerchantPublicKeyP *merchant_pub, 3249 const struct TALER_MerchantSignatureP *merchant_sig, 3250 const struct TALER_PrivateContractHashP *h_contract_terms, 3251 uint64_t rtransaction_id, 3252 bool full_refund, 3253 const struct TALER_Amount *amount_with_fee); 3254 3255 3256 /** 3257 * Function called with details about incoming wire transfers. 3258 * 3259 * @param cls closure 3260 * @param rowid unique serial ID for the refresh session in our DB 3261 * @param reserve_pub public key of the reserve (also the wire subject) 3262 * @param credit amount that was received 3263 * @param sender_account_details information about the sender's bank account, in payto://-format 3264 * @param wire_reference unique identifier for the wire transfer 3265 * @param execution_date when did we receive the funds 3266 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 3267 */ 3268 typedef enum GNUNET_GenericReturnValue 3269 (*TALER_EXCHANGEDB_ReserveInCallback)( 3270 void *cls, 3271 uint64_t rowid, 3272 const struct TALER_ReservePublicKeyP *reserve_pub, 3273 const struct TALER_Amount *credit, 3274 const struct TALER_FullPayto sender_account_details, 3275 uint64_t wire_reference, 3276 struct GNUNET_TIME_Timestamp execution_date); 3277 3278 3279 /** 3280 * Provide information about a wire account. 3281 * 3282 * @param cls closure 3283 * @param payto_uri the exchange bank account URI 3284 * @param conversion_url URL of a conversion service, NULL if there is no conversion 3285 * @param open_banking_gateway open banking gateway service, NULL if unavailable 3286 * @param wire_transfer_gateway wire transfer gateway service, NULL if unavailable 3287 * @param debit_restrictions JSON array with debit restrictions on the account 3288 * @param credit_restrictions JSON array with credit restrictions on the account 3289 * @param master_sig master key signature affirming that this is a bank 3290 * account of the exchange (of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS) 3291 * @param bank_label label the wallet should use to display the account, can be NULL 3292 * @param priority priority for ordering bank account labels 3293 */ 3294 typedef void 3295 (*TALER_EXCHANGEDB_WireAccountCallback)( 3296 void *cls, 3297 const struct TALER_FullPayto payto_uri, 3298 const char *conversion_url, 3299 const char *open_banking_gateway, 3300 const char *wire_transfer_gateway, 3301 const json_t *debit_restrictions, 3302 const json_t *credit_restrictions, 3303 const struct TALER_MasterSignatureP *master_sig, 3304 const char *bank_label, 3305 int64_t priority); 3306 3307 3308 /** 3309 * Function called with historic AML events of an 3310 * account. 3311 * 3312 * @param cls closure 3313 * @param outcome_serial_id row ID of the decision 3314 * @param decision_time when was the decision taken 3315 * @param justification what was the given justification 3316 * @param decider_pub which key signed the decision 3317 * @param jproperties what are the new account properties 3318 * @param jnew_rules what are the new account rules 3319 * @param to_investigate should AML staff investigate 3320 * after the decision 3321 * @param is_active is this the active decision 3322 */ 3323 typedef void 3324 (*TALER_EXCHANGEDB_AmlHistoryCallback) ( 3325 void *cls, 3326 uint64_t outcome_serial_id, 3327 struct GNUNET_TIME_Timestamp decision_time, 3328 const char *justification, 3329 const struct TALER_AmlOfficerPublicKeyP *decider_pub, 3330 const json_t *jproperties, 3331 const json_t *jnew_rules, 3332 bool to_investigate, 3333 bool is_active); 3334 3335 3336 /** 3337 * Function called with historic KYC events of an 3338 * account. 3339 * 3340 * @param cls closure 3341 * @param provider_name name of the KYC provider 3342 * @param finished did the KYC process finish 3343 * @param error_code error code from the KYC process 3344 * @param error_message error message from the KYC process, 3345 * or NULL for none 3346 * @param provider_user_id user ID at the provider 3347 * or NULL for none 3348 * @param provider_legitimization_id legitimization process ID at the provider 3349 * or NULL for none 3350 * @param collection_time when was the data collected 3351 * @param expiration_time when does the collected data expire 3352 * @param encrypted_attributes_len number of bytes in @a encrypted_attributes 3353 * @param encrypted_attributes encrypted KYC attributes 3354 */ 3355 typedef void 3356 (*TALER_EXCHANGEDB_KycHistoryCallback) ( 3357 void *cls, 3358 const char *provider_name, 3359 bool finished, 3360 enum TALER_ErrorCode error_code, 3361 const char *error_message, 3362 const char *provider_user_id, 3363 const char *provider_legitimization_id, 3364 struct GNUNET_TIME_Timestamp collection_time, 3365 struct GNUNET_TIME_Absolute expiration_time, 3366 size_t encrypted_attributes_len, 3367 const void *encrypted_attributes); 3368 3369 3370 /** 3371 * Function called with legitimization measures. 3372 * 3373 * @param cls closure 3374 * @param h_payto hash of account the measure applies to 3375 * @param start_time when was the process started 3376 * @param jmeasures object of type ``LegitimizationMeasures`` 3377 * @param is_finished true if the measure was finished 3378 * @param measure_serial_id row ID of the measure in the exchange table 3379 */ 3380 typedef void 3381 (*TALER_EXCHANGEDB_LegitimizationMeasureCallback) ( 3382 void *cls, 3383 struct TALER_NormalizedPaytoHashP *h_payto, 3384 struct GNUNET_TIME_Absolute start_time, 3385 const json_t *jmeasures, 3386 bool is_finished, 3387 uint64_t measure_serial_id); 3388 3389 3390 /** 3391 * Provide information about wire fees. 3392 * 3393 * @param cls closure 3394 * @param fees the wire fees we charge 3395 * @param start_date from when are these fees valid (start date) 3396 * @param end_date until when are these fees valid (end date, exclusive) 3397 * @param master_sig master key signature affirming that this is the correct 3398 * fee (of purpose #TALER_SIGNATURE_MASTER_WIRE_FEES) 3399 */ 3400 typedef void 3401 (*TALER_EXCHANGEDB_WireFeeCallback)( 3402 void *cls, 3403 const struct TALER_WireFeeSet *fees, 3404 struct GNUNET_TIME_Timestamp start_date, 3405 struct GNUNET_TIME_Timestamp end_date, 3406 const struct TALER_MasterSignatureP *master_sig); 3407 3408 3409 /** 3410 * Provide information about global fees. 3411 * 3412 * @param cls closure 3413 * @param fees the global fees we charge 3414 * @param purse_timeout when do purses time out 3415 * @param history_expiration how long are account histories preserved 3416 * @param purse_account_limit how many purses are free per account 3417 * @param start_date from when are these fees valid (start date) 3418 * @param end_date until when are these fees valid (end date, exclusive) 3419 * @param master_sig master key signature affirming that this is the correct 3420 * fee (of purpose #TALER_SIGNATURE_MASTER_GLOBAL_FEES) 3421 */ 3422 typedef void 3423 (*TALER_EXCHANGEDB_GlobalFeeCallback)( 3424 void *cls, 3425 const struct TALER_GlobalFeeSet *fees, 3426 struct GNUNET_TIME_Relative purse_timeout, 3427 struct GNUNET_TIME_Relative history_expiration, 3428 uint32_t purse_account_limit, 3429 struct GNUNET_TIME_Timestamp start_date, 3430 struct GNUNET_TIME_Timestamp end_date, 3431 const struct TALER_MasterSignatureP *master_sig); 3432 3433 3434 /** 3435 * Function called with details about withdraw operations. 3436 * 3437 * @param cls closure 3438 * @param rowid unique serial ID for the refresh session in our DB 3439 * @param num_denom_serials number of elements in @e denom_serials array 3440 * @param denom_serials array with length @e num_denom_serials of serial ID's of denominations in our DB 3441 * @param selected_h hash over the gamma-selected planchets 3442 * @param h_planchets running hash over all hashes of blinded planchets in the original withdraw request 3443 * @param blinding_seed the blinding seed for CS denominations that was provided during withdraw; might be NULL 3444 * @param age_proof_required true if the withdraw request required an age proof. 3445 * @param max_age if @e age_proof_required is true, the maximum age that was set on the coins. 3446 * @param noreveal_index if @e age_proof_required is true, the index that was returned by the exchange for the reveal phase. 3447 * @param reserve_pub public key of the reserve 3448 * @param reserve_sig signature over the withdraw operation 3449 * @param execution_date when did the wallet withdraw the coin 3450 * @param amount_with_fee amount that was withdrawn 3451 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 3452 */ 3453 typedef enum GNUNET_GenericReturnValue 3454 (*TALER_EXCHANGEDB_WithdrawCallback)( 3455 void *cls, 3456 uint64_t rowid, 3457 size_t num_denom_serials, 3458 const uint64_t *denom_serials, 3459 const struct TALER_HashBlindedPlanchetsP *selected_h, 3460 const struct TALER_HashBlindedPlanchetsP *h_planchets, 3461 const struct TALER_BlindingMasterSeedP *blinding_seed, 3462 bool age_proof_required, 3463 uint8_t max_age, 3464 uint8_t noreveal_index, 3465 const struct TALER_ReservePublicKeyP *reserve_pub, 3466 const struct TALER_ReserveSignatureP *reserve_sig, 3467 struct GNUNET_TIME_Timestamp execution_date, 3468 const struct TALER_Amount *amount_with_fee); 3469 3470 3471 /** 3472 * Function called with the session hashes and transfer secret 3473 * information for a given coin. 3474 * 3475 * @param cls closure 3476 * @param transfer_pub public transfer key for the session 3477 * @param ldl link data for @a transfer_pub 3478 */ 3479 typedef void 3480 (*TALER_EXCHANGEDB_LinkCallback)( 3481 void *cls, 3482 const struct TALER_TransferPublicKeyP *transfer_pub, 3483 const struct TALER_EXCHANGEDB_LinkList *ldl); 3484 3485 3486 /** 3487 * Function called with the results of the lookup of the 3488 * transaction data associated with a wire transfer identifier. 3489 * 3490 * @param cls closure 3491 * @param rowid which row in the table is the information from (for diagnostics) 3492 * @param merchant_pub public key of the merchant (should be same for all callbacks with the same @e cls) 3493 * @param account_payto_uri which account did the transfer go to? 3494 * @param h_payto hash over @a account_payto_uri as it is in the DB 3495 * @param exec_time execution time of the wire transfer (should be same for all callbacks with the same @e cls) 3496 * @param h_contract_terms which proposal was this payment about 3497 * @param denom_pub denomination of @a coin_pub 3498 * @param coin_pub which public key was this payment about 3499 * @param coin_value amount contributed by this coin in total (with fee) 3500 * @param coin_fee applicable fee for this coin 3501 */ 3502 typedef void 3503 (*TALER_EXCHANGEDB_AggregationDataCallback)( 3504 void *cls, 3505 uint64_t rowid, 3506 const struct TALER_MerchantPublicKeyP *merchant_pub, 3507 const struct TALER_FullPayto account_payto_uri, 3508 const struct TALER_FullPaytoHashP *h_payto, 3509 struct GNUNET_TIME_Timestamp exec_time, 3510 const struct TALER_PrivateContractHashP *h_contract_terms, 3511 const struct TALER_DenominationPublicKey *denom_pub, 3512 const struct TALER_CoinSpendPublicKeyP *coin_pub, 3513 const struct TALER_Amount *coin_value, 3514 const struct TALER_Amount *coin_fee); 3515 3516 3517 /** 3518 * Function called with the results of the lookup of the 3519 * wire transfer data of the exchange. 3520 * 3521 * @param cls closure 3522 * @param rowid identifier of the respective row in the database 3523 * @param date timestamp of the wire transfer (roughly) 3524 * @param wtid wire transfer subject 3525 * @param payto_uri details of the receiver, URI in payto://-format 3526 * @param amount amount that was wired 3527 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to stop iteration 3528 */ 3529 typedef enum GNUNET_GenericReturnValue 3530 (*TALER_EXCHANGEDB_WireTransferOutCallback)( 3531 void *cls, 3532 uint64_t rowid, 3533 struct GNUNET_TIME_Timestamp date, 3534 const struct TALER_WireTransferIdentifierRawP *wtid, 3535 const struct TALER_FullPayto payto_uri, 3536 const struct TALER_Amount *amount); 3537 3538 3539 /** 3540 * Callback with data about a prepared wire transfer. 3541 * 3542 * @param cls closure 3543 * @param rowid row identifier used to mark prepared transaction as done 3544 * @param wire_method which wire method is this preparation data for 3545 * @param buf transaction data that was persisted, NULL on error 3546 * @param buf_size number of bytes in @a buf, 0 on error 3547 * @param finished did we complete the transfer yet? 3548 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to stop iteration 3549 */ 3550 typedef enum GNUNET_GenericReturnValue 3551 (*TALER_EXCHANGEDB_WirePreparationCallback)( 3552 void *cls, 3553 uint64_t rowid, 3554 const char *wire_method, 3555 const char *buf, 3556 size_t buf_size, 3557 int finished); 3558 3559 3560 /** 3561 * Function called about recoups the exchange has to perform. 3562 * 3563 * @param cls closure 3564 * @param rowid row identifier used to uniquely identify the recoup operation 3565 * @param timestamp when did we receive the recoup request 3566 * @param amount how much should be added back to the reserve 3567 * @param reserve_pub public key of the reserve 3568 * @param coin public information about the coin 3569 * @param denom_pub denomination key of @a coin 3570 * @param coin_sig signature with @e coin_pub of type #TALER_SIGNATURE_WALLET_COIN_RECOUP 3571 * @param coin_blind blinding factor used to blind the coin 3572 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 3573 */ 3574 typedef enum GNUNET_GenericReturnValue 3575 (*TALER_EXCHANGEDB_RecoupCallback)( 3576 void *cls, 3577 uint64_t rowid, 3578 struct GNUNET_TIME_Timestamp timestamp, 3579 const struct TALER_Amount *amount, 3580 const struct TALER_ReservePublicKeyP *reserve_pub, 3581 const struct TALER_CoinPublicInfo *coin, 3582 const struct TALER_DenominationPublicKey *denom_pub, 3583 const struct TALER_CoinSpendSignatureP *coin_sig, 3584 const union GNUNET_CRYPTO_BlindingSecretP *coin_blind); 3585 3586 3587 /** 3588 * Function called about recoups on refreshed coins the exchange has to 3589 * perform. 3590 * 3591 * @param cls closure 3592 * @param rowid row identifier used to uniquely identify the recoup operation 3593 * @param timestamp when did we receive the recoup request 3594 * @param amount how much should be added back to the old coin 3595 * @param old_coin_pub original coin that was refreshed to create @a coin 3596 * @param old_denom_pub_hash hash of public key of @a old_coin_pub 3597 * @param coin public information about the fresh coin 3598 * @param denom_pub denomination key of @a coin 3599 * @param coin_sig signature with @e coin_pub of type #TALER_SIGNATURE_WALLET_COIN_RECOUP 3600 * @param coin_blind blinding factor used to blind the coin 3601 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 3602 */ 3603 typedef enum GNUNET_GenericReturnValue 3604 (*TALER_EXCHANGEDB_RecoupRefreshCallback)( 3605 void *cls, 3606 uint64_t rowid, 3607 struct GNUNET_TIME_Timestamp timestamp, 3608 const struct TALER_Amount *amount, 3609 const struct TALER_CoinSpendPublicKeyP *old_coin_pub, 3610 const struct TALER_DenominationHashP *old_denom_pub_hash, 3611 const struct TALER_CoinPublicInfo *coin, 3612 const struct TALER_DenominationPublicKey *denom_pub, 3613 const struct TALER_CoinSpendSignatureP *coin_sig, 3614 const union GNUNET_CRYPTO_BlindingSecretP *coin_blind); 3615 3616 3617 /** 3618 * Function called about reserve opening operations. 3619 * 3620 * @param cls closure 3621 * @param rowid row identifier used to uniquely identify the reserve closing operation 3622 * @param reserve_payment how much to pay from the 3623 * reserve's own balance for opening the reserve 3624 * @param request_timestamp when was the request created 3625 * @param reserve_expiration desired expiration time for the reserve 3626 * @param purse_limit minimum number of purses the client 3627 * wants to have concurrently open for this reserve 3628 * @param reserve_pub public key of the reserve 3629 * @param reserve_sig signature affirming the operation 3630 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 3631 */ 3632 typedef enum GNUNET_GenericReturnValue 3633 (*TALER_EXCHANGEDB_ReserveOpenCallback)( 3634 void *cls, 3635 uint64_t rowid, 3636 const struct TALER_Amount *reserve_payment, 3637 struct GNUNET_TIME_Timestamp request_timestamp, 3638 struct GNUNET_TIME_Timestamp reserve_expiration, 3639 uint32_t purse_limit, 3640 const struct TALER_ReservePublicKeyP *reserve_pub, 3641 const struct TALER_ReserveSignatureP *reserve_sig); 3642 3643 3644 /** 3645 * Function called with AML statistics (counters). 3646 * 3647 * @param cls closure 3648 * @param name name of the counter 3649 * @param cnt number of events for @a name in the query range 3650 */ 3651 typedef void 3652 (*TALER_EXCHANGEDB_AmlStatisticsCallback)( 3653 void *cls, 3654 const char *name, 3655 uint64_t cnt); 3656 3657 3658 /** 3659 * Function called about reserve closing operations 3660 * the aggregator triggered. 3661 * 3662 * @param cls closure 3663 * @param rowid row identifier used to uniquely identify the reserve closing operation 3664 * @param execution_date when did we execute the close operation 3665 * @param amount_with_fee how much did we debit the reserve 3666 * @param closing_fee how much did we charge for closing the reserve 3667 * @param reserve_pub public key of the reserve 3668 * @param receiver_account where did we send the funds, in payto://-format 3669 * @param wtid identifier used for the wire transfer 3670 * @param close_request_row row with the responsible close 3671 * request, 0 if regular expiration triggered close 3672 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop 3673 */ 3674 typedef enum GNUNET_GenericReturnValue 3675 (*TALER_EXCHANGEDB_ReserveClosedCallback)( 3676 void *cls, 3677 uint64_t rowid, 3678 struct GNUNET_TIME_Timestamp execution_date, 3679 const struct TALER_Amount *amount_with_fee, 3680 const struct TALER_Amount *closing_fee, 3681 const struct TALER_ReservePublicKeyP *reserve_pub, 3682 const struct TALER_FullPayto receiver_account, 3683 const struct TALER_WireTransferIdentifierRawP *wtid, 3684 uint64_t close_request_row); 3685 3686 3687 /** 3688 * Function called with the amounts historically 3689 * withdrawn from the same origin account. 3690 * 3691 * @param cls closure 3692 * @param val one of the withdrawn amounts 3693 */ 3694 typedef void 3695 (*TALER_EXCHANGEDB_WithdrawHistoryCallback)( 3696 void *cls, 3697 const struct TALER_Amount *val); 3698 3699 /** 3700 * Function called with details about expired reserves. 3701 * 3702 * @param cls closure 3703 * @param reserve_pub public key of the reserve 3704 * @param left amount left in the reserve 3705 * @param account_details information about the reserve's bank account, in payto://-format 3706 * @param expiration_date when did the reserve expire 3707 * @param close_request_row row that caused the reserve 3708 * to be closed, 0 if it expired without request 3709 * @return #GNUNET_OK on success, 3710 * #GNUNET_NO to retry 3711 * #GNUNET_SYSERR on hard failures (exit) 3712 */ 3713 typedef enum GNUNET_GenericReturnValue 3714 (*TALER_EXCHANGEDB_ReserveExpiredCallback)( 3715 void *cls, 3716 const struct TALER_ReservePublicKeyP *reserve_pub, 3717 const struct TALER_Amount *left, 3718 const struct TALER_FullPayto account_details, 3719 struct GNUNET_TIME_Timestamp expiration_date, 3720 uint64_t close_request_row); 3721 3722 3723 /** 3724 * Function called with information justifying an aggregate recoup. 3725 * (usually implemented by the auditor when verifying losses from recoups). 3726 * 3727 * @param cls closure 3728 * @param rowid row identifier used to uniquely identify the recoup operation 3729 * @param coin information about the coin 3730 * @param coin_sig signature of the coin of type #TALER_SIGNATURE_WALLET_COIN_RECOUP 3731 * @param coin_blind blinding key of the coin 3732 * @param h_blinded_ev blinded envelope, as calculated by the exchange 3733 * @param amount total amount to be paid back 3734 */ 3735 typedef void 3736 (*TALER_EXCHANGEDB_RecoupJustificationCallback)( 3737 void *cls, 3738 uint64_t rowid, 3739 const struct TALER_CoinPublicInfo *coin, 3740 const struct TALER_CoinSpendSignatureP *coin_sig, 3741 const union GNUNET_CRYPTO_BlindingSecretP *coin_blind, 3742 const struct TALER_BlindedCoinHashP *h_blinded_ev, 3743 const struct TALER_Amount *amount); 3744 3745 3746 /** 3747 * Function called on (batch) deposits will need a wire 3748 * transfer. 3749 * 3750 * @param cls closure 3751 * @param batch_deposit_serial_id where in the table are we 3752 * @param total_amount value of all missing deposits, including fees 3753 * @param wire_target_h_payto hash of the recipient account's payto URI 3754 * @param deadline what was the earliest requested wire transfer deadline 3755 */ 3756 typedef void 3757 (*TALER_EXCHANGEDB_WireMissingCallback)( 3758 void *cls, 3759 uint64_t batch_deposit_serial_id, 3760 const struct TALER_Amount *total_amount, 3761 const struct TALER_FullPaytoHashP *wire_target_h_payto, 3762 struct GNUNET_TIME_Timestamp deadline); 3763 3764 3765 /** 3766 * Function called on aggregations that were done for 3767 * a (batch) deposit. 3768 * 3769 * @param cls closure 3770 * @param amount affected amount 3771 * @param tracking_serial_id where in the table are we 3772 * @param batch_deposit_serial_id which batch deposit was aggregated 3773 */ 3774 typedef void 3775 (*TALER_EXCHANGEDB_AggregationCallback)( 3776 void *cls, 3777 const struct TALER_Amount *amount, 3778 uint64_t tracking_serial_id, 3779 uint64_t batch_deposit_serial_id); 3780 3781 3782 /** 3783 * Function called on purse requests. 3784 * 3785 * @param cls closure 3786 * @param rowid purse request table row of the purse 3787 * @param purse_pub public key of the purse 3788 * @param merge_pub public key representing the merge capability 3789 * @param purse_creation when was the purse created? 3790 * @param purse_expiration when would an unmerged purse expire 3791 * @param h_contract_terms contract associated with the purse 3792 * @param age_limit the age limit for deposits into the purse 3793 * @param target_amount amount to be put into the purse 3794 * @param purse_sig signature of the purse over the initialization data 3795 * @return #GNUNET_OK to continue to iterate 3796 */ 3797 typedef enum GNUNET_GenericReturnValue 3798 (*TALER_EXCHANGEDB_PurseRequestCallback)( 3799 void *cls, 3800 uint64_t rowid, 3801 const struct TALER_PurseContractPublicKeyP *purse_pub, 3802 const struct TALER_PurseMergePublicKeyP *merge_pub, 3803 struct GNUNET_TIME_Timestamp purse_creation, 3804 struct GNUNET_TIME_Timestamp purse_expiration, 3805 const struct TALER_PrivateContractHashP *h_contract_terms, 3806 uint32_t age_limit, 3807 const struct TALER_Amount *target_amount, 3808 const struct TALER_PurseContractSignatureP *purse_sig); 3809 3810 3811 /** 3812 * Function called with information about the exchange's denomination keys. 3813 * Note that the 'master' field in @a issue will not yet be initialized when 3814 * this function is called! 3815 * 3816 * @param cls closure 3817 * @param denom_serial table row of the denomination 3818 * @param denom_pub public key of the denomination 3819 * @param issue detailed information about the denomination (value, expiration times, fees); 3820 */ 3821 typedef void 3822 (*TALER_EXCHANGEDB_DenominationCallback)( 3823 void *cls, 3824 uint64_t denom_serial, 3825 const struct TALER_DenominationPublicKey *denom_pub, 3826 const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue); 3827 3828 3829 /** 3830 * Return AML decision information. 3831 * 3832 * @param cls closure 3833 * @param row_id current row in legitimization outcomes table 3834 * @param justification human-readable reason for the decision, NULL if none is available 3835 * @param h_payto account for which the attribute data is stored 3836 * @param decision_time when was the decision taken 3837 * @param expiration_time when will the rules expire 3838 * @param jproperties properties set for the account, 3839 * NULL if no properties were set 3840 * @param to_investigate true if AML staff should look at the account 3841 * @param is_active true if this is the currently active decision about the account 3842 * @param is_wallet true if the @a h_payto is for a Taler wallet 3843 * @param payto payto URI of the account the decision is about 3844 * @param account_rules current active rules for the account 3845 */ 3846 typedef void 3847 (*TALER_EXCHANGEDB_AmlDecisionCallback)( 3848 void *cls, 3849 uint64_t row_id, 3850 const char *justification, 3851 const struct TALER_NormalizedPaytoHashP *h_payto, 3852 struct GNUNET_TIME_Timestamp decision_time, 3853 struct GNUNET_TIME_Absolute expiration_time, 3854 const json_t *jproperties, 3855 bool to_investigate, 3856 bool is_active, 3857 bool is_wallet, 3858 struct TALER_FullPayto payto, 3859 const json_t *account_rules); 3860 3861 3862 /** 3863 * Return account summary information. 3864 * 3865 * @param cls closure 3866 * @param row_id current row in AML status table 3867 * @param h_payto account for which the attribute data is stored 3868 * @param open_time when was the account opened formally, 3869 * GNUNET_TIME_UNIT_FOREVER_TS if it was never opened 3870 * @param close_time when was the account formally closed, 3871 * GNUNET_TIME_UNIT_ZERO_TS if it was never closed 3872 * @param comments comments on the account 3873 * @param high_risk is this a high-risk business relationship 3874 * @param to_investigate TRUE if this account should be investigated 3875 * @param payto the payto URI of the account 3876 */ 3877 typedef void 3878 (*TALER_EXCHANGEDB_AmlAccountListCallback)( 3879 void *cls, 3880 uint64_t row_id, 3881 const struct TALER_NormalizedPaytoHashP *h_payto, 3882 struct GNUNET_TIME_Timestamp open_time, 3883 struct GNUNET_TIME_Timestamp close_time, 3884 const char *comments, 3885 bool high_risk, 3886 bool to_investigate, 3887 struct TALER_FullPayto payto); 3888 3889 3890 /** 3891 * Return AML attribute information. 3892 * 3893 * @param cls closure 3894 * @param row_id current row in kyc_attributes table 3895 * @param collection_time when were the attributes collected 3896 * @param by_aml_officer true if the data was filed by an AML officer 3897 * @param officer_name name of the officer, NULL if not @a by_aml_officer 3898 * @param enc_attributes_size size of @a enc_attributes 3899 * @param enc_attributes the encrypted collected attributes 3900 */ 3901 typedef void 3902 (*TALER_EXCHANGEDB_AmlAttributeCallback)( 3903 void *cls, 3904 uint64_t row_id, 3905 struct GNUNET_TIME_Timestamp collection_time, 3906 bool by_aml_officer, 3907 const char *officer_name, 3908 size_t enc_attributes_size, 3909 const void *enc_attributes); 3910 3911 3912 /** 3913 * Return KYC attribute information. 3914 * 3915 * @param cls closure 3916 * @param row_id current row in kyc_attributes table 3917 * @param h_payto account the attributes are about 3918 * @param provider_name name of the provider that collected the attributes 3919 * @param collection_time when were the attributes collected 3920 * @param expiration_time when does the data expire 3921 * @param properties properties that were set for @a h_payto 3922 * @param enc_attributes_size size of @a enc_attributes 3923 * @param enc_attributes the encrypted collected attributes 3924 * @return true to continue to iterate 3925 */ 3926 typedef bool 3927 (*TALER_EXCHANGEDB_AllAttributesCallback)( 3928 void *cls, 3929 uint64_t row_id, 3930 const struct TALER_NormalizedPaytoHashP *h_payto, 3931 const char *provider_name, 3932 struct GNUNET_TIME_Timestamp collection_time, 3933 struct GNUNET_TIME_Timestamp expiration_time, 3934 const json_t *properties, 3935 size_t enc_attributes_size, 3936 const void *enc_attributes); 3937 3938 3939 /** 3940 * Callback that is given AML-relevant transfer data. 3941 * 3942 * @param cls closure 3943 * @param row_id current row in AML status table 3944 * @param payto_uri account involved with the wire transfer 3945 * @param execution_time when was the transfer made 3946 * @param amount wire amount of the transfer 3947 */ 3948 typedef void 3949 (*TALER_EXCHANGEDB_AmlTransferCallback)( 3950 void *cls, 3951 uint64_t row_id, 3952 const char *payto_uri, 3953 struct GNUNET_TIME_Absolute execution_time, 3954 const struct TALER_Amount *amount); 3955 3956 3957 /** 3958 * @brief The plugin API, returned from the plugin's "init" function. 3959 * The argument given to "init" is simply a configuration handle. 3960 */ 3961 struct TALER_EXCHANGEDB_Plugin 3962 { 3963 3964 /** 3965 * Closure for all callbacks. 3966 */ 3967 void *cls; 3968 3969 /** 3970 * Name of the library which generated this plugin. Set by the 3971 * plugin loader. 3972 */ 3973 char *library_name; 3974 3975 /** 3976 * How long are AML programs allowed to run? 3977 */ 3978 struct GNUNET_TIME_Relative max_aml_program_runtime; 3979 3980 /** 3981 * Drop the Taler tables. This should only be used in testcases. 3982 * 3983 * @param cls the @e cls of this struct with the plugin-specific state 3984 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 3985 */ 3986 enum GNUNET_GenericReturnValue 3987 (*drop_tables)(void *cls); 3988 3989 /** 3990 * Create the necessary tables if they are not present 3991 * 3992 * @param cls the @e cls of this struct with the plugin-specific state 3993 * @param support_partitions true to enable partitioning support (disables foreign key constraints) 3994 * @param num_partitions number of partitions to create, 3995 * (0 to not actually use partitions, 1 to only 3996 * setup a default partition, >1 for real partitions) 3997 * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure 3998 */ 3999 enum GNUNET_GenericReturnValue 4000 (*create_tables)(void *cls, 4001 bool support_partitions, 4002 uint32_t num_partitions); 4003 4004 4005 /** 4006 * Start a transaction. 4007 * 4008 * @param cls the @e cls of this struct with the plugin-specific state 4009 * @param name unique name identifying the transaction (for debugging), 4010 * must point to a constant 4011 * @return #GNUNET_OK on success 4012 */ 4013 enum GNUNET_GenericReturnValue 4014 (*start)(void *cls, 4015 const char *name); 4016 4017 4018 /** 4019 * Start a READ COMMITTED transaction. 4020 * 4021 * @param cls the `struct PostgresClosure` with the plugin-specific state 4022 * @param name unique name identifying the transaction (for debugging) 4023 * must point to a constant 4024 * @return #GNUNET_OK on success 4025 */ 4026 enum GNUNET_GenericReturnValue 4027 (*start_read_committed)(void *cls, 4028 const char *name); 4029 4030 /** 4031 * Start a READ ONLY serializable transaction. 4032 * 4033 * @param cls the `struct PostgresClosure` with the plugin-specific state 4034 * @param name unique name identifying the transaction (for debugging) 4035 * must point to a constant 4036 * @return #GNUNET_OK on success 4037 */ 4038 enum GNUNET_GenericReturnValue 4039 (*start_read_only)(void *cls, 4040 const char *name); 4041 4042 4043 /** 4044 * Commit a transaction. 4045 * 4046 * @param cls the @e cls of this struct with the plugin-specific state 4047 * @return transaction status 4048 */ 4049 enum GNUNET_DB_QueryStatus 4050 (*commit)(void *cls); 4051 4052 4053 /** 4054 * Do a pre-flight check that we are not in an uncommitted transaction. 4055 * If we are, try to commit the previous transaction and output a warning. 4056 * Does not return anything, as we will continue regardless of the outcome. 4057 * 4058 * @param cls the `struct PostgresClosure` with the plugin-specific state 4059 * @return #GNUNET_OK if everything is fine 4060 * #GNUNET_NO if a transaction was rolled back 4061 * #GNUNET_SYSERR on hard errors 4062 */ 4063 enum GNUNET_GenericReturnValue 4064 (*preflight)(void *cls); 4065 4066 4067 /** 4068 * Abort/rollback a transaction. 4069 * 4070 * @param cls the @e cls of this struct with the plugin-specific state 4071 */ 4072 void 4073 (*rollback) (void *cls); 4074 4075 4076 /** 4077 * Register callback to be invoked on events of type @a es. 4078 * 4079 * @param cls database context to use 4080 * @param timeout how long to wait at most 4081 * @param es specification of the event to listen for 4082 * @param cb function to call when the event happens, possibly 4083 * multiple times (until cancel is invoked) 4084 * @param cb_cls closure for @a cb 4085 * @return handle useful to cancel the listener 4086 */ 4087 struct GNUNET_DB_EventHandler * 4088 (*event_listen)(void *cls, 4089 struct GNUNET_TIME_Relative timeout, 4090 const struct GNUNET_DB_EventHeaderP *es, 4091 GNUNET_DB_EventCallback cb, 4092 void *cb_cls); 4093 4094 /** 4095 * Stop notifications. 4096 * 4097 * @param cls database context to use 4098 * @param eh handle to unregister. 4099 */ 4100 void 4101 (*event_listen_cancel)(void *cls, 4102 struct GNUNET_DB_EventHandler *eh); 4103 4104 4105 /** 4106 * Notify all that listen on @a es of an event. 4107 * 4108 * @param cls database context to use 4109 * @param es specification of the event to generate 4110 * @param extra additional event data provided 4111 * @param extra_size number of bytes in @a extra 4112 */ 4113 void 4114 (*event_notify)(void *cls, 4115 const struct GNUNET_DB_EventHeaderP *es, 4116 const void *extra, 4117 size_t extra_size); 4118 4119 4120 /** 4121 * Insert information about a denomination key and in particular 4122 * the properties (value, fees, expiration times) the coins signed 4123 * with this key have. 4124 * 4125 * @param cls the @e cls of this struct with the plugin-specific state 4126 * @param denom_pub the public key used for signing coins of this denomination 4127 * @param issue issuing information with value, fees and other info about the denomination 4128 * @return status of the query 4129 */ 4130 enum GNUNET_DB_QueryStatus 4131 (*insert_denomination_info)( 4132 void *cls, 4133 const struct TALER_DenominationPublicKey *denom_pub, 4134 const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue); 4135 4136 4137 /** 4138 * Fetch information about a denomination key. 4139 * 4140 * @param cls the @e cls of this struct with the plugin-specific state 4141 * @param denom_pub_hash hash of the public key used for signing coins of this denomination 4142 * @param[out] denom_serial row in the denomination table, might be NULL 4143 * @param[out] issue set to issue information with value, fees and other info about the coin 4144 * @return transaction status code 4145 */ 4146 enum GNUNET_DB_QueryStatus 4147 (*get_denomination_info)( 4148 void *cls, 4149 const struct TALER_DenominationHashP *denom_pub_hash, 4150 uint64_t *denom_serial, 4151 struct TALER_EXCHANGEDB_DenominationKeyInformation *issue); 4152 4153 /** 4154 * Fetch information about a denomination by a given serial id. 4155 * 4156 * @param cls the @e cls of this struct with the plugin-specific state 4157 * @param denom_serial row in the denomination table 4158 * @param[out] issue set to issue information with value, fees and other info about the coin 4159 * @return transaction status code 4160 */ 4161 enum GNUNET_DB_QueryStatus 4162 (*get_denomination_by_serial)( 4163 void *cls, 4164 uint64_t denom_serial, 4165 struct TALER_EXCHANGEDB_DenominationKeyInformation *issue); 4166 4167 4168 /** 4169 * Function called on every known denomination key. Runs in its 4170 * own read-only transaction (hence no session provided). Note that 4171 * the "master" field in the callback's 'issue' argument will NOT 4172 * be initialized yet. 4173 * 4174 * @param cls the @e cls of this struct with the plugin-specific state 4175 * @param cb function to call on each denomination key 4176 * @param cb_cls closure for @a cb 4177 * @return transaction status code 4178 */ 4179 enum GNUNET_DB_QueryStatus 4180 (*iterate_denomination_info)(void *cls, 4181 TALER_EXCHANGEDB_DenominationCallback cb, 4182 void *cb_cls); 4183 4184 4185 /** 4186 * Function called to invoke @a cb on every known denomination key (revoked 4187 * and non-revoked) that has been signed by the master key. Runs in its own 4188 * read-only transaction. 4189 * 4190 * @param cls the @e cls of this struct with the plugin-specific state 4191 * @param cb function to call on each denomination key 4192 * @param cb_cls closure for @a cb 4193 * @return transaction status code 4194 */ 4195 enum GNUNET_DB_QueryStatus 4196 (*iterate_denominations)(void *cls, 4197 TALER_EXCHANGEDB_DenominationsCallback cb, 4198 void *cb_cls); 4199 4200 /** 4201 * Function called to invoke @a cb on every non-revoked exchange signing key 4202 * that has been signed by the master key. Revoked and (for signing!) 4203 * expired keys are skipped. Runs in its own read-only transaction. 4204 * 4205 * @param cls the @e cls of this struct with the plugin-specific state 4206 * @param cb function to call on each signing key 4207 * @param cb_cls closure for @a cb 4208 * @return transaction status code 4209 */ 4210 enum GNUNET_DB_QueryStatus 4211 (*iterate_active_signkeys)(void *cls, 4212 TALER_EXCHANGEDB_ActiveSignkeysCallback cb, 4213 void *cb_cls); 4214 4215 4216 /** 4217 * Function called to invoke @a cb on every active auditor. Disabled 4218 * auditors are skipped. Runs in its own read-only transaction. 4219 * 4220 * @param cls the @e cls of this struct with the plugin-specific state 4221 * @param cb function to call on each active auditor 4222 * @param cb_cls closure for @a cb 4223 * @return transaction status code 4224 */ 4225 enum GNUNET_DB_QueryStatus 4226 (*iterate_active_auditors)(void *cls, 4227 TALER_EXCHANGEDB_AuditorsCallback cb, 4228 void *cb_cls); 4229 4230 4231 /** 4232 * Function called to invoke @a cb on every denomination with an active 4233 * auditor. Disabled auditors and denominations without auditor are 4234 * skipped. Runs in its own read-only transaction. 4235 * 4236 * @param cls the @e cls of this struct with the plugin-specific state 4237 * @param cb function to call on each active auditor-denomination pair 4238 * @param cb_cls closure for @a cb 4239 * @return transaction status code 4240 */ 4241 enum GNUNET_DB_QueryStatus 4242 (*iterate_auditor_denominations)( 4243 void *cls, 4244 TALER_EXCHANGEDB_AuditorDenominationsCallback cb, 4245 void *cb_cls); 4246 4247 4248 /** 4249 * Get the summary of a reserve. 4250 * 4251 * @param cls the @e cls of this struct with the plugin-specific state 4252 * @param[in,out] reserve the reserve data. The public key of the reserve should be set 4253 * in this structure; it is used to query the database. The balance 4254 * and expiration are then filled accordingly. 4255 * @return transaction status 4256 */ 4257 enum GNUNET_DB_QueryStatus 4258 (*reserves_get)(void *cls, 4259 struct TALER_EXCHANGEDB_Reserve *reserve); 4260 4261 4262 /** 4263 * Get the origin of funds of a reserve. 4264 * 4265 * @param cls the `struct PostgresClosure` with the plugin-specific state 4266 * @param reserve_pub public key of the reserve 4267 * @param[out] h_payto set to hash of the wire source payto://-URI 4268 * @param[out] payto_uri set to the wire source payto://-URI 4269 * @return transaction status 4270 */ 4271 enum GNUNET_DB_QueryStatus 4272 (*reserves_get_origin)( 4273 void *cls, 4274 const struct TALER_ReservePublicKeyP *reserve_pub, 4275 struct TALER_FullPaytoHashP *h_payto, 4276 struct TALER_FullPayto *payto_uri); 4277 4278 4279 /** 4280 * Extract next KYC alert. Deletes the alert. 4281 * 4282 * @param cls the @e cls of this struct with the plugin-specific state 4283 * @param trigger_type which type of alert to drain 4284 * @param[out] h_payto set to hash of payto-URI where KYC status changed 4285 * @return transaction status 4286 */ 4287 enum GNUNET_DB_QueryStatus 4288 (*drain_kyc_alert)(void *cls, 4289 uint32_t trigger_type, 4290 struct TALER_NormalizedPaytoHashP *h_payto); 4291 4292 4293 /** 4294 * Insert a batch of incoming transaction into reserves. New reserves are 4295 * also created through this function. 4296 * 4297 * @param cls the @e cls of this struct with the plugin-specific state 4298 * @param reserves 4299 * @param reserves_length length of the @a reserves array 4300 * @param[out] results array of transaction status codes of length @a reserves_length, 4301 * set to the status of the 4302 */ 4303 enum GNUNET_DB_QueryStatus 4304 (*reserves_in_insert)( 4305 void *cls, 4306 const struct TALER_EXCHANGEDB_ReserveInInfo *reserves, 4307 unsigned int reserves_length, 4308 enum GNUNET_DB_QueryStatus *results); 4309 4310 4311 /** 4312 * Insert an incoming KCYAUTH wire transfer into 4313 * the database and update the authentication key 4314 * for the origin account. 4315 * 4316 * @param cls the @e cls of this struct with the plugin-specific state 4317 * @param account_pub public key of the account 4318 * @param credit_amount amount we were credited 4319 * @param execution_date when was the transfer made 4320 * @param debit_account_uri URI of the debit account 4321 * @param section_name section of the exchange bank account that received the transfer 4322 * @param serial_id bank-specific row identifying the transfer 4323 */ 4324 enum GNUNET_DB_QueryStatus 4325 (*kycauth_in_insert)( 4326 void *cls, 4327 const union TALER_AccountPublicKeyP *account_pub, 4328 const struct TALER_Amount *credit_amount, 4329 struct GNUNET_TIME_Timestamp execution_date, 4330 const struct TALER_FullPayto debit_account_uri, 4331 const char *section_name, 4332 uint64_t serial_id); 4333 4334 4335 /** 4336 * Insert an incoming WAD wire transfer into the database. 4337 * 4338 * @param cls the @e cls of this struct with the plugin-specific state 4339 * @param wad_id WAD identifier 4340 * @param origin_exchange_url exchange base URL originating the transfer 4341 * @param amount the amount that was transferred 4342 * @param execution_date when was the transfer made 4343 * @param debit_account_uri URI of the debit account 4344 * @param section_name section of the exchange bank account that received the transfer 4345 * @param serial_id bank-specific row identifying the transfer 4346 */ 4347 enum GNUNET_DB_QueryStatus 4348 (*wad_in_insert)( 4349 void *cls, 4350 const struct TALER_WadIdentifierP *wad_id, 4351 const char *origin_exchange_url, 4352 const struct TALER_Amount *amount, 4353 struct GNUNET_TIME_Timestamp execution_date, 4354 const struct TALER_FullPayto debit_account_uri, 4355 const char *section_name, 4356 uint64_t serial_id); 4357 4358 4359 /** 4360 * Locate a nonce for use with a particular public key. 4361 * 4362 * @param cls the @e cls of this struct with the plugin-specific state 4363 * @param nonce the nonce to be locked 4364 * @param denom_pub_hash hash of the public key of the denomination 4365 * @param target public key the nonce is to be locked to 4366 * @return statement execution status 4367 */ 4368 enum GNUNET_DB_QueryStatus 4369 (*lock_nonce)(void *cls, 4370 const struct GNUNET_CRYPTO_CsSessionNonce *nonce, 4371 const struct TALER_DenominationHashP *denom_pub_hash, 4372 const union TALER_EXCHANGEDB_NonceLockTargetP *target); 4373 4374 /** 4375 * Locate the response for a withdraw request under a hash of the 4376 * commitment that uniquely identifies the withdraw operation. 4377 * Used to ensure idempotency of the request. 4378 * 4379 * @param cls the @e cls of this struct with the plugin-specific state 4380 * @param h_planchets hash that uniquely identifies the withdraw operation 4381 * @param[out] wr corresponding details of the previous withdraw request if an entry was found 4382 * @return statement execution status 4383 */ 4384 enum GNUNET_DB_QueryStatus 4385 (*get_withdraw)( 4386 void *cls, 4387 const struct TALER_HashBlindedPlanchetsP *h_planchets, 4388 struct TALER_EXCHANGEDB_Withdraw *wr); 4389 4390 /** 4391 * Perform an withdraw operation, checking for sufficient balance and 4392 * fulfillment of age requirements and possibly persisting the withdrawal 4393 * details. 4394 * 4395 * @param cls the `struct PostgresClosure` with the plugin-specific state 4396 * @param withdraw the withdraw data 4397 * @param[out] balance_ok set to true if the balance was sufficient 4398 * @param[out] reserve_balance set to original balance of the reserve 4399 * @param[out] age_ok set to true if age requirements were met 4400 * @param[out] allowed_maximum_age if @e age_ok is FALSE, this is set to the allowed maximum age 4401 * @param[out] reserve_birthday if @e age_ok is FALSE, this is set to the reserve's birthday 4402 * @param[out] idempotent set to true if an entry already exists for the given h_planchets and reserve_pub 4403 * @param[out] noreveal_index if @e idempotent is true, set to the existing noreveal_index 4404 * @param[out] nonce_resue set to true if the blinding_seed has been found in the table for a different withdraw 4405 * @return 0 if no reserve was found, 1 if a reserve was found, else the query execution status 4406 */ 4407 enum GNUNET_DB_QueryStatus 4408 (*do_withdraw)( 4409 void *cls, 4410 const struct TALER_EXCHANGEDB_Withdraw *withdraw, 4411 const struct GNUNET_TIME_Timestamp *now, 4412 bool *balance_ok, 4413 struct TALER_Amount *reserve_balance, 4414 bool *age_ok, 4415 uint16_t *allowed_maximum_age, 4416 uint32_t *reserve_birthday, 4417 bool *idempotent, 4418 uint16_t *noreveal_index, 4419 bool *nonce_reuse); 4420 4421 /** 4422 * Retrieve the details to a policy given by its hash_code 4423 * 4424 * @param cls the `struct PostgresClosure` with the plugin-specific state 4425 * @param hc Hash code that identifies the policy 4426 * @param[out] detail retrieved policy details 4427 * @return query execution status 4428 */ 4429 enum GNUNET_DB_QueryStatus 4430 (*get_policy_details)( 4431 void *cls, 4432 const struct GNUNET_HashCode *hc, 4433 struct TALER_PolicyDetails *detail); 4434 4435 /** 4436 * Persist the policy details that extends a deposit. The particular policy 4437 * - referenced by details->hash_code - might already exist in the table, in 4438 * which case the call will update the contents of the record with @e details 4439 * 4440 * @param cls the `struct PostgresClosure` with the plugin-specific state 4441 * @param details The parsed `struct TALER_PolicyDetails` according to the responsible policy extension. 4442 * @param[out] policy_details_serial_id The ID of the entry in the policy_details table 4443 * @param[out] accumulated_total The total amount accumulated in that policy 4444 * @param[out] fulfillment_state The state of policy. If the state was Insufficient prior to the call and the provided deposit raises the accumulated_total above the commitment, it will be set to Ready. 4445 * @return query execution status 4446 */ 4447 enum GNUNET_DB_QueryStatus 4448 (*persist_policy_details)( 4449 void *cls, 4450 const struct TALER_PolicyDetails *details, 4451 uint64_t *policy_details_serial_id, 4452 struct TALER_Amount *accumulated_total, 4453 enum TALER_PolicyFulfillmentState *fulfillment_state); 4454 4455 4456 /** 4457 * Perform deposit operation, checking for sufficient balance 4458 * of the coin and possibly persisting the deposit details. 4459 * 4460 * @param cls the `struct PostgresClosure` with the plugin-specific state 4461 * @param bd batch deposit operation details 4462 * @param deposit_fees array of "bd->num_cids" deposit fees 4463 * of the respective coins 4464 * @param[in,out] exchange_timestamp time to use for the deposit (possibly updated) 4465 * @param[out] accumulated_total_without_fee set to the sum of all deposits 4466 * made for this merchant and contract (minus deposit fees) 4467 * @param[out] balance_ok set to true if the balance was sufficient 4468 * @param[out] bad_balance_index set to the first index of a coin for which the balance was insufficient, 4469 * only used if @a balance_ok is set to false. 4470 * @param[out] ctr_conflict set to true if the same contract terms hash was previously submitted with other meta data (deadlines, wallet_data_hash, wire data etc.) 4471 * @return query execution status 4472 */ 4473 enum GNUNET_DB_QueryStatus 4474 (*do_deposit)( 4475 void *cls, 4476 const struct TALER_EXCHANGEDB_BatchDeposit *bd, 4477 const struct TALER_Amount deposit_fees[], 4478 struct GNUNET_TIME_Timestamp *exchange_timestamp, 4479 struct TALER_Amount *accumulated_total_without_fee, 4480 bool *balance_ok, 4481 uint32_t *bad_balance_index, 4482 bool *ctr_conflict); 4483 4484 4485 /** 4486 * Check ifdeposit operation is idempotent to existing one. 4487 * 4488 * @param cls the `struct PostgresClosure` with the plugin-specific state 4489 * @param bd batch deposit operation details 4490 * @param[in,out] exchange_timestamp time to use for the deposit (possibly updated) 4491 * @param[out] is_idempotent set to true if the request is idempotent 4492 * @return query execution status 4493 */ 4494 enum GNUNET_DB_QueryStatus 4495 (*do_check_deposit_idempotent)( 4496 void *cls, 4497 const struct TALER_EXCHANGEDB_BatchDeposit *bd, 4498 struct GNUNET_TIME_Timestamp *exchange_timestamp, 4499 bool *is_idempotent); 4500 4501 /** 4502 * Perform refresh operation--introduced with v27 of the API--, 4503 * checking for sufficient balance of the coin and possibly persisting the melt/refresh details. 4504 * 4505 * @param cls the plugin-specific state 4506 * @param[in,out] refresh refresh operation details; the noreveal_index 4507 * is set in case the coin was already melted before 4508 * @param timestamp the timestamp of this melt operation, helpful for the coin history. 4509 * @param[in,out] zombie_required true if the melt must only succeed 4510 * if the coin is a zombie, set to false if the requirement was satisfied 4511 * @param[out] found set to true if there exists already an entry in the database for 4512 * the calculated commitment hash. 4513 * @param[out] noreveal_index if @e found ist true, the existing value of the noreveal_index. 4514 * @param[out] nonce_reuse set to true if the blinding seed for CS was re-used. 4515 * @param[out] balance_ok set to true if the balance was sufficient 4516 * @param[out] insufficient_funds if balance_ok is false, set to the remaining value of the coin 4517 * @return query execution status, NO_RESULTS in case of an unknown coin. 4518 */ 4519 enum GNUNET_DB_QueryStatus 4520 (*do_refresh)( 4521 void *cls, 4522 struct TALER_EXCHANGEDB_Refresh_vDOLDPLUS *refresh, 4523 const struct GNUNET_TIME_Timestamp *timestamp, 4524 bool *found, 4525 uint32_t *noreveal_index, 4526 bool *zombie_required, 4527 bool *nonce_reuse, 4528 bool *balance_ok, 4529 struct TALER_Amount *coin_balance); 4530 4531 4532 /** 4533 * Lookup refresh data under the given @a rc, starting with protocol version v27 4534 * 4535 * @param cls the @e cls of this struct with the plugin-specific state 4536 * @param rc commitment to use for the lookup 4537 * @param[out] refresh where to store the result; note that 4538 * refresh->coin.denom_sig will be set to NULL 4539 * and is not fetched by this routine (as it is not needed by the client) 4540 * @return transaction status 4541 */ 4542 enum GNUNET_DB_QueryStatus 4543 (*get_refresh)(void *cls, 4544 const struct TALER_RefreshCommitmentP *rc, 4545 struct TALER_EXCHANGEDB_Refresh_vDOLDPLUS *refresh); 4546 4547 /** 4548 * @since vDOLDPLUS 4549 * 4550 * Mark the successful reveal for a refresh in the database. 4551 * 4552 * @param cls the @e cls of this struct with the plugin-specific state 4553 * @param rc commitment to use for the lookup 4554 * @return transaction status 4555 */ 4556 enum GNUNET_DB_QueryStatus 4557 (*mark_refresh_reveal_success)( 4558 void *cls, 4559 const struct TALER_RefreshCommitmentP *rc); 4560 4561 /** 4562 * Add a proof of fulfillment of an policy 4563 * 4564 * @param cls the plugin-specific state 4565 * @param[in,out] fulfillment The proof of fulfillment and serial_ids of the policy_details along with their new state and potential new amounts. 4566 * @return query execution status 4567 */ 4568 enum GNUNET_DB_QueryStatus 4569 (*add_policy_fulfillment_proof)( 4570 void *cls, 4571 struct TALER_PolicyFulfillmentTransactionData *fulfillment); 4572 4573 4574 /** 4575 * Perform refund operation, checking for sufficient deposits 4576 * of the coin and possibly persisting the refund details. 4577 * 4578 * @param cls the `struct PostgresClosure` with the plugin-specific state 4579 * @param refund refund operation details 4580 * @param deposit_fee deposit fee applicable for the coin, possibly refunded 4581 * @param known_coin_id row of the coin in the known_coins table 4582 * @param[out] not_found set if the deposit was not found 4583 * @param[out] refund_ok set if the refund succeeded (below deposit amount) 4584 * @param[out] gone if the merchant was already paid 4585 * @param[out] conflict set if the refund ID was reused 4586 * @return query execution status 4587 */ 4588 enum GNUNET_DB_QueryStatus 4589 (*do_refund)( 4590 void *cls, 4591 const struct TALER_EXCHANGEDB_Refund *refund, 4592 const struct TALER_Amount *deposit_fee, 4593 uint64_t known_coin_id, 4594 bool *not_found, 4595 bool *refund_ok, 4596 bool *gone, 4597 bool *conflict); 4598 4599 4600 /** 4601 * Perform recoup operation, checking for sufficient deposits 4602 * of the coin and possibly persisting the recoup details. 4603 * 4604 * @param cls the `struct PostgresClosure` with the plugin-specific state 4605 * @param reserve_pub public key of the reserve to credit 4606 * @param withdraw_serial_id row in the withdraw table justifying the recoup 4607 * @param coin_bks coin blinding key secret to persist 4608 * @param coin_pub public key of the coin being recouped 4609 * @param known_coin_id row of the @a coin_pub in the known_coins table 4610 * @param coin_sig signature of the coin requesting the recoup 4611 * @param[in,out] recoup_timestamp recoup timestamp, set if recoup existed 4612 * @param[out] recoup_ok set if the recoup succeeded (balance ok) 4613 * @param[out] internal_failure set on internal failures 4614 * @return query execution status 4615 */ 4616 enum GNUNET_DB_QueryStatus 4617 (*do_recoup)( 4618 void *cls, 4619 const struct TALER_ReservePublicKeyP *reserve_pub, 4620 uint64_t withdraw_serial_id, 4621 const union GNUNET_CRYPTO_BlindingSecretP *coin_bks, 4622 const struct TALER_CoinSpendPublicKeyP *coin_pub, 4623 uint64_t known_coin_id, 4624 const struct TALER_CoinSpendSignatureP *coin_sig, 4625 struct GNUNET_TIME_Timestamp *recoup_timestamp, 4626 bool *recoup_ok, 4627 bool *internal_failure); 4628 4629 4630 /** 4631 * Perform recoup-refresh operation, checking for sufficient deposits of the 4632 * coin and possibly persisting the recoup-refresh details. 4633 * 4634 * @param cls the `struct PostgresClosure` with the plugin-specific state 4635 * @param old_coin_pub public key of the old coin to credit 4636 * @param rrc_serial row in the refresh_revealed_coins table justifying the recoup-refresh 4637 * @param coin_bks coin blinding key secret to persist 4638 * @param coin_pub public key of the coin being recouped 4639 * @param known_coin_id row of the @a coin_pub in the known_coins table 4640 * @param coin_sig signature of the coin requesting the recoup 4641 * @param[in,out] recoup_timestamp recoup timestamp, set if recoup existed 4642 * @param[out] recoup_ok set if the recoup-refresh succeeded (balance ok) 4643 * @param[out] internal_failure set on internal failures 4644 * @return query execution status 4645 */ 4646 enum GNUNET_DB_QueryStatus 4647 (*do_recoup_refresh)( 4648 void *cls, 4649 const struct TALER_CoinSpendPublicKeyP *old_coin_pub, 4650 uint64_t rrc_serial, 4651 const union GNUNET_CRYPTO_BlindingSecretP *coin_bks, 4652 const struct TALER_CoinSpendPublicKeyP *coin_pub, 4653 uint64_t known_coin_id, 4654 const struct TALER_CoinSpendSignatureP *coin_sig, 4655 struct GNUNET_TIME_Timestamp *recoup_timestamp, 4656 bool *recoup_ok, 4657 bool *internal_failure); 4658 4659 4660 /** 4661 * Compile a list of (historic) transactions performed with the given reserve 4662 * (withdraw, incoming wire, open, close operations). Should return 0 if the @a 4663 * reserve_pub is unknown, otherwise determine @a etag_out and if it is past @a 4664 * etag_in return the history after @a start_off. @a etag_out should be set 4665 * to the last row ID of the given @a reserve_pub in the reserve history table. 4666 * 4667 * @param cls the @e cls of this struct with the plugin-specific state 4668 * @param reserve_pub public key of the reserve 4669 * @param start_off maximum starting offset in history to exclude from returning 4670 * @param etag_in up to this offset the client already has a response, do not 4671 * return anything unless @a etag_out will be larger 4672 * @param[out] etag_out set to the latest history offset known for this @a coin_pub 4673 * @param[out] balance set to the reserve balance 4674 * @param[out] rhp set to known transaction history (NULL if reserve is unknown) 4675 * @return transaction status 4676 */ 4677 enum GNUNET_DB_QueryStatus 4678 (*get_reserve_history)( 4679 void *cls, 4680 const struct TALER_ReservePublicKeyP *reserve_pub, 4681 uint64_t start_off, 4682 uint64_t etag_in, 4683 uint64_t *etag_out, 4684 struct TALER_Amount *balance, 4685 struct TALER_EXCHANGEDB_ReserveHistory **rhp); 4686 4687 4688 /** 4689 * The current reserve balance of the specified reserve. 4690 * 4691 * @param cls the @e cls of this struct with the plugin-specific state 4692 * @param reserve_pub public key of the reserve 4693 * @param[out] balance set to the reserve balance 4694 * @param[out] origin_account set to URI of the origin account, NULL 4695 * if we have no origin account (reserve created by P2P merge) 4696 * @return transaction status 4697 */ 4698 enum GNUNET_DB_QueryStatus 4699 (*get_reserve_balance)( 4700 void *cls, 4701 const struct TALER_ReservePublicKeyP *reserve_pub, 4702 struct TALER_Amount *balance, 4703 struct TALER_FullPayto *origin_account); 4704 4705 4706 /** 4707 * Free memory associated with the given reserve history. 4708 * 4709 * @param cls the @e cls of this struct with the plugin-specific state 4710 * @param rh history to free. 4711 */ 4712 void 4713 (*free_reserve_history) ( 4714 void *cls, 4715 struct TALER_EXCHANGEDB_ReserveHistory *rh); 4716 4717 4718 /** 4719 * Count the number of known coins by denomination. 4720 * 4721 * @param cls database connection plugin state 4722 * @param denom_pub_hash denomination to count by 4723 * @return number of coins if non-negative, otherwise an `enum GNUNET_DB_QueryStatus` 4724 */ 4725 long long 4726 (*count_known_coins) (void *cls, 4727 const struct TALER_DenominationHashP *denom_pub_hash); 4728 4729 4730 /** 4731 * Make sure the given @a coin is known to the database. 4732 * 4733 * @param cls database connection plugin state 4734 * @param coin the coin that must be made known 4735 * @param[out] known_coin_id set to the unique row of the coin 4736 * @param[out] denom_pub_hash set to the conflicting denomination hash on conflict 4737 * @param[out] age_hash set to the conflicting age hash on conflict 4738 * @return database transaction status, non-negative on success 4739 */ 4740 enum TALER_EXCHANGEDB_CoinKnownStatus 4741 { 4742 /** 4743 * The coin was successfully added. 4744 */ 4745 TALER_EXCHANGEDB_CKS_ADDED = 1, 4746 4747 /** 4748 * The coin was already present. 4749 */ 4750 TALER_EXCHANGEDB_CKS_PRESENT = 0, 4751 4752 /** 4753 * Serialization failure. 4754 */ 4755 TALER_EXCHANGEDB_CKS_SOFT_FAIL = -1, 4756 4757 /** 4758 * Hard database failure. 4759 */ 4760 TALER_EXCHANGEDB_CKS_HARD_FAIL = -2, 4761 4762 /** 4763 * Conflicting coin (different denomination key) already in database. 4764 */ 4765 TALER_EXCHANGEDB_CKS_DENOM_CONFLICT = -3, 4766 4767 /** 4768 * Conflicting coin (expected NULL age hash) already in database. 4769 */ 4770 TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NULL = -4, 4771 4772 /** 4773 * Conflicting coin (unexpected NULL age hash) already in database. 4774 */ 4775 TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NON_NULL = -5, 4776 4777 /** 4778 * Conflicting coin (different age hash) already in database. 4779 */ 4780 TALER_EXCHANGEDB_CKS_AGE_CONFLICT_VALUE_DIFFERS = -6, 4781 4782 } 4783 (*ensure_coin_known)(void *cls, 4784 const struct TALER_CoinPublicInfo *coin, 4785 uint64_t *known_coin_id, 4786 struct TALER_DenominationHashP *denom_pub_hash, 4787 struct TALER_AgeCommitmentHashP *age_hash); 4788 4789 4790 /** 4791 * Make sure the array of given @a coin is known to the database. 4792 * 4793 * @param cls database connection plugin state 4794 * @param coin array of coins that must be made known 4795 * @param[out] result array where to store information about each coin 4796 * @param coin_length length of the @a coin and @a result arraysf 4797 * @param batch_size desired (maximum) batch size 4798 * @return database transaction status, non-negative on success 4799 */ 4800 enum GNUNET_DB_QueryStatus 4801 (*batch_ensure_coin_known)( 4802 void *cls, 4803 const struct TALER_CoinPublicInfo *coin, 4804 struct TALER_EXCHANGEDB_CoinInfo *result, 4805 unsigned int coin_length, 4806 unsigned int batch_size); 4807 4808 4809 /** 4810 * Retrieve information about the given @a coin from the database. 4811 * 4812 * @param cls database connection plugin state 4813 * @param coin_pub the coin that must be made known 4814 * @param[out] coin_info detailed information about the coin 4815 * @return database transaction status, non-negative on success 4816 */ 4817 enum GNUNET_DB_QueryStatus 4818 (*get_known_coin)(void *cls, 4819 const struct TALER_CoinSpendPublicKeyP *coin_pub, 4820 struct TALER_CoinPublicInfo *coin_info); 4821 4822 /** 4823 * Retrieve the signature and corresponding denomination for a given @a coin 4824 * from the database 4825 * 4826 * @param cls database connection plugin state 4827 * @param coin_pub the public key of the coin we search for 4828 * @param[out] denom_pub the public key of the denomination that the coin was signed with 4829 * @param[out] denom_sig the signature with the denomination's private key over the coin_pub 4830 */ 4831 enum GNUNET_DB_QueryStatus 4832 (*get_signature_for_known_coin)( 4833 void *cls, 4834 const struct TALER_CoinSpendPublicKeyP *coin_pub, 4835 struct TALER_DenominationPublicKey *denom_pub, 4836 struct TALER_DenominationSignature *denom_sig); 4837 4838 /** 4839 * Retrieve the denomination of a known coin. 4840 * 4841 * @param cls the plugin closure 4842 * @param coin_pub the public key of the coin to search for 4843 * @param[out] known_coin_id set to the ID of the coin in the known_coins table 4844 * @param[out] denom_hash where to store the hash of the coins denomination 4845 * @return transaction status code 4846 */ 4847 enum GNUNET_DB_QueryStatus 4848 (*get_coin_denomination)(void *cls, 4849 const struct TALER_CoinSpendPublicKeyP *coin_pub, 4850 uint64_t *known_coin_id, 4851 struct TALER_DenominationHashP *denom_hash); 4852 4853 4854 /** 4855 * Try to retrieve the salted hash of the merchant's bank account to a 4856 * deposit contract. Used in case of conflicts for a given (merchant_pub, 4857 * h_contract_terms) to provide the client the necessary input to retrieve 4858 * more details about the conflict. 4859 * 4860 * @param cls the plugin closure 4861 * @param merchant_pub public key of the merchant 4862 * @param h_contract_terms contract to check for 4863 * @param[out] h_wire hash of the wire details 4864 */ 4865 enum GNUNET_DB_QueryStatus 4866 (*get_wire_hash_for_contract)( 4867 void *cls, 4868 const struct TALER_MerchantPublicKeyP *merchant_pub, 4869 const struct TALER_PrivateContractHashP *h_contract_terms, 4870 struct TALER_MerchantWireHashP *h_wire); 4871 4872 4873 /** 4874 * Check if we have the specified deposit already in the database. 4875 * 4876 * @param cls the `struct PostgresClosure` with the plugin-specific state 4877 * @param h_contract_terms contract to check for 4878 * @param h_wire wire hash to check for 4879 * @param coin_pub public key of the coin to check for 4880 * @param merchant merchant public key to check for 4881 * @param refund_deadline expected refund deadline 4882 * @param[out] deposit_fee set to the deposit fee the exchange charged 4883 * @param[out] exchange_timestamp set to the time when the exchange received the deposit 4884 * @return 1 if we know this operation, 4885 * 0 if this exact deposit is unknown to us, 4886 * otherwise transaction error status 4887 */ 4888 // FIXME: rename! 4889 enum GNUNET_DB_QueryStatus 4890 (*have_deposit2)( 4891 void *cls, 4892 const struct TALER_PrivateContractHashP *h_contract_terms, 4893 const struct TALER_MerchantWireHashP *h_wire, 4894 const struct TALER_CoinSpendPublicKeyP *coin_pub, 4895 const struct TALER_MerchantPublicKeyP *merchant, 4896 struct GNUNET_TIME_Timestamp refund_deadline, 4897 struct TALER_Amount *deposit_fee, 4898 struct GNUNET_TIME_Timestamp *exchange_timestamp); 4899 4900 4901 /** 4902 * Insert information about refunded coin into the database. 4903 * Used in tests and for benchmarking. 4904 * 4905 * @param cls the @e cls of this struct with the plugin-specific state 4906 * @param refund refund information to store 4907 * @return query result status 4908 */ 4909 enum GNUNET_DB_QueryStatus 4910 (*insert_refund)(void *cls, 4911 const struct TALER_EXCHANGEDB_Refund *refund); 4912 4913 4914 /** 4915 * Select refunds by @a coin_pub, @a merchant_pub and @a h_contract. 4916 * 4917 * @param cls closure of plugin 4918 * @param coin_pub coin to get refunds for 4919 * @param merchant_pub merchant to get refunds for 4920 * @param h_contract_pub contract (hash) to get refunds for 4921 * @param cb function to call for each refund found 4922 * @param cb_cls closure for @a cb 4923 * @return query result status 4924 */ 4925 enum GNUNET_DB_QueryStatus 4926 (*select_refunds_by_coin)( 4927 void *cls, 4928 const struct TALER_CoinSpendPublicKeyP *coin_pub, 4929 const struct TALER_MerchantPublicKeyP *merchant_pub, 4930 const struct TALER_PrivateContractHashP *h_contract, 4931 TALER_EXCHANGEDB_RefundCoinCallback cb, 4932 void *cb_cls); 4933 4934 4935 /** 4936 * Obtain information about deposits that are ready to be executed. 4937 * Such deposits must not be marked as "done", and the 4938 * execution time, the refund deadlines must both be in the past and 4939 * the KYC status must be 'ok'. 4940 * 4941 * @param cls the @e cls of this struct with the plugin-specific state 4942 * @param start_shard_row minimum shard row to select 4943 * @param end_shard_row maximum shard row to select (inclusive) 4944 * @param[out] merchant_pub set to the public key of a merchant with a ready deposit 4945 * @param[out] payto_uri set to the account of the merchant, to be freed by caller 4946 * @param[out] extra_wire_subject_metadata set to additional metadata to include in the wire subject, or NULL for none 4947 * @return transaction status code 4948 */ 4949 enum GNUNET_DB_QueryStatus 4950 (*get_ready_deposit)(void *cls, 4951 uint64_t start_shard_row, 4952 uint64_t end_shard_row, 4953 struct TALER_MerchantPublicKeyP *merchant_pub, 4954 struct TALER_FullPayto *payto_uri, 4955 char **extra_wire_subject_metadata); 4956 4957 4958 /** 4959 * Aggregate all matching deposits for @a h_payto and 4960 * @a merchant_pub, returning the total amounts. 4961 * 4962 * @param cls the @e cls of this struct with the plugin-specific state 4963 * @param h_payto destination of the wire transfer 4964 * @param merchant_pub public key of the merchant 4965 * @param wtid wire transfer ID to set for the aggregate 4966 * @param[out] total set to the sum of the total deposits minus applicable deposit fees and refunds 4967 * @return transaction status 4968 */ 4969 enum GNUNET_DB_QueryStatus 4970 (*aggregate)( 4971 void *cls, 4972 const struct TALER_FullPaytoHashP *h_payto, 4973 const struct TALER_MerchantPublicKeyP *merchant_pub, 4974 const struct TALER_WireTransferIdentifierRawP *wtid, 4975 struct TALER_Amount *total); 4976 4977 4978 /** 4979 * Create a new entry in the transient aggregation table. 4980 * 4981 * @param cls the @e cls of this struct with the plugin-specific state 4982 * @param h_payto destination of the wire transfer 4983 * @param exchange_account_section exchange account to use 4984 * @param merchant_pub public key of the merchant 4985 * @param wtid the raw wire transfer identifier to be used 4986 * @param kyc_requirement_row row in legitimization_requirements that need to be satisfied to continue, or 0 for none 4987 * @param total amount to be wired in the future 4988 * @return transaction status 4989 */ 4990 enum GNUNET_DB_QueryStatus 4991 (*create_aggregation_transient)( 4992 void *cls, 4993 const struct TALER_FullPaytoHashP *h_payto, 4994 const char *exchange_account_section, 4995 const struct TALER_MerchantPublicKeyP *merchant_pub, 4996 const struct TALER_WireTransferIdentifierRawP *wtid, 4997 uint64_t kyc_requirement_row, 4998 const struct TALER_Amount *total); 4999 5000 5001 /** 5002 * Select existing entry in the transient aggregation table. 5003 * 5004 * @param cls the @e cls of this struct with the plugin-specific state 5005 * @param h_payto destination of the wire transfer 5006 * @param merchant_pub public key of the merchant 5007 * @param exchange_account_section exchange account to use 5008 * @param[out] wtid set to the raw wire transfer identifier to be used 5009 * @param[out] total existing amount to be wired in the future 5010 * @return transaction status 5011 */ 5012 enum GNUNET_DB_QueryStatus 5013 (*select_aggregation_transient)( 5014 void *cls, 5015 const struct TALER_FullPaytoHashP *h_payto, 5016 const struct TALER_MerchantPublicKeyP *merchant_pub, 5017 const char *exchange_account_section, 5018 struct TALER_WireTransferIdentifierRawP *wtid, 5019 struct TALER_Amount *total); 5020 5021 5022 /** 5023 * Find existing entry in the transient aggregation table. 5024 * 5025 * @param cls the @e cls of this struct with the plugin-specific state 5026 * @param h_payto destination of the wire transfer 5027 * @param[out] payto_uri corresponding payto URI, to be freed by caller 5028 * @param[out] wtid wire transfer identifier of transient aggregation 5029 * @param[out] merchant_pub public key of the merchant 5030 * @param[out] total amount aggregated so far 5031 * @return transaction status 5032 */ 5033 enum GNUNET_DB_QueryStatus 5034 (*find_aggregation_transient)( 5035 void *cls, 5036 const struct TALER_NormalizedPaytoHashP *h_payto, 5037 struct TALER_FullPayto *payto_uri, 5038 struct TALER_WireTransferIdentifierRawP *wtid, 5039 struct TALER_MerchantPublicKeyP *merchant_pub, 5040 struct TALER_Amount *total); 5041 5042 5043 /** 5044 * Update existing entry in the transient aggregation table. 5045 * @a h_payto is only needed for query performance. 5046 * 5047 * @param cls the @e cls of this struct with the plugin-specific state 5048 * @param h_payto destination of the wire transfer 5049 * @param wtid the raw wire transfer identifier to update 5050 * @param kyc_requirement_row row in legitimization_requirements that need to be satisfied to continue, or 0 for none 5051 * @param total new total amount to be wired in the future 5052 * @return transaction status 5053 */ 5054 enum GNUNET_DB_QueryStatus 5055 (*update_aggregation_transient)( 5056 void *cls, 5057 const struct TALER_FullPaytoHashP *h_payto, 5058 const struct TALER_WireTransferIdentifierRawP *wtid, 5059 uint64_t kyc_requirement_row, 5060 const struct TALER_Amount *total); 5061 5062 5063 /** 5064 * Delete existing entry in the transient aggregation table. 5065 * @a h_payto is only needed for query performance. 5066 * 5067 * @param cls the @e cls of this struct with the plugin-specific state 5068 * @param h_payto destination of the wire transfer 5069 * @param wtid the raw wire transfer identifier to update 5070 * @return transaction status 5071 */ 5072 enum GNUNET_DB_QueryStatus 5073 (*delete_aggregation_transient)( 5074 void *cls, 5075 const struct TALER_FullPaytoHashP *h_payto, 5076 const struct TALER_WireTransferIdentifierRawP *wtid); 5077 5078 /** 5079 * Compile a list of (historic) transactions performed with the given coin 5080 * (melt, refund, recoup and deposit operations). Should return 0 if the @a 5081 * coin_pub is unknown, otherwise determine @a etag_out and if it is past @a 5082 * etag_in return the history after @a start_off. @a etag_out should be set 5083 * to the last row ID of the given @a coin_pub in the coin history table. 5084 * 5085 * @param cls the @e cls of this struct with the plugin-specific state 5086 * @param begin_transaction true to run this in its own transaction(s) 5087 * @param coin_pub coin to investigate 5088 * @param start_off starting offset from which on to return entries 5089 * @param etag_in up to this offset the client already has a response, do not 5090 * return anything unless @a etag_out will be larger 5091 * @param[out] etag_out set to the latest history offset known for this @a coin_pub 5092 * @param[out] balance set to current balance of the coin 5093 * @param[out] h_denom_pub set to denomination public key of the coin 5094 * @param[out] tlp set to list of transactions, set to NULL if coin has no 5095 * transaction history past @a start_off or if @a etag_in is equal 5096 * to the value written to @a etag_out. 5097 * @return database transaction status 5098 */ 5099 enum GNUNET_DB_QueryStatus 5100 (*get_coin_transactions)( 5101 void *cls, 5102 bool begin_transaction, 5103 const struct TALER_CoinSpendPublicKeyP *coin_pub, 5104 uint64_t start_off, 5105 uint64_t etag_in, 5106 uint64_t *etag_out, 5107 struct TALER_Amount *balance, 5108 struct TALER_DenominationHashP *h_denom_pub, 5109 struct TALER_EXCHANGEDB_TransactionList **tlp); 5110 5111 5112 /** 5113 * Free linked list of transactions. 5114 * 5115 * @param cls the @e cls of this struct with the plugin-specific state 5116 * @param list list to free 5117 */ 5118 void 5119 (*free_coin_transaction_list) ( 5120 void *cls, 5121 struct TALER_EXCHANGEDB_TransactionList *list); 5122 5123 5124 /** 5125 * Lookup the list of Taler transactions that was aggregated 5126 * into a wire transfer by the respective @a raw_wtid. 5127 * 5128 * @param cls the @e cls of this struct with the plugin-specific state 5129 * @param wtid the raw wire transfer identifier we used 5130 * @param cb function to call on each transaction found 5131 * @param cb_cls closure for @a cb 5132 * @return query status of the transaction 5133 */ 5134 enum GNUNET_DB_QueryStatus 5135 (*lookup_wire_transfer)( 5136 void *cls, 5137 const struct TALER_WireTransferIdentifierRawP *wtid, 5138 TALER_EXCHANGEDB_AggregationDataCallback cb, 5139 void *cb_cls); 5140 5141 5142 /** 5143 * Try to find the wire transfer details for a deposit operation. 5144 * If we did not execute the deposit yet, return when it is supposed 5145 * to be executed. 5146 * 5147 * @param cls closure 5148 * @param h_contract_terms hash of the proposal data 5149 * @param h_wire hash of merchant wire details 5150 * @param coin_pub public key of deposited coin 5151 * @param merchant_pub merchant public key 5152 * @param[out] pending set to true if the transaction is still pending 5153 * @param[out] wtid wire transfer identifier, only set if @a pending is false 5154 * @param[out] coin_contribution how much did the coin we asked about 5155 * contribute to the total transfer value? (deposit value including fee) 5156 * @param[out] coin_fee how much did the exchange charge for the deposit fee 5157 * @param[out] execution_time when was the transaction done, or 5158 * when we expect it to be done (if @a pending is false) 5159 * @param[out] kyc set to the kyc status of the receiver (if @a pending) 5160 * @param[out] account_pub set to public key that is authorized to start the KYC process; unchanged if no such key is known 5161 * @return transaction status code 5162 */ 5163 enum GNUNET_DB_QueryStatus 5164 (*lookup_transfer_by_deposit)( 5165 void *cls, 5166 const struct TALER_PrivateContractHashP *h_contract_terms, 5167 const struct TALER_MerchantWireHashP *h_wire, 5168 const struct TALER_CoinSpendPublicKeyP *coin_pub, 5169 const struct TALER_MerchantPublicKeyP *merchant_pub, 5170 bool *pending, 5171 struct TALER_WireTransferIdentifierRawP *wtid, 5172 struct GNUNET_TIME_Timestamp *exec_time, 5173 struct TALER_Amount *amount_with_fee, 5174 struct TALER_Amount *deposit_fee, 5175 struct TALER_EXCHANGEDB_KycStatus *kyc, 5176 union TALER_AccountPublicKeyP *account_pub); 5177 5178 5179 /** 5180 * Insert wire transfer fee into database. 5181 * 5182 * @param cls closure 5183 * @param wire_method which wire method is the fee about? 5184 * @param start_date when does the fee go into effect 5185 * @param end_date when does the fee end being valid 5186 * @param fees how high is are the wire fees 5187 * @param master_sig signature over the above by the exchange master key 5188 * @return transaction status code 5189 */ 5190 enum GNUNET_DB_QueryStatus 5191 (*insert_wire_fee)( 5192 void *cls, 5193 const char *wire_method, 5194 struct GNUNET_TIME_Timestamp start_date, 5195 struct GNUNET_TIME_Timestamp end_date, 5196 const struct TALER_WireFeeSet *fees, 5197 const struct TALER_MasterSignatureP *master_sig); 5198 5199 5200 /** 5201 * Insert global fee set into database. 5202 * 5203 * @param cls closure 5204 * @param start_date when does the fees go into effect 5205 * @param end_date when does the fees end being valid 5206 * @param fees how high is are the global fees 5207 * @param purse_timeout when do purses time out 5208 * @param history_expiration how long are account histories preserved 5209 * @param purse_account_limit how many purses are free per account 5210 * @param master_sig signature over the above by the exchange master key 5211 * @return transaction status code 5212 */ 5213 enum GNUNET_DB_QueryStatus 5214 (*insert_global_fee)( 5215 void *cls, 5216 struct GNUNET_TIME_Timestamp start_date, 5217 struct GNUNET_TIME_Timestamp end_date, 5218 const struct TALER_GlobalFeeSet *fees, 5219 struct GNUNET_TIME_Relative purse_timeout, 5220 struct GNUNET_TIME_Relative history_expiration, 5221 uint32_t purse_account_limit, 5222 const struct TALER_MasterSignatureP *master_sig); 5223 5224 5225 /** 5226 * Obtain wire fee from database. 5227 * 5228 * @param cls closure 5229 * @param type type of wire transfer the fee applies for 5230 * @param date for which date do we want the fee? 5231 * @param[out] rowid set to row in the database with the wire fee 5232 * @param[out] start_date when does the fee go into effect 5233 * @param[out] end_date when does the fee end being valid 5234 * @param[out] fees how high are the wire fees 5235 * @param[out] master_sig signature over the above by the exchange master key 5236 * @return query status of the transaction 5237 */ 5238 enum GNUNET_DB_QueryStatus 5239 (*get_wire_fee)( 5240 void *cls, 5241 const char *type, 5242 struct GNUNET_TIME_Timestamp date, 5243 uint64_t *rowid, 5244 struct GNUNET_TIME_Timestamp *start_date, 5245 struct GNUNET_TIME_Timestamp *end_date, 5246 struct TALER_WireFeeSet *fees, 5247 struct TALER_MasterSignatureP *master_sig); 5248 5249 5250 /** 5251 * Obtain global fees from database. 5252 * 5253 * @param cls closure 5254 * @param date for which date do we want the fee? 5255 * @param[out] start_date when does the fee go into effect 5256 * @param[out] end_date when does the fee end being valid 5257 * @param[out] fees how high are the global fees 5258 * @param[out] purse_timeout when do purses time out 5259 * @param[out] history_expiration how long are account histories preserved 5260 * @param[out] purse_account_limit how many purses are free per account 5261 * @param[out] master_sig signature over the above by the exchange master key 5262 * @return query status of the transaction 5263 */ 5264 enum GNUNET_DB_QueryStatus 5265 (*get_global_fee)( 5266 void *cls, 5267 struct GNUNET_TIME_Timestamp date, 5268 struct GNUNET_TIME_Timestamp *start_date, 5269 struct GNUNET_TIME_Timestamp *end_date, 5270 struct TALER_GlobalFeeSet *fees, 5271 struct GNUNET_TIME_Relative *purse_timeout, 5272 struct GNUNET_TIME_Relative *history_expiration, 5273 uint32_t *purse_account_limit, 5274 struct TALER_MasterSignatureP *master_sig); 5275 5276 5277 /** 5278 * Obtain information about expired reserves and their 5279 * remaining balances. 5280 * 5281 * @param cls closure of the plugin 5282 * @param now timestamp based on which we decide expiration 5283 * @param rec function to call on expired reserves 5284 * @param rec_cls closure for @a rec 5285 * @return transaction status 5286 */ 5287 enum GNUNET_DB_QueryStatus 5288 (*get_expired_reserves)( 5289 void *cls, 5290 struct GNUNET_TIME_Timestamp now, 5291 TALER_EXCHANGEDB_ReserveExpiredCallback rec, 5292 void *rec_cls); 5293 5294 5295 /** 5296 * Obtain information about force-closed reserves 5297 * where the close was not yet done (and their remaining 5298 * balances). Updates the returned reserve's close 5299 * status to "done". 5300 * 5301 * @param cls closure of the plugin 5302 * @param rec function to call on (to be) closed reserves 5303 * @param rec_cls closure for @a rec 5304 * @return transaction status 5305 */ 5306 enum GNUNET_DB_QueryStatus 5307 (*get_unfinished_close_requests)( 5308 void *cls, 5309 TALER_EXCHANGEDB_ReserveExpiredCallback rec, 5310 void *rec_cls); 5311 5312 5313 /** 5314 * Insert reserve open coin deposit data into database. 5315 * Subtracts the @a coin_total from the coin's balance. 5316 * 5317 * @param cls closure 5318 * @param cpi public information about the coin 5319 * @param coin_sig signature with @e coin_pub of type #TALER_SIGNATURE_WALLET_RESERVE_OPEN_DEPOSIT 5320 * @param known_coin_id ID of the coin in the known_coins table 5321 * @param coin_total amount to be spent of the coin (including deposit fee) 5322 * @param reserve_sig signature by the reserve affirming the open operation 5323 * @param reserve_pub public key of the reserve being opened 5324 * @param[out] insufficient_funds set to true if the coin's balance is insufficient, otherwise to false 5325 * @return transaction status code, 0 if operation is already in the DB 5326 */ 5327 enum GNUNET_DB_QueryStatus 5328 (*insert_reserve_open_deposit)( 5329 void *cls, 5330 const struct TALER_CoinPublicInfo *cpi, 5331 const struct TALER_CoinSpendSignatureP *coin_sig, 5332 uint64_t known_coin_id, 5333 const struct TALER_Amount *coin_total, 5334 const struct TALER_ReserveSignatureP *reserve_sig, 5335 const struct TALER_ReservePublicKeyP *reserve_pub, 5336 bool *insufficient_funds); 5337 5338 5339 /** 5340 * Insert reserve close operation into database. 5341 * 5342 * @param cls closure 5343 * @param reserve_pub which reserve is this about? 5344 * @param total_paid total amount paid (coins and reserve) 5345 * @param reserve_payment amount to be paid from the reserve 5346 * @param min_purse_limit minimum number of purses we should be able to open 5347 * @param reserve_sig signature by the reserve for the operation 5348 * @param desired_expiration when should the reserve expire (earliest time) 5349 * @param now when did we the client initiate the action 5350 * @param open_fee annual fee to be charged for the open operation by the exchange 5351 * @param[out] no_funds set to true if reserve balance is insufficient 5352 * @param[out] reserve_balance set to original balance of the reserve 5353 * @param[out] open_cost set to the actual cost 5354 * @param[out] final_expiration when will the reserve expire now 5355 * @return transaction status code 5356 */ 5357 enum GNUNET_DB_QueryStatus 5358 (*do_reserve_open)( 5359 void *cls, 5360 const struct TALER_ReservePublicKeyP *reserve_pub, 5361 const struct TALER_Amount *total_paid, 5362 const struct TALER_Amount *reserve_payment, 5363 uint32_t min_purse_limit, 5364 const struct TALER_ReserveSignatureP *reserve_sig, 5365 struct GNUNET_TIME_Timestamp desired_expiration, 5366 struct GNUNET_TIME_Timestamp now, 5367 const struct TALER_Amount *open_fee, 5368 bool *no_funds, 5369 struct TALER_Amount *reserve_balance, 5370 struct TALER_Amount *open_cost, 5371 struct GNUNET_TIME_Timestamp *final_expiration); 5372 5373 5374 /** 5375 * Select information needed to see if we can close 5376 * a reserve. 5377 * 5378 * @param cls closure 5379 * @param reserve_pub which reserve is this about? 5380 * @param[out] balance current reserve balance 5381 * @param[out] payto_uri set to URL of account that 5382 * originally funded the reserve; 5383 * could be set to NULL if not known 5384 * @return transaction status code, 0 if reserve unknown 5385 */ 5386 enum GNUNET_DB_QueryStatus 5387 (*select_reserve_close_info)( 5388 void *cls, 5389 const struct TALER_ReservePublicKeyP *reserve_pub, 5390 struct TALER_Amount *balance, 5391 struct TALER_FullPayto *payto_uri); 5392 5393 5394 /** 5395 * Select information about reserve close requests. 5396 * 5397 * @param cls closure 5398 * @param reserve_pub which reserve is this about? 5399 * @param rowid row ID of the close request 5400 * @param[out] reserve_sig reserve signature affirming 5401 * @param[out] request_timestamp when was the request made 5402 * @param[out] close_balance reserve balance at close time 5403 * @param[out] close_fee closing fee to be charged 5404 * @param[out] payto_uri set to URL of account that 5405 * should receive the money; 5406 * could be set to NULL for origin 5407 * @return transaction status code, 0 if reserve unknown 5408 */ 5409 enum GNUNET_DB_QueryStatus 5410 (*select_reserve_close_request_info)( 5411 void *cls, 5412 const struct TALER_ReservePublicKeyP *reserve_pub, 5413 uint64_t rowid, 5414 struct TALER_ReserveSignatureP *reserve_sig, 5415 struct GNUNET_TIME_Timestamp *request_timestamp, 5416 struct TALER_Amount *close_balance, 5417 struct TALER_Amount *close_fee, 5418 struct TALER_FullPayto *payto_uri); 5419 5420 5421 /** 5422 * Select information needed for KYC checks on reserve close: historic 5423 * reserve closures going to the same account. 5424 * 5425 * @param cls closure 5426 * @param h_payto which target account is this about? 5427 * @param time_limit oldest transaction that could be relevant 5428 * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK). 5429 * @param kac_cls closure for @a kac 5430 * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error 5431 */ 5432 enum GNUNET_DB_QueryStatus 5433 (*iterate_reserve_close_info)( 5434 void *cls, 5435 const struct TALER_NormalizedPaytoHashP *h_payto, 5436 struct GNUNET_TIME_Absolute time_limit, 5437 TALER_EXCHANGEDB_KycAmountCallback kac, 5438 void *kac_cls); 5439 5440 5441 /** 5442 * Insert reserve close operation into database. 5443 * 5444 * @param cls closure 5445 * @param reserve_pub which reserve is this about? 5446 * @param execution_date when did we perform the transfer? 5447 * @param receiver_account to which account do we transfer, in payto://-format 5448 * @param wtid identifier for the wire transfer 5449 * @param amount_with_fee amount we charged to the reserve 5450 * @param closing_fee how high is the closing fee 5451 * @param close_request_row identifies explicit close request, 0 for none 5452 * @return transaction status code 5453 */ 5454 enum GNUNET_DB_QueryStatus 5455 (*insert_reserve_closed)( 5456 void *cls, 5457 const struct TALER_ReservePublicKeyP *reserve_pub, 5458 struct GNUNET_TIME_Timestamp execution_date, 5459 const struct TALER_FullPayto receiver_account, 5460 const struct TALER_WireTransferIdentifierRawP *wtid, 5461 const struct TALER_Amount *amount_with_fee, 5462 const struct TALER_Amount *closing_fee, 5463 uint64_t close_request_row); 5464 5465 5466 /** 5467 * Function called to insert wire transfer commit data into the DB. 5468 * 5469 * @param cls closure 5470 * @param type type of the wire transfer (i.e. "iban") 5471 * @param buf buffer with wire transfer preparation data 5472 * @param buf_size number of bytes in @a buf 5473 * @return query status code 5474 */ 5475 enum GNUNET_DB_QueryStatus 5476 (*wire_prepare_data_insert)(void *cls, 5477 const char *type, 5478 const char *buf, 5479 size_t buf_size); 5480 5481 5482 /** 5483 * Function called to mark wire transfer commit data as finished. 5484 * 5485 * @param cls closure 5486 * @param rowid which entry to mark as finished 5487 * @return transaction status code 5488 */ 5489 enum GNUNET_DB_QueryStatus 5490 (*wire_prepare_data_mark_finished)(void *cls, 5491 uint64_t rowid); 5492 5493 5494 /** 5495 * Function called to mark wire transfer as failed. 5496 * 5497 * @param cls closure 5498 * @param rowid which entry to mark as failed 5499 * @return transaction status code 5500 */ 5501 enum GNUNET_DB_QueryStatus 5502 (*wire_prepare_data_mark_failed)(void *cls, 5503 uint64_t rowid); 5504 5505 5506 /** 5507 * Function called to get an unfinished wire transfer 5508 * preparation data. 5509 * 5510 * @param cls closure 5511 * @param start_row offset to query table at 5512 * @param limit maximum number of results to return 5513 * @param cb function to call for unfinished work 5514 * @param cb_cls closure for @a cb 5515 * @return transaction status code 5516 */ 5517 enum GNUNET_DB_QueryStatus 5518 (*wire_prepare_data_get)( 5519 void *cls, 5520 uint64_t start_row, 5521 uint64_t limit, 5522 TALER_EXCHANGEDB_WirePreparationIterator cb, 5523 void *cb_cls); 5524 5525 5526 /** 5527 * Starts a READ COMMITTED transaction where we transiently violate the foreign 5528 * constraints on the "wire_out" table as we insert aggregations 5529 * and only add the wire transfer out at the end. 5530 * 5531 * @param cls the @e cls of this struct with the plugin-specific state 5532 * @return #GNUNET_OK on success 5533 */ 5534 enum GNUNET_GenericReturnValue 5535 (*start_deferred_wire_out)(void *cls); 5536 5537 5538 /** 5539 * Store information about an outgoing wire transfer that was executed. 5540 * 5541 * @param cls closure 5542 * @param date time of the wire transfer 5543 * @param h_payto identifies the receiver account of the wire transfer 5544 * @param wire_account details about the receiver account of the wire transfer, 5545 * including 'url' in payto://-format 5546 * @param amount amount that was transmitted 5547 * @param exchange_account_section configuration section of the exchange specifying the 5548 * exchange's bank account being used 5549 * @param extra_wire_subject_metadata additional meta data for the wire transfer subject, can be NULL 5550 * @return transaction status code 5551 */ 5552 enum GNUNET_DB_QueryStatus 5553 (*store_wire_transfer_out)( 5554 void *cls, 5555 struct GNUNET_TIME_Timestamp date, 5556 const struct TALER_WireTransferIdentifierRawP *wtid, 5557 const struct TALER_FullPaytoHashP *h_payto, 5558 const char *exchange_account_section, 5559 const struct TALER_Amount *amount, 5560 const char *extra_wire_subject_metadata); 5561 5562 5563 /** 5564 * Function called to perform "garbage collection" on the 5565 * database, expiring records we no longer require. 5566 * 5567 * @param cls closure 5568 * @return #GNUNET_OK on success, 5569 * #GNUNET_SYSERR on DB errors 5570 */ 5571 enum GNUNET_GenericReturnValue 5572 (*gc)(void *cls); 5573 5574 5575 /** 5576 * Select deposits above @a serial_id in monotonically increasing 5577 * order. 5578 * 5579 * @param cls closure 5580 * @param serial_id highest serial ID to exclude (select strictly larger) 5581 * @param cb function to call on each result 5582 * @param cb_cls closure for @a cb 5583 * @return transaction status code 5584 */ 5585 enum GNUNET_DB_QueryStatus 5586 (*select_coin_deposits_above_serial_id)( 5587 void *cls, 5588 uint64_t serial_id, 5589 TALER_EXCHANGEDB_DepositCallback cb, 5590 void *cb_cls); 5591 5592 5593 /** 5594 * Function called to return meta data about a purses 5595 * above a certain serial ID. 5596 * 5597 * @param cls the @e cls of this struct with the plugin-specific state 5598 * @param serial_id number to select requests by 5599 * @param cb function to call on each request 5600 * @param cb_cls closure for @a cb 5601 * @return transaction status code 5602 */ 5603 enum GNUNET_DB_QueryStatus 5604 (*select_purse_requests_above_serial_id)( 5605 void *cls, 5606 uint64_t serial_id, 5607 TALER_EXCHANGEDB_PurseRequestCallback cb, 5608 void *cb_cls); 5609 5610 5611 /** 5612 * Select purse deposits above @a serial_id in monotonically increasing 5613 * order. 5614 * 5615 * @param cls closure 5616 * @param serial_id highest serial ID to exclude (select strictly larger) 5617 * @param cb function to call on each result 5618 * @param cb_cls closure for @a cb 5619 * @return transaction status code 5620 */ 5621 enum GNUNET_DB_QueryStatus 5622 (*select_purse_deposits_above_serial_id)( 5623 void *cls, 5624 uint64_t serial_id, 5625 TALER_EXCHANGEDB_PurseDepositCallback cb, 5626 void *cb_cls); 5627 5628 5629 /** 5630 * Select account merges above @a serial_id in monotonically increasing 5631 * order. 5632 * 5633 * @param cls closure 5634 * @param serial_id highest serial ID to exclude (select strictly larger) 5635 * @param cb function to call on each result 5636 * @param cb_cls closure for @a cb 5637 * @return transaction status code 5638 */ 5639 enum GNUNET_DB_QueryStatus 5640 (*select_account_merges_above_serial_id)( 5641 void *cls, 5642 uint64_t serial_id, 5643 TALER_EXCHANGEDB_AccountMergeCallback cb, 5644 void *cb_cls); 5645 5646 5647 /** 5648 * Select purse merges deposits above @a serial_id in monotonically increasing 5649 * order. 5650 * 5651 * @param cls closure 5652 * @param serial_id highest serial ID to exclude (select strictly larger) 5653 * @param cb function to call on each result 5654 * @param cb_cls closure for @a cb 5655 * @return transaction status code 5656 */ 5657 enum GNUNET_DB_QueryStatus 5658 (*select_purse_merges_above_serial_id)( 5659 void *cls, 5660 uint64_t serial_id, 5661 TALER_EXCHANGEDB_PurseMergeCallback cb, 5662 void *cb_cls); 5663 5664 5665 /** 5666 * Select purse refunds above @a serial_id in monotonically increasing 5667 * order. 5668 * 5669 * @param cls closure 5670 * @param serial_id highest serial ID to exclude (select strictly larger) 5671 * @param refunded which refund status to select for 5672 * @param cb function to call on each result 5673 * @param cb_cls closure for @a cb 5674 * @return transaction status code 5675 */ 5676 enum GNUNET_DB_QueryStatus 5677 (*select_purse_decisions_above_serial_id)( 5678 void *cls, 5679 uint64_t serial_id, 5680 bool refunded, 5681 TALER_EXCHANGEDB_PurseDecisionCallback cb, 5682 void *cb_cls); 5683 5684 5685 /** 5686 * Select all purse decisions above @a serial_id in monotonically increasing 5687 * order. 5688 * 5689 * @param cls closure 5690 * @param serial_id highest serial ID to exclude (select strictly larger) 5691 * @param cb function to call on each result 5692 * @param cb_cls closure for @a cb 5693 * @return transaction status code 5694 */ 5695 enum GNUNET_DB_QueryStatus 5696 (*select_all_purse_decisions_above_serial_id)( 5697 void *cls, 5698 uint64_t serial_id, 5699 TALER_EXCHANGEDB_AllPurseDecisionCallback cb, 5700 void *cb_cls); 5701 5702 5703 /** 5704 * Select all purse deletions above @a serial_id in monotonically increasing 5705 * order. 5706 * 5707 * @param cls closure 5708 * @param serial_id highest serial ID to exclude (select strictly larger) 5709 * @param cb function to call on each result 5710 * @param cb_cls closure for @a cb 5711 * @return transaction status code 5712 */ 5713 enum GNUNET_DB_QueryStatus 5714 (*select_all_purse_deletions_above_serial_id)( 5715 void *cls, 5716 uint64_t serial_id, 5717 TALER_EXCHANGEDB_AllPurseDeletionsCallback cb, 5718 void *cb_cls); 5719 5720 5721 /** 5722 * Select coins deposited into a purse. 5723 * 5724 * @param cls closure 5725 * @param purse_pub public key of the purse 5726 * @param cb function to call on each result 5727 * @param cb_cls closure for @a cb 5728 * @return transaction status code 5729 */ 5730 enum GNUNET_DB_QueryStatus 5731 (*select_purse_deposits_by_purse)( 5732 void *cls, 5733 const struct TALER_PurseContractPublicKeyP *purse_pub, 5734 TALER_EXCHANGEDB_PurseRefundCoinCallback cb, 5735 void *cb_cls); 5736 5737 5738 /** 5739 * Select refresh sessions above @a serial_id in monotonically increasing 5740 * order. 5741 * 5742 * @param cls closure 5743 * @param serial_id highest serial ID to exclude (select strictly larger) 5744 * @param cb function to call on each result 5745 * @param cb_cls closure for @a cb 5746 * @return transaction status code 5747 */ 5748 enum GNUNET_DB_QueryStatus 5749 (*select_refreshes_above_serial_id)( 5750 void *cls, 5751 uint64_t serial_id, 5752 TALER_EXCHANGEDB_RefreshesCallback cb, 5753 void *cb_cls); 5754 5755 5756 /** 5757 * Select refunds above @a serial_id in monotonically increasing 5758 * order. 5759 * 5760 * @param cls closure 5761 * @param serial_id highest serial ID to exclude (select strictly larger) 5762 * @param cb function to call on each result 5763 * @param cb_cls closure for @a cb 5764 * @return transaction status code 5765 */ 5766 enum GNUNET_DB_QueryStatus 5767 (*select_refunds_above_serial_id)( 5768 void *cls, 5769 uint64_t serial_id, 5770 TALER_EXCHANGEDB_RefundCallback cb, 5771 void *cb_cls); 5772 5773 5774 /** 5775 * Select inbound wire transfers into reserves_in above @a serial_id 5776 * in monotonically increasing order. 5777 * 5778 * @param cls closure 5779 * @param serial_id highest serial ID to exclude (select strictly larger) 5780 * @param cb function to call on each result 5781 * @param cb_cls closure for @a cb 5782 * @return transaction status code 5783 */ 5784 enum GNUNET_DB_QueryStatus 5785 (*select_reserves_in_above_serial_id)( 5786 void *cls, 5787 uint64_t serial_id, 5788 TALER_EXCHANGEDB_ReserveInCallback cb, 5789 void *cb_cls); 5790 5791 5792 /** 5793 * Select inbound wire transfers into reserves_in above @a serial_id 5794 * in monotonically increasing order by @a account_name. 5795 * 5796 * @param cls closure 5797 * @param account_name name of the account for which we do the selection 5798 * @param serial_id highest serial ID to exclude (select strictly larger) 5799 * @param cb function to call on each result 5800 * @param cb_cls closure for @a cb 5801 * @return transaction status code 5802 */ 5803 enum GNUNET_DB_QueryStatus 5804 (*select_reserves_in_above_serial_id_by_account)( 5805 void *cls, 5806 const char *account_name, 5807 uint64_t serial_id, 5808 TALER_EXCHANGEDB_ReserveInCallback cb, 5809 void *cb_cls); 5810 5811 5812 /** 5813 * Select withdraw operations from withdraw table above @a serial_id 5814 * in monotonically increasing order. 5815 * 5816 * @param cls closure 5817 * @param serial_id highest serial ID to exclude (select strictly larger) 5818 * @param cb function to call on each result 5819 * @param cb_cls closure for @a cb 5820 * @return transaction status code 5821 */ 5822 enum GNUNET_DB_QueryStatus 5823 (*select_withdrawals_above_serial_id)( 5824 void *cls, 5825 uint64_t serial_id, 5826 TALER_EXCHANGEDB_WithdrawCallback cb, 5827 void *cb_cls); 5828 5829 5830 /** 5831 * Function called to select outgoing wire transfers the exchange 5832 * executed, ordered by serial ID (monotonically increasing). 5833 * 5834 * @param cls closure 5835 * @param serial_id lowest serial ID to include (select larger or equal) 5836 * @param cb function to call for ONE unfinished item 5837 * @param cb_cls closure for @a cb 5838 * @return transaction status code 5839 */ 5840 enum GNUNET_DB_QueryStatus 5841 (*select_wire_out_above_serial_id)( 5842 void *cls, 5843 uint64_t serial_id, 5844 TALER_EXCHANGEDB_WireTransferOutCallback cb, 5845 void *cb_cls); 5846 5847 /** 5848 * Function called to select outgoing wire transfers the exchange 5849 * executed, ordered by serial ID (monotonically increasing). 5850 * 5851 * @param cls closure 5852 * @param account_name name to select by 5853 * @param serial_id lowest serial ID to include (select larger or equal) 5854 * @param cb function to call for ONE unfinished item 5855 * @param cb_cls closure for @a cb 5856 * @return transaction status code 5857 */ 5858 enum GNUNET_DB_QueryStatus 5859 (*select_wire_out_above_serial_id_by_account)( 5860 void *cls, 5861 const char *account_name, 5862 uint64_t serial_id, 5863 TALER_EXCHANGEDB_WireTransferOutCallback cb, 5864 void *cb_cls); 5865 5866 5867 /** 5868 * Function called to select recoup requests the exchange 5869 * received, ordered by serial ID (monotonically increasing). 5870 * 5871 * @param cls closure 5872 * @param serial_id lowest serial ID to include (select larger or equal) 5873 * @param cb function to call for ONE unfinished item 5874 * @param cb_cls closure for @a cb 5875 * @return transaction status code 5876 */ 5877 enum GNUNET_DB_QueryStatus 5878 (*select_recoup_above_serial_id)( 5879 void *cls, 5880 uint64_t serial_id, 5881 TALER_EXCHANGEDB_RecoupCallback cb, 5882 void *cb_cls); 5883 5884 5885 /** 5886 * Function called to select recoup requests the exchange received for 5887 * refreshed coins, ordered by serial ID (monotonically increasing). 5888 * 5889 * @param cls closure 5890 * @param serial_id lowest serial ID to include (select larger or equal) 5891 * @param cb function to call for ONE unfinished item 5892 * @param cb_cls closure for @a cb 5893 * @return transaction status code 5894 */ 5895 enum GNUNET_DB_QueryStatus 5896 (*select_recoup_refresh_above_serial_id)( 5897 void *cls, 5898 uint64_t serial_id, 5899 TALER_EXCHANGEDB_RecoupRefreshCallback cb, 5900 void *cb_cls); 5901 5902 5903 /** 5904 * Function called to select reserve open operations, ordered by serial ID 5905 * (monotonically increasing). 5906 * 5907 * @param cls closure 5908 * @param serial_id lowest serial ID to include (select larger or equal) 5909 * @param cb function to call 5910 * @param cb_cls closure for @a cb 5911 * @return transaction status code 5912 */ 5913 enum GNUNET_DB_QueryStatus 5914 (*select_reserve_open_above_serial_id)( 5915 void *cls, 5916 uint64_t serial_id, 5917 TALER_EXCHANGEDB_ReserveOpenCallback cb, 5918 void *cb_cls); 5919 5920 5921 /** 5922 * Function called to select reserve close operations the aggregator 5923 * triggered, ordered by serial ID (monotonically increasing). 5924 * 5925 * @param cls closure 5926 * @param serial_id lowest serial ID to include (select larger or equal) 5927 * @param cb function to call 5928 * @param cb_cls closure for @a cb 5929 * @return transaction status code 5930 */ 5931 enum GNUNET_DB_QueryStatus 5932 (*select_reserve_closed_above_serial_id)( 5933 void *cls, 5934 uint64_t serial_id, 5935 TALER_EXCHANGEDB_ReserveClosedCallback cb, 5936 void *cb_cls); 5937 5938 5939 /** 5940 * Obtain information about which reserve was involved in a 5941 * withdraw protocol, given the commitment. 5942 * 5943 * @param cls closure 5944 * @param h_planchets hash of the planchets, identifying the withdraw operation 5945 * @param[out] reserve_pub set to information about the reserve (on success only) 5946 * @param[out] withdraw_serial_id set to row of the @a h_planchet in withdraw 5947 * @return transaction status code 5948 */ 5949 enum GNUNET_DB_QueryStatus 5950 (*get_reserve_by_h_planchets)( 5951 void *cls, 5952 const struct TALER_HashBlindedPlanchetsP *h_planchets, 5953 struct TALER_ReservePublicKeyP *reserve_pub, 5954 uint64_t *withdraw_serial_id); 5955 5956 5957 /** 5958 * Obtain information about which old coin a coin was refreshed 5959 * given the hash of the blinded (fresh) coin. 5960 * 5961 * @param cls closure 5962 * @param h_blind_ev hash of the blinded coin 5963 * @param[out] old_coin_pub set to information about the old coin (on success only) 5964 * @param[out] rrc_serial set to the row of the @a h_blind_ev in the refresh_revealed_coins table 5965 * @return transaction status code 5966 */ 5967 enum GNUNET_DB_QueryStatus 5968 (*get_old_coin_by_h_blind)( 5969 void *cls, 5970 const struct TALER_BlindedCoinHashP *h_blind_ev, 5971 struct TALER_CoinSpendPublicKeyP *old_coin_pub, 5972 uint64_t *rrc_serial); 5973 5974 5975 /** 5976 * Store information that a denomination key was revoked 5977 * in the database. 5978 * 5979 * @param cls closure 5980 * @param denom_pub_hash hash of the revoked denomination key 5981 * @param master_sig signature affirming the revocation 5982 * @return transaction status code 5983 */ 5984 enum GNUNET_DB_QueryStatus 5985 (*insert_denomination_revocation)( 5986 void *cls, 5987 const struct TALER_DenominationHashP *denom_pub_hash, 5988 const struct TALER_MasterSignatureP *master_sig); 5989 5990 5991 /** 5992 * Obtain information about a denomination key's revocation from 5993 * the database. 5994 * 5995 * @param cls closure 5996 * @param denom_pub_hash hash of the revoked denomination key 5997 * @param[out] master_sig signature affirming the revocation 5998 * @param[out] rowid row where the information is stored 5999 * @return transaction status code 6000 */ 6001 enum GNUNET_DB_QueryStatus 6002 (*get_denomination_revocation)( 6003 void *cls, 6004 const struct TALER_DenominationHashP *denom_pub_hash, 6005 struct TALER_MasterSignatureP *master_sig, 6006 uint64_t *rowid); 6007 6008 6009 /** 6010 * Select all (batch) deposits in the database 6011 * above a given @a min_batch_deposit_serial_id. 6012 * 6013 * @param cls closure 6014 * @param min_batch_deposit_serial_id only return entries strictly above this row (and in order) 6015 * @param cb function to call on all such deposits 6016 * @param cb_cls closure for @a cb 6017 * @return transaction status code 6018 */ 6019 enum GNUNET_DB_QueryStatus 6020 (*select_batch_deposits_missing_wire)( 6021 void *cls, 6022 uint64_t min_batch_deposit_serial_id, 6023 TALER_EXCHANGEDB_WireMissingCallback cb, 6024 void *cb_cls); 6025 6026 6027 /** 6028 * Select all aggregation tracking IDs in the database 6029 * above a given @a min_tracking_serial_id. 6030 * 6031 * @param cls closure 6032 * @param min_tracking_serial_id only return entries strictly above this row (and in order) 6033 * @param cb function to call on all such aggregations 6034 * @param cb_cls closure for @a cb 6035 * @return transaction status code 6036 */ 6037 enum GNUNET_DB_QueryStatus 6038 (*select_aggregations_above_serial)( 6039 void *cls, 6040 uint64_t min_tracking_serial_id, 6041 TALER_EXCHANGEDB_AggregationCallback cb, 6042 void *cb_cls); 6043 6044 6045 /** 6046 * Return any applicable justification as to why a wire transfer might have 6047 * been held. Used by the auditor to determine if a wire transfer is 6048 * legitimately stalled. 6049 * 6050 * @param cls closure 6051 * @param wire_target_h_payto effected target account 6052 * @param[out] payto_uri target account URI, set to NULL if unknown 6053 * @param[out] jproperties account properties 6054 * @param[out] jrules applicable KYC rules 6055 * @return transaction status code 6056 */ 6057 enum GNUNET_DB_QueryStatus 6058 (*select_justification_for_missing_wire)( 6059 void *cls, 6060 const struct TALER_FullPaytoHashP *wire_target_h_payto, 6061 struct TALER_FullPayto *payto_uri, 6062 json_t **jproperties, 6063 json_t **jrules); 6064 6065 6066 /** 6067 * Check the last date an auditor was modified. 6068 * 6069 * @param cls closure 6070 * @param auditor_pub key to look up information for 6071 * @param[out] last_date last modification date to auditor status 6072 * @return transaction status code 6073 */ 6074 enum GNUNET_DB_QueryStatus 6075 (*lookup_auditor_timestamp)( 6076 void *cls, 6077 const struct TALER_AuditorPublicKeyP *auditor_pub, 6078 struct GNUNET_TIME_Timestamp *last_date); 6079 6080 6081 /** 6082 * Lookup current state of an auditor. 6083 * 6084 * @param cls closure 6085 * @param auditor_pub key to look up information for 6086 * @param[out] auditor_url set to the base URL of the auditor's REST API; memory to be 6087 * released by the caller! 6088 * @param[out] enabled set if the auditor is currently in use 6089 * @return transaction status code 6090 */ 6091 enum GNUNET_DB_QueryStatus 6092 (*lookup_auditor_status)( 6093 void *cls, 6094 const struct TALER_AuditorPublicKeyP *auditor_pub, 6095 char **auditor_url, 6096 bool *enabled); 6097 6098 6099 /** 6100 * Insert information about an auditor that will audit this exchange. 6101 * 6102 * @param cls closure 6103 * @param auditor_pub key of the auditor 6104 * @param auditor_url base URL of the auditor's REST service 6105 * @param auditor_name name of the auditor (for humans) 6106 * @param start_date date when the auditor was added by the offline system 6107 * (only to be used for replay detection) 6108 * @return transaction status code 6109 */ 6110 enum GNUNET_DB_QueryStatus 6111 (*insert_auditor)( 6112 void *cls, 6113 const struct TALER_AuditorPublicKeyP *auditor_pub, 6114 const char *auditor_url, 6115 const char *auditor_name, 6116 struct GNUNET_TIME_Timestamp start_date); 6117 6118 6119 /** 6120 * Update information about an auditor that will audit this exchange. 6121 * 6122 * @param cls closure 6123 * @param auditor_pub key of the auditor (primary key for the existing record) 6124 * @param auditor_url base URL of the auditor's REST service, to be updated 6125 * @param auditor_name name of the auditor (for humans) 6126 * @param change_date date when the auditor status was last changed 6127 * (only to be used for replay detection) 6128 * @param enabled true to enable, false to disable 6129 * @return transaction status code 6130 */ 6131 enum GNUNET_DB_QueryStatus 6132 (*update_auditor)( 6133 void *cls, 6134 const struct TALER_AuditorPublicKeyP *auditor_pub, 6135 const char *auditor_url, 6136 const char *auditor_name, 6137 struct GNUNET_TIME_Timestamp change_date, 6138 bool enabled); 6139 6140 6141 /** 6142 * Check the last date an exchange wire account was modified. 6143 * 6144 * @param cls closure 6145 * @param payto_uri key to look up information for 6146 * @param[out] last_date last modification date to auditor status 6147 * @return transaction status code 6148 */ 6149 enum GNUNET_DB_QueryStatus 6150 (*lookup_wire_timestamp)(void *cls, 6151 const struct TALER_FullPayto payto_uri, 6152 struct GNUNET_TIME_Timestamp *last_date); 6153 6154 6155 /** 6156 * Insert information about an wire account used by this exchange. 6157 * 6158 * @param cls closure 6159 * @param payto_uri wire account of the exchange 6160 * @param conversion_url URL of a conversion service, NULL if there is no conversion 6161 * @param open_banking_gateway open banking gateway service, NULL if unavailable 6162 * @param wire_transfer_gateway wire transfer gateway service, NULL if unavailable 6163 * @param debit_restrictions JSON array with debit restrictions on the account 6164 * @param credit_restrictions JSON array with credit restrictions on the account 6165 * @param start_date date when the account was added by the offline system 6166 * (only to be used for replay detection) 6167 * @param master_sig public signature affirming the existence of the account, 6168 * must be of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS 6169 * @param bank_label label to show this entry under in the UI, can be NULL 6170 * @param priority determines order in which entries are shown in the UI 6171 * @return transaction status code 6172 */ 6173 enum GNUNET_DB_QueryStatus 6174 (*insert_wire)(void *cls, 6175 const struct TALER_FullPayto payto_uri, 6176 const char *conversion_url, 6177 const char *open_banking_gateway, 6178 const char *wire_transfer_gateway, 6179 const json_t *debit_restrictions, 6180 const json_t *credit_restrictions, 6181 struct GNUNET_TIME_Timestamp start_date, 6182 const struct TALER_MasterSignatureP *master_sig, 6183 const char *bank_label, 6184 int64_t priority); 6185 6186 6187 /** 6188 * Update information about a wire account of the exchange. 6189 * 6190 * @param cls closure 6191 * @param payto_uri account the update is about 6192 * @param conversion_url URL of a conversion service, NULL if there is no conversion 6193 * @param open_banking_gateway open banking gateway service, NULL if unavailable 6194 * @param wire_transfer_gateway wire transfer gateway service, NULL if unavailable 6195 * @param debit_restrictions JSON array with debit restrictions on the account; NULL allowed if not @a enabled 6196 * @param credit_restrictions JSON array with credit restrictions on the account; NULL allowed if not @a enabled 6197 * @param change_date date when the account status was last changed 6198 * (only to be used for replay detection) 6199 * @param master_sig master signature to store, can be NULL (if @a enabled is false) 6200 * @param bank_label label to show this entry under in the UI, can be NULL 6201 * @param priority determines order in which entries are shown in the UI 6202 * @param enabled true to enable, false to disable (the actual change) 6203 * @return transaction status code 6204 */ 6205 enum GNUNET_DB_QueryStatus 6206 (*update_wire)(void *cls, 6207 const struct TALER_FullPayto payto_uri, 6208 const char *conversion_url, 6209 const char *open_banking_gateway, 6210 const char *wire_transfer_gateway, 6211 const json_t *debit_restrictions, 6212 const json_t *credit_restrictions, 6213 struct GNUNET_TIME_Timestamp change_date, 6214 const struct TALER_MasterSignatureP *master_sig, 6215 const char *bank_label, 6216 int64_t priority, 6217 bool enabled); 6218 6219 6220 /** 6221 * Obtain information about the enabled wire accounts of the exchange. 6222 * 6223 * @param cls closure 6224 * @param cb function to call on each account 6225 * @param cb_cls closure for @a cb 6226 * @return transaction status code 6227 */ 6228 enum GNUNET_DB_QueryStatus 6229 (*get_wire_accounts)(void *cls, 6230 TALER_EXCHANGEDB_WireAccountCallback cb, 6231 void *cb_cls); 6232 6233 6234 /** 6235 * Obtain information about the fee structure of the exchange for 6236 * a given @a wire_method 6237 * 6238 * @param cls closure 6239 * @param wire_method which wire method to obtain fees for 6240 * @param cb function to call on each account 6241 * @param cb_cls closure for @a cb 6242 * @return transaction status code 6243 */ 6244 enum GNUNET_DB_QueryStatus 6245 (*get_wire_fees)(void *cls, 6246 const char *wire_method, 6247 TALER_EXCHANGEDB_WireFeeCallback cb, 6248 void *cb_cls); 6249 6250 6251 /** 6252 * Obtain information about the global fee structure of the exchange. 6253 * 6254 * @param cls closure 6255 * @param cb function to call on each fee entry 6256 * @param cb_cls closure for @a cb 6257 * @return transaction status code 6258 */ 6259 enum GNUNET_DB_QueryStatus 6260 (*get_global_fees)(void *cls, 6261 TALER_EXCHANGEDB_GlobalFeeCallback cb, 6262 void *cb_cls); 6263 6264 6265 /** 6266 * Store information about a revoked online signing key. 6267 * 6268 * @param cls closure 6269 * @param exchange_pub exchange online signing key that was revoked 6270 * @param master_sig signature affirming the revocation 6271 * @return transaction status code 6272 */ 6273 enum GNUNET_DB_QueryStatus 6274 (*insert_signkey_revocation)( 6275 void *cls, 6276 const struct TALER_ExchangePublicKeyP *exchange_pub, 6277 const struct TALER_MasterSignatureP *master_sig); 6278 6279 6280 /** 6281 * Obtain information about a revoked online signing key. 6282 * 6283 * @param cls closure 6284 * @param exchange_pub exchange online signing key that was revoked 6285 * @param[out] master_sig signature affirming the revocation 6286 * @return transaction status code 6287 */ 6288 enum GNUNET_DB_QueryStatus 6289 (*lookup_signkey_revocation)( 6290 void *cls, 6291 const struct TALER_ExchangePublicKeyP *exchange_pub, 6292 struct TALER_MasterSignatureP *master_sig); 6293 6294 6295 /** 6296 * Lookup information about current denomination key. 6297 * 6298 * @param cls closure 6299 * @param h_denom_pub hash of the denomination public key 6300 * @param[out] meta set to various meta data about the key 6301 * @return transaction status code 6302 */ 6303 enum GNUNET_DB_QueryStatus 6304 (*lookup_denomination_key)( 6305 void *cls, 6306 const struct TALER_DenominationHashP *h_denom_pub, 6307 struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta); 6308 6309 6310 /** 6311 * Add denomination key. 6312 * 6313 * @param cls closure 6314 * @param h_denom_pub hash of the denomination public key 6315 * @param denom_pub the denomination public key 6316 * @param meta meta data about the denomination 6317 * @param master_sig master signature to add 6318 * @return transaction status code 6319 */ 6320 enum GNUNET_DB_QueryStatus 6321 (*add_denomination_key)( 6322 void *cls, 6323 const struct TALER_DenominationHashP *h_denom_pub, 6324 const struct TALER_DenominationPublicKey *denom_pub, 6325 const struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta, 6326 const struct TALER_MasterSignatureP *master_sig); 6327 6328 6329 /** 6330 * Activate future signing key, turning it into a "current" or "valid" 6331 * denomination key by adding the master signature. 6332 * 6333 * @param cls closure 6334 * @param exchange_pub the exchange online signing public key 6335 * @param meta meta data about @a exchange_pub 6336 * @param master_sig master signature to add 6337 * @return transaction status code 6338 */ 6339 enum GNUNET_DB_QueryStatus 6340 (*activate_signing_key)( 6341 void *cls, 6342 const struct TALER_ExchangePublicKeyP *exchange_pub, 6343 const struct TALER_EXCHANGEDB_SignkeyMetaData *meta, 6344 const struct TALER_MasterSignatureP *master_sig); 6345 6346 6347 /** 6348 * Lookup signing key meta data. 6349 * 6350 * @param cls closure 6351 * @param exchange_pub the exchange online signing public key 6352 * @param[out] meta meta data about @a exchange_pub 6353 * @return transaction status code 6354 */ 6355 enum GNUNET_DB_QueryStatus 6356 (*lookup_signing_key)( 6357 void *cls, 6358 const struct TALER_ExchangePublicKeyP *exchange_pub, 6359 struct TALER_EXCHANGEDB_SignkeyMetaData *meta); 6360 6361 6362 /** 6363 * Insert information about an auditor auditing a denomination key. 6364 * 6365 * @param cls closure 6366 * @param h_denom_pub the audited denomination 6367 * @param auditor_pub the auditor's key 6368 * @param auditor_sig signature affirming the auditor's audit activity 6369 * @return transaction status code 6370 */ 6371 enum GNUNET_DB_QueryStatus 6372 (*insert_auditor_denom_sig)( 6373 void *cls, 6374 const struct TALER_DenominationHashP *h_denom_pub, 6375 const struct TALER_AuditorPublicKeyP *auditor_pub, 6376 const struct TALER_AuditorSignatureP *auditor_sig); 6377 6378 6379 /** 6380 * Obtain information about an auditor auditing a denomination key. 6381 * 6382 * @param cls closure 6383 * @param h_denom_pub the audited denomination 6384 * @param auditor_pub the auditor's key 6385 * @param[out] auditor_sig set to signature affirming the auditor's audit activity 6386 * @return transaction status code 6387 */ 6388 enum GNUNET_DB_QueryStatus 6389 (*select_auditor_denom_sig)( 6390 void *cls, 6391 const struct TALER_DenominationHashP *h_denom_pub, 6392 const struct TALER_AuditorPublicKeyP *auditor_pub, 6393 struct TALER_AuditorSignatureP *auditor_sig); 6394 6395 6396 /** 6397 * Lookup information about known wire fees. 6398 * 6399 * @param cls closure 6400 * @param wire_method the wire method to lookup fees for 6401 * @param start_time starting time of fee 6402 * @param end_time end time of fee 6403 * @param[out] fees set to wire fees for that time period; if 6404 * different wire fee exists within this time 6405 * period, an 'invalid' amount is returned. 6406 * @return transaction status code 6407 */ 6408 enum GNUNET_DB_QueryStatus 6409 (*lookup_wire_fee_by_time)( 6410 void *cls, 6411 const char *wire_method, 6412 struct GNUNET_TIME_Timestamp start_time, 6413 struct GNUNET_TIME_Timestamp end_time, 6414 struct TALER_WireFeeSet *fees); 6415 6416 6417 /** 6418 * Lookup information about known global fees. 6419 * 6420 * @param cls closure 6421 * @param start_time starting time of fee 6422 * @param end_time end time of fee 6423 * @param[out] fees set to wire fees for that time period; if 6424 * different global fee exists within this time 6425 * period, an 'invalid' amount is returned. 6426 * @param[out] purse_timeout set to when unmerged purses expire 6427 * @param[out] history_expiration set to when we expire reserve histories 6428 * @param[out] purse_account_limit set to number of free purses 6429 * @return transaction status code 6430 */ 6431 enum GNUNET_DB_QueryStatus 6432 (*lookup_global_fee_by_time)( 6433 void *cls, 6434 struct GNUNET_TIME_Timestamp start_time, 6435 struct GNUNET_TIME_Timestamp end_time, 6436 struct TALER_GlobalFeeSet *fees, 6437 struct GNUNET_TIME_Relative *purse_timeout, 6438 struct GNUNET_TIME_Relative *history_expiration, 6439 uint32_t *purse_account_limit); 6440 6441 6442 /** 6443 * Lookup the latest serial number of @a table. Used in 6444 * exchange-auditor database replication. 6445 * 6446 * @param cls closure 6447 * @param table table for which we should return the serial 6448 * @param[out] latest serial number in use 6449 * @return transaction status code, #GNUNET_DB_STATUS_HARD_ERROR if 6450 * @a table does not have a serial number 6451 */ 6452 enum GNUNET_DB_QueryStatus 6453 (*lookup_serial_by_table)(void *cls, 6454 enum TALER_EXCHANGEDB_ReplicatedTable table, 6455 uint64_t *serial); 6456 6457 /** 6458 * Lookup records above @a serial number in @a table. Used in 6459 * exchange-auditor database replication. 6460 * 6461 * @param cls closure 6462 * @param table table for which we should return the serial 6463 * @param serial largest serial number to exclude 6464 * @param cb function to call on the records 6465 * @param cb_cls closure for @a cb 6466 * @return transaction status code, GNUNET_DB_STATUS_HARD_ERROR if 6467 * @a table does not have a serial number 6468 */ 6469 enum GNUNET_DB_QueryStatus 6470 (*lookup_records_by_table)(void *cls, 6471 enum TALER_EXCHANGEDB_ReplicatedTable table, 6472 uint64_t serial, 6473 TALER_EXCHANGEDB_ReplicationCallback cb, 6474 void *cb_cls); 6475 6476 6477 /** 6478 * Insert record set into @a table. Used in exchange-auditor database 6479 * replication. 6480 * 6481 memset (&awc, 0, sizeof (awc)); 6482 * @param cls closure 6483 * @param tb table data to insert 6484 * @return transaction status code, #GNUNET_DB_STATUS_HARD_ERROR if 6485 * @a table does not have a serial number 6486 */ 6487 enum GNUNET_DB_QueryStatus 6488 (*insert_records_by_table)(void *cls, 6489 const struct TALER_EXCHANGEDB_TableData *td); 6490 6491 6492 /** 6493 * Function called to grab a work shard on an operation @a op. Runs in its 6494 * own transaction. 6495 * 6496 * @param cls the @e cls of this struct with the plugin-specific state 6497 * @param job_name name of the operation to grab a word shard for 6498 * @param delay minimum age of a shard to grab 6499 * @param size desired shard size 6500 * @param[out] start_row inclusive start row of the shard (returned) 6501 * @param[out] end_row exclusive end row of the shard (returned) 6502 * @return transaction status code 6503 */ 6504 enum GNUNET_DB_QueryStatus 6505 (*begin_shard)(void *cls, 6506 const char *job_name, 6507 struct GNUNET_TIME_Relative delay, 6508 uint64_t shard_size, 6509 uint64_t *start_row, 6510 uint64_t *end_row); 6511 6512 /** 6513 * Function called to abort work on a shard. 6514 * 6515 * @param cls the @e cls of this struct with the plugin-specific state 6516 * @param job_name name of the operation to abort a word shard for 6517 * @param start_row inclusive start row of the shard 6518 * @param end_row exclusive end row of the shard 6519 * @return transaction status code 6520 */ 6521 enum GNUNET_DB_QueryStatus 6522 (*abort_shard)(void *cls, 6523 const char *job_name, 6524 uint64_t start_row, 6525 uint64_t end_row); 6526 6527 /** 6528 * Function called to persist that work on a shard was completed. 6529 * 6530 * @param cls the @e cls of this struct with the plugin-specific state 6531 * @param job_name name of the operation to grab a word shard for 6532 * @param start_row inclusive start row of the shard 6533 * @param end_row exclusive end row of the shard 6534 * @return transaction status code 6535 */ 6536 enum GNUNET_DB_QueryStatus 6537 (*complete_shard)(void *cls, 6538 const char *job_name, 6539 uint64_t start_row, 6540 uint64_t end_row); 6541 6542 6543 /** 6544 * Function called to grab a revolving work shard on an operation @a op. Runs 6545 * in its own transaction. Returns the oldest inactive shard. 6546 * 6547 * @param cls the @e cls of this struct with the plugin-specific state 6548 * @param job_name name of the operation to grab a revolving shard for 6549 * @param shard_size desired shard size 6550 * @param shard_limit exclusive end of the shard range 6551 * @param[out] start_row inclusive start row of the shard (returned) 6552 * @param[out] end_row inclusive end row of the shard (returned) 6553 * @return transaction status code 6554 */ 6555 enum GNUNET_DB_QueryStatus 6556 (*begin_revolving_shard)(void *cls, 6557 const char *job_name, 6558 uint32_t shard_size, 6559 uint32_t shard_limit, 6560 uint32_t *start_row, 6561 uint32_t *end_row); 6562 6563 6564 /** 6565 * Function called to release a revolving shard back into the work pool. 6566 * Clears the "completed" flag. 6567 * 6568 * @param cls the @e cls of this struct with the plugin-specific state 6569 * @param job_name name of the operation to grab a word shard for 6570 * @param start_row inclusive start row of the shard 6571 * @param end_row inclusive end row of the shard 6572 * @return transaction status code 6573 */ 6574 enum GNUNET_DB_QueryStatus 6575 (*release_revolving_shard)(void *cls, 6576 const char *job_name, 6577 uint32_t start_row, 6578 uint32_t end_row); 6579 6580 6581 /** 6582 * Function called to delete all revolving shards. 6583 * To be used after a crash or when the shard size is 6584 * changed. 6585 * 6586 * @param cls the @e cls of this struct with the plugin-specific state 6587 * @return #GNUNET_OK on success 6588 * #GNUNET_SYSERR on failure 6589 */ 6590 enum GNUNET_GenericReturnValue 6591 (*delete_shard_locks)(void *cls); 6592 6593 6594 /** 6595 * Function called to save the manifest of an extension 6596 * (age-restriction, policy-extension, ...) 6597 * 6598 * @param cls the @e cls of this struct with the plugin-specific state 6599 * @param extension_name the name of the extension 6600 * @param manifest JSON object of the Manifest as string, maybe NULL (== disabled extension) 6601 * @return transaction status code 6602 */ 6603 enum GNUNET_DB_QueryStatus 6604 (*set_extension_manifest)(void *cls, 6605 const char *extension_name, 6606 const char *manifest); 6607 6608 6609 /** 6610 * Function called to retrieve the manifest of an extension 6611 * (age-restriction, policy-extension, ...) 6612 * 6613 * @param cls the @e cls of this struct with the plugin-specific state 6614 * @param extension_name the name of the extension 6615 * @param[out] manifest Manifest of the extension in JSON encoding, maybe NULL (== disabled extension) 6616 * @return transaction status code 6617 */ 6618 enum GNUNET_DB_QueryStatus 6619 (*get_extension_manifest)(void *cls, 6620 const char *extension_name, 6621 char **manifest); 6622 6623 6624 /** 6625 * Function called to store configuration data about a partner 6626 * exchange that we are federated with. 6627 * 6628 * @param cls the @e cls of this struct with the plugin-specific state 6629 * @param master_pub public offline signing key of the partner exchange 6630 * @param start_date when does the following data start to be valid 6631 * @param end_date when does the validity end (exclusive) 6632 * @param wad_frequency how often do we do exchange-to-exchange settlements? 6633 * @param wad_fee how much do we charge for transfers to the partner 6634 * @param partner_base_url base URL of the partner exchange 6635 * @param master_sig signature with our offline signing key affirming the above 6636 * @return transaction status code 6637 */ 6638 enum GNUNET_DB_QueryStatus 6639 (*insert_partner)(void *cls, 6640 const struct TALER_MasterPublicKeyP *master_pub, 6641 struct GNUNET_TIME_Timestamp start_date, 6642 struct GNUNET_TIME_Timestamp end_date, 6643 struct GNUNET_TIME_Relative wad_frequency, 6644 const struct TALER_Amount *wad_fee, 6645 const char *partner_base_url, 6646 const struct TALER_MasterSignatureP *master_sig); 6647 6648 6649 /** 6650 * Function called to persist an encrypted contract associated with a reserve. 6651 * 6652 * @param cls the @e cls of this struct with the plugin-specific state 6653 * @param econtract the encrypted contract 6654 * @param[out] econtract_sig set to the signature over the encrypted contract 6655 * @param[out] in_conflict set to true if @a econtract 6656 * conflicts with an existing contract; 6657 * in this case, the return value will be 6658 * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT despite the failure 6659 * @return transaction status code 6660 */ 6661 enum GNUNET_DB_QueryStatus 6662 (*insert_contract)(void *cls, 6663 const struct TALER_PurseContractPublicKeyP *purse_pub, 6664 const struct TALER_EncryptedContract *econtract, 6665 bool *in_conflict); 6666 6667 6668 /** 6669 * Function called to retrieve an encrypted contract. 6670 * 6671 * @param cls the @e cls of this struct with the plugin-specific state 6672 * @param pub_ckey set to the ephemeral DH used to encrypt the contract, key used to lookup the contract by 6673 * @param[out] purse_pub public key of the purse of the contract 6674 * @param[out] econtract_sig set to the signature over the encrypted contract 6675 * @param[out] econtract_size set to the number of bytes in @a econtract 6676 * @param[out] econtract set to the encrypted contract on success, to be freed by the caller 6677 * @return transaction status code 6678 */ 6679 enum GNUNET_DB_QueryStatus 6680 (*select_contract)( 6681 void *cls, 6682 const struct TALER_ContractDiffiePublicP *pub_ckey, 6683 struct TALER_PurseContractPublicKeyP *purse_pub, 6684 struct TALER_PurseContractSignatureP *econtract_sig, 6685 size_t *econtract_size, 6686 void **econtract); 6687 6688 6689 /** 6690 * Function called to retrieve an encrypted contract. 6691 * 6692 * @param cls the @e cls of this struct with the plugin-specific state 6693 * @param purse_pub key to lookup the contract by 6694 * @param[out] econtract set to the encrypted contract on success, to be freed by the caller 6695 * @return transaction status code 6696 */ 6697 enum GNUNET_DB_QueryStatus 6698 (*select_contract_by_purse)( 6699 void *cls, 6700 const struct TALER_PurseContractPublicKeyP *purse_pub, 6701 struct TALER_EncryptedContract *econtract); 6702 6703 6704 /** 6705 * Function called to create a new purse with certain meta data. 6706 * 6707 * @param cls the @e cls of this struct with the plugin-specific state 6708 * @param purse_pub public key of the new purse 6709 * @param merge_pub public key providing the merge capability 6710 * @param purse_expiration time when the purse will expire 6711 * @param h_contract_terms hash of the contract for the purse 6712 * @param age_limit age limit to enforce for payments into the purse 6713 * @param flags flags for the operation 6714 * @param purse_fee fee we are allowed to charge to the reserve (depending on @a flags) 6715 * @param amount target amount (with fees) to be put into the purse 6716 * @param purse_sig signature with @a purse_pub's private key affirming the above 6717 * @param[out] in_conflict set to true if the meta data 6718 * conflicts with an existing purse; 6719 * in this case, the return value will be 6720 * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT despite the failure 6721 * @return transaction status code 6722 */ 6723 enum GNUNET_DB_QueryStatus 6724 (*insert_purse_request)( 6725 void *cls, 6726 const struct TALER_PurseContractPublicKeyP *purse_pub, 6727 const struct TALER_PurseMergePublicKeyP *merge_pub, 6728 struct GNUNET_TIME_Timestamp purse_expiration, 6729 const struct TALER_PrivateContractHashP *h_contract_terms, 6730 uint32_t age_limit, 6731 enum TALER_WalletAccountMergeFlags flags, 6732 const struct TALER_Amount *purse_fee, 6733 const struct TALER_Amount *amount, 6734 const struct TALER_PurseContractSignatureP *purse_sig, 6735 bool *in_conflict); 6736 6737 6738 /** 6739 * Function called to clean up one expired purse. 6740 * 6741 * @param cls the @e cls of this struct with the plugin-specific state 6742 * @param start_time select purse expired after this time 6743 * @param end_time select purse expired before this time 6744 * @return transaction status code (#GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if no purse expired in the given time interval). 6745 */ 6746 enum GNUNET_DB_QueryStatus 6747 (*expire_purse)( 6748 void *cls, 6749 struct GNUNET_TIME_Absolute start_time, 6750 struct GNUNET_TIME_Absolute end_time); 6751 6752 6753 /** 6754 * Function called to obtain information about a purse. 6755 * 6756 * @param cls the @e cls of this struct with the plugin-specific state 6757 * @param purse_pub public key of the new purse 6758 * @param[out] purse_creation set to time when the purse was created 6759 * @param[out] purse_expiration set to time when the purse will expire 6760 * @param[out] amount set to target amount (with fees) to be put into the purse 6761 * @param[out] deposited set to actual amount put into the purse so far 6762 * @param[out] h_contract_terms set to hash of the contract for the purse 6763 * @param[out] merge_timestamp set to time when the purse was merged, or NEVER if not 6764 * @param[out] purse_deleted set to true if purse was deleted 6765 * @param[out] purse_refunded set to true if purse was refunded (after expiration) 6766 * @return transaction status code 6767 */ 6768 enum GNUNET_DB_QueryStatus 6769 (*select_purse)( 6770 void *cls, 6771 const struct TALER_PurseContractPublicKeyP *purse_pub, 6772 struct GNUNET_TIME_Timestamp *purse_creation, 6773 struct GNUNET_TIME_Timestamp *purse_expiration, 6774 struct TALER_Amount *amount, 6775 struct TALER_Amount *deposited, 6776 struct TALER_PrivateContractHashP *h_contract_terms, 6777 struct GNUNET_TIME_Timestamp *merge_timestamp, 6778 bool *purse_deleted, 6779 bool *purse_refunded); 6780 6781 6782 /** 6783 * Function called to return meta data about a purse by the 6784 * purse public key. 6785 * 6786 * @param cls the @e cls of this struct with the plugin-specific state 6787 * @param purse_pub public key of the purse 6788 * @param[out] merge_pub public key representing the merge capability 6789 * @param[out] purse_expiration when would an unmerged purse expire 6790 * @param[out] h_contract_terms contract associated with the purse 6791 * @param[out] age_limit the age limit for deposits into the purse 6792 * @param[out] target_amount amount to be put into the purse 6793 * @param[out] balance amount put so far into the purse 6794 * @param[out] purse_sig signature of the purse over the initialization data 6795 * @return transaction status code 6796 */ 6797 enum GNUNET_DB_QueryStatus 6798 (*get_purse_request)( 6799 void *cls, 6800 const struct TALER_PurseContractPublicKeyP *purse_pub, 6801 struct TALER_PurseMergePublicKeyP *merge_pub, 6802 struct GNUNET_TIME_Timestamp *purse_expiration, 6803 struct TALER_PrivateContractHashP *h_contract_terms, 6804 uint32_t *age_limit, 6805 struct TALER_Amount *target_amount, 6806 struct TALER_Amount *balance, 6807 struct TALER_PurseContractSignatureP *purse_sig); 6808 6809 6810 /** 6811 * Function called to return meta data about a purse by the 6812 * merge capability key. 6813 * 6814 * @param cls the @e cls of this struct with the plugin-specific state 6815 * @param merge_pub public key representing the merge capability 6816 * @param[out] purse_pub public key of the purse 6817 * @param[out] purse_expiration when would an unmerged purse expire 6818 * @param[out] h_contract_terms contract associated with the purse 6819 * @param[out] age_limit the age limit for deposits into the purse 6820 * @param[out] target_amount amount to be put into the purse 6821 * @param[out] balance amount put so far into the purse 6822 * @param[out] purse_sig signature of the purse over the initialization data 6823 * @return transaction status code 6824 */ 6825 enum GNUNET_DB_QueryStatus 6826 (*select_purse_by_merge_pub)( 6827 void *cls, 6828 const struct TALER_PurseMergePublicKeyP *merge_pub, 6829 struct TALER_PurseContractPublicKeyP *purse_pub, 6830 struct GNUNET_TIME_Timestamp *purse_expiration, 6831 struct TALER_PrivateContractHashP *h_contract_terms, 6832 uint32_t *age_limit, 6833 struct TALER_Amount *target_amount, 6834 struct TALER_Amount *balance, 6835 struct TALER_PurseContractSignatureP *purse_sig); 6836 6837 6838 /** 6839 * Function called to execute a transaction crediting 6840 * a purse with @a amount from @a coin_pub. Reduces the 6841 * value of @a coin_pub and increase the balance of 6842 * the @a purse_pub purse. If the balance reaches the 6843 * target amount and the purse has been merged, triggers 6844 * the updates of the reserve/account balance. 6845 * 6846 * @param cls the @e cls of this struct with the plugin-specific state 6847 * @param purse_pub purse to credit 6848 * @param coin_pub coin to deposit (debit) 6849 * @param amount fraction of the coin's value to deposit 6850 * @param coin_sig signature affirming the operation 6851 * @param amount_minus_fee amount to add to the purse 6852 * @param[out] balance_ok set to false if the coin's 6853 * remaining balance is below @a amount; 6854 * in this case, the return value will be 6855 * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT despite the failure 6856 * @param[out] too_late it is too late to deposit into this purse 6857 * @param[out] conflict the same coin was deposited into 6858 * this purse with a different amount already 6859 * @return transaction status code 6860 */ 6861 enum GNUNET_DB_QueryStatus 6862 (*do_purse_deposit)( 6863 void *cls, 6864 const struct TALER_PurseContractPublicKeyP *purse_pub, 6865 const struct TALER_CoinSpendPublicKeyP *coin_pub, 6866 const struct TALER_Amount *amount, 6867 const struct TALER_CoinSpendSignatureP *coin_sig, 6868 const struct TALER_Amount *amount_minus_fee, 6869 bool *balance_ok, 6870 bool *too_late, 6871 bool *conflict); 6872 6873 6874 /** 6875 * Function called to explicitly delete a purse. 6876 * 6877 * @param cls the @e cls of this struct with the plugin-specific state 6878 * @param purse_pub purse to delete 6879 * @param purse_sig signature affirming the deletion 6880 * @param[out] decided set to true if the purse was 6881 * already decided and thus could not be deleted 6882 * @param[out] found set to true if the purse was found 6883 * (if false, purse could not be deleted) 6884 * @return transaction status code 6885 */ 6886 enum GNUNET_DB_QueryStatus 6887 (*do_purse_delete)( 6888 void *cls, 6889 const struct TALER_PurseContractPublicKeyP *purse_pub, 6890 const struct TALER_PurseContractSignatureP *purse_sig, 6891 bool *decided, 6892 bool *found); 6893 6894 6895 /** 6896 * Set the current @a balance in the purse 6897 * identified by @a purse_pub. Used by the auditor 6898 * to update the balance as calculated by the auditor. 6899 * 6900 * @param cls closure 6901 * @param purse_pub public key of a purse 6902 * @param balance new balance to store under the purse 6903 * @return transaction status 6904 */ 6905 enum GNUNET_DB_QueryStatus 6906 (*set_purse_balance)( 6907 void *cls, 6908 const struct TALER_PurseContractPublicKeyP *purse_pub, 6909 const struct TALER_Amount *balance); 6910 6911 6912 /** 6913 * Function called to obtain a coin deposit data from 6914 * depositing the coin into a purse. 6915 * 6916 * @param cls the @e cls of this struct with the plugin-specific state 6917 * @param purse_pub purse to credit 6918 * @param coin_pub coin to deposit (debit) 6919 * @param[out] amount set fraction of the coin's value that was deposited (with fee) 6920 * @param[out] h_denom_pub set to hash of denomination of the coin 6921 * @param[out] phac set to hash of age restriction on the coin 6922 * @param[out] coin_sig set to signature affirming the operation 6923 * @param[out] partner_url set to the URL of the partner exchange, or NULL for ourselves, must be freed by caller 6924 * @return transaction status code 6925 */ 6926 enum GNUNET_DB_QueryStatus 6927 (*get_purse_deposit)( 6928 void *cls, 6929 const struct TALER_PurseContractPublicKeyP *purse_pub, 6930 const struct TALER_CoinSpendPublicKeyP *coin_pub, 6931 struct TALER_Amount *amount, 6932 struct TALER_DenominationHashP *h_denom_pub, 6933 struct TALER_AgeCommitmentHashP *phac, 6934 struct TALER_CoinSpendSignatureP *coin_sig, 6935 char **partner_url); 6936 6937 6938 /** 6939 * Function called to approve merging a purse into a 6940 * reserve by the respective purse merge key. The purse 6941 * must not have been merged into a different reserve. 6942 * 6943 * @param cls the @e cls of this struct with the plugin-specific state 6944 * @param purse_pub purse to merge 6945 * @param merge_sig signature affirming the merge 6946 * @param merge_timestamp time of the merge 6947 * @param reserve_sig signature of the reserve affirming the merge 6948 * @param partner_url URL of the partner exchange, can be NULL if the reserves lives with us 6949 * @param reserve_pub public key of the reserve to credit 6950 * @param[out] no_partner set to true if @a partner_url is unknown 6951 * @param[out] no_balance set to true if the @a purse_pub is not paid up yet 6952 * @param[out] no_reserve set to true if the @a reserve_pub is not known 6953 * @param[out] in_conflict set to true if @a purse_pub was merged into a different reserve already 6954 * @return transaction status code 6955 */ 6956 enum GNUNET_DB_QueryStatus 6957 (*do_purse_merge)( 6958 void *cls, 6959 const struct TALER_PurseContractPublicKeyP *purse_pub, 6960 const struct TALER_PurseMergeSignatureP *merge_sig, 6961 const struct GNUNET_TIME_Timestamp merge_timestamp, 6962 const struct TALER_ReserveSignatureP *reserve_sig, 6963 const char *partner_url, 6964 const struct TALER_ReservePublicKeyP *reserve_pub, 6965 bool *no_partner, 6966 bool *no_balance, 6967 bool *in_conflict); 6968 6969 6970 /** 6971 * Function called insert request to merge a purse into a reserve by the 6972 * respective purse merge key. The purse must not have been merged into a 6973 * different reserve. 6974 * 6975 * @param cls the @e cls of this struct with the plugin-specific state 6976 * @param purse_pub purse to merge 6977 * @param merge_sig signature affirming the merge 6978 * @param merge_timestamp time of the merge 6979 * @param reserve_sig signature of the reserve affirming the merge 6980 * @param purse_fee amount to charge the reserve for the purse creation, NULL to use the quota 6981 * @param reserve_pub public key of the reserve to credit 6982 * @param[out] in_conflict set to true if @a purse_pub was merged into a different reserve already 6983 * @param[out] no_reserve set to true if @a reserve_pub is not a known reserve 6984 * @param[out] insufficient_funds set to true if @a reserve_pub has insufficient capacity to create another purse 6985 * @return transaction status code 6986 */ 6987 enum GNUNET_DB_QueryStatus 6988 (*do_reserve_purse)( 6989 void *cls, 6990 const struct TALER_PurseContractPublicKeyP *purse_pub, 6991 const struct TALER_PurseMergeSignatureP *merge_sig, 6992 const struct GNUNET_TIME_Timestamp merge_timestamp, 6993 const struct TALER_ReserveSignatureP *reserve_sig, 6994 const struct TALER_Amount *purse_fee, 6995 const struct TALER_ReservePublicKeyP *reserve_pub, 6996 bool *in_conflict, 6997 bool *no_reserve, 6998 bool *insufficient_funds); 6999 7000 7001 /** 7002 * Function called to approve merging of a purse with 7003 * an account, made by the receiving account. 7004 * 7005 * @param cls the @e cls of this struct with the plugin-specific state 7006 * @param purse_pub public key of the purse 7007 * @param[out] merge_sig set to the signature confirming the merge 7008 * @param[out] merge_timestamp set to the time of the merge 7009 * @param[out] partner_url set to the URL of the target exchange, or NULL if the target exchange is us. To be freed by the caller. 7010 * @param[out] reserve_pub set to the public key of the reserve/account being credited 7011 * @param[out] refunded set to true if purse was refunded 7012 * @return transaction status code 7013 */ 7014 enum GNUNET_DB_QueryStatus 7015 (*select_purse_merge)( 7016 void *cls, 7017 const struct TALER_PurseContractPublicKeyP *purse_pub, 7018 struct TALER_PurseMergeSignatureP *merge_sig, 7019 struct GNUNET_TIME_Timestamp *merge_timestamp, 7020 char **partner_url, 7021 struct TALER_ReservePublicKeyP *reserve_pub, 7022 bool *refunded); 7023 7024 7025 /** 7026 * Function called to initiate closure of an account. 7027 * 7028 * @param cls the @e cls of this struct with the plugin-specific state 7029 * @param reserve_pub public key of the account to close 7030 * @param payto_uri where to wire the funds 7031 * @param reserve_sig signature affiming that the account is to be closed 7032 * @param request_timestamp timestamp of the close request 7033 * @param balance balance at the time of closing 7034 * @param closing_fee closing fee to charge 7035 * @return transaction status code 7036 */ 7037 enum GNUNET_DB_QueryStatus 7038 (*insert_close_request)(void *cls, 7039 const struct TALER_ReservePublicKeyP *reserve_pub, 7040 const struct TALER_FullPayto payto_uri, 7041 const struct TALER_ReserveSignatureP *reserve_sig, 7042 struct GNUNET_TIME_Timestamp request_timestamp, 7043 const struct TALER_Amount *balance, 7044 const struct TALER_Amount *closing_fee); 7045 7046 7047 /** 7048 * Function called to persist a request to drain profits. 7049 * 7050 * @param cls the @e cls of this struct with the plugin-specific state 7051 * @param wtid wire transfer ID to use 7052 * @param account_section account to drain 7053 * @param payto_uri account to wire funds to 7054 * @param request_timestamp time of the signature 7055 * @param amount amount to wire 7056 * @param master_sig signature affirming the operation 7057 * @return transaction status code 7058 */ 7059 enum GNUNET_DB_QueryStatus 7060 (*insert_drain_profit)(void *cls, 7061 const struct TALER_WireTransferIdentifierRawP *wtid, 7062 const char *account_section, 7063 const struct TALER_FullPayto payto_uri, 7064 struct GNUNET_TIME_Timestamp request_timestamp, 7065 const struct TALER_Amount *amount, 7066 const struct TALER_MasterSignatureP *master_sig); 7067 7068 7069 /** 7070 * Function called to get information about a profit drain event. 7071 * 7072 * @param cls the @e cls of this struct with the plugin-specific state 7073 * @param wtid wire transfer ID to look up drain event for 7074 * @param[out] serial set to serial ID of the entry 7075 * @param[out] account_section set to account to drain 7076 * @param[out] payto_uri set to account to wire funds to 7077 * @param[out] request_timestamp set to time of the signature 7078 * @param[out] amount set to amount to wire 7079 * @param[out] master_sig set to signature affirming the operation 7080 * @return transaction status code 7081 */ 7082 enum GNUNET_DB_QueryStatus 7083 (*get_drain_profit)(void *cls, 7084 const struct TALER_WireTransferIdentifierRawP *wtid, 7085 uint64_t *serial, 7086 char **account_section, 7087 struct TALER_FullPayto *payto_uri, 7088 struct GNUNET_TIME_Timestamp *request_timestamp, 7089 struct TALER_Amount *amount, 7090 struct TALER_MasterSignatureP *master_sig); 7091 7092 7093 /** 7094 * Get profit drain operation ready to execute. 7095 * 7096 * @param cls the @e cls of this struct with the plugin-specific state 7097 * @param[out] serial set to serial ID of the entry 7098 * @param[out] wtid set set to wire transfer ID to use 7099 * @param[out] account_section set to account to drain 7100 * @param[out] payto_uri set to account to wire funds to 7101 * @param[out] request_timestamp set to time of the signature 7102 * @param[out] amount set to amount to wire 7103 * @param[out] master_sig set to signature affirming the operation 7104 * @return transaction status code 7105 */ 7106 enum GNUNET_DB_QueryStatus 7107 (*profit_drains_get_pending)( 7108 void *cls, 7109 uint64_t *serial, 7110 struct TALER_WireTransferIdentifierRawP *wtid, 7111 char **account_section, 7112 struct TALER_FullPayto *payto_uri, 7113 struct GNUNET_TIME_Timestamp *request_timestamp, 7114 struct TALER_Amount *amount, 7115 struct TALER_MasterSignatureP *master_sig); 7116 7117 7118 /** 7119 * Set profit drain operation to finished. 7120 * 7121 * @param cls the @e cls of this struct with the plugin-specific state 7122 * @param serial serial ID of the entry to mark finished 7123 * @return transaction status code 7124 */ 7125 enum GNUNET_DB_QueryStatus 7126 (*profit_drains_set_finished)( 7127 void *cls, 7128 uint64_t serial); 7129 7130 7131 /** 7132 * Insert KYC requirement for @a h_payto account into table. 7133 * 7134 * @param cls closure 7135 * @param payto_uri account that must be KYC'ed, 7136 * can be NULL if @a h_payto is already 7137 * guaranteed to be in wire_targets 7138 * @param h_payto hash of @a payto_uri 7139 * @param set_account_pub public key to enable for the 7140 * KYC authorization, NULL if not known 7141 * @param check_merchant_pub public key that must already 7142 * be enabled for a KYC authorzation for it to be 7143 * valid, NULL if not known 7144 * @param jmeasures serialized MeasureSet to put in place 7145 * @param display_priority priority of the rule 7146 * @param[out] requirement_row set to legitimization requirement row for this check 7147 * @param[out] bad_kyc_auth set if @a check_account_pub 7148 * did not match the existing KYC auth 7149 * @return database transaction status 7150 */ 7151 enum GNUNET_DB_QueryStatus 7152 (*trigger_kyc_rule_for_account)( 7153 void *cls, 7154 const struct TALER_FullPayto payto_uri, 7155 const struct TALER_NormalizedPaytoHashP *h_payto, 7156 const union TALER_AccountPublicKeyP *set_account_pub, 7157 const struct TALER_MerchantPublicKeyP *check_merchant_pub, 7158 const json_t *jmeasures, 7159 uint32_t display_priority, 7160 uint64_t *requirement_row, 7161 bool *bad_kyc_auth); 7162 7163 7164 /** 7165 * Begin KYC requirement process. 7166 * 7167 * @param cls closure 7168 * @param h_payto account that must be KYC'ed 7169 * @param measure_index which of the measures in 7170 * jmeasures does this KYC process relate to 7171 * @param legitimization_measure_serial_id which 7172 * legitimization measure set does this KYC process 7173 * relate to (uniquely identifies jmeasures) 7174 * @param provider_name provider that must be checked 7175 * @param provider_account_id provider account ID 7176 * @param provider_legitimization_id provider legitimization ID 7177 * @param[out] process_row row the process is stored under 7178 * @return database transaction status 7179 */ 7180 enum GNUNET_DB_QueryStatus 7181 (*insert_kyc_requirement_process)( 7182 void *cls, 7183 const struct TALER_NormalizedPaytoHashP *h_payto, 7184 uint32_t measure_index, 7185 uint64_t legitimization_measure_serial_id, 7186 const char *provider_name, 7187 const char *provider_account_id, 7188 const char *provider_legitimization_id, 7189 uint64_t *process_row); 7190 7191 7192 /** 7193 * Fetch information about pending KYC requirement process. 7194 * 7195 * @param cls closure 7196 * @param h_payto account that must be KYC'ed 7197 * @param provider_name provider that must be checked 7198 * @param[out] redirect_url set to redirect URL for the process 7199 * @return database transaction status 7200 */ 7201 enum GNUNET_DB_QueryStatus 7202 (*get_pending_kyc_requirement_process)( 7203 void *cls, 7204 const struct TALER_NormalizedPaytoHashP *h_payto, 7205 const char *provider_name, 7206 char **redirect_url); 7207 7208 7209 /** 7210 * Update KYC process with updated provider-linkage and/or 7211 * expiration data. 7212 * 7213 * @param cls closure 7214 * @param process_row row to select by 7215 * @param provider_name provider that must be checked (technically redundant) 7216 * @param h_payto account that must be KYC'ed (helps access by shard, otherwise also redundant) 7217 * @param provider_account_id provider account ID 7218 * @param provider_legitimization_id provider legitimization ID 7219 * @param redirect_url where the user should be redirected to start the KYC process 7220 * @param expiration how long is this KYC check set to be valid (in the past if invalid) 7221 * @param ec error code, #TALER_EC_NONE on success 7222 * @param error_message_hint human-readable error message details (in addition to @a ec, NULL on success) 7223 * @param finished true to mark the process as done 7224 * @return database transaction status 7225 */ 7226 enum GNUNET_DB_QueryStatus 7227 (*update_kyc_process_by_row)( 7228 void *cls, 7229 uint64_t process_row, 7230 const char *provider_name, 7231 const struct TALER_NormalizedPaytoHashP *h_payto, 7232 const char *provider_account_id, 7233 const char *provider_legitimization_id, 7234 const char *redirect_url, 7235 struct GNUNET_TIME_Absolute expiration, 7236 enum TALER_ErrorCode ec, 7237 const char *error_message_hint, 7238 bool finished); 7239 7240 7241 /** 7242 * Lookup KYC requirement. 7243 * 7244 * @param cls closure 7245 * @param h_payto identifies account to look up requirement for 7246 * @param account_pub set to public key of the account 7247 * needed to authorize access 7248 * @param[out] is_wallet set to #GNUNET_YES if the account is 7249 * that of a wallet (#GNUNET_SYSERR is used if unknown) 7250 * @param[out] access_token set to the access token to begin 7251 * work on KYC processes for this account 7252 * @param[out] rule_gen row ID of the last decision this 7253 * response is based on (for long-polling by clients) 7254 * @param[out] jrules set to active ``LegitimizationRuleSet`` 7255 * of the account impacted by the requirement 7256 * @param[out] aml_review set to true if the account is under 7257 * active review by AML staff 7258 * @param[out] kyc_required set to true if the user must pass 7259 * some KYC check before some previous operation may continue 7260 * @return database transaction status 7261 */ 7262 enum GNUNET_DB_QueryStatus 7263 (*lookup_kyc_requirement_by_row)( 7264 void *cls, 7265 const struct TALER_NormalizedPaytoHashP *h_payto, 7266 const union TALER_AccountPublicKeyP *account_pub, 7267 enum GNUNET_GenericReturnValue *is_wallet, 7268 struct TALER_AccountAccessTokenP *access_token, 7269 uint64_t *rule_gen, 7270 json_t **jrules, 7271 bool *aml_review, 7272 bool *kyc_required); 7273 7274 7275 /** 7276 * Lookup KYC status by account access token. 7277 * 7278 * @param cls closure 7279 * @param access_token key to look under 7280 * @param[out] row set to requirement row that matches 7281 * @param[out] jmeasures set to the LegitimizationMeasures for the @a access_token; must be freed by caller! 7282 * @return database transaction status 7283 */ 7284 enum GNUNET_DB_QueryStatus 7285 (*lookup_kyc_status_by_token)( 7286 void *cls, 7287 const struct TALER_AccountAccessTokenP *access_token, 7288 uint64_t *row, 7289 json_t **jmeasures); 7290 7291 7292 /** 7293 * Lookup KYC rules by account access token. 7294 * 7295 * @param cls closure 7296 * @param h_payto account payto hash to look under 7297 * @param[out] jnew_rules set to active LegitimizationRuleSet 7298 * @param[out] rowid row of the last legitimization outcome 7299 * @return database transaction status 7300 */ 7301 enum GNUNET_DB_QueryStatus 7302 (*lookup_rules_by_access_token)( 7303 void *cls, 7304 const struct TALER_NormalizedPaytoHashP *h_payto, 7305 json_t **jnew_rules, 7306 uint64_t *rowid); 7307 7308 7309 /** 7310 * Lookup KYC process meta data. 7311 * 7312 * @param cls closure 7313 * @param provider_name provider that must be checked 7314 * @param h_payto account that must be KYC'ed 7315 * @param[out] process_row set to row with the legitimization data 7316 * @param[out] expiration how long is this KYC check set to be valid (in the past if invalid) 7317 * @param[out] provider_account_id provider account ID 7318 * @param[out] provider_legitimization_id provider legitimization ID 7319 * @param[out] is_wallet set to true if @a h_payto is for a wallet 7320 * @return database transaction status 7321 */ 7322 enum GNUNET_DB_QueryStatus 7323 (*lookup_kyc_process_by_account)( 7324 void *cls, 7325 const char *provider_name, 7326 const struct TALER_NormalizedPaytoHashP *h_payto, 7327 uint64_t *process_row, 7328 struct GNUNET_TIME_Absolute *expiration, 7329 char **provider_account_id, 7330 char **provider_legitimization_id, 7331 bool *is_wallet); 7332 7333 7334 /** 7335 * Lookup an @a h_payto by @a provider_legitimization_id. 7336 * 7337 * @param cls closure 7338 * @param provider_name 7339 * @param provider_legitimization_id legi to look up 7340 * @param[out] h_payto where to write the result 7341 * @param[out] is_wallet set to true if @a h_payto is for a wallet 7342 * @param[out] process_row identifies the legitimization process on our end 7343 * @return database transaction status 7344 */ 7345 enum GNUNET_DB_QueryStatus 7346 (*kyc_provider_account_lookup)( 7347 void *cls, 7348 const char *provider_name, 7349 const char *provider_legitimization_id, 7350 struct TALER_NormalizedPaytoHashP *h_payto, 7351 bool *is_wallet, 7352 uint64_t *process_row); 7353 7354 7355 /** 7356 * Return KYC rules that apply to the given account. 7357 * 7358 * @param cls the @e cls of this struct with the plugin-specific state 7359 * @param h_payto account identifier 7360 * @param merchant_pub merchant public key used by the client, or NULL 7361 * if not available; if multiple @a reserve_pub values could be returned, 7362 * we should use this one 7363 * @param[out] no_account_pub set to true if no @a account_pub is available 7364 * @param[out] account_pub set to account public key the rules 7365 * apply to (because this key was used in KYC auth) 7366 * @param[out] no_reserve_pub set to true if no @a reserve_pub is available 7367 * @param[out] reserve_pub set to last incoming reserve public key 7368 * of a wire transfer to the exchange from the given @a h_payto 7369 * apply to (because this key was used in KYC auth) 7370 * @param[out] jrules set to the active KYC rules for the 7371 * given account, set to NULL if no custom rules are active 7372 * @return transaction status code 7373 */ 7374 enum GNUNET_DB_QueryStatus 7375 (*get_kyc_rules)( 7376 void *cls, 7377 const struct TALER_NormalizedPaytoHashP *h_payto, 7378 const struct TALER_MerchantPublicKeyP *merchant_pub, 7379 bool *no_account_pub, 7380 union TALER_AccountPublicKeyP *account_pub, 7381 bool *no_reserve_pub, 7382 struct TALER_ReservePublicKeyP *reserve_pub, 7383 json_t **jrules); 7384 7385 7386 /** 7387 * Return just the KYC rules that apply to the given account. 7388 * 7389 * @param cls the @e cls of this struct with the plugin-specific state 7390 * @param h_payto account identifier 7391 * @param[out] jrules set to the active KYC rules for the 7392 * given account, set to NULL if no custom rules are active 7393 * @return transaction status code 7394 */ 7395 enum GNUNET_DB_QueryStatus 7396 (*get_kyc_rules2)( 7397 void *cls, 7398 const struct TALER_NormalizedPaytoHashP *h_payto, 7399 json_t **jrules); 7400 7401 7402 /** 7403 * Call us on KYC legitimization processes satisfied and not expired for the 7404 * given account. 7405 * 7406 * @param cls the @e cls of this struct with the plugin-specific state 7407 * @param h_payto account identifier 7408 * @param lpc function to call for each satisfied KYC legitimization process 7409 * @param lpc_cls closure for @a lpc 7410 * @return transaction status code 7411 */ 7412 enum GNUNET_DB_QueryStatus 7413 (*iterate_kyc_reference)( 7414 void *cls, 7415 const struct TALER_NormalizedPaytoHashP *h_payto, 7416 TALER_EXCHANGEDB_LegitimizationProcessCallback lpc, 7417 void *lpc_cls); 7418 7419 7420 /** 7421 * Call @a kac on withdrawn amounts after @a time_limit which are relevant 7422 * for a KYC trigger for a the (debited) account identified by @a h_payto. 7423 * 7424 * @param cls the @e cls of this struct with the plugin-specific state 7425 * @param h_payto account identifier 7426 * @param time_limit oldest transaction that could be relevant 7427 * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK). 7428 * @param kac_cls closure for @a kac 7429 * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error 7430 */ 7431 enum GNUNET_DB_QueryStatus 7432 (*select_withdraw_amounts_for_kyc_check)( 7433 void *cls, 7434 const struct TALER_NormalizedPaytoHashP *h_payto, 7435 struct GNUNET_TIME_Absolute time_limit, 7436 TALER_EXCHANGEDB_KycAmountCallback kac, 7437 void *kac_cls); 7438 7439 7440 /** 7441 * Call @a kac on aggregated amounts after @a time_limit which are relevant for a 7442 * KYC trigger for a the (credited) account identified by @a h_payto. 7443 * 7444 * @param cls the @e cls of this struct with the plugin-specific state 7445 * @param h_payto account identifier 7446 * @param time_limit oldest transaction that could be relevant 7447 * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK). 7448 * @param kac_cls closure for @a kac 7449 * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error 7450 */ 7451 enum GNUNET_DB_QueryStatus 7452 (*select_aggregation_amounts_for_kyc_check)( 7453 void *cls, 7454 const struct TALER_NormalizedPaytoHashP *h_payto, 7455 struct GNUNET_TIME_Absolute time_limit, 7456 TALER_EXCHANGEDB_KycAmountCallback kac, 7457 void *kac_cls); 7458 7459 7460 /** 7461 * Call @a kac on merged reserve amounts after @a time_limit which are relevant for a 7462 * KYC trigger for a the wallet identified by @a h_payto. 7463 * 7464 * @param cls the @e cls of this struct with the plugin-specific state 7465 * @param h_payto account identifier 7466 * @param time_limit oldest transaction that could be relevant 7467 * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK). 7468 * @param kac_cls closure for @a kac 7469 * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error 7470 */ 7471 enum GNUNET_DB_QueryStatus 7472 (*select_merge_amounts_for_kyc_check)( 7473 void *cls, 7474 const struct TALER_NormalizedPaytoHashP *h_payto, 7475 struct GNUNET_TIME_Absolute time_limit, 7476 TALER_EXCHANGEDB_KycAmountCallback kac, 7477 void *kac_cls); 7478 7479 7480 /** 7481 * Call @a kac on deposited amounts after @a time_limit which are relevant for a 7482 * KYC trigger for a merchant identified by @a h_payto. 7483 * 7484 * @param cls the @e cls of this struct with the plugin-specific state 7485 * @param h_payto account identifier 7486 * @param time_limit oldest transaction that could be relevant 7487 * @param kac function to call for each applicable amount, 7488 * in reverse chronological order (or until @a kac aborts 7489 * by returning anything except #GNUNET_OK). 7490 * @param kac_cls closure for @a kac 7491 * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error 7492 */ 7493 enum GNUNET_DB_QueryStatus 7494 (*select_deposit_amounts_for_kyc_check)( 7495 void *cls, 7496 const struct TALER_NormalizedPaytoHashP *h_payto, 7497 struct GNUNET_TIME_Absolute time_limit, 7498 TALER_EXCHANGEDB_KycAmountCallback kac, 7499 void *kac_cls); 7500 7501 7502 /** 7503 * Update sanction list hit status of the given account. 7504 * 7505 * @param cls closure 7506 * @param h_payto account for which the hit is to be stored 7507 * @param to_investigate true to flag account for investigation, 7508 * false to **preserve** existing status 7509 * @param new_rules new KYC rules to apply to the account, NULL to preserve 7510 * existing rules 7511 * @param account_properties new account properties 7512 * @param num_events length of the @a events array 7513 * @param events array of KYC events to trigger 7514 * @return database transaction status 7515 */ 7516 enum GNUNET_DB_QueryStatus 7517 (*insert_sanction_list_hit)( 7518 void *cls, 7519 const struct TALER_NormalizedPaytoHashP *h_payto, 7520 bool to_investigate, 7521 const json_t *new_rules, 7522 const json_t *account_properties, 7523 unsigned int num_events, 7524 const char **events); 7525 7526 7527 /** 7528 * Update AML program status to finished (and failed). 7529 * 7530 * @param cls closure 7531 * @param process_row KYC process row to update 7532 * @param h_payto account for which the attribute data is stored 7533 * @param error_message details about what went wrong 7534 * @param ec error code about the failure 7535 * @return database transaction status 7536 */ 7537 enum GNUNET_DB_QueryStatus 7538 (*insert_aml_program_failure) ( 7539 void *cls, 7540 uint64_t process_row, 7541 const struct TALER_NormalizedPaytoHashP *h_payto, 7542 const char *error_message, 7543 enum TALER_ErrorCode ec); 7544 7545 7546 /** 7547 * Revert account back to default rules and insert successor measure. 7548 */ 7549 enum GNUNET_DB_QueryStatus 7550 (*insert_successor_measure)( 7551 void *cls, 7552 const struct TALER_NormalizedPaytoHashP *h_payto, 7553 struct GNUNET_TIME_Timestamp decision_time, 7554 const char *new_measure_name, 7555 const json_t *jmeasures, 7556 bool *unknown_account, 7557 struct GNUNET_TIME_Timestamp *last_date); 7558 7559 7560 /** 7561 * Lookup KYC attribute data for a specific account. 7562 * 7563 * @param cls closure 7564 * @param h_payto account for which the attribute data is stored 7565 * @param cb callback to invoke on each match 7566 * @param cb_cls closure for @a cb 7567 * @return database transaction status 7568 */ 7569 enum GNUNET_DB_QueryStatus 7570 (*select_kyc_attributes)( 7571 void *cls, 7572 const struct TALER_NormalizedPaytoHashP *h_payto, 7573 TALER_EXCHANGEDB_AttributeCallback cb, 7574 void *cb_cls); 7575 7576 7577 /** 7578 * Lookup all KYC attributes above @a min_row_id. 7579 * 7580 * @param cls closure 7581 * @param min_row_id minimum row ID to return (exclusive) 7582 * @param cb callback to invoke on each match 7583 * @param cb_cls closure for @a cb 7584 * @return database transaction status 7585 */ 7586 enum GNUNET_DB_QueryStatus 7587 (*select_all_kyc_attributes)( 7588 void *cls, 7589 uint64_t min_row_id, 7590 TALER_EXCHANGEDB_AllAttributesCallback cb, 7591 void *cb_cls); 7592 7593 7594 /** 7595 * Lookup legitimization measures. 7596 * 7597 * @param cls closure 7598 * @param h_payto account for which the attribute data is stored, 7599 * NULL to select for all accounts 7600 * @param finished_only select only measures that are finished 7601 * @param offset row offset to select from 7602 * @param limit number of results to return, negative to 7603 * return in descending order from @a offset 7604 * @param cb callback to invoke on each match 7605 * @param cb_cls closure for @a cb 7606 * @return database transaction status 7607 */ 7608 enum GNUNET_DB_QueryStatus 7609 (*select_aml_measures)( 7610 void *cls, 7611 const struct TALER_NormalizedPaytoHashP *h_payto, 7612 enum TALER_EXCHANGE_YesNoAll active_only, 7613 uint64_t offset, 7614 int64_t limit, 7615 TALER_EXCHANGEDB_LegitimizationMeasureCallback cb, 7616 void *cb_cls); 7617 7618 7619 /** 7620 * Insert AML staff record. 7621 * 7622 * @param cls closure 7623 * @param decider_pub public key of the staff member 7624 * @param master_sig offline signature affirming the AML officer 7625 * @param decider_name full name of the staff member 7626 * @param is_active true to enable, false to set as inactive 7627 * @param read_only true to set read-only access 7628 * @param last_change when was the change made effective 7629 * @param[out] previous_change when was the previous change made 7630 * @return database transaction status 7631 */ 7632 enum GNUNET_DB_QueryStatus 7633 (*insert_aml_officer)( 7634 void *cls, 7635 const struct TALER_AmlOfficerPublicKeyP *decider_pub, 7636 const struct TALER_MasterSignatureP *master_sig, 7637 const char *decider_name, 7638 bool is_active, 7639 bool read_only, 7640 struct GNUNET_TIME_Timestamp last_change, 7641 struct GNUNET_TIME_Timestamp *previous_change); 7642 7643 7644 /** 7645 * Test if the given AML staff member is active 7646 * (at least read-only). 7647 * 7648 * @param cls closure 7649 * @param decider_pub public key of the staff member 7650 * @param[out] read_only set to true if the member is read-only 7651 * @return database transaction status, if member is unknown or not active, 1 if member is active 7652 */ 7653 enum GNUNET_DB_QueryStatus 7654 (*test_aml_officer)( 7655 void *cls, 7656 const struct TALER_AmlOfficerPublicKeyP *decider_pub, 7657 bool *read_only); 7658 7659 7660 /** 7661 * Fetch AML staff record. 7662 * 7663 * @param cls closure 7664 * @param decider_pub public key of the staff member 7665 * @param[out] master_sig offline signature affirming the AML officer 7666 * @param[out] decider_name full name of the staff member 7667 * @param[out] is_active true to enable, false to set as inactive 7668 * @param[out] read_only true to set read-only access 7669 * @param[out] last_change when was the change made effective 7670 * @return database transaction status 7671 */ 7672 enum GNUNET_DB_QueryStatus 7673 (*lookup_aml_officer)( 7674 void *cls, 7675 const struct TALER_AmlOfficerPublicKeyP *decider_pub, 7676 struct TALER_MasterSignatureP *master_sig, 7677 char **decider_name, 7678 bool *is_active, 7679 bool *read_only, 7680 struct GNUNET_TIME_Absolute *last_change); 7681 7682 7683 /** 7684 * Obtain the AML statistics for a given set of @a names and 7685 * timeframe. 7686 * 7687 * @param cls closure 7688 * @param num_names length of the @e names array 7689 * @param names array of names of the statistics to fetch 7690 * @param start_date start of time range 7691 * @param end_date end of time range 7692 * @param cb function to call on each statistic 7693 * @param cb_cls closure for @a cb 7694 * @return database transaction status 7695 */ 7696 enum GNUNET_DB_QueryStatus 7697 (*select_aml_statistics)( 7698 void *cls, 7699 size_t num_names, 7700 const char *names[static num_names], 7701 struct GNUNET_TIME_Timestamp start_date, 7702 struct GNUNET_TIME_Timestamp end_date, 7703 TALER_EXCHANGEDB_AmlStatisticsCallback cb, 7704 void *cb_cls); 7705 7706 7707 /** 7708 * Lookup AML decisions that have a particular state. 7709 * 7710 * @param cls closure 7711 * @param h_payto which account should we return the AML decision history for, NULL to return all accounts 7712 * @param investigation_only filter by investigation state 7713 * @param active_only filter for only active states 7714 * @param offset row to start from 7715 * @param limit how many records to return (negative 7716 * to go back in time, positive to go forward) 7717 * @param cb callback to invoke on each match 7718 * @param cb_cls closure for @a cb 7719 * @return database transaction status 7720 */ 7721 enum GNUNET_DB_QueryStatus 7722 (*select_aml_decisions)( 7723 void *cls, 7724 const struct TALER_NormalizedPaytoHashP *h_payto, 7725 enum TALER_EXCHANGE_YesNoAll investigation_only, 7726 enum TALER_EXCHANGE_YesNoAll active_only, 7727 uint64_t offset, 7728 int64_t limit, 7729 TALER_EXCHANGEDB_AmlDecisionCallback cb, 7730 void *cb_cls); 7731 7732 7733 /** 7734 * List accounts managed by the exchange (for AML/KYC). 7735 * 7736 * @param cls closure 7737 * @param investigation_only filter by investigation state 7738 * @param open_only filter for only open accounts 7739 * @param high_risk_only filter for only high-risk accounts 7740 * @param offset row to start from 7741 * @param limit how many records to return (negative 7742 * to go back in time, positive to go forward) 7743 * @param cb callback to invoke on each match 7744 * @param cb_cls closure for @a cb 7745 * @return database transaction status 7746 */ 7747 enum GNUNET_DB_QueryStatus 7748 (*select_kyc_accounts)( 7749 void *cls, 7750 enum TALER_EXCHANGE_YesNoAll investigation_only, 7751 enum TALER_EXCHANGE_YesNoAll open_only, 7752 enum TALER_EXCHANGE_YesNoAll high_risk_only, 7753 uint64_t offset, 7754 int64_t limit, 7755 TALER_EXCHANGEDB_AmlAccountListCallback cb, 7756 void *cb_cls); 7757 7758 7759 /** 7760 * Lookup AML attributes of a particular account. 7761 * 7762 * @param cls closure 7763 * @param h_payto which account should we return attributes for 7764 * @param offset row to start from 7765 * @param limit how many records to return (negative 7766 * to go back in time, positive to go forward) 7767 * @param cb callback to invoke on each match 7768 * @param cb_cls closure for @a cb 7769 * @return database transaction status 7770 */ 7771 enum GNUNET_DB_QueryStatus 7772 (*select_aml_attributes)( 7773 void *cls, 7774 const struct TALER_NormalizedPaytoHashP *h_payto, 7775 uint64_t offset, 7776 int64_t limit, 7777 TALER_EXCHANGEDB_AmlAttributeCallback cb, 7778 void *cb_cls); 7779 7780 7781 /** 7782 * Lookup @a h_payto based on an @a access_token. 7783 * 7784 * @param cls closure 7785 * @param access_token 7786 * set to token for access control 7787 * @param[out] h_payto set to the the hash of the 7788 * payto URI of the account (if found) 7789 * @param[out] is_wallet set to true if @a h_payto 7790 * is for a wallet 7791 * @return database transaction status 7792 */ 7793 enum GNUNET_DB_QueryStatus 7794 (*lookup_h_payto_by_access_token)( 7795 void *cls, 7796 const struct TALER_AccountAccessTokenP *access_token, 7797 struct TALER_NormalizedPaytoHashP *h_payto, 7798 bool *is_wallet); 7799 7800 7801 /** 7802 * Lookup measure data for a legitimization process. 7803 * 7804 * @param cls closure 7805 * @param legitimization_measure_serial_id 7806 * row in legitimization_measures table to access 7807 * @param[out] access_token 7808 * set to token for access control that must match 7809 * @param[out] h_payto set to the the hash of the 7810 * payto URI of the account undergoing legitimization 7811 * @param[out] jmeasures set to the legitimization 7812 * measures that were put on the account 7813 * @param[out] is_finished set to true if the legitimization was 7814 * already finished 7815 * @param[out] is_wallet set to true if @a h_payto is for a wallet 7816 * @return database transaction status 7817 */ 7818 enum GNUNET_DB_QueryStatus 7819 (*lookup_pending_legitimization)( 7820 void *cls, 7821 uint64_t legitimization_measure_serial_id, 7822 struct TALER_AccountAccessTokenP *access_token, 7823 struct TALER_NormalizedPaytoHashP *h_payto, 7824 json_t **jmeasures, 7825 bool *is_finished, 7826 bool *is_wallet); 7827 7828 7829 /** 7830 * Lookup measure data for a legitimization process. 7831 * 7832 * @param cls closure 7833 * @param legitimization_measure_serial_id 7834 * row in legitimization_measures table to access 7835 * @param measure_index index of the measure to return 7836 * attribute data for 7837 * @param[out] access_token 7838 * set to token for access control that must match 7839 * @param[out] h_payto set to the the hash of the 7840 * payto URI of the account undergoing legitimization 7841 * @param[out] is_wallet set to true if @a h_payto is for a wallet 7842 * @param[out] jmeasures set to the legitimization 7843 * measures that were put on the account 7844 * @param[out] is_finished set to true if the legitimization was 7845 * already finished 7846 * @param[out] encrypted_attributes_len set to length of 7847 * @a encrypted_attributes 7848 * @param[out] encrypted_attributes set to the attributes 7849 * obtained for the legitimization process, if it 7850 * succeeded, otherwise set to NULL 7851 * @return database transaction status 7852 */ 7853 enum GNUNET_DB_QueryStatus 7854 (*lookup_completed_legitimization)( 7855 void *cls, 7856 uint64_t legitimization_measure_serial_id, 7857 uint32_t measure_index, 7858 struct TALER_AccountAccessTokenP *access_token, 7859 struct TALER_NormalizedPaytoHashP *h_payto, 7860 bool *is_wallet, 7861 json_t **jmeasures, 7862 bool *is_finished, 7863 size_t *encrypted_attributes_len, 7864 void **encrypted_attributes); 7865 7866 7867 /** 7868 * Lookup AML history for an account identified via 7869 * @a h_payto. 7870 * 7871 * @param cls closure 7872 * @param h_payto hash of account to lookup history for 7873 * @param offset row ID to start returning results from 7874 * @param limit how many results to return, negative for descending order 7875 * @param cb function to call on results 7876 * @param cb_cls closure for @a cb 7877 * @return database transaction status 7878 */ 7879 enum GNUNET_DB_QueryStatus 7880 (*lookup_aml_history)( 7881 void *cls, 7882 const struct TALER_NormalizedPaytoHashP *h_payto, 7883 uint64_t offset, 7884 int64_t limit, 7885 TALER_EXCHANGEDB_AmlHistoryCallback cb, 7886 void *cb_cls); 7887 7888 7889 /** 7890 * Lookup AML history for an account identified via 7891 * @a h_payto. 7892 * 7893 * @param cls closure 7894 * @param h_payto hash of account to lookup history for 7895 * @param cb function to call on results 7896 * @param cb_cls closure for @a cb 7897 * @return database transaction status 7898 */ 7899 enum GNUNET_DB_QueryStatus 7900 (*lookup_kyc_history)( 7901 void *cls, 7902 const struct TALER_NormalizedPaytoHashP *h_payto, 7903 TALER_EXCHANGEDB_KycHistoryCallback cb, 7904 void *cb_cls); 7905 7906 7907 /** 7908 * Lookup measure data for an active legitimization process. 7909 * 7910 * @param cls closure 7911 * @param legitimization_process_serial_id 7912 * row in legitimization_processes table to access 7913 * @param[out] measure_index set to the measure the 7914 * process is trying to satisfy 7915 * @param[out] jmeasures set to the legitimization 7916 * measures that were put on the account 7917 * @return database transaction status 7918 */ 7919 enum GNUNET_DB_QueryStatus 7920 (*lookup_active_legitimization) ( 7921 void *cls, 7922 uint64_t legitimization_process_serial_id, 7923 uint32_t *measure_index, 7924 json_t **jmeasures); 7925 7926 7927 /** 7928 * Create new active legitimization measure. 7929 * 7930 * 7931 * @param cls closure 7932 * @param access_token access token that identifies the 7933 * account the legitimization measures apply to 7934 * @param jmeasures new legitimization measures 7935 * @param[out] legitimization_measure_serial_id 7936 * set to new row in legitimization_measures table 7937 * @return database transaction status 7938 */ 7939 enum GNUNET_DB_QueryStatus 7940 (*insert_active_legitimization_measure) ( 7941 void *cls, 7942 const struct TALER_AccountAccessTokenP *access_token, 7943 const json_t *jmeasures, 7944 uint64_t *legitimization_measure_serial_id); 7945 7946 7947 /** 7948 * Insert an AML decision. Inserts into AML history and insert or updates AML 7949 * status. 7950 * 7951 * @param cls closure 7952 * @param payto_uri full URI of the account, optional, 7953 * can be NULL if the backend already knows the account 7954 * @param h_payto account for which the attribute data is stored 7955 * @param decision_time when was the decision made 7956 * @param expiration_time when does the decision expire 7957 * @param properties JSON object with properties to set for the account 7958 * @param new_rules JSON array with new AML/KYC rules 7959 * @param to_investigate true if AML staff should look more into this account 7960 * @param new_measure_name name of the @a jmeasures measure that was triggered, or NULL for none 7961 * @param jmeasures a JSON with LegitimizationMeasures to apply to the 7962 * account, or NULL to not apply any measure right now 7963 * @param justification human-readable text justifying the decision 7964 * @param decider_pub public key of the staff member 7965 * @param decider_sig signature of the staff member 7966 * @param num_events length of the @a events array 7967 * @param events array of events to trigger 7968 * @param form_name name of the form from which @a enc_attributes originate, can be NULL 7969 * @param enc_attributes_size number of bytes in @a enc_attributes 7970 * @param enc_attributes encrypted attribute data 7971 * @param attributes_hash hash of the unencrypted attribute data 7972 * @param attributes_expiration_time when does the attribute data expire 7973 * @param[out] invalid_officer set to TRUE if @a decider_pub is not allowed to make decisions right now 7974 * @param[out] unknown_account set to TRUE if @a h_payto does not refer to a known account and @a jmeasures was given 7975 * @param[out] last_date set to the previous decision time; 7976 * the INSERT is not performed if @a last_date is not before @a decision_time 7977 * @param[out] legitimization_measure_serial_id serial ID of the legitimization measures 7978 * of the decision 7979 * @param[out] is_wallet set to true if @a h_payto is for a wallet 7980 * @return database transaction status 7981 */ 7982 enum GNUNET_DB_QueryStatus 7983 (*insert_aml_decision)( 7984 void *cls, 7985 const struct TALER_FullPayto payto_uri, 7986 const struct TALER_NormalizedPaytoHashP *h_payto, 7987 struct GNUNET_TIME_Timestamp decision_time, 7988 struct GNUNET_TIME_Timestamp expiration_time, 7989 const json_t *properties, 7990 const json_t *new_rules, 7991 bool to_investigate, 7992 const char *new_measure_name, 7993 const json_t *jmeasures, 7994 const char *justification, 7995 const struct TALER_AmlOfficerPublicKeyP *decider_pub, 7996 const struct TALER_AmlOfficerSignatureP *decider_sig, 7997 size_t num_events, 7998 const char *events[static num_events], 7999 const char *form_name, 8000 size_t enc_attributes_size, 8001 const void *enc_attributes, 8002 struct GNUNET_HashCode *attributes_hash, 8003 struct GNUNET_TIME_Timestamp attributes_expiration_time, 8004 bool *invalid_officer, 8005 bool *unknown_account, 8006 struct GNUNET_TIME_Timestamp *last_date, 8007 uint64_t *legitimization_measure_serial_id, 8008 bool *is_wallet); 8009 8010 8011 /** 8012 * Store KYC attribute data. 8013 * 8014 * @param cls closure 8015 * @param process_row KYC process row to update 8016 * @param h_payto account for which the attribute data is stored 8017 * @param provider_name name of the provider that provided the attributes 8018 * @param provider_account_id provider account ID 8019 * @param provider_legitimization_id provider legitimization ID 8020 * @param birthday birthdate of user, in days after 1990, or 0 if unknown or definitively adult 8021 * @param expiration_time when does the data expire 8022 * @param form_name name of the form from which the @a enc_attributes originate, can be NULL 8023 * @param enc_attributes_size number of bytes in @a enc_attributes 8024 * @param enc_attributes encrypted attribute data 8025 * @return database transaction status 8026 */ 8027 enum GNUNET_DB_QueryStatus 8028 (*persist_kyc_attributes) ( 8029 void *cls, 8030 uint64_t process_row, 8031 const struct TALER_NormalizedPaytoHashP *h_payto, 8032 const char *provider_name, 8033 const char *provider_account_id, 8034 const char *provider_legitimization_id, 8035 uint32_t birthday, 8036 struct GNUNET_TIME_Absolute expiration_time, 8037 const char *form_name, 8038 size_t enc_attributes_size, 8039 const void *enc_attributes); 8040 8041 8042 /** 8043 * Update KYC process status to finished (and failed). 8044 * 8045 * @param cls closure 8046 * @param process_row KYC process row to update 8047 * @param h_payto account for which the attribute data is stored 8048 * @param provider_name provider that must be checked 8049 * @param provider_account_id provider account ID 8050 * @param provider_legitimization_id provider legitimization ID 8051 * @param error_message details about what went wrong 8052 * @param ec error code about the failure 8053 * @return database transaction status 8054 */ 8055 enum GNUNET_DB_QueryStatus 8056 (*insert_kyc_failure)( 8057 void *cls, 8058 uint64_t process_row, 8059 const struct TALER_NormalizedPaytoHashP *h_payto, 8060 const char *provider_name, 8061 const char *provider_account_id, 8062 const char *provider_legitimization_id, 8063 const char *error_message, 8064 enum TALER_ErrorCode ec); 8065 8066 /** 8067 * Function called to inject auditor triggers into the 8068 * database, triggering the real-time auditor upon 8069 * relevant INSERTs. 8070 * 8071 * @param cls closure 8072 * @return #GNUNET_OK on success, 8073 * #GNUNET_SYSERR on DB errors 8074 */ 8075 enum GNUNET_GenericReturnValue 8076 (*inject_auditor_triggers)(void *cls); 8077 8078 8079 /** 8080 * Set a lock for @a lock_duration on running AML programs for the @a h_payto 8081 * account. If a lock already exists, returns the timeout of the 8082 * @a existing_lock. Returns 0 if @a h_payto is not known. 8083 * 8084 * @param cls closure 8085 * @param h_payto account to lock 8086 * @param lock_duration how long to lock the account 8087 * @param[out] existing_lock set to timeout of existing lock, or 8088 * to zero if there is no existing lock 8089 * @return transaction status 8090 */ 8091 enum GNUNET_DB_QueryStatus 8092 (*set_aml_lock) ( 8093 void *cls, 8094 const struct TALER_NormalizedPaytoHashP *h_payto, 8095 struct GNUNET_TIME_Relative lock_duration, 8096 struct GNUNET_TIME_Absolute *existing_lock); 8097 8098 8099 /** 8100 * Clear a lock on running AML programs for the @a h_payto 8101 * account. Returns 0 if @a h_payto is not known; does not 8102 * actually care if there was a lock. Also does not by 8103 * itself notify clients waiting for the lock, that 8104 * notification the caller must do separately after finishing 8105 * the database update. 8106 * 8107 * @param cls closure 8108 * @param h_payto account to clear the lock for 8109 * @return transaction status 8110 */ 8111 enum GNUNET_DB_QueryStatus 8112 (*clear_aml_lock) ( 8113 void *cls, 8114 const struct TALER_NormalizedPaytoHashP *h_payto); 8115 8116 8117 /** 8118 * Return AML-relevant wire transfer credit data. 8119 * 8120 * @param cls closure 8121 * @param threshold minimum wire amount to return data for 8122 * @param offset offset in table to filter by 8123 * @param limit maximum number of entries to return, negative for descending 8124 * @param h_payto account to filter transfer data by 8125 * @param cb function to call on each result 8126 * @param cb_cls closure to pass to @a cb 8127 * @return transaction status 8128 */ 8129 enum GNUNET_DB_QueryStatus 8130 (*select_exchange_credit_transfers) ( 8131 void *cls, 8132 const struct TALER_Amount *threshold, 8133 uint64_t offset, 8134 int64_t limit, 8135 const struct TALER_NormalizedPaytoHashP *h_payto, 8136 TALER_EXCHANGEDB_AmlTransferCallback cb, 8137 void *cb_cls); 8138 8139 8140 /** 8141 * Return AML-relevant wire transfer debit data. 8142 * 8143 * @param cls closure 8144 * @param threshold minimum wire amount to return data for 8145 * @param offset offset in table to filter by 8146 * @param limit maximum number of entries to return, negative for descending 8147 * @param h_payto account to filter transfer data by 8148 * @param cb function to call on each result 8149 * @param cb_cls closure to pass to @a cb 8150 * @return transaction status 8151 */ 8152 enum GNUNET_DB_QueryStatus 8153 (*select_exchange_debit_transfers) ( 8154 void *cls, 8155 const struct TALER_Amount *threshold, 8156 uint64_t offset, 8157 int64_t limit, 8158 const struct TALER_NormalizedPaytoHashP *h_payto, 8159 TALER_EXCHANGEDB_AmlTransferCallback cb, 8160 void *cb_cls); 8161 8162 8163 /** 8164 * Return wire transfer kycauth data. 8165 * 8166 * @param cls closure 8167 * @param threshold minimum wire amount to return data for 8168 * @param offset offset in table to filter by 8169 * @param limit maximum number of entries to return, negative for descending 8170 * @param h_payto account to filter transfer data by 8171 * @param cb function to call on each result 8172 * @param cb_cls closure to pass to @a cb 8173 * @return transaction status 8174 */ 8175 enum GNUNET_DB_QueryStatus 8176 (*select_exchange_kycauth_transfers) ( 8177 void *cls, 8178 const struct TALER_Amount *threshold, 8179 uint64_t offset, 8180 int64_t limit, 8181 const struct TALER_NormalizedPaytoHashP *h_payto, 8182 TALER_EXCHANGEDB_AmlTransferCallback cb, 8183 void *cb_cls); 8184 8185 8186 /** 8187 * Disable (delete/drop) customization rule schema from a deployment. 8188 * 8189 * @param cls closure 8190 * @param schema name of the schema with customization rules to remove 8191 * @return transaction status 8192 */ 8193 enum GNUNET_DB_QueryStatus 8194 (*disable_rules)( 8195 void *cls, 8196 const char *schema); 8197 8198 /** 8199 * Enable (create/insert) customization rule schema from a deployment. 8200 * 8201 * @param cls closure 8202 * @param schema name of the schema with customization rules to remove 8203 * @return transaction status 8204 */ 8205 enum GNUNET_GenericReturnValue 8206 (*enable_rules)( 8207 void *cls, 8208 const char *schema); 8209 8210 /** 8211 * Lookup AML file number by the payto address. 8212 * 8213 * @param cls closure 8214 * @param h_payto account for which to find the row ID 8215 * @param[out] kyw_target_row set to row in the kyc_targets table for @a h_payto 8216 * @param[out] is_wallet set to true if this account is for a wallet 8217 * @return database transaction status 8218 */ 8219 enum GNUNET_DB_QueryStatus 8220 (*lookup_aml_file_number) ( 8221 void *cls, 8222 const struct TALER_NormalizedPaytoHashP *h_payto, 8223 uint64_t *kyc_target_row, 8224 bool *is_wallet); 8225 8226 }; 8227 8228 #endif /* _TALER_EXCHANGE_DB_H */