update_auth_iban_in_currency.c (2806B)
1 /* 2 This file is part of Anastasis 3 Copyright (C) 2026 Anastasis SARL 4 5 Anastasis is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 Anastasis 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 Affero General Public License for more details. 12 13 You should have received a copy of the GNU Affero General Public License along with 14 Anastasis; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file stasis/update_auth_iban_in_currency.c 18 * @brief Anastasis database: stamp the configured currency onto IBAN 19 * transfers migrated from before amounts carried one 20 * @author Christian Grothoff 21 */ 22 #include "platform.h" 23 #include "anastasis-db_pg.h" 24 #include "anastasis/anastasis-database/update_auth_iban_in_currency.h" 25 #include "anastasis/anastasis-database/transaction.h" 26 #include "anastasis/anastasis-database/preflight.h" 27 #include <taler/taler_pq_lib.h> 28 29 30 /** 31 * Fill in the currency of IBAN wire transfers recorded before amounts 32 * carried one. 33 * 34 * The stasis-0004 migration widened the amount columns to include a 35 * currency, but SQL cannot know which one: it lives in [anastasis] 36 * CURRENCY. The rows are therefore left with a NULL currency for this 37 * function to complete. Unlike the three payment tables, these rows 38 * cannot simply be stamped with a placeholder --- the IBAN plugin 39 * compares them against the amount it expects, so a wrong currency would 40 * silently invalidate every challenge still in flight across the upgrade. 41 * 42 * @return transaction status; #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if 43 * there was nothing left to fill in, which is the normal case 44 */ 45 enum GNUNET_DB_QueryStatus 46 ANASTASIS_DB_update_auth_iban_in_currency (void) 47 { 48 struct GNUNET_PQ_QueryParam params[] = { 49 GNUNET_PQ_query_param_string (pg->currency), 50 GNUNET_PQ_query_param_end 51 }; 52 53 /* Idempotent: the WHERE clause matches nothing once the backfill has 54 run, so re-running anastasis-dbinit is free, and a provider that 55 changes CURRENCY later does not have its history rewritten. */ 56 PREPARE ("update_auth_iban_in_currency", 57 "UPDATE anastasis_auth_iban_in" 58 " SET credit=ROW((credit).val,(credit).frac,$1)::taler_amount_currency" 59 " WHERE (credit).curr IS NULL;"); 60 return GNUNET_PQ_eval_prepared_non_select (pg->conn, 61 "update_auth_iban_in_currency", 62 params); 63 } 64 65 66 /* end of update_auth_iban_in_currency.c */