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_wire_fees.c (4790B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2020 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_wire_fees.c
     22  * @brief run the taler-exchange-offline command to download, sign and upload wire 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_Process *offlinesign_proc;
     43 
     44   /**
     45    * Configuration file used by the command.
     46    */
     47   const char *config_filename;
     48 
     49   /**
     50    * The wire fee to sign.
     51    */
     52   const char *wire_fee_s;
     53 
     54   /**
     55    * The closing fee to sign.
     56    */
     57   const char *closing_fee_s;
     58 
     59 };
     60 
     61 
     62 /**
     63  * Run the command; calls the `taler-exchange-offline` program.
     64  *
     65  * @param cls closure.
     66  * @param cmd the commaind being run.
     67  * @param is interpreter state.
     68  */
     69 static void
     70 offlinesign_run (void *cls,
     71                  const struct TALER_TESTING_Command *cmd,
     72                  struct TALER_TESTING_Interpreter *is)
     73 {
     74   struct OfflineSignState *ks = cls;
     75 
     76   ks->offlinesign_proc = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ERR);
     77   if (GNUNET_OK !=
     78       GNUNET_process_run_command_va (
     79         ks->offlinesign_proc,
     80         "taler-exchange-offline",
     81         "taler-exchange-offline",
     82         "-c", ks->config_filename,
     83         "-L", "INFO",
     84         "wire-fee",
     85         "now",
     86         "x-taler-bank",
     87         ks->wire_fee_s,
     88         ks->closing_fee_s,
     89         "upload",
     90         NULL))
     91   {
     92     GNUNET_break (0);
     93     GNUNET_process_destroy (ks->offlinesign_proc);
     94     ks->offlinesign_proc = NULL;
     95     TALER_TESTING_interpreter_fail (is);
     96     return;
     97   }
     98   TALER_TESTING_wait_for_sigchld (is);
     99 }
    100 
    101 
    102 /**
    103  * Free the state of a "offlinesign" CMD, and possibly kills its
    104  * process if it did not terminate correctly.
    105  *
    106  * @param cls closure.
    107  * @param cmd the command being freed.
    108  */
    109 static void
    110 offlinesign_cleanup (void *cls,
    111                      const struct TALER_TESTING_Command *cmd)
    112 {
    113   struct OfflineSignState *ks = cls;
    114 
    115   (void) cmd;
    116   if (NULL != ks->offlinesign_proc)
    117   {
    118     GNUNET_break (GNUNET_OK ==
    119                   GNUNET_process_kill (ks->offlinesign_proc,
    120                                        SIGKILL));
    121     GNUNET_process_wait (ks->offlinesign_proc,
    122                          true,
    123                          NULL,
    124                          NULL);
    125     GNUNET_process_destroy (ks->offlinesign_proc);
    126     ks->offlinesign_proc = NULL;
    127   }
    128   GNUNET_free (ks);
    129 }
    130 
    131 
    132 /**
    133  * Offer "offlinesign" CMD internal data to other commands.
    134  *
    135  * @param cls closure.
    136  * @param[out] ret result
    137  * @param trait name of the trait.
    138  * @param index index number of the object to offer.
    139  * @return #GNUNET_OK on success.
    140  */
    141 static enum GNUNET_GenericReturnValue
    142 offlinesign_traits (void *cls,
    143                     const void **ret,
    144                     const char *trait,
    145                     unsigned int index)
    146 {
    147   struct OfflineSignState *ks = cls;
    148   struct TALER_TESTING_Trait traits[] = {
    149     TALER_TESTING_make_trait_process (&ks->offlinesign_proc),
    150     TALER_TESTING_trait_end ()
    151   };
    152 
    153   return TALER_TESTING_get_trait (traits,
    154                                   ret,
    155                                   trait,
    156                                   index);
    157 }
    158 
    159 
    160 struct TALER_TESTING_Command
    161 TALER_TESTING_cmd_exec_offline_sign_fees (const char *label,
    162                                           const char *config_filename,
    163                                           const char *wire_fee,
    164                                           const char *closing_fee)
    165 {
    166   struct OfflineSignState *ks;
    167 
    168   ks = GNUNET_new (struct OfflineSignState);
    169   ks->config_filename = config_filename;
    170   ks->wire_fee_s = wire_fee;
    171   ks->closing_fee_s = closing_fee;
    172   {
    173     struct TALER_TESTING_Command cmd = {
    174       .cls = ks,
    175       .label = label,
    176       .run = &offlinesign_run,
    177       .cleanup = &offlinesign_cleanup,
    178       .traits = &offlinesign_traits
    179     };
    180 
    181     return cmd;
    182   }
    183 }
    184 
    185 
    186 /* end of testing_api_cmd_exec_offline_sign_fees.c */