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 (6668B)


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