Electroneum
gen_multisig.cpp File Reference

Generates a set of multisig wallets. More...

#include <iostream>
#include <sstream>
#include <boost/program_options.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/format.hpp>
#include "include_base_utils.h"
#include "crypto/crypto.h"
#include "common/i18n.h"
#include "common/command_line.h"
#include "common/util.h"
#include "common/scoped_message_writer.h"
#include "wallet/wallet_args.h"
#include "wallet/wallet2.h"
Include dependency graph for gen_multisig.cpp:

Go to the source code of this file.

Namespaces

 genms
 

Macros

#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "wallet.gen_multisig"
 

Functions

const char * genms::tr (const char *str)
 
int main (int argc, char *argv[])
 

Detailed Description

Generates a set of multisig wallets.

Definition in file gen_multisig.cpp.

Macro Definition Documentation

◆ ELECTRONEUM_DEFAULT_LOG_CATEGORY

#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "wallet.gen_multisig"

Definition at line 57 of file gen_multisig.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 164 of file gen_multisig.cpp.

165 {
166  TRY_ENTRY();
167 
168  po::options_description desc_params(wallet_args::tr("Wallet options"));
169  command_line::add_arg(desc_params, arg_filename_base);
170  command_line::add_arg(desc_params, arg_scheme);
171  command_line::add_arg(desc_params, arg_threshold);
172  command_line::add_arg(desc_params, arg_participants);
173  command_line::add_arg(desc_params, arg_testnet);
174  command_line::add_arg(desc_params, arg_stagenet);
175  command_line::add_arg(desc_params, arg_create_address_file);
176 
177  boost::optional<po::variables_map> vm;
178  bool should_terminate = false;
179  std::tie(vm, should_terminate) = wallet_args::main(
180  argc, argv,
181  "electroneum-gen-multisig [(--testnet|--stagenet)] [--filename-base=<filename>] [--scheme=M/N] [--threshold=M] [--participants=N]",
182  genms::tr("This program generates a set of multisig wallets - use this simpler scheme only if all the participants trust each other"),
183  desc_params,
184  boost::program_options::positional_options_description(),
185  [](const std::string &s, bool emphasis){ tools::scoped_message_writer(emphasis ? epee::console_color_white : epee::console_color_default, true) << s; },
186  "electroneum-gen-multisig.log"
187  );
188  if (!vm)
189  return 1;
190  if (should_terminate)
191  return 0;
192 
193  bool testnet, stagenet;
194  uint32_t threshold = 0, total = 0;
195  std::string basename;
196 
197  testnet = command_line::get_arg(*vm, arg_testnet);
198  stagenet = command_line::get_arg(*vm, arg_stagenet);
199  if (testnet && stagenet)
200  {
201  tools::fail_msg_writer() << genms::tr("Error: Can't specify more than one of --testnet and --stagenet");
202  return 1;
203  }
204  if (command_line::has_arg(*vm, arg_scheme))
205  {
206  if (sscanf(command_line::get_arg(*vm, arg_scheme).c_str(), "%u/%u", &threshold, &total) != 2)
207  {
208  tools::fail_msg_writer() << genms::tr("Error: expected N/M, but got: ") << command_line::get_arg(*vm, arg_scheme);
209  return 1;
210  }
211  }
212  if (!(*vm)["threshold"].defaulted())
213  {
214  if (threshold)
215  {
216  tools::fail_msg_writer() << genms::tr("Error: either --scheme or both of --threshold and --participants may be given");
217  return 1;
218  }
219  threshold = command_line::get_arg(*vm, arg_threshold);
220  }
221  if (!(*vm)["participants"].defaulted())
222  {
223  if (total)
224  {
225  tools::fail_msg_writer() << genms::tr("Error: either --scheme or both of --threshold and --participants may be given");
226  return 1;
227  }
228  total = command_line::get_arg(*vm, arg_participants);
229  }
230  if (threshold <= 1 || threshold > total)
231  {
232  tools::fail_msg_writer() << (boost::format(genms::tr("Error: expected N > 1 and N <= M, but got N==%u and M==%d")) % threshold % total).str();
233  return 1;
234  }
235  if (!(*vm)["filename-base"].defaulted() && !command_line::get_arg(*vm, arg_filename_base).empty())
236  {
237  basename = command_line::get_arg(*vm, arg_filename_base);
238  }
239  else
240  {
241  tools::fail_msg_writer() << genms::tr("Error: --filename-base is required");
242  return 1;
243  }
244 
245  bool create_address_file = command_line::get_arg(*vm, arg_create_address_file);
246  if (!generate_multisig(threshold, total, basename, testnet ? TESTNET : stagenet ? STAGENET : MAINNET, create_address_file))
247  return 1;
248 
249  return 0;
250  CATCH_ENTRY_L0("main", 1);
251 }
const char * tr(const char *str)
::std::string string
Definition: gtest-port.h:1097
const char * tr(const char *str)
Definition: wallet_args.cpp:81
std::enable_if<!std::is_same< T, bool >::value, bool >::type has_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg)
Definition: command_line.h:258
#define TRY_ENTRY()
Definition: misc_log_ex.h:151
unsigned int uint32_t
Definition: stdint.h:126
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
Definition: command_line.h:188
std::pair< boost::optional< boost::program_options::variables_map >, bool > main(int argc, char **argv, const char *const usage, const char *const notice, boost::program_options::options_description desc_params, const boost::program_options::positional_options_description &positional_options, const std::function< void(const std::string &, bool)> &print, const char *default_log_name, bool log_to_console)
Definition: wallet_args.cpp:86
scoped_message_writer fail_msg_writer()
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
Definition: command_line.h:271
#define CATCH_ENTRY_L0(lacation, return_val)
Definition: misc_log_ex.h:165
uint8_t threshold
Definition: blockchain.cpp:92
Here is the call graph for this function: