do_import_credits.h (4613B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2022--2026 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 src/include/exchange-database/do_import_credits.h 18 * @brief implementation of the do_import_credits function for Postgres 19 * @author Christian Grothoff 20 */ 21 #ifndef EXCHANGE_DATABASE_DO_IMPORT_CREDITS_H 22 #define EXCHANGE_DATABASE_DO_IMPORT_CREDITS_H 23 24 #include "exchangedb_lib.h" 25 26 27 /** 28 * Incoming wire transfer that credits a reserve. 29 */ 30 struct TALER_EXCHANGEDB_ReserveInInfo 31 { 32 const struct TALER_ReservePublicKeyP *reserve_pub; 33 const struct TALER_Amount *balance; 34 struct GNUNET_TIME_Timestamp execution_time; 35 struct TALER_FullPayto sender_account_details; 36 uint64_t wire_reference; 37 }; 38 39 40 /** 41 * Incoming wire transfer that authenticates an account by carrying an 42 * account public key in its subject. 43 */ 44 struct TALER_EXCHANGEDB_KycauthInInfo 45 { 46 const union TALER_AccountPublicKeyP *account_pub; 47 const struct TALER_Amount *balance; 48 struct GNUNET_TIME_Timestamp execution_time; 49 struct TALER_FullPayto sender_account_details; 50 uint64_t wire_reference; 51 }; 52 53 54 /** 55 * Incoming WAD transfer from another exchange. 56 */ 57 struct TALER_EXCHANGEDB_WadInInfo 58 { 59 const struct TALER_WadIdentifierP *wad_id; 60 const char *origin_exchange_url; 61 const struct TALER_Amount *balance; 62 struct GNUNET_TIME_Timestamp execution_time; 63 }; 64 65 66 /** 67 * One batch of incoming wire transfers to import, together with the work 68 * shard they were read under. All transfers in a batch come from the same 69 * bank account, which is why @e exchange_account_name is not per transfer. 70 */ 71 struct TALER_EXCHANGEDB_CreditBatch 72 { 73 /** 74 * Configuration section name of the exchange bank account the transfers 75 * arrived at. 76 */ 77 const char *exchange_account_name; 78 79 /** 80 * Transfers into reserves, may be NULL if @e reserves_length is 0. 81 */ 82 const struct TALER_EXCHANGEDB_ReserveInInfo *reserves; 83 84 /** 85 * Length of the @e reserves array. 86 */ 87 unsigned int reserves_length; 88 89 /** 90 * KYC authentication transfers, may be NULL if @e kycauths_length is 0. 91 */ 92 const struct TALER_EXCHANGEDB_KycauthInInfo *kycauths; 93 94 /** 95 * Length of the @e kycauths array. 96 */ 97 unsigned int kycauths_length; 98 99 /** 100 * WAD transfers, may be NULL if @e wads_length is 0. 101 */ 102 const struct TALER_EXCHANGEDB_WadInInfo *wads; 103 104 /** 105 * Length of the @e wads array. 106 */ 107 unsigned int wads_length; 108 109 /** 110 * Name of the job whose shard this batch was read under. 111 */ 112 const char *job_name; 113 114 /** 115 * Inclusive start row of that shard. 116 */ 117 uint64_t shard_start; 118 119 /** 120 * Exclusive end row of that shard. 121 */ 122 uint64_t shard_end; 123 124 /** 125 * Row up to which (exclusive) the shard is done once this batch is in. 126 * Pass @e shard_end to complete the shard. 127 */ 128 uint64_t progress_row; 129 130 /** 131 * For how much longer we intend to hold the shard. 132 */ 133 struct GNUNET_TIME_Relative lease; 134 }; 135 136 137 /** 138 * Import one batch of incoming wire transfers and advance the work shard it 139 * belongs to. 140 * 141 * This is a single statement, so it needs no transaction of its own: the 142 * transfers and the record of how far the shard has come either both land or 143 * neither does. That is what lets a caller commit as soon as the bank 144 * answers, rather than holding everything open until the shard is finished. 145 * 146 * @param pg the database context 147 * @param batch the transfers to import and the shard they belong to 148 * @param[out] reserve_results set to the query status per entry of 149 * @a batch->reserves, must be of length @a batch->reserves_length; 150 * #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS means the transfer had 151 * already been imported 152 * @return transaction status code; on success, the number of reserve 153 * transfers that were looked at 154 */ 155 enum GNUNET_DB_QueryStatus 156 TALER_EXCHANGEDB_do_import_credits ( 157 struct TALER_EXCHANGEDB_PostgresContext *pg, 158 const struct TALER_EXCHANGEDB_CreditBatch *batch, 159 enum GNUNET_DB_QueryStatus *reserve_results); 160 161 #endif