diff options
Diffstat (limited to 'src/mint/taler-mint-httpd_responses.c')
-rw-r--r-- | src/mint/taler-mint-httpd_responses.c | 78 |
1 files changed, 66 insertions, 12 deletions
diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c index bad87429c..ffb764a1d 100644 --- a/src/mint/taler-mint-httpd_responses.c +++ b/src/mint/taler-mint-httpd_responses.c | |||
@@ -351,26 +351,25 @@ TALER_MINT_reply_insufficient_funds (struct MHD_Connection *connection, | |||
351 | 351 | ||
352 | 352 | ||
353 | /** | 353 | /** |
354 | * Send reserve status information to client. | 354 | * Compile the history of a reserve into a JSON object |
355 | * and calculate the total balance. | ||
355 | * | 356 | * |
356 | * @param connection connection to the client | 357 | * @param rh reserve history to JSON-ify |
357 | * @param rh reserve history to return | 358 | * @param balance[OUT] set to current reserve balance |
358 | * @return MHD result code | 359 | * @return json representation of the @a rh |
359 | */ | 360 | */ |
360 | int | 361 | static json_t * |
361 | TALER_MINT_reply_withdraw_status_success (struct MHD_Connection *connection, | 362 | compile_reserve_history (const struct ReserveHistory *rh, |
362 | const struct ReserveHistory *rh) | 363 | struct TALER_Amount *balance) |
363 | { | 364 | { |
364 | struct TALER_Amount deposit_total; | 365 | struct TALER_Amount deposit_total; |
365 | struct TALER_Amount withdraw_total; | 366 | struct TALER_Amount withdraw_total; |
366 | struct TALER_Amount balance; | ||
367 | struct TALER_Amount value; | 367 | struct TALER_Amount value; |
368 | json_t *json_balance; | ||
369 | json_t *json_history; | 368 | json_t *json_history; |
370 | int ret; | 369 | int ret; |
371 | struct MintKeyState *key_state; | ||
372 | const struct ReserveHistory *pos; | 370 | const struct ReserveHistory *pos; |
373 | struct TALER_MINT_DenomKeyIssuePriv *dki; | 371 | struct TALER_MINT_DenomKeyIssuePriv *dki; |
372 | struct MintKeyState *key_state; | ||
374 | 373 | ||
375 | json_history = json_array (); | 374 | json_history = json_array (); |
376 | ret = 0; | 375 | ret = 0; |
@@ -425,8 +424,30 @@ TALER_MINT_reply_withdraw_status_success (struct MHD_Connection *connection, | |||
425 | } | 424 | } |
426 | TALER_MINT_key_state_release (key_state); | 425 | TALER_MINT_key_state_release (key_state); |
427 | 426 | ||
428 | balance = TALER_amount_subtract (deposit_total, | 427 | *balance = TALER_amount_subtract (deposit_total, |
429 | withdraw_total); | 428 | withdraw_total); |
429 | return json_history; | ||
430 | } | ||
431 | |||
432 | |||
433 | /** | ||
434 | * Send reserve status information to client. | ||
435 | * | ||
436 | * @param connection connection to the client | ||
437 | * @param rh reserve history to return | ||
438 | * @return MHD result code | ||
439 | */ | ||
440 | int | ||
441 | TALER_MINT_reply_withdraw_status_success (struct MHD_Connection *connection, | ||
442 | const struct ReserveHistory *rh) | ||
443 | { | ||
444 | json_t *json_balance; | ||
445 | json_t *json_history; | ||
446 | struct TALER_Amount balance; | ||
447 | int ret; | ||
448 | |||
449 | json_history = compile_reserve_history (rh, | ||
450 | &balance); | ||
430 | json_balance = TALER_JSON_from_amount (balance); | 451 | json_balance = TALER_JSON_from_amount (balance); |
431 | ret = TALER_MINT_reply_json_pack (connection, | 452 | ret = TALER_MINT_reply_json_pack (connection, |
432 | MHD_HTTP_OK, | 453 | MHD_HTTP_OK, |
@@ -440,6 +461,39 @@ TALER_MINT_reply_withdraw_status_success (struct MHD_Connection *connection, | |||
440 | 461 | ||
441 | 462 | ||
442 | /** | 463 | /** |
464 | * Send reserve status information to client with the | ||
465 | * message that we have insufficient funds for the | ||
466 | * requested /withdraw/sign operation. | ||
467 | * | ||
468 | * @param connection connection to the client | ||
469 | * @param rh reserve history to return | ||
470 | * @return MHD result code | ||
471 | */ | ||
472 | int | ||
473 | TALER_MINT_reply_withdraw_sign_insufficient_funds (struct MHD_Connection *connection, | ||
474 | const struct ReserveHistory *rh) | ||
475 | { | ||
476 | json_t *json_balance; | ||
477 | json_t *json_history; | ||
478 | struct TALER_Amount balance; | ||
479 | int ret; | ||
480 | |||
481 | json_history = compile_reserve_history (rh, | ||
482 | &balance); | ||
483 | json_balance = TALER_JSON_from_amount (balance); | ||
484 | ret = TALER_MINT_reply_json_pack (connection, | ||
485 | MHD_HTTP_PAYMENT_REQUIRED, | ||
486 | "{s:s, s:o, s:o}", | ||
487 | "error", "Insufficient funds" | ||
488 | "balance", json_balance, | ||
489 | "history", json_history); | ||
490 | json_decref (json_history); | ||
491 | json_decref (json_balance); | ||
492 | return ret; | ||
493 | } | ||
494 | |||
495 | |||
496 | /** | ||
443 | * Send blinded coin information to client. | 497 | * Send blinded coin information to client. |
444 | * | 498 | * |
445 | * @param connection connection to the client | 499 | * @param connection connection to the client |