LCOV - code coverage report
Current view: top level - bank-lib - fakebank_common_make_admin_transfer.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.8 % 64 60
Test Date: 2026-04-14 15:39:31 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   (C) 2016-2024 Taler Systems SA
       4              : 
       5              :   TALER is free software; you can redistribute it and/or
       6              :   modify it under the terms of the GNU General Public License
       7              :   as published by the Free Software Foundation; either version 3,
       8              :   or (at your option) any later version.
       9              : 
      10              :   TALER is distributed in the hope that it will be useful,
      11              :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      12              :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13              :   GNU General Public License for more details.
      14              : 
      15              :   You should have received a copy of the GNU General Public
      16              :   License along with TALER; see the file COPYING.  If not,
      17              :   see <http://www.gnu.org/licenses/>
      18              : */
      19              : /**
      20              :  * @file bank-lib/fakebank_common_make_admin_transfer.c
      21              :  * @brief routine to create transfers to the exchange
      22              :  * @author Christian Grothoff <christian@grothoff.org>
      23              :  */
      24              : #include <pthread.h>
      25              : #include "taler/taler_fakebank_lib.h"
      26              : #include "taler/taler_bank_service.h"
      27              : #include "taler/taler_mhd_lib.h"
      28              : #include <gnunet/gnunet_mhd_compat.h>
      29              : #include "fakebank.h"
      30              : #include "fakebank_common_make_admin_transfer.h"
      31              : #include "fakebank_common_lookup.h"
      32              : #include "fakebank_common_lp.h"
      33              : #include "fakebank_common_transact.h"
      34              : 
      35              : 
      36              : enum GNUNET_GenericReturnValue
      37           61 : TALER_FAKEBANK_make_admin_transfer_ (
      38              :   struct TALER_FAKEBANK_Handle *h,
      39              :   const char *debit_account,
      40              :   const char *credit_account,
      41              :   const struct TALER_Amount *amount,
      42              :   const struct TALER_ReservePublicKeyP *reserve_pub,
      43              :   uint64_t *row_id,
      44              :   struct GNUNET_TIME_Timestamp *timestamp)
      45              : {
      46              :   struct Transaction *t;
      47              :   const struct GNUNET_PeerIdentity *pid;
      48              :   struct Account *debit_acc;
      49              :   struct Account *credit_acc;
      50              : 
      51              :   GNUNET_static_assert (sizeof (*pid) ==
      52              :                         sizeof (*reserve_pub));
      53           61 :   pid = (const struct GNUNET_PeerIdentity *) reserve_pub;
      54           61 :   GNUNET_assert (NULL != debit_account);
      55           61 :   GNUNET_assert (NULL != credit_account);
      56           61 :   GNUNET_assert (0 == strcasecmp (amount->currency,
      57              :                                   h->currency));
      58           61 :   GNUNET_break (0 != strncasecmp ("payto://",
      59              :                                   debit_account,
      60              :                                   strlen ("payto://")));
      61           61 :   GNUNET_break (0 != strncasecmp ("payto://",
      62              :                                   credit_account,
      63              :                                   strlen ("payto://")));
      64           61 :   debit_acc = TALER_FAKEBANK_lookup_account_ (h,
      65              :                                               debit_account,
      66              :                                               debit_account);
      67           61 :   credit_acc = TALER_FAKEBANK_lookup_account_ (h,
      68              :                                                credit_account,
      69              :                                                credit_account);
      70           61 :   GNUNET_assert (0 ==
      71              :                  pthread_mutex_lock (&h->rpubs_lock));
      72           61 :   t = GNUNET_CONTAINER_multipeermap_get (h->rpubs,
      73              :                                          pid);
      74           61 :   GNUNET_assert (0 ==
      75              :                  pthread_mutex_unlock (&h->rpubs_lock));
      76           61 :   if (NULL != t)
      77              :   {
      78              :     /* duplicate reserve public key not allowed */
      79            2 :     GNUNET_break_op (0);
      80            2 :     return GNUNET_NO;
      81              :   }
      82              : 
      83           59 :   t = GNUNET_new (struct Transaction);
      84           59 :   t->unchecked = true;
      85           59 :   t->debit_account = debit_acc;
      86           59 :   t->credit_account = credit_acc;
      87           59 :   t->amount = *amount;
      88           59 :   t->date = GNUNET_TIME_timestamp_get ();
      89           59 :   if (NULL != timestamp)
      90           59 :     *timestamp = t->date;
      91           59 :   t->type = T_CREDIT;
      92           59 :   t->subject.credit.reserve_pub = *reserve_pub;
      93           59 :   GNUNET_assert (0 ==
      94              :                  pthread_mutex_lock (&h->rpubs_lock));
      95           59 :   if (GNUNET_OK !=
      96           59 :       GNUNET_CONTAINER_multipeermap_put (
      97              :         h->rpubs,
      98              :         pid,
      99              :         t,
     100              :         GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
     101              :   {
     102              :     /* duplicate reserve public key not allowed */
     103            0 :     GNUNET_break_op (0);
     104            0 :     GNUNET_free (t);
     105            0 :     GNUNET_assert (0 ==
     106              :                    pthread_mutex_unlock (&h->rpubs_lock));
     107            0 :     return GNUNET_NO;
     108              :   }
     109           59 :   GNUNET_assert (0 ==
     110              :                  pthread_mutex_unlock (&h->rpubs_lock));
     111           59 :   TALER_FAKEBANK_transact_ (h,
     112              :                             t);
     113           59 :   if (NULL != row_id)
     114           59 :     *row_id = t->row_id;
     115           59 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     116              :               "Making transfer from %s to %s over %s and subject %s at row %llu\n",
     117              :               debit_account,
     118              :               credit_account,
     119              :               TALER_amount2s (amount),
     120              :               TALER_B2S (reserve_pub),
     121              :               (unsigned long long) t->row_id);
     122           59 :   TALER_FAKEBANK_notify_transaction_ (h,
     123              :                                       t);
     124           59 :   return GNUNET_OK;
     125              : }
     126              : 
     127              : 
     128              : enum GNUNET_GenericReturnValue
     129           16 : TALER_FAKEBANK_make_kycauth_transfer_ (
     130              :   struct TALER_FAKEBANK_Handle *h,
     131              :   const char *debit_account,
     132              :   const char *credit_account,
     133              :   const struct TALER_Amount *amount,
     134              :   const union TALER_AccountPublicKeyP *account_pub,
     135              :   uint64_t *row_id,
     136              :   struct GNUNET_TIME_Timestamp *timestamp)
     137              : {
     138              :   struct Transaction *t;
     139              :   const struct GNUNET_PeerIdentity *pid;
     140              :   struct Account *debit_acc;
     141              :   struct Account *credit_acc;
     142              : 
     143              :   GNUNET_static_assert (sizeof (*pid) ==
     144              :                         sizeof (*account_pub));
     145           16 :   pid = (const struct GNUNET_PeerIdentity *) account_pub;
     146           16 :   GNUNET_assert (NULL != debit_account);
     147           16 :   GNUNET_assert (NULL != credit_account);
     148           16 :   GNUNET_assert (0 == strcasecmp (amount->currency,
     149              :                                   h->currency));
     150           16 :   GNUNET_break (0 != strncasecmp ("payto://",
     151              :                                   debit_account,
     152              :                                   strlen ("payto://")));
     153           16 :   GNUNET_break (0 != strncasecmp ("payto://",
     154              :                                   credit_account,
     155              :                                   strlen ("payto://")));
     156           16 :   debit_acc = TALER_FAKEBANK_lookup_account_ (h,
     157              :                                               debit_account,
     158              :                                               debit_account);
     159           16 :   credit_acc = TALER_FAKEBANK_lookup_account_ (h,
     160              :                                                credit_account,
     161              :                                                credit_account);
     162           16 :   t = GNUNET_new (struct Transaction);
     163           16 :   t->unchecked = true;
     164           16 :   t->debit_account = debit_acc;
     165           16 :   t->credit_account = credit_acc;
     166           16 :   t->amount = *amount;
     167           16 :   t->date = GNUNET_TIME_timestamp_get ();
     168           16 :   if (NULL != timestamp)
     169           16 :     *timestamp = t->date;
     170           16 :   t->type = T_AUTH;
     171           16 :   t->subject.auth.account_pub = *account_pub;
     172           16 :   TALER_FAKEBANK_transact_ (h,
     173              :                             t);
     174           16 :   if (NULL != row_id)
     175           16 :     *row_id = t->row_id;
     176           16 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     177              :               "Making transfer from %s to %s over %s and subject %s at row %llu\n",
     178              :               debit_account,
     179              :               credit_account,
     180              :               TALER_amount2s (amount),
     181              :               TALER_B2S (account_pub),
     182              :               (unsigned long long) t->row_id);
     183           16 :   TALER_FAKEBANK_notify_transaction_ (h,
     184              :                                       t);
     185           16 :   return GNUNET_OK;
     186              : }
        

Generated by: LCOV version 2.0-1