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-01-12 22:36:41 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 "taler/platform.h"
      25              : #include <pthread.h>
      26              : #include "taler/taler_fakebank_lib.h"
      27              : #include "taler/taler_bank_service.h"
      28              : #include "taler/taler_mhd_lib.h"
      29              : #include <gnunet/gnunet_mhd_compat.h>
      30              : #include "fakebank.h"
      31              : #include "fakebank_common_make_admin_transfer.h"
      32              : #include "fakebank_common_lookup.h"
      33              : #include "fakebank_common_lp.h"
      34              : #include "fakebank_common_transact.h"
      35              : 
      36              : 
      37              : enum GNUNET_GenericReturnValue
      38           61 : TALER_FAKEBANK_make_admin_transfer_ (
      39              :   struct TALER_FAKEBANK_Handle *h,
      40              :   const char *debit_account,
      41              :   const char *credit_account,
      42              :   const struct TALER_Amount *amount,
      43              :   const struct TALER_ReservePublicKeyP *reserve_pub,
      44              :   uint64_t *row_id,
      45              :   struct GNUNET_TIME_Timestamp *timestamp)
      46              : {
      47              :   struct Transaction *t;
      48              :   const struct GNUNET_PeerIdentity *pid;
      49              :   struct Account *debit_acc;
      50              :   struct Account *credit_acc;
      51              : 
      52              :   GNUNET_static_assert (sizeof (*pid) ==
      53              :                         sizeof (*reserve_pub));
      54           61 :   pid = (const struct GNUNET_PeerIdentity *) reserve_pub;
      55           61 :   GNUNET_assert (NULL != debit_account);
      56           61 :   GNUNET_assert (NULL != credit_account);
      57           61 :   GNUNET_assert (0 == strcasecmp (amount->currency,
      58              :                                   h->currency));
      59           61 :   GNUNET_break (0 != strncasecmp ("payto://",
      60              :                                   debit_account,
      61              :                                   strlen ("payto://")));
      62           61 :   GNUNET_break (0 != strncasecmp ("payto://",
      63              :                                   credit_account,
      64              :                                   strlen ("payto://")));
      65           61 :   debit_acc = TALER_FAKEBANK_lookup_account_ (h,
      66              :                                               debit_account,
      67              :                                               debit_account);
      68           61 :   credit_acc = TALER_FAKEBANK_lookup_account_ (h,
      69              :                                                credit_account,
      70              :                                                credit_account);
      71           61 :   GNUNET_assert (0 ==
      72              :                  pthread_mutex_lock (&h->rpubs_lock));
      73           61 :   t = GNUNET_CONTAINER_multipeermap_get (h->rpubs,
      74              :                                          pid);
      75           61 :   GNUNET_assert (0 ==
      76              :                  pthread_mutex_unlock (&h->rpubs_lock));
      77           61 :   if (NULL != t)
      78              :   {
      79              :     /* duplicate reserve public key not allowed */
      80            2 :     GNUNET_break_op (0);
      81            2 :     return GNUNET_NO;
      82              :   }
      83              : 
      84           59 :   t = GNUNET_new (struct Transaction);
      85           59 :   t->unchecked = true;
      86           59 :   t->debit_account = debit_acc;
      87           59 :   t->credit_account = credit_acc;
      88           59 :   t->amount = *amount;
      89           59 :   t->date = GNUNET_TIME_timestamp_get ();
      90           59 :   if (NULL != timestamp)
      91           59 :     *timestamp = t->date;
      92           59 :   t->type = T_CREDIT;
      93           59 :   t->subject.credit.reserve_pub = *reserve_pub;
      94           59 :   GNUNET_assert (0 ==
      95              :                  pthread_mutex_lock (&h->rpubs_lock));
      96           59 :   if (GNUNET_OK !=
      97           59 :       GNUNET_CONTAINER_multipeermap_put (
      98              :         h->rpubs,
      99              :         pid,
     100              :         t,
     101              :         GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
     102              :   {
     103              :     /* duplicate reserve public key not allowed */
     104            0 :     GNUNET_break_op (0);
     105            0 :     GNUNET_free (t);
     106            0 :     GNUNET_assert (0 ==
     107              :                    pthread_mutex_unlock (&h->rpubs_lock));
     108            0 :     return GNUNET_NO;
     109              :   }
     110           59 :   GNUNET_assert (0 ==
     111              :                  pthread_mutex_unlock (&h->rpubs_lock));
     112           59 :   TALER_FAKEBANK_transact_ (h,
     113              :                             t);
     114           59 :   if (NULL != row_id)
     115           59 :     *row_id = t->row_id;
     116           59 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     117              :               "Making transfer from %s to %s over %s and subject %s at row %llu\n",
     118              :               debit_account,
     119              :               credit_account,
     120              :               TALER_amount2s (amount),
     121              :               TALER_B2S (reserve_pub),
     122              :               (unsigned long long) t->row_id);
     123           59 :   TALER_FAKEBANK_notify_transaction_ (h,
     124              :                                       t);
     125           59 :   return GNUNET_OK;
     126              : }
     127              : 
     128              : 
     129              : enum GNUNET_GenericReturnValue
     130           16 : TALER_FAKEBANK_make_kycauth_transfer_ (
     131              :   struct TALER_FAKEBANK_Handle *h,
     132              :   const char *debit_account,
     133              :   const char *credit_account,
     134              :   const struct TALER_Amount *amount,
     135              :   const union TALER_AccountPublicKeyP *account_pub,
     136              :   uint64_t *row_id,
     137              :   struct GNUNET_TIME_Timestamp *timestamp)
     138              : {
     139              :   struct Transaction *t;
     140              :   const struct GNUNET_PeerIdentity *pid;
     141              :   struct Account *debit_acc;
     142              :   struct Account *credit_acc;
     143              : 
     144              :   GNUNET_static_assert (sizeof (*pid) ==
     145              :                         sizeof (*account_pub));
     146           16 :   pid = (const struct GNUNET_PeerIdentity *) account_pub;
     147           16 :   GNUNET_assert (NULL != debit_account);
     148           16 :   GNUNET_assert (NULL != credit_account);
     149           16 :   GNUNET_assert (0 == strcasecmp (amount->currency,
     150              :                                   h->currency));
     151           16 :   GNUNET_break (0 != strncasecmp ("payto://",
     152              :                                   debit_account,
     153              :                                   strlen ("payto://")));
     154           16 :   GNUNET_break (0 != strncasecmp ("payto://",
     155              :                                   credit_account,
     156              :                                   strlen ("payto://")));
     157           16 :   debit_acc = TALER_FAKEBANK_lookup_account_ (h,
     158              :                                               debit_account,
     159              :                                               debit_account);
     160           16 :   credit_acc = TALER_FAKEBANK_lookup_account_ (h,
     161              :                                                credit_account,
     162              :                                                credit_account);
     163           16 :   t = GNUNET_new (struct Transaction);
     164           16 :   t->unchecked = true;
     165           16 :   t->debit_account = debit_acc;
     166           16 :   t->credit_account = credit_acc;
     167           16 :   t->amount = *amount;
     168           16 :   t->date = GNUNET_TIME_timestamp_get ();
     169           16 :   if (NULL != timestamp)
     170           16 :     *timestamp = t->date;
     171           16 :   t->type = T_AUTH;
     172           16 :   t->subject.auth.account_pub = *account_pub;
     173           16 :   TALER_FAKEBANK_transact_ (h,
     174              :                             t);
     175           16 :   if (NULL != row_id)
     176           16 :     *row_id = t->row_id;
     177           16 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     178              :               "Making transfer from %s to %s over %s and subject %s at row %llu\n",
     179              :               debit_account,
     180              :               credit_account,
     181              :               TALER_amount2s (amount),
     182              :               TALER_B2S (account_pub),
     183              :               (unsigned long long) t->row_id);
     184           16 :   TALER_FAKEBANK_notify_transaction_ (h,
     185              :                                       t);
     186           16 :   return GNUNET_OK;
     187              : }
        

Generated by: LCOV version 2.0-1