aboutsummaryrefslogtreecommitdiff
path: root/src/mint/taler-mint-httpd_responses.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mint/taler-mint-httpd_responses.c')
-rw-r--r--src/mint/taler-mint-httpd_responses.c119
1 files changed, 110 insertions, 9 deletions
diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c
index 307e6ec17..bad87429c 100644
--- a/src/mint/taler-mint-httpd_responses.c
+++ b/src/mint/taler-mint-httpd_responses.c
@@ -309,31 +309,132 @@ TALER_MINT_reply_deposit_success (struct MHD_Connection *connection,
309 309
310 310
311/** 311/**
312 * Send proof that a /deposit, /refresh/melt or /lock request is
313 * invalid to client. This function will create a message with all of
314 * the operations affecting the coin that demonstrate that the coin
315 * has insufficient value.
316 *
317 * @param connection connection to the client
318 * @param tl transaction list to use to build reply
319 * @return MHD result code
320 */
321int
322TALER_MINT_reply_insufficient_funds (struct MHD_Connection *connection,
323 const struct TALER_MINT_DB_TransactionList *tl)
324{
325 const struct TALER_MINT_DB_TransactionList *pos;
326 int ret;
327
328 // FIXME: implement properly!
329 for (pos = tl; NULL != pos; pos = pos->next)
330 {
331 switch (pos->type)
332 {
333 case TALER_MINT_DB_TT_DEPOSIT:
334 /* FIXME: add operation details to json reply */
335 break;
336 case TALER_MINT_DB_TT_REFRESH_MELT:
337 /* FIXME: add operation details to json reply */
338 break;
339 case TALER_MINT_DB_TT_LOCK:
340 /* FIXME: add operation details to json reply */
341 break;
342 }
343 }
344
345 ret = TALER_MINT_reply_json_pack (connection,
346 MHD_HTTP_FORBIDDEN,
347 "{s:s}",
348 "error", "insufficient funds");
349 return ret;
350}
351
352
353/**
312 * Send reserve status information to client. 354 * Send reserve status information to client.
313 * 355 *
314 * @param connection connection to the client 356 * @param connection connection to the client
315 * @param balance current reserve balance 357 * @param rh reserve history to return
316 * @param expiration when will the reserve expire
317 * @return MHD result code 358 * @return MHD result code
318 */ 359 */
319int 360int
320TALER_MINT_reply_withdraw_status_success (struct MHD_Connection *connection, 361TALER_MINT_reply_withdraw_status_success (struct MHD_Connection *connection,
321 const struct TALER_Amount balance, 362 const struct ReserveHistory *rh)
322 struct GNUNET_TIME_Absolute expiration)
323{ 363{
364 struct TALER_Amount deposit_total;
365 struct TALER_Amount withdraw_total;
366 struct TALER_Amount balance;
367 struct TALER_Amount value;
324 json_t *json_balance; 368 json_t *json_balance;
325 json_t *json_expiration; 369 json_t *json_history;
326 int ret; 370 int ret;
371 struct MintKeyState *key_state;
372 const struct ReserveHistory *pos;
373 struct TALER_MINT_DenomKeyIssuePriv *dki;
374
375 json_history = json_array ();
376 ret = 0;
377 for (pos = rh; NULL != pos; pos = pos->next)
378 {
379 switch (pos->type)
380 {
381 case TALER_MINT_DB_RO_BANK_TO_MINT:
382 if (0 == ret)
383 deposit_total = pos->details.bank->amount;
384 else
385 deposit_total = TALER_amount_add (deposit_total,
386 pos->details.bank->amount);
387 ret = 1;
388 json_array_append_new (json_history,
389 json_pack ("{s:s, s:o, s:o}",
390 "type", "DEPOSIT",
391 "wire", pos->details.bank->wire,
392 "amount", TALER_JSON_from_amount (pos->details.bank->amount)));
393 break;
394 case TALER_MINT_DB_RO_WITHDRAW_COIN:
395 break;
396 }
397 }
398
399 key_state = TALER_MINT_key_state_acquire ();
400 ret = 0;
401 for (pos = rh; NULL != pos; pos = pos->next)
402 {
403 switch (pos->type)
404 {
405 case TALER_MINT_DB_RO_BANK_TO_MINT:
406 break;
407 case TALER_MINT_DB_RO_WITHDRAW_COIN:
408 dki = TALER_MINT_get_denom_key (key_state,
409 pos->details.withdraw->denom_pub);
410 value = TALER_amount_ntoh (dki->issue.value);
411 if (0 == ret)
412 withdraw_total = value;
413 else
414 withdraw_total = TALER_amount_add (withdraw_total,
415 value);
416 ret = 1;
417 /* FIXME: add `struct CollectableBlindcoin` as JSON here as well! (#3527) */
418 json_array_append_new (json_history,
419 json_pack ("{s:s, s:o, s:o}",
420 "type", "WITHDRAW",
421 "amount", TALER_JSON_from_amount (value)));
422
423 break;
424 }
425 }
426 TALER_MINT_key_state_release (key_state);
327 427
428 balance = TALER_amount_subtract (deposit_total,
429 withdraw_total);
328 json_balance = TALER_JSON_from_amount (balance); 430 json_balance = TALER_JSON_from_amount (balance);
329 json_expiration = TALER_JSON_from_abs (expiration);
330 ret = TALER_MINT_reply_json_pack (connection, 431 ret = TALER_MINT_reply_json_pack (connection,
331 MHD_HTTP_OK, 432 MHD_HTTP_OK,
332 "{s:o, s:o}", 433 "{s:o, s:o}",
333 "balance", json_balance, 434 "balance", json_balance,
334 "expiration", json_expiration); 435 "history", json_history);
436 json_decref (json_history);
335 json_decref (json_balance); 437 json_decref (json_balance);
336 json_decref (json_expiration);
337 return ret; 438 return ret;
338} 439}
339 440
@@ -354,7 +455,7 @@ TALER_MINT_reply_withdraw_sign_success (struct MHD_Connection *connection,
354 char *sig_buf; 455 char *sig_buf;
355 int ret; 456 int ret;
356 457
357 /* FIXME: use TALER_JSON_from_sig here instead! */ 458 /* FIXME: use TALER_JSON_from_sig here instead!? */
358 sig_buf_size = GNUNET_CRYPTO_rsa_signature_encode (collectable->sig, 459 sig_buf_size = GNUNET_CRYPTO_rsa_signature_encode (collectable->sig,
359 &sig_buf); 460 &sig_buf);
360 sig_json = TALER_JSON_from_data (sig_buf, 461 sig_json = TALER_JSON_from_data (sig_buf,