diff options
Diffstat (limited to 'src/mint/mint_db.h')
-rw-r--r-- | src/mint/mint_db.h | 182 |
1 files changed, 111 insertions, 71 deletions
diff --git a/src/mint/mint_db.h b/src/mint/mint_db.h index ff14ba1e4..4cb2a5f1e 100644 --- a/src/mint/mint_db.h +++ b/src/mint/mint_db.h | |||
@@ -38,77 +38,6 @@ int | |||
38 | TALER_MINT_DB_prepare (PGconn *db_conn); | 38 | TALER_MINT_DB_prepare (PGconn *db_conn); |
39 | 39 | ||
40 | 40 | ||
41 | /** | ||
42 | * Reserve row. Corresponds to table 'reserves' in the mint's | ||
43 | * database. FIXME: not sure this is how we want to store this | ||
44 | * information. Also, may currently used in different ways in the | ||
45 | * code, so we might need to separate the struct into different ones | ||
46 | * depending on the context it is used in. | ||
47 | */ | ||
48 | struct Reserve | ||
49 | { | ||
50 | /** | ||
51 | * Signature over the purse. | ||
52 | * Only valid if (blind_session_missing==GNUNET_YES). | ||
53 | */ | ||
54 | struct GNUNET_CRYPTO_EddsaSignature status_sig; | ||
55 | |||
56 | /** | ||
57 | * Signature with purpose TALER_SIGNATURE_PURSE. | ||
58 | * Only valid if (blind_session_missing==GNUNET_YES). | ||
59 | */ | ||
60 | struct GNUNET_CRYPTO_EccSignaturePurpose status_sig_purpose; | ||
61 | |||
62 | /** | ||
63 | * Signing key used to sign the purse. | ||
64 | * Only valid if (blind_session_missing==GNUNET_YES). | ||
65 | */ | ||
66 | struct GNUNET_CRYPTO_EddsaPublicKey status_sign_pub; | ||
67 | |||
68 | /** | ||
69 | * Withdraw public key, identifies the purse. | ||
70 | * Only the customer knows the corresponding private key. | ||
71 | */ | ||
72 | struct GNUNET_CRYPTO_EddsaPublicKey reserve_pub; | ||
73 | |||
74 | /** | ||
75 | * Remaining balance in the purse. // FIXME: do not use NBO here! | ||
76 | */ | ||
77 | struct TALER_AmountNBO balance; | ||
78 | |||
79 | /** | ||
80 | * Expiration date for the purse. | ||
81 | */ | ||
82 | struct GNUNET_TIME_AbsoluteNBO expiration; | ||
83 | }; | ||
84 | |||
85 | |||
86 | int | ||
87 | TALER_MINT_DB_get_reserve (PGconn *db_conn, | ||
88 | const struct GNUNET_CRYPTO_EddsaPublicKey *reserve_pub, | ||
89 | struct Reserve *reserve_res); | ||
90 | |||
91 | |||
92 | /** | ||
93 | * Update information about a reserve. | ||
94 | * | ||
95 | * @param db_conn | ||
96 | * @param reserve current reserve status | ||
97 | * @param fresh FIXME | ||
98 | * @return #GNUNET_OK on success | ||
99 | */ | ||
100 | int | ||
101 | TALER_MINT_DB_update_reserve (PGconn *db_conn, | ||
102 | const struct Reserve *reserve, | ||
103 | int fresh); | ||
104 | |||
105 | |||
106 | |||
107 | |||
108 | |||
109 | |||
110 | |||
111 | |||
112 | int | 41 | int |
113 | TALER_MINT_DB_insert_refresh_order (PGconn *db_conn, | 42 | TALER_MINT_DB_insert_refresh_order (PGconn *db_conn, |
114 | uint16_t newcoin_index, | 43 | uint16_t newcoin_index, |
@@ -328,6 +257,34 @@ void | |||
328 | TALER_MINT_DB_rollback (PGconn *db_conn); | 257 | TALER_MINT_DB_rollback (PGconn *db_conn); |
329 | 258 | ||
330 | 259 | ||
260 | /** | ||
261 | * Information we keep on a bank transfer that | ||
262 | * established a reserve. | ||
263 | */ | ||
264 | struct BankTransfer | ||
265 | { | ||
266 | |||
267 | /** | ||
268 | * Public key of the reserve that was filled. | ||
269 | */ | ||
270 | struct GNUNET_CRYPTO_EddsaPublicKey reserve_pub; | ||
271 | |||
272 | /** | ||
273 | * Amount that was transferred to the mint. | ||
274 | */ | ||
275 | struct TALER_Amount amount; | ||
276 | |||
277 | /** | ||
278 | * Detailed wire information about the transaction. | ||
279 | */ | ||
280 | const json_t *wire; | ||
281 | |||
282 | }; | ||
283 | |||
284 | |||
285 | /* FIXME: add functions to add bank transfers to our DB | ||
286 | (and to test if we already did add one) */ | ||
287 | |||
331 | 288 | ||
332 | /** | 289 | /** |
333 | * Information we keep for a withdrawn coin to reproduce | 290 | * Information we keep for a withdrawn coin to reproduce |
@@ -360,6 +317,9 @@ struct CollectableBlindcoin | |||
360 | }; | 317 | }; |
361 | 318 | ||
362 | 319 | ||
320 | /* FIXME: need call to convert CollectableBlindcoin to JSON (#3527) */ | ||
321 | |||
322 | |||
363 | /** | 323 | /** |
364 | * Locate the response for a /withdraw request under the | 324 | * Locate the response for a /withdraw request under the |
365 | * key of the hash of the blinded message. | 325 | * key of the hash of the blinded message. |
@@ -396,6 +356,86 @@ TALER_MINT_DB_insert_collectable_blindcoin (PGconn *db_conn, | |||
396 | const struct CollectableBlindcoin *collectable); | 356 | const struct CollectableBlindcoin *collectable); |
397 | 357 | ||
398 | 358 | ||
359 | |||
360 | /** | ||
361 | * Types of operations on a reserved. | ||
362 | */ | ||
363 | enum TALER_MINT_DB_ReserveOperation | ||
364 | { | ||
365 | /** | ||
366 | * Money was deposited into the reserve via a bank transfer. | ||
367 | */ | ||
368 | TALER_MINT_DB_RO_BANK_TO_MINT = 0, | ||
369 | |||
370 | /** | ||
371 | * A Coin was withdrawn from the reserve using /withdraw. | ||
372 | */ | ||
373 | TALER_MINT_DB_RO_WITHDRAW_COIN = 1 | ||
374 | }; | ||
375 | |||
376 | |||
377 | /** | ||
378 | * Reserve history as a linked list. Lists all of the transactions | ||
379 | * associated with this reserve (such as the bank transfers that | ||
380 | * established the reserve and all /withdraw operations we have done | ||
381 | * since). | ||
382 | */ | ||
383 | struct ReserveHistory | ||
384 | { | ||
385 | |||
386 | /** | ||
387 | * Next entry in the reserve history. | ||
388 | */ | ||
389 | struct ReserveHistory *next; | ||
390 | |||
391 | /** | ||
392 | * Type of the event, determins @e details. | ||
393 | */ | ||
394 | enum TALER_MINT_DB_ReserveOperation type; | ||
395 | |||
396 | /** | ||
397 | * Details of the operation, depending on @e type. | ||
398 | */ | ||
399 | union | ||
400 | { | ||
401 | |||
402 | /** | ||
403 | * Details about a bank transfer to the mint. | ||
404 | */ | ||
405 | struct BankTransfer *bank; | ||
406 | |||
407 | /** | ||
408 | * Details about a /withdraw operation. | ||
409 | */ | ||
410 | struct CollectableBlindcoin *withdraw; | ||
411 | |||
412 | } details; | ||
413 | |||
414 | }; | ||
415 | |||
416 | |||
417 | /** | ||
418 | * Get all of the transaction history associated with the specified | ||
419 | * reserve. | ||
420 | * | ||
421 | * @param db_conn connection to use | ||
422 | * @param reserve_pub public key of the reserve | ||
423 | * @return known transaction history (NULL if reserve is unknown) | ||
424 | */ | ||
425 | struct ReserveHistory * | ||
426 | TALER_MINT_DB_get_reserve_history (PGconn *db_conn, | ||
427 | const struct GNUNET_CRYPTO_EddsaPublicKey *reserve_pub); | ||
428 | |||
429 | |||
430 | /** | ||
431 | * Free memory associated with the given reserve history. | ||
432 | * | ||
433 | * @param rh history to free. | ||
434 | */ | ||
435 | void | ||
436 | TALER_MINT_DB_free_reserve_history (struct ReserveHistory *rh); | ||
437 | |||
438 | |||
399 | /** | 439 | /** |
400 | * Specification for a /deposit operation. | 440 | * Specification for a /deposit operation. |
401 | */ | 441 | */ |