exchange

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

pq_common.c (1997B)


      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.c
     18  * @brief common defines for the pq functions
     19  * @author Özgür Kesim
     20  */
     21 #include "taler/platform.h"
     22 #include "pq_common.h"
     23 
     24 struct TALER_PQ_AmountP
     25 TALER_PQ_make_taler_pq_amount_ (
     26   const struct TALER_Amount *amount,
     27   uint32_t oid_v,
     28   uint32_t oid_f)
     29 {
     30   struct TALER_PQ_AmountP rval = {
     31     .cnt = htonl (2),
     32     .oid_v = htonl (oid_v),
     33     .oid_f = htonl (oid_f),
     34     .sz_v = htonl (sizeof((amount)->value)),
     35     .sz_f = htonl (sizeof((amount)->fraction)),
     36     .v = GNUNET_htonll ((amount)->value),
     37     .f = htonl ((amount)->fraction)
     38   };
     39 
     40   return rval;
     41 }
     42 
     43 
     44 size_t
     45 TALER_PQ_make_taler_pq_amount_currency_ (
     46   const struct TALER_Amount *amount,
     47   uint32_t oid_v,
     48   uint32_t oid_f,
     49   uint32_t oid_c,
     50   struct TALER_PQ_AmountCurrencyP *rval)
     51 {
     52   size_t clen = strlen (amount->currency);
     53 
     54   GNUNET_assert (clen < TALER_CURRENCY_LEN);
     55   rval->cnt = htonl (3);
     56   rval->oid_v = htonl (oid_v);
     57   rval->oid_f = htonl (oid_f);
     58   rval->oid_c = htonl (oid_c);
     59   rval->sz_v = htonl (sizeof(amount->value));
     60   rval->sz_f = htonl (sizeof(amount->fraction));
     61   rval->sz_c = htonl (clen);
     62   rval->v = GNUNET_htonll (amount->value);
     63   rval->f = htonl (amount->fraction);
     64   memcpy (rval->c,
     65           amount->currency,
     66           clen);
     67   return sizeof (*rval) - TALER_CURRENCY_LEN + clen;
     68 }