summaryrefslogtreecommitdiff
path: root/src/exchange/taler-exchange-httpd_common_deposit.h
blob: 10fd7e8bfc4ac6ec30b0976160b8a3c2bd7447ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
  This file is part of TALER
  Copyright (C) 2022 Taler Systems SA

  TALER is free software; you can redistribute it and/or modify it under the
  terms of the GNU Affero General Public License as published by the Free Software
  Foundation; either version 3, or (at your option) any later version.

  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License along with
  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
*/
/**
 * @file taler-exchange-httpd_common_deposit.h
 * @brief shared logic for handling deposited coins
 * @author Christian Grothoff
 */
#ifndef TALER_EXCHANGE_HTTPD_COMMON_DEPOSIT_H
#define TALER_EXCHANGE_HTTPD_COMMON_DEPOSIT_H

#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_json_lib.h>
#include <jansson.h>
#include <microhttpd.h>
#include "taler_json_lib.h"
#include "taler_mhd_lib.h"


/**
 * Information about an individual coin being deposited.
 */
struct TEH_PurseDepositedCoin
{
  /**
   * Public information about the coin.
   */
  struct TALER_CoinPublicInfo cpi;

  /**
   * Signature affirming spending the coin.
   */
  struct TALER_CoinSpendSignatureP coin_sig;

  /**
   * Amount to be put into the purse from this coin.
   */
  struct TALER_Amount amount;

  /**
   * Deposit fee applicable for this coin.
   */
  struct TALER_Amount deposit_fee;

  /**
   * Amount to be put into the purse from this coin.
   */
  struct TALER_Amount amount_minus_fee;

  /**
   * Age attestation provided, set if @e no_attest is false.
   */
  struct TALER_AgeAttestation attest;

  /**
   * Age commitment provided, set if @e cpi.no_age_commitment is false.
   */
  struct TALER_AgeCommitment age_commitment;

  /**
   * ID of the coin in known_coins.
   */
  uint64_t known_coin_id;

  /**
   * True if @e attest was not provided.
   */
  bool no_attest;

};


/**
 * Parse a coin and check signature of the coin and the denomination
 * signature over the coin.
 *
 * @param[in,out] connection our HTTP connection
 * @param[out] coin coin to initialize
 * @param jcoin coin to parse
 * @return #GNUNET_OK on success, #GNUNET_NO if an error was returned,
 *         #GNUNET_SYSERR on failure and no error could be returned
 */
enum GNUNET_GenericReturnValue
TEH_common_purse_deposit_parse_coin (
  struct MHD_Connection *connection,
  struct TEH_PurseDepositedCoin *coin,
  const json_t *jcoin);


/**
 * Check that the deposited @a coin is valid for @a purse_pub
 * and has a valid age commitment for @a min_age.
 *
 * @param[in,out] connection our HTTP connection
 * @param coin the coin to evaluate
 * @param purse_pub public key of the purse the coin was deposited into
 * @param min_age minimum age restriction expected for this purse
 * @return #GNUNET_OK on success, #GNUNET_NO if an error was returned,
 *         #GNUNET_SYSERR on failure and no error could be returned
 */
enum GNUNET_GenericReturnValue
TEH_common_deposit_check_purse_deposit (
  struct MHD_Connection *connection,
  const struct TEH_PurseDepositedCoin *coin,
  const struct TALER_PurseContractPublicKeyP *purse_pub,
  uint32_t min_age);


/**
 * Release data structures of @a coin. Note that
 * @a coin itself is NOT freed.
 *
 * @param[in] coin information to release
 */
void
TEH_common_purse_deposit_free_coin (struct TEH_PurseDepositedCoin *coin);

#endif