syncdb_lookup_block_TR.c (3760B)
1 /* 2 This file is part of TALER 3 (C) 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 Lesser 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 syncdb/syncdb_lookup_block_TR.c 18 * @brief lookup a single block by nonce 19 * @author Iván Ávalos 20 */ 21 #include "syncdb_pg.h" 22 23 24 enum SYNC_DB_QueryStatus 25 SYNCDB_lookup_block_TR ( 26 const struct SYNC_AccountPublicKeyP *account_pub, 27 const struct SYNC_BlockNonce *nonce, 28 struct GNUNET_HashCode *block_hash, 29 struct SYNC_BlockNonce *prev_nonce, 30 struct SYNC_BlockNonce *next_nonce, 31 size_t *data_size, 32 struct GNUNET_HashCode *refs_hash, 33 bool *is_first, 34 bool *is_last) 35 { 36 bool account_missing; 37 bool block_missing; 38 struct GNUNET_PQ_QueryParam params[] = { 39 GNUNET_PQ_query_param_auto_from_type (account_pub), 40 GNUNET_PQ_query_param_auto_from_type (nonce), 41 GNUNET_PQ_query_param_end, 42 }; 43 struct GNUNET_PQ_ResultSpec rs[] = { 44 GNUNET_PQ_result_spec_bool ("out_account_missing", 45 &account_missing), 46 GNUNET_PQ_result_spec_bool ("out_block_missing", 47 &block_missing), 48 GNUNET_PQ_result_spec_bool ("out_is_first", 49 is_first), 50 GNUNET_PQ_result_spec_bool ("out_is_last", 51 is_last), 52 GNUNET_PQ_result_spec_auto_from_type ("block_hash", 53 block_hash), 54 GNUNET_PQ_result_spec_allow_null ( 55 GNUNET_PQ_result_spec_auto_from_type ("prev_nonce", 56 prev_nonce), 57 NULL), 58 GNUNET_PQ_result_spec_allow_null ( 59 GNUNET_PQ_result_spec_auto_from_type ("next_nonce", 60 next_nonce), 61 NULL), 62 GNUNET_PQ_result_spec_uint64 ("data_size", 63 data_size), 64 GNUNET_PQ_result_spec_auto_from_type ("refs_hash", 65 refs_hash), 66 GNUNET_PQ_result_spec_end, 67 }; 68 enum GNUNET_DB_QueryStatus qs; 69 70 SYNCDB_preflight (); 71 PREPARE ("block_select", 72 "SELECT" 73 " out_account_missing" 74 ",out_block_missing" 75 ",out_is_first" 76 ",out_is_last" 77 ",nonce" 78 ",block_hash" 79 ",prev_nonce" 80 ",next_nonce" 81 ",data_size" 82 ",refs_hash" 83 " FROM sync_do_lookup_block" 84 " ($1,$2)"); 85 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 86 "block_select", 87 params, 88 rs); 89 switch (qs) 90 { 91 case GNUNET_DB_STATUS_HARD_ERROR: 92 return SYNC_DB_HARD_ERROR; 93 case GNUNET_DB_STATUS_SOFT_ERROR: 94 GNUNET_break (0); 95 return SYNC_DB_SOFT_ERROR; 96 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 97 GNUNET_break (0); 98 return SYNC_DB_HARD_ERROR; 99 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 100 if (account_missing) 101 return SYNC_DB_PAYMENT_REQUIRED; 102 if (block_missing) 103 return SYNC_DB_TARGET_MISSING; 104 return SYNC_DB_ONE_RESULT; 105 default: 106 GNUNET_break (0); 107 return SYNC_DB_HARD_ERROR; 108 } 109 } 110 111 112 /* end of syncdb_lookup_block_TR.c */