aboutsummaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_exchanges.h
blob: 5fc57a3efe88a66aace29659cead39846501faa5 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
  This file is part of TALER
  (C) 2014-2023 Taler Systems SA

  TALER is free software; you can redistribute it and/or modify it under the
  terms of the GNU 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 General Public License for more details.

  You should have received a copy of the GNU General Public License along with
  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
*/
/**
 * @file taler-merchant-httpd_exchanges.h
 * @brief logic this HTTPD keeps for each exchange we interact with
 * @author Marcello Stanisci
 * @author Christian Grothoff
 */
#ifndef TALER_MERCHANT_HTTPD_EXCHANGES_H
#define TALER_MERCHANT_HTTPD_EXCHANGES_H

#include <jansson.h>
#include <gnunet/gnunet_util_lib.h>
#include <curl/curl.h>
#include <taler/taler_util.h>
#include <taler/taler_exchange_service.h>
#include "taler-merchant-httpd.h"


/**
 * Exchange
 */
struct TMH_Exchange;


/**
 * Check if we would trust @a ex to deposit funds
 * into our account @a wm. Checks that both @a ex
 * is trusted and that @a ex allows wire transfers
 * into the account given in @a wm.
 *
 * @param ex the exchange to check
 * @param wm the wire method to check with
 * @return #GNUNET_OK if such a debit can happen
 */
enum GNUNET_GenericReturnValue
TMH_exchange_check_debit (struct TMH_Exchange *ex,
                          const struct TMH_WireMethod *wm);


/**
 * Return the list of exchanges we would find
 * acceptable for a payment given the @a wire_method.
 *
 * @param wm wire method the payment should be
 *        made with
 * @return list of exchanges we accept for @a wire_method
 *   (and that would accept our bank account)
 */
json_t *
TMH_exchange_get_acceptable (const struct TMH_WireMethod *wm);


/**
 * Parses "trusted" exchanges listed in the configuration.
 *
 * @param cfg the configuration
 * @return number of trusted exchanges on success; #GNUNET_SYSERR upon error in
 *          parsing.
 */
enum GNUNET_GenericReturnValue
TMH_EXCHANGES_init (const struct GNUNET_CONFIGURATION_Handle *cfg);


/**
 * Function called to shutdown the exchanges subsystem.
 */
void
TMH_EXCHANGES_done (void);


/**
 * Function called with the result of a #TMH_EXCHANGES_keys4exchange()
 * operation.
 *
 * @param cls closure
 * @param keys the keys of the exchange
 */
typedef void
(*TMH_EXCHANGES_Find2Continuation)(
  void *cls,
  struct TALER_EXCHANGE_Keys *keys);


/**
 * Function called with the result of a #TMH_EXCHANGES_wire4exchange()
 * operation.
 *
 * @param cls closure
 * @param wire the wire data of the exchange
 */
typedef void
(*TMH_EXCHANGES_WireContinuation)(
  void *cls,
  struct TMH_Exchange *wire);


/**
 * Information we keep for a pending #MMH_EXCHANGES_keys4exchange() operation.
 */
struct TMH_EXCHANGES_Find2Operation;

/**
 * Information we keep for a pending #MMH_EXCHANGES_wire4exchange() operation.
 */
struct TMH_EXCHANGES_WireOperation;


/**
 * Get /keys of the given @a exchange.
 *
 * @param exchange URL of the exchange we would like to talk to
 * @param fc function to call with the handles for the exchange
 * @param fc_cls closure for @a fc
 */
struct TMH_EXCHANGES_Find2Operation *
TMH_EXCHANGES_keys4exchange (const char *exchange,
                             TMH_EXCHANGES_Find2Continuation fc,
                             void *fc_cls);


/**
 * Get /wire of the given @a exchange.
 *
 * @param exchange URL of the exchange we would like to talk to
 * @param fc function to call with the handles for the exchange
 * @param fc_cls closure for @a fc
 */
struct TMH_EXCHANGES_WireOperation *
TMH_EXCHANGES_wire4exchange (const char *exchange,
                             TMH_EXCHANGES_WireContinuation fc,
                             void *fc_cls);


/**
 * Lookup current wire fee by @a exchange_url and
 * @a wire_method.
 *
 * @param exchange_url base URL of the exchange
 * @param wire_method wire method to lookup fee by
 * @param[out] wire_fee set to the wire fee
 * @return #GNUNET_OK on success
 *         #GNUNET_NO if @a wire_method is not supported
 *         #GNUNET_SYSERR if @a exchange_url did not yet respond properly to our /wire request
 */
enum GNUNET_GenericReturnValue
TMH_EXCHANGES_lookup_wire_fee (const char *exchange_url,
                               const char *wire_method,
                               struct TALER_Amount *wire_fee);


/**
 * Abort pending keys details lookup operation.
 *
 * @param fo handle to operation to abort
 */
void
TMH_EXCHANGES_keys4exchange_cancel (struct TMH_EXCHANGES_Find2Operation *fo);


/**
 * Abort pending wire details lookup operation.
 *
 * @param fo handle to operation to abort
 */
void
TMH_EXCHANGES_wire4exchange_cancel (struct TMH_EXCHANGES_WireOperation *fo);


#endif