exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

pq_common.h (4379B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2023 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  * @file pq/pq_common.h
     18  * @brief common defines for the pq functions
     19  * @author Özgür Kesim
     20  */
     21 #ifndef TALER_PQ_COMMON_H_
     22 #define TALER_PQ_COMMON_H_
     23 
     24 #include "taler/taler_util.h"
     25 
     26 /**
     27  * Internal types that are supported as TALER-exchange-specific array types.
     28  *
     29  * To support a new type,
     30  *   1. add a new entry into this list,
     31  *   2. for query-support, implement the size calculation and memory copying in
     32  *      qconv_array() accordingly, in pq_query_helper.c
     33  *   3. provide a query-API for arrays of the type, by calling
     34  *      query_param_array_generic with the appropriate parameters,
     35  *      in pq_query_helper.c
     36  *   4. for result-support, implement memory copying by adding another case
     37  *      to extract_array_generic, in pq_result_helper.c
     38  *   5. provide a result-spec-API for arrays of the type,
     39  *      in pq_result_helper.c
     40  *   6. expose the API's in taler_pq_lib.h
     41  */
     42 enum TALER_PQ_ArrayType
     43 {
     44   TALER_PQ_array_of_blinded_denom_sig,
     45   TALER_PQ_array_of_blinded_coin_hash,
     46   TALER_PQ_array_of_denom_hash,
     47   TALER_PQ_array_of_hash_code,
     48   TALER_PQ_array_of_cs_r_pub,
     49   /**
     50    * Amounts *without* currency.
     51    */
     52   TALER_PQ_array_of_amount,
     53   /**
     54    * Amounts *with* currency.
     55    */
     56   TALER_PQ_array_of_amount_currency,
     57   TALER_PQ_array_of_MAX,       /* must be last */
     58 };
     59 
     60 
     61 /**
     62  * Memory representation of an taler amount record for Postgres.
     63  *
     64  * All values need to be in network-byte-order.
     65  */
     66 struct TALER_PQ_AmountP
     67 {
     68   uint32_t cnt;   /* # elements in the tuple (== 2) */
     69   uint32_t oid_v; /* oid of .v  */
     70   uint32_t sz_v;  /* size of .v */
     71   uint64_t v;     /* value      */
     72   uint32_t oid_f; /* oid of .f  */
     73   uint32_t sz_f;  /* size of .f */
     74   uint32_t f;     /* fraction   */
     75 } __attribute__((packed));
     76 
     77 
     78 /**
     79  * Memory representation of an taler amount record for Postgres.
     80  *
     81  * All values need to be in network-byte-order.
     82  */
     83 struct TALER_PQ_AmountNullP
     84 {
     85   uint32_t cnt;   /* # elements in the tuple (== 2) */
     86   uint32_t oid_v; /* oid of .v  */
     87   uint32_t sz_v;  /* size of .v */
     88   uint32_t oid_f; /* oid of .f  */
     89   uint32_t sz_f;  /* size of .f */
     90 } __attribute__((packed));
     91 
     92 
     93 /**
     94  * Memory representation of an taler amount record with currency for Postgres.
     95  *
     96  * All values need to be in network-byte-order.
     97  */
     98 struct TALER_PQ_AmountCurrencyP
     99 {
    100   uint32_t cnt;   /* # elements in the tuple (== 3) */
    101   uint32_t oid_v; /* oid of .v  */
    102   uint32_t sz_v;  /* size of .v */
    103   uint64_t v;     /* value      */
    104   uint32_t oid_f; /* oid of .f  */
    105   uint32_t sz_f;  /* size of .f */
    106   uint32_t f;     /* fraction   */
    107   uint32_t oid_c; /* oid of .c  */
    108   uint32_t sz_c;  /* size of .c */
    109   uint8_t c[TALER_CURRENCY_LEN];  /* currency */
    110 } __attribute__((packed));
    111 
    112 
    113 /**
    114  * Create a `struct TALER_PQ_AmountP` for initialization
    115  *
    116  * @param amount amount of type `struct TALER_Amount *`
    117  * @param oid_v OID of the INT8 type in postgres
    118  * @param oid_f OID of the INT4 type in postgres
    119  */
    120 struct TALER_PQ_AmountP
    121 TALER_PQ_make_taler_pq_amount_ (
    122   const struct TALER_Amount *amount,
    123   uint32_t oid_v,
    124   uint32_t oid_f);
    125 
    126 
    127 /**
    128  * Create a `struct TALER_PQ_AmountCurrencyP` for initialization
    129  *
    130  * @param amount amount of type `struct TALER_Amount *`
    131  * @param oid_v OID of the INT8 type in postgres
    132  * @param oid_f OID of the INT4 type in postgres
    133  * @param oid_c OID of the TEXT type in postgres
    134  * @param[out] rval set to encoded @a amount
    135  * @return actual (useful) size of @a rval for Postgres
    136  */
    137 size_t
    138 TALER_PQ_make_taler_pq_amount_currency_ (
    139   const struct TALER_Amount *amount,
    140   uint32_t oid_v,
    141   uint32_t oid_f,
    142   uint32_t oid_c,
    143   struct TALER_PQ_AmountCurrencyP *rval);
    144 
    145 
    146 #endif  /* TALER_PQ_COMMON_H_ */
    147 /* end of pg/pq_common.h */