sync

Backup service to store encrypted wallet databases (experimental)
Log | Files | Refs | Submodules | README | LICENSE

syncdb_lookup_block_hashes_TR.sql (1973B)


      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_hashes;
     18 CREATE FUNCTION sync_do_lookup_block_hashes (
     19   IN in_account_pub BYTEA)
     20 RETURNS SETOF sync_do_lookup_block_hashes_return_type
     21 LANGUAGE plpgsql
     22 AS $$
     23 DECLARE
     24   my_first_block BYTEA;
     25   r RECORD;
     26 BEGIN
     27 
     28   -- Check if account exists
     29   SELECT first_block
     30     INTO my_first_block
     31     FROM accounts
     32    WHERE account_pub = in_account_pub;
     33 
     34   IF NOT FOUND
     35   THEN
     36     RETURN NEXT (TRUE -- out_account_missing
     37                 ,FALSE
     38                 ,decode(repeat('00', 24), 'hex')
     39                 ,decode(repeat('00', 64), 'hex'));
     40     RETURN;
     41   END IF;
     42 
     43   -- Check if backup is empty
     44   IF my_first_block IS NULL
     45   THEN
     46     RETURN NEXT (FALSE
     47                 ,TRUE -- out_backup_empty
     48                 ,decode(repeat('00', 24), 'hex')
     49                 ,decode(repeat('00', 64), 'hex'));
     50     RETURN;
     51   END IF;
     52 
     53   -- Stream the identities of all the blocks in the account's linked
     54   -- list (the order does not matter, the caller builds an invertible
     55   -- bloom filter over them).
     56   FOR r IN
     57     SELECT nonce
     58           ,block_hash
     59       FROM blocks
     60      WHERE account_pub = in_account_pub
     61   LOOP
     62     RETURN NEXT (FALSE
     63                 ,FALSE
     64                 ,r.nonce
     65                 ,r.block_hash);
     66   END LOOP;
     67 
     68   RETURN;
     69 END $$;