sync

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

syncdb_lookup_account_TR.c (2947B)


      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_account_TR.c
     18  * @brief look up the status of an account
     19  * @author Christian Grothoff
     20  */
     21 #include "syncdb_pg.h"
     22 
     23 
     24 enum SYNC_DB_QueryStatus
     25 SYNCDB_lookup_account_TR (
     26   const struct SYNC_AccountPublicKeyP *account_pub,
     27   struct GNUNET_TIME_Timestamp *expiration_date,
     28   uint64_t *storage_used_bytes,
     29   uint64_t *block_count)
     30 {
     31   struct GNUNET_PQ_QueryParam params[] = {
     32     GNUNET_PQ_query_param_auto_from_type (account_pub),
     33     GNUNET_PQ_query_param_end
     34   };
     35   struct GNUNET_PQ_ResultSpec rs[] = {
     36     GNUNET_PQ_result_spec_timestamp ("expiration_date",
     37                                      expiration_date),
     38     GNUNET_PQ_result_spec_uint64 ("storage_used_bytes",
     39                                   storage_used_bytes),
     40     GNUNET_PQ_result_spec_uint64 ("block_count",
     41                                   block_count),
     42     GNUNET_PQ_result_spec_end
     43   };
     44   enum GNUNET_DB_QueryStatus qs;
     45 
     46   SYNCDB_preflight ();
     47   /* No stored procedure: this only reads, and an expired account is a
     48      result here rather than an error, so none of the checks the
     49      procedures share apply. */
     50   PREPARE ("account_select",
     51            "SELECT"
     52            " a.expiration_date"
     53            ",(SELECT COALESCE(SUM(octet_length(b.data_blob)),0)"
     54            "    FROM blocks b"
     55            "   WHERE b.account_pub = a.account_pub) AS storage_used_bytes"
     56            ",(SELECT COUNT(*)"
     57            "    FROM blocks b"
     58            "   WHERE b.account_pub = a.account_pub) AS block_count"
     59            " FROM accounts a"
     60            " WHERE a.account_pub=$1");
     61   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
     62                                                  "account_select",
     63                                                  params,
     64                                                  rs);
     65   switch (qs)
     66   {
     67   case GNUNET_DB_STATUS_HARD_ERROR:
     68     GNUNET_break (0);
     69     return SYNC_DB_HARD_ERROR;
     70   case GNUNET_DB_STATUS_SOFT_ERROR:
     71     GNUNET_break (0);
     72     return SYNC_DB_SOFT_ERROR;
     73   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     74     return SYNC_DB_TARGET_MISSING;
     75   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     76     return SYNC_DB_ONE_RESULT;
     77   default:
     78     GNUNET_break (0);
     79     return SYNC_DB_HARD_ERROR;
     80   }
     81 }
     82 
     83 
     84 /* end of syncdb_lookup_account_TR.c */