Line data Source code
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 28101 : TALER_PQ_make_taler_pq_amount_ (
26 : const struct TALER_Amount *amount,
27 : uint32_t oid_v,
28 : uint32_t oid_f)
29 : {
30 56202 : struct TALER_PQ_AmountP rval = {
31 28101 : .cnt = htonl (2),
32 28101 : .oid_v = htonl (oid_v),
33 28101 : .oid_f = htonl (oid_f),
34 28101 : .sz_v = htonl (sizeof((amount)->value)),
35 28101 : .sz_f = htonl (sizeof((amount)->fraction)),
36 28101 : .v = GNUNET_htonll ((amount)->value),
37 28101 : .f = htonl ((amount)->fraction)
38 : };
39 :
40 28101 : return rval;
41 : }
42 :
43 :
44 : size_t
45 5 : 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 5 : size_t clen = strlen (amount->currency);
53 :
54 5 : GNUNET_assert (clen < TALER_CURRENCY_LEN);
55 5 : rval->cnt = htonl (3);
56 5 : rval->oid_v = htonl (oid_v);
57 5 : rval->oid_f = htonl (oid_f);
58 5 : rval->oid_c = htonl (oid_c);
59 5 : rval->sz_v = htonl (sizeof(amount->value));
60 5 : rval->sz_f = htonl (sizeof(amount->fraction));
61 5 : rval->sz_c = htonl (clen);
62 5 : rval->v = GNUNET_htonll (amount->value);
63 5 : rval->f = htonl (amount->fraction);
64 5 : memcpy (rval->c,
65 5 : amount->currency,
66 : clen);
67 5 : return sizeof (*rval) - TALER_CURRENCY_LEN + clen;
68 : }
|