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 "pq_common.h"
22 :
23 : struct TALER_PQ_AmountP
24 3800 : TALER_PQ_make_taler_pq_amount_ (
25 : const struct TALER_Amount *amount,
26 : uint32_t oid_v,
27 : uint32_t oid_f)
28 : {
29 7600 : struct TALER_PQ_AmountP rval = {
30 3800 : .cnt = htonl (2),
31 3800 : .oid_v = htonl (oid_v),
32 3800 : .oid_f = htonl (oid_f),
33 3800 : .sz_v = htonl (sizeof((amount)->value)),
34 3800 : .sz_f = htonl (sizeof((amount)->fraction)),
35 3800 : .v = GNUNET_htonll ((amount)->value),
36 3800 : .f = htonl ((amount)->fraction)
37 : };
38 :
39 3800 : return rval;
40 : }
41 :
42 :
43 : size_t
44 5 : TALER_PQ_make_taler_pq_amount_currency_ (
45 : const struct TALER_Amount *amount,
46 : uint32_t oid_v,
47 : uint32_t oid_f,
48 : uint32_t oid_c,
49 : struct TALER_PQ_AmountCurrencyP *rval)
50 : {
51 5 : size_t clen = strlen (amount->currency);
52 :
53 5 : GNUNET_assert (clen < TALER_CURRENCY_LEN);
54 5 : rval->cnt = htonl (3);
55 5 : rval->oid_v = htonl (oid_v);
56 5 : rval->oid_f = htonl (oid_f);
57 5 : rval->oid_c = htonl (oid_c);
58 5 : rval->sz_v = htonl (sizeof(amount->value));
59 5 : rval->sz_f = htonl (sizeof(amount->fraction));
60 5 : rval->sz_c = htonl (clen);
61 5 : rval->v = GNUNET_htonll (amount->value);
62 5 : rval->f = htonl (amount->fraction);
63 5 : memcpy (rval->c,
64 5 : amount->currency,
65 : clen);
66 5 : return sizeof (*rval) - TALER_CURRENCY_LEN + clen;
67 : }
|