LCOV - code coverage report
Current view: top level - exchangedb - exchangedb_transactions.c (source / functions) Hit Total Coverage
Test: GNU Taler coverage report Lines: 0 68 0.0 %
Date: 2021-04-12 06:08:44 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2017-2020 Taler Systems SA
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify it under the
       6             :   terms of the GNU General Public License as published by the Free Software
       7             :   Foundation; either version 3, or (at your option) any later version.
       8             : 
       9             :   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
      10             :   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
      11             :   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
      12             : 
      13             :   You should have received a copy of the GNU General Public License along with
      14             :   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
      15             : */
      16             : /**
      17             :  * @file exchangedb/exchangedb_transactions.c
      18             :  * @brief Logic to compute transaction totals of a transaction list for a coin
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include "taler_exchangedb_lib.h"
      23             : 
      24             : 
      25             : /**
      26             :  * Calculate the total value of all transactions performed.
      27             :  * Stores @a off plus the cost of all transactions in @a tl
      28             :  * in @a ret.
      29             :  *
      30             :  * @param tl transaction list to process
      31             :  * @param off offset to use as the starting value
      32             :  * @param[out] ret where the resulting total is to be stored (may alias @a off)
      33             :  * @return #GNUNET_OK on success, #GNUNET_SYSERR on errors
      34             :  */
      35             : int
      36           0 : TALER_EXCHANGEDB_calculate_transaction_list_totals (
      37             :   struct TALER_EXCHANGEDB_TransactionList *tl,
      38             :   const struct TALER_Amount *off,
      39             :   struct TALER_Amount *ret)
      40             : {
      41           0 :   struct TALER_Amount spent = *off;
      42             :   struct TALER_Amount refunded;
      43             :   struct TALER_Amount deposit_fee;
      44             :   bool have_refund;
      45             : 
      46           0 :   GNUNET_assert (GNUNET_OK ==
      47             :                  TALER_amount_get_zero (spent.currency,
      48             :                                         &refunded));
      49           0 :   have_refund = false;
      50           0 :   for (struct TALER_EXCHANGEDB_TransactionList *pos = tl;
      51             :        NULL != pos;
      52           0 :        pos = pos->next)
      53             :   {
      54           0 :     switch (pos->type)
      55             :     {
      56           0 :     case TALER_EXCHANGEDB_TT_DEPOSIT:
      57             :       /* spent += pos->amount_with_fee */
      58           0 :       if (0 >
      59           0 :           TALER_amount_add (&spent,
      60             :                             &spent,
      61           0 :                             &pos->details.deposit->amount_with_fee))
      62             :       {
      63           0 :         GNUNET_break (0);
      64           0 :         return GNUNET_SYSERR;
      65             :       }
      66           0 :       deposit_fee = pos->details.deposit->deposit_fee;
      67           0 :       break;
      68           0 :     case TALER_EXCHANGEDB_TT_MELT:
      69             :       /* spent += pos->amount_with_fee */
      70           0 :       if (0 >
      71           0 :           TALER_amount_add (&spent,
      72             :                             &spent,
      73           0 :                             &pos->details.melt->amount_with_fee))
      74             :       {
      75           0 :         GNUNET_break (0);
      76           0 :         return GNUNET_SYSERR;
      77             :       }
      78           0 :       break;
      79           0 :     case TALER_EXCHANGEDB_TT_REFUND:
      80             :       /* refunded += pos->refund_amount - pos->refund_fee */
      81           0 :       if (0 >
      82           0 :           TALER_amount_add (&refunded,
      83             :                             &refunded,
      84           0 :                             &pos->details.refund->refund_amount))
      85             :       {
      86           0 :         GNUNET_break (0);
      87           0 :         return GNUNET_SYSERR;
      88             :       }
      89           0 :       if (0 >
      90           0 :           TALER_amount_add (&spent,
      91             :                             &spent,
      92           0 :                             &pos->details.refund->refund_fee))
      93             :       {
      94           0 :         GNUNET_break (0);
      95           0 :         return GNUNET_SYSERR;
      96             :       }
      97           0 :       have_refund = true;
      98           0 :       break;
      99           0 :     case TALER_EXCHANGEDB_TT_OLD_COIN_RECOUP:
     100             :       /* refunded += pos->value */
     101           0 :       if (0 >
     102           0 :           TALER_amount_add (&refunded,
     103             :                             &refunded,
     104           0 :                             &pos->details.old_coin_recoup->value))
     105             :       {
     106           0 :         GNUNET_break (0);
     107           0 :         return GNUNET_SYSERR;
     108             :       }
     109           0 :       break;
     110           0 :     case TALER_EXCHANGEDB_TT_RECOUP:
     111             :       /* spent += pos->value */
     112           0 :       if (0 >
     113           0 :           TALER_amount_add (&spent,
     114             :                             &spent,
     115           0 :                             &pos->details.recoup->value))
     116             :       {
     117           0 :         GNUNET_break (0);
     118           0 :         return GNUNET_SYSERR;
     119             :       }
     120           0 :       break;
     121           0 :     case TALER_EXCHANGEDB_TT_RECOUP_REFRESH:
     122             :       /* spent += pos->value */
     123           0 :       if (0 >
     124           0 :           TALER_amount_add (&spent,
     125             :                             &spent,
     126           0 :                             &pos->details.recoup_refresh->value))
     127             :       {
     128           0 :         GNUNET_break (0);
     129           0 :         return GNUNET_SYSERR;
     130             :       }
     131           0 :       break;
     132             :     }
     133           0 :   }
     134           0 :   if (have_refund)
     135             :   {
     136             :     /* If we gave any refund, also discount ONE deposit fee */
     137           0 :     if (0 >
     138           0 :         TALER_amount_add (&refunded,
     139             :                           &refunded,
     140             :                           &deposit_fee))
     141             :     {
     142           0 :       GNUNET_break (0);
     143           0 :       return GNUNET_SYSERR;
     144             :     }
     145             :   }
     146             :   /* spent = spent - refunded */
     147           0 :   if (0 >
     148           0 :       TALER_amount_subtract (&spent,
     149             :                              &spent,
     150             :                              &refunded))
     151             :   {
     152           0 :     GNUNET_break (0);
     153           0 :     return GNUNET_SYSERR;
     154             :   }
     155           0 :   *ret = spent;
     156           0 :   return GNUNET_OK;
     157             : }

Generated by: LCOV version 1.14