exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

fakebank_common_make_admin_transfer.c (6640B)


      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 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   pid = (const struct GNUNET_PeerIdentity *) reserve_pub;
     54   GNUNET_assert (NULL != debit_account);
     55   GNUNET_assert (NULL != credit_account);
     56   GNUNET_assert (0 == strcasecmp (amount->currency,
     57                                   h->currency));
     58   GNUNET_break (0 != strncasecmp ("payto://",
     59                                   debit_account,
     60                                   strlen ("payto://")));
     61   GNUNET_break (0 != strncasecmp ("payto://",
     62                                   credit_account,
     63                                   strlen ("payto://")));
     64   debit_acc = TALER_FAKEBANK_lookup_account_ (h,
     65                                               debit_account,
     66                                               debit_account);
     67   credit_acc = TALER_FAKEBANK_lookup_account_ (h,
     68                                                credit_account,
     69                                                credit_account);
     70   GNUNET_assert (0 ==
     71                  pthread_mutex_lock (&h->rpubs_lock));
     72   t = GNUNET_CONTAINER_multipeermap_get (h->rpubs,
     73                                          pid);
     74   GNUNET_assert (0 ==
     75                  pthread_mutex_unlock (&h->rpubs_lock));
     76   if (NULL != t)
     77   {
     78     /* duplicate reserve public key not allowed */
     79     GNUNET_break_op (0);
     80     return GNUNET_NO;
     81   }
     82 
     83   t = GNUNET_new (struct Transaction);
     84   t->unchecked = true;
     85   t->debit_account = debit_acc;
     86   t->credit_account = credit_acc;
     87   t->amount = *amount;
     88   t->date = GNUNET_TIME_timestamp_get ();
     89   if (NULL != timestamp)
     90     *timestamp = t->date;
     91   t->type = T_CREDIT;
     92   t->subject.credit.reserve_pub = *reserve_pub;
     93   GNUNET_assert (0 ==
     94                  pthread_mutex_lock (&h->rpubs_lock));
     95   if (GNUNET_OK !=
     96       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     GNUNET_break_op (0);
    104     GNUNET_free (t);
    105     GNUNET_assert (0 ==
    106                    pthread_mutex_unlock (&h->rpubs_lock));
    107     return GNUNET_NO;
    108   }
    109   GNUNET_assert (0 ==
    110                  pthread_mutex_unlock (&h->rpubs_lock));
    111   TALER_FAKEBANK_transact_ (h,
    112                             t);
    113   if (NULL != row_id)
    114     *row_id = t->row_id;
    115   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   TALER_FAKEBANK_notify_transaction_ (h,
    123                                       t);
    124   return GNUNET_OK;
    125 }
    126 
    127 
    128 enum GNUNET_GenericReturnValue
    129 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   pid = (const struct GNUNET_PeerIdentity *) account_pub;
    146   GNUNET_assert (NULL != debit_account);
    147   GNUNET_assert (NULL != credit_account);
    148   GNUNET_assert (0 == strcasecmp (amount->currency,
    149                                   h->currency));
    150   GNUNET_break (0 != strncasecmp ("payto://",
    151                                   debit_account,
    152                                   strlen ("payto://")));
    153   GNUNET_break (0 != strncasecmp ("payto://",
    154                                   credit_account,
    155                                   strlen ("payto://")));
    156   debit_acc = TALER_FAKEBANK_lookup_account_ (h,
    157                                               debit_account,
    158                                               debit_account);
    159   credit_acc = TALER_FAKEBANK_lookup_account_ (h,
    160                                                credit_account,
    161                                                credit_account);
    162   t = GNUNET_new (struct Transaction);
    163   t->unchecked = true;
    164   t->debit_account = debit_acc;
    165   t->credit_account = credit_acc;
    166   t->amount = *amount;
    167   t->date = GNUNET_TIME_timestamp_get ();
    168   if (NULL != timestamp)
    169     *timestamp = t->date;
    170   t->type = T_AUTH;
    171   t->subject.auth.account_pub = *account_pub;
    172   TALER_FAKEBANK_transact_ (h,
    173                             t);
    174   if (NULL != row_id)
    175     *row_id = t->row_id;
    176   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   TALER_FAKEBANK_notify_transaction_ (h,
    184                                       t);
    185   return GNUNET_OK;
    186 }