syncdb_lookup_block_TR.sql (3237B)
1 -- 2 -- This file is part of TALER 3 -- Copyright (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 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 DROP FUNCTION IF EXISTS sync_do_lookup_block; 18 CREATE FUNCTION sync_do_lookup_block ( 19 IN in_account_pub BYTEA, 20 IN in_nonce BYTEA) 21 RETURNS sync_do_lookup_block_return_type 22 LANGUAGE plpgsql 23 AS $$ 24 DECLARE 25 my_first_block BYTEA; 26 my_last_block BYTEA; 27 my_hash BYTEA; 28 my_prev BYTEA; 29 my_next BYTEA; 30 my_data_size INT8; 31 my_refs_hash BYTEA; 32 BEGIN 33 -- Check if account exists 34 SELECT first_block 35 ,last_block 36 INTO my_first_block 37 ,my_last_block 38 FROM accounts 39 WHERE account_pub = in_account_pub; 40 41 IF NOT FOUND 42 THEN 43 RETURN (TRUE -- out_account_missing 44 ,FALSE -- out_block_missing 45 ,FALSE -- out_is_first 46 ,FALSE -- out_is_last 47 ,in_nonce -- nonce 48 ,decode(repeat('00', 64), 'hex') -- block_hash 49 ,decode(repeat('00', 24), 'hex') -- prev_nonce 50 ,decode(repeat('00', 24), 'hex') -- next_nonce 51 ,0::INT8 -- data_size 52 ,decode(repeat('00', 64), 'hex')); -- refs_hash 53 END IF; 54 55 -- Look up the block 56 SELECT block_hash 57 ,prev_nonce 58 ,next_nonce 59 ,octet_length(data_blob) 60 ,refs_hash 61 INTO my_hash 62 ,my_prev 63 ,my_next 64 ,my_data_size 65 ,my_refs_hash 66 FROM blocks 67 WHERE account_pub = in_account_pub 68 AND nonce = in_nonce; 69 70 IF NOT FOUND 71 THEN 72 RETURN (FALSE -- out_account_missing 73 ,TRUE -- out_block_missing 74 ,FALSE -- out_is_first 75 ,FALSE -- out_is_last 76 ,in_nonce -- nonce 77 ,decode(repeat('00', 64), 'hex') -- block_hash 78 ,decode(repeat('00', 24), 'hex') -- prev_nonce 79 ,decode(repeat('00', 24), 'hex') -- next_nonce 80 ,0::INT8 -- data_size 81 ,decode(repeat('00', 64), 'hex')); -- refs_hash 82 END IF; 83 84 RETURN (FALSE -- out_account_missing 85 ,FALSE -- out_block_missing 86 ,in_nonce IS NOT DISTINCT FROM my_first_block -- out_is_first 87 ,in_nonce IS NOT DISTINCT FROM my_last_block -- out_is_last 88 ,in_nonce -- nonce 89 ,my_hash -- block_hash 90 ,my_prev -- prev_nonce 91 ,my_next -- next_nonce 92 ,my_data_size -- data_size 93 ,my_refs_hash); -- refs_hash 94 END $$;