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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
/*
This file is part of TALER
Copyright (C) 2014-2022 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 include/taler_pq_lib.h
* @brief helper functions for DB interactions
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
* @author Florian Dold
* @author Christian Grothoff
* @author Özgür Kesim
*/
#ifndef TALER_PQ_LIB_H_
#define TALER_PQ_LIB_H_
#include <libpq-fe.h>
#include <jansson.h>
#include <gnunet/gnunet_common.h>
#include <gnunet/gnunet_pq_lib.h>
#include "taler_util.h"
/**
* Enumerates the composite types that Taler defines in Postgres.
* The corresponding OIDs (which are assigned by postgres at time of
* declaration) are stored in TALER_PQ_CompositeOIDs.
*/
enum TALER_PQ_CompositeType
{
TALER_PQ_CompositeAmount,
TALER_PQ_CompositeMAX /* MUST be last */
};
/**
* The correspondence of the Composite types and their OID in Postgres
*/
extern Oid TALER_PQ_CompositeOIDs[TALER_PQ_CompositeMAX];
/**
* Initialize the list of OIDs in TALER_PQ_CompositeOIDs. MUST be called
* before any composite type is used in arrays-specs/-params.
*
* @return GNUNET_SYSERR on failure
*/
enum GNUNET_GenericReturnValue
TALER_PQ_load_oids_for_composite_types (struct GNUNET_PQ_Context *db);
/**
* Generate query parameter for a currency, consisting of the three
* components "value", "fraction" and "currency" in this order. The
* types must be a 64-bit integer, 32-bit integer and a
* #TALER_CURRENCY_LEN-sized BLOB/VARCHAR respectively.
*
* @param x pointer to the query parameter to pass
*/
struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x);
/**
* Generate query parameter for an amount, consisting of the two
* components "value" and "fraction" in this order. The
* types must be a 64-bit integer and a 32-bit integer
* respectively. The currency is dropped.
*
* @param x pointer to the query parameter to pass
*/
struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_amount (const struct TALER_Amount *x);
/**
* Generate query parameter (as record tuple) for an amount, consisting
* of the two components "value" and "fraction" in this order. The
* types must be a 64-bit integer and a 32-bit integer
* respectively. The currency is dropped.
*
* @param db The database context for OID lookup
* @param amount pointer to the query parameter to pass
*/
struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_amount_tuple (
const struct GNUNET_PQ_Context *db,
const struct TALER_Amount *amount);
/**
* Generate query parameter for a denomination public
* key. Internally, the various attributes of the
* public key will be serialized into on variable-size
* BLOB.
*
* @param denom_pub pointer to the query parameter to pass
*/
struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_denom_pub (
const struct TALER_DenominationPublicKey *denom_pub);
/**
* Generate query parameter for a denomination signature. Internally, the
* various attributes of the signature will be serialized into on
* variable-size BLOB.
*
* @param denom_sig pointer to the query parameter to pass
*/
struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_denom_sig (
const struct TALER_DenominationSignature *denom_sig);
/**
* Generate query parameter for a blinded planchet.
* Internally, various attributes of the blinded
* planchet will be serialized into on
* variable-size BLOB.
*
* @param bp pointer to the query parameter to pass
*/
struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_blinded_planchet (
const struct TALER_BlindedPlanchet *bp);
/**
* Generate query parameter for a blinded denomination signature. Internally,
* the various attributes of the signature will be serialized into on
* variable-size BLOB.
*
* @param denom_sig pointer to the query parameter to pass
*/
struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_blinded_denom_sig (
const struct TALER_BlindedDenominationSignature *denom_sig);
/**
* Generate query parameter for the exchange's contribution during a
* withdraw. Internally, the various attributes of the @a alg_values will be
* serialized into on variable-size BLOB.
*
* @param alg_values pointer to the query parameter to pass
*/
struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_exchange_withdraw_values (
const struct TALER_ExchangeWithdrawValues *alg_values);
/**
* Generate query parameter for a JSON object (stored as a string
* in the DB). Note that @a x must really be a JSON object or array,
* passing just a value (string, integer) is not supported and will
* result in an abort.
*
* @param x pointer to the json object to pass
*/
struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_json (const json_t *x);
/**
* Generate query parameter for an array of blinded denomination signatures
*
* @param num number of elements in @e denom_sigs
* @param denom_sigs array of blinded denomination signatures
* @param db context for the db-connection
*/
struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_array_blinded_denom_sig (
size_t num,
const struct TALER_BlindedDenominationSignature *denom_sigs,
const struct GNUNET_PQ_Context *db
);
/**
* Generate query parameter for an array of blinded hashes of coin envelopes
*
* @param num number of elements in @e denom_sigs
* @param coin_evs array of blinded hashes of coin envelopes
* @param db context for the db-connection
*/
struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_array_blinded_coin_hash (
size_t num,
const struct TALER_BlindedCoinHashP *coin_evs,
const struct GNUNET_PQ_Context *db);
/**
* Currency amount expected.
*
* @param name name of the field in the table
* @param currency currency to use for @a amount
* @param[out] amount where to store the result
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_amount_nbo (const char *name,
const char *currency,
struct TALER_AmountNBO *amount);
/**
* Currency amount expected.
*
* @param name name of the field in the table
* @param currency currency to use for @a amount
* @param[out] amount where to store the result
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_amount (const char *name,
const char *currency,
struct TALER_Amount *amount);
/**
* Currency amount expected, from a record-field of (DB) taler_amount type
*
* @param name name of the field in the table
* @param currency currency to use for @a amount
* @param[out] amount where to store the result
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_amount_tuple (const char *name,
const char *currency,
struct TALER_Amount *amount);
/**
* Denomination public key expected.
*
* @param name name of the field in the table
* @param[out] denom_pub where to store the public key
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_denom_pub (const char *name,
struct TALER_DenominationPublicKey *denom_pub);
/**
* Denomination signature expected.
*
* @param name name of the field in the table
* @param[out] denom_sig where to store the denomination signature
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_denom_sig (const char *name,
struct TALER_DenominationSignature *denom_sig);
/**
* Blinded denomination signature expected.
*
* @param name name of the field in the table
* @param[out] denom_sig where to store the denomination signature
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_blinded_denom_sig (
const char *name,
struct TALER_BlindedDenominationSignature *denom_sig);
/**
* Exchange withdraw values expected.
*
* @param name name of the field in the table
* @param[out] ewv where to store the exchange values
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_exchange_withdraw_values (
const char *name,
struct TALER_ExchangeWithdrawValues *ewv);
/**
* Blinded planchet expected.
*
* @param name name of the field in the table
* @param[out] bp where to store the blinded planchet
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_blinded_planchet (
const char *name,
struct TALER_BlindedPlanchet *bp);
/**
* json_t expected.
*
* @param name name of the field in the table
* @param[out] jp where to store the result
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_json (const char *name,
json_t **jp);
/**
* Array of blinded denomination signature expected
*
* @param db context of the database connection
* @param name name of the field in the table
* @param[out] num number of elements in @e denom_sigs
* @param[out] denom_sigs where to store the result
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_array_blinded_denom_sig (
const struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
struct TALER_BlindedDenominationSignature **denom_sigs);
/**
* Array of blinded hashes of coin envelopes
*
* @param db context of the database connection
* @param name name of the field in the table
* @param[out] num number of elements in @e denom_sigs
* @param[out] h_coin_evs where to store the result
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_array_blinded_coin_hash (
const struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
struct TALER_BlindedCoinHashP **h_coin_evs);
/**
* Array of hashes of denominations
*
* @param db context of the database connection
* @param name name of the field in the table
* @param[out] num number of elements in @e denom_sigs
* @param[out] denom_hs where to store the result
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_array_denom_hash (
const struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
struct TALER_DenominationHashP **denom_hs);
#endif /* TALER_PQ_LIB_H_ */
/* end of include/taler_pq_lib.h */
|