exchange

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

testing_api_cmd_offline_sign_global_fees.c (5894B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2022 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it
      6   under the terms of the GNU General Public License as published
      7   by the Free Software Foundation; either version 3, or (at your
      8   option) any later version.
      9 
     10   TALER is distributed in the hope that it will be useful, but
     11   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 /**
     21  * @file testing/testing_api_cmd_offline_sign_global_fees.c
     22  * @brief run the taler-exchange-offline command to download, sign and upload global fees
     23  * @author Marcello Stanisci
     24  * @author Christian Grothoff
     25  */
     26 #include "taler/platform.h"
     27 #include "taler/taler_json_lib.h"
     28 #include <gnunet/gnunet_curl_lib.h>
     29 #include "taler/taler_signatures.h"
     30 #include "taler/taler_testing_lib.h"
     31 
     32 
     33 /**
     34  * State for a "offlinesign" CMD.
     35  */
     36 struct OfflineSignState
     37 {
     38 
     39   /**
     40    * Process for the "offlinesign" command.
     41    */
     42   struct GNUNET_OS_Process *offlinesign_proc;
     43 
     44   /**
     45    * Configuration file used by the command.
     46    */
     47   const char *config_filename;
     48 
     49   /**
     50    * The history fee to sign.
     51    */
     52   const char *history_fee_s;
     53 
     54   /**
     55    * The account fee to sign.
     56    */
     57   const char *account_fee_s;
     58 
     59   /**
     60    * The purse fee to sign.
     61    */
     62   const char *purse_fee_s;
     63 
     64   /**
     65    * When MUST purses time out?
     66    */
     67   struct GNUNET_TIME_Relative purse_timeout;
     68 
     69   /**
     70    * How long do we keep the history?
     71    */
     72   struct GNUNET_TIME_Relative history_expiration;
     73 
     74   /**
     75    * Number of (free) purses per account.
     76    */
     77   unsigned int num_purses;
     78 };
     79 
     80 
     81 /**
     82  * Run the command; calls the `taler-exchange-offline' program.
     83  *
     84  * @param cls closure.
     85  * @param cmd the commaind being run.
     86  * @param is interpreter state.
     87  */
     88 static void
     89 offlinesign_run (void *cls,
     90                  const struct TALER_TESTING_Command *cmd,
     91                  struct TALER_TESTING_Interpreter *is)
     92 {
     93   struct OfflineSignState *ks = cls;
     94   char num_purses[12];
     95   char history_expiration[32];
     96   char purse_timeout[32];
     97 
     98   GNUNET_snprintf (num_purses,
     99                    sizeof (num_purses),
    100                    "%u",
    101                    ks->num_purses);
    102   GNUNET_snprintf (history_expiration,
    103                    sizeof (history_expiration),
    104                    "%s",
    105                    GNUNET_TIME_relative2s (ks->history_expiration,
    106                                            false));
    107   GNUNET_snprintf (purse_timeout,
    108                    sizeof (purse_timeout),
    109                    "%s",
    110                    GNUNET_TIME_relative2s (ks->purse_timeout,
    111                                            false));
    112   ks->offlinesign_proc
    113     = GNUNET_OS_start_process (
    114         GNUNET_OS_INHERIT_STD_ALL,
    115         NULL, NULL, NULL,
    116         "taler-exchange-offline",
    117         "taler-exchange-offline",
    118         "-c", ks->config_filename,
    119         "-L", "INFO",
    120         "global-fee",
    121         "now",
    122         ks->history_fee_s,
    123         ks->account_fee_s,
    124         ks->purse_fee_s,
    125         purse_timeout,
    126         history_expiration,
    127         num_purses,
    128         "upload",
    129         NULL);
    130   if (NULL == ks->offlinesign_proc)
    131   {
    132     GNUNET_break (0);
    133     TALER_TESTING_interpreter_fail (is);
    134     return;
    135   }
    136   TALER_TESTING_wait_for_sigchld (is);
    137 }
    138 
    139 
    140 /**
    141  * Free the state of a "offlinesign" CMD, and possibly kills its
    142  * process if it did not terminate correctly.
    143  *
    144  * @param cls closure.
    145  * @param cmd the command being freed.
    146  */
    147 static void
    148 offlinesign_cleanup (void *cls,
    149                      const struct TALER_TESTING_Command *cmd)
    150 {
    151   struct OfflineSignState *ks = cls;
    152 
    153   (void) cmd;
    154   if (NULL != ks->offlinesign_proc)
    155   {
    156     GNUNET_break (0 ==
    157                   GNUNET_OS_process_kill (ks->offlinesign_proc,
    158                                           SIGKILL));
    159     GNUNET_OS_process_wait (ks->offlinesign_proc);
    160     GNUNET_OS_process_destroy (ks->offlinesign_proc);
    161     ks->offlinesign_proc = NULL;
    162   }
    163   GNUNET_free (ks);
    164 }
    165 
    166 
    167 /**
    168  * Offer "offlinesign" CMD internal data to other commands.
    169  *
    170  * @param cls closure.
    171  * @param[out] ret result
    172  * @param trait name of the trait.
    173  * @param index index number of the object to offer.
    174  * @return #GNUNET_OK on success.
    175  */
    176 static enum GNUNET_GenericReturnValue
    177 offlinesign_traits (void *cls,
    178                     const void **ret,
    179                     const char *trait,
    180                     unsigned int index)
    181 {
    182   struct OfflineSignState *ks = cls;
    183   struct TALER_TESTING_Trait traits[] = {
    184     TALER_TESTING_make_trait_process (&ks->offlinesign_proc),
    185     TALER_TESTING_trait_end ()
    186   };
    187 
    188   return TALER_TESTING_get_trait (traits,
    189                                   ret,
    190                                   trait,
    191                                   index);
    192 }
    193 
    194 
    195 struct TALER_TESTING_Command
    196 TALER_TESTING_cmd_exec_offline_sign_global_fees (
    197   const char *label,
    198   const char *config_filename,
    199   const char *history_fee,
    200   const char *account_fee,
    201   const char *purse_fee,
    202   struct GNUNET_TIME_Relative purse_timeout,
    203   struct GNUNET_TIME_Relative history_expiration,
    204   unsigned int num_purses)
    205 {
    206   struct OfflineSignState *ks;
    207 
    208   ks = GNUNET_new (struct OfflineSignState);
    209   ks->config_filename = config_filename;
    210   ks->history_fee_s = history_fee;
    211   ks->account_fee_s = account_fee;
    212   ks->purse_fee_s = purse_fee;
    213   ks->purse_timeout = purse_timeout;
    214   ks->history_expiration = history_expiration;
    215   ks->num_purses = num_purses;
    216   {
    217     struct TALER_TESTING_Command cmd = {
    218       .cls = ks,
    219       .label = label,
    220       .run = &offlinesign_run,
    221       .cleanup = &offlinesign_cleanup,
    222       .traits = &offlinesign_traits
    223     };
    224 
    225     return cmd;
    226   }
    227 }
    228 
    229 
    230 /* end of testing_api_cmd_exec_offline_sign_global_fees.c */