diff options
Diffstat (limited to 'src/exchangedb/exchangedb_transactions.c')
-rw-r--r-- | src/exchangedb/exchangedb_transactions.c | 62 |
1 files changed, 45 insertions, 17 deletions
diff --git a/src/exchangedb/exchangedb_transactions.c b/src/exchangedb/exchangedb_transactions.c index c1723958f..f78393776 100644 --- a/src/exchangedb/exchangedb_transactions.c +++ b/src/exchangedb/exchangedb_transactions.c @@ -22,17 +22,7 @@ #include "taler_exchangedb_lib.h" -/** - * Calculate the total value of all transactions performed. - * Stores @a off plus the cost of all transactions in @a tl - * in @a ret. - * - * @param tl transaction list to process - * @param off offset to use as the starting value - * @param[out] ret where the resulting total is to be stored (may alias @a off) - * @return #GNUNET_OK on success, #GNUNET_SYSERR on errors - */ -int +enum GNUNET_GenericReturnValue TALER_EXCHANGEDB_calculate_transaction_list_totals ( struct TALER_EXCHANGEDB_TransactionList *tl, const struct TALER_Amount *off, @@ -42,13 +32,11 @@ TALER_EXCHANGEDB_calculate_transaction_list_totals ( struct TALER_Amount refunded; struct TALER_Amount deposit_fee; bool have_refund; - bool have_deposit_or_melt; GNUNET_assert (GNUNET_OK == - TALER_amount_get_zero (spent.currency, + TALER_amount_set_zero (spent.currency, &refunded)); have_refund = false; - have_deposit_or_melt = false; for (struct TALER_EXCHANGEDB_TransactionList *pos = tl; NULL != pos; pos = pos->next) @@ -57,7 +45,6 @@ TALER_EXCHANGEDB_calculate_transaction_list_totals ( { case TALER_EXCHANGEDB_TT_DEPOSIT: /* spent += pos->amount_with_fee */ - have_deposit_or_melt = true; if (0 > TALER_amount_add (&spent, &spent, @@ -70,7 +57,6 @@ TALER_EXCHANGEDB_calculate_transaction_list_totals ( break; case TALER_EXCHANGEDB_TT_MELT: /* spent += pos->amount_with_fee */ - have_deposit_or_melt = true; if (0 > TALER_amount_add (&spent, &spent, @@ -133,6 +119,49 @@ TALER_EXCHANGEDB_calculate_transaction_list_totals ( return GNUNET_SYSERR; } break; + case TALER_EXCHANGEDB_TT_PURSE_DEPOSIT: + /* spent += pos->amount_with_fee */ + if (0 > + TALER_amount_add (&spent, + &spent, + &pos->details.purse_deposit->amount)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + deposit_fee = pos->details.purse_deposit->deposit_fee; + break; + case TALER_EXCHANGEDB_TT_PURSE_REFUND: + /* refunded += pos->refund_amount - pos->refund_fee */ + if (0 > + TALER_amount_add (&refunded, + &refunded, + &pos->details.purse_refund->refund_amount)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + if (0 > + TALER_amount_add (&spent, + &spent, + &pos->details.purse_refund->refund_fee)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + have_refund = true; + break; + case TALER_EXCHANGEDB_TT_RESERVE_OPEN: + /* spent += pos->amount_with_fee */ + if (0 > + TALER_amount_add (&spent, + &spent, + &pos->details.reserve_open->coin_contribution)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + break; } } if (have_refund) @@ -156,7 +185,6 @@ TALER_EXCHANGEDB_calculate_transaction_list_totals ( GNUNET_break (0); return GNUNET_SYSERR; } - GNUNET_break (have_deposit_or_melt); *ret = spent; return GNUNET_OK; } |