Electroneum
Loading...
Searching...
No Matches
wallet_args Namespace Reference

Functions

command_line::arg_descriptor< std::string > arg_generate_from_json ()
command_line::arg_descriptor< std::string > arg_wallet_file ()
const char * tr (const char *str)
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)

Function Documentation

◆ arg_generate_from_json()

command_line::arg_descriptor< std::string > wallet_args::arg_generate_from_json ( )

Definition at line 72 of file wallet_args.cpp.

73 {
74 return {"generate-from-json", wallet_args::tr("Generate wallet from JSON format file"), ""};
75 }
const char * tr(const char *str)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ arg_wallet_file()

command_line::arg_descriptor< std::string > wallet_args::arg_wallet_file ( )

Definition at line 76 of file wallet_args.cpp.

77 {
78 return {"wallet-file", wallet_args::tr("Use wallet <arg>"), ""};
79 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

std::pair< boost::optional< boost::program_options::variables_map >, bool > wallet_args::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 = false )

Processes command line arguments (argc and argv) using desc_params and positional_options, while adding parameters for log files and concurrency. Log file and concurrency arguments are handled, along with basic global init for the wallet process.

Returns
pair.first: The list of parsed options, iff there are no errors. pair.second: Should the execution terminate succesfully without actually launching the application

Definition at line 86 of file wallet_args.cpp.

96 {
97 namespace bf = boost::filesystem;
98 namespace po = boost::program_options;
99#ifdef WIN32
100 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
101#endif
102
103 const command_line::arg_descriptor<std::string> arg_log_level = {"log-level", "0-4 or categories", ""};
104 const command_line::arg_descriptor<std::size_t> arg_max_log_file_size = {"max-log-file-size", "Specify maximum log file size [B]", MAX_LOG_FILE_SIZE};
105 const command_line::arg_descriptor<std::size_t> arg_max_log_files = {"max-log-files", "Specify maximum number of rotated log files to be saved (no limit by setting to 0)", MAX_LOG_FILES};
106 const command_line::arg_descriptor<uint32_t> arg_max_concurrency = {"max-concurrency", wallet_args::tr("Max number of threads to use for a parallel job"), DEFAULT_MAX_CONCURRENCY};
107 const command_line::arg_descriptor<std::string> arg_log_file = {"log-file", wallet_args::tr("Specify log file"), ""};
108 const command_line::arg_descriptor<std::string> arg_config_file = {"config-file", wallet_args::tr("Config file"), "", true};
109
110
111 std::string lang = i18n_get_language();
113#ifdef NDEBUG
115#endif
117
119
120 po::options_description desc_general(wallet_args::tr("General options"));
123
124 command_line::add_arg(desc_params, arg_log_file);
125 command_line::add_arg(desc_params, arg_log_level);
126 command_line::add_arg(desc_params, arg_max_log_file_size);
127 command_line::add_arg(desc_params, arg_max_log_files);
128 command_line::add_arg(desc_params, arg_max_concurrency);
129 command_line::add_arg(desc_params, arg_config_file);
130
131 i18n_set_language("translations", "electroneum", lang);
132
133 po::options_description desc_all;
134 desc_all.add(desc_general).add(desc_params);
135 po::variables_map vm;
136 bool should_terminate = false;
137 bool r = command_line::handle_error_helper(desc_all, [&]()
138 {
139 auto parser = po::command_line_parser(argc, argv).options(desc_all).positional(positional_options);
140 po::store(parser.run(), vm);
141
143 {
144 Print(print) << "Electroneum '" << ELECTRONEUM_RELEASE_NAME << "' (v" << ELECTRONEUM_VERSION_FULL << ")" << ENDL;
145 Print(print) << wallet_args::tr("This is the command line electroneum wallet. It needs to connect to a electroneum\n"
146 "daemon to work correctly.") << ENDL;
147 Print(print) << wallet_args::tr("Usage:") << ENDL << " " << usage;
148 Print(print) << desc_all;
149 should_terminate = true;
150 return true;
151 }
153 {
154 Print(print) << "Electroneum '" << ELECTRONEUM_RELEASE_NAME << "' (v" << ELECTRONEUM_VERSION_FULL << ")";
155 should_terminate = true;
156 return true;
157 }
158
159 if(command_line::has_arg(vm, arg_config_file))
160 {
161 std::string config = command_line::get_arg(vm, arg_config_file);
162 bf::path config_path(config);
163 boost::system::error_code ec;
164 if (bf::exists(config_path, ec))
165 {
166 po::store(po::parse_config_file<char>(config_path.string<std::string>().c_str(), desc_params), vm);
167 }
168 else
169 {
170 MERROR(wallet_args::tr("Can't find config file ") << config);
171 return false;
172 }
173 }
174
175 po::notify(vm);
176 return true;
177 });
178 if (!r)
179 return {boost::none, true};
180
181 if (should_terminate)
182 return {std::move(vm), should_terminate};
183
184 std::string log_path;
185 if (!command_line::is_arg_defaulted(vm, arg_log_file))
186 log_path = command_line::get_arg(vm, arg_log_file);
187 else
188 log_path = mlog_get_default_log_path(default_log_name);
189 mlog_configure(log_path, log_to_console, command_line::get_arg(vm, arg_max_log_file_size), command_line::get_arg(vm, arg_max_log_files));
190 if (!command_line::is_arg_defaulted(vm, arg_log_level))
191 {
192 mlog_set_log(command_line::get_arg(vm, arg_log_level).c_str());
193 }
194 else if (!log_to_console)
195 {
197 }
198
200 {
201 Print(print) << "Electroneum '" << ELECTRONEUM_RELEASE_NAME << "' (v" << ELECTRONEUM_VERSION_FULL << ")" << ENDL;
202 Print(print) << wallet_args::tr("This is the command line electroneum wallet. It needs to connect to a electroneum\n"
203 "daemon to work correctly.") << ENDL;
204 Print(print) << wallet_args::tr("Usage:") << ENDL << " " << usage;
205 Print(print) << desc_all;
206 return {boost::none, true};
207 }
209 {
210 Print(print) << "Electroneum '" << ELECTRONEUM_RELEASE_NAME << "' (v" << ELECTRONEUM_VERSION_FULL << ")";
211 return {boost::none, true};
212 }
213
214 if (notice)
215 Print(print) << notice << ENDL;
216
217 if (!command_line::is_arg_defaulted(vm, arg_max_concurrency))
218 tools::set_max_concurrency(command_line::get_arg(vm, arg_max_concurrency));
219
220 Print(print) << "Electroneum '" << ELECTRONEUM_RELEASE_NAME << "' (v" << ELECTRONEUM_VERSION_FULL << ")";
221
222 if (!command_line::is_arg_defaulted(vm, arg_log_level))
223 MINFO("Setting log level = " << command_line::get_arg(vm, arg_log_level));
224 else
225 MINFO("Setting log levels = " << getenv("ELECTRONEUM_LOGS"));
226 MINFO(wallet_args::tr("Logging to: ") << log_path);
227
228 Print(print) << boost::format(wallet_args::tr("Logging to %s")) % log_path;
229
230 const ssize_t lockable_memory = tools::get_lockable_memory();
231 if (lockable_memory >= 0 && lockable_memory < 256 * 4096) // 256 pages -> at least 256 secret keys and other such small/medium objects
232 Print(print) << tr("WARNING: You may not have a high enough lockable memory limit")
233#ifdef ELPP_OS_UNIX
234 << ", " << tr("see ulimit -l")
235#endif
236 ;
237
238 return {std::move(vm), should_terminate};
239 }
#define tr(x)
std::string i18n_get_language()
Definition i18n.cpp:54
int i18n_set_language(const char *directory, const char *base, std::string language)
Definition i18n.cpp:133
#define MERROR(x)
Definition misc_log_ex.h:73
void mlog_configure(const std::string &filename_base, bool console, const std::size_t max_log_file_size=MAX_LOG_FILE_SIZE, const std::size_t max_log_files=MAX_LOG_FILES)
Definition mlog.cpp:148
std::string mlog_get_default_log_path(const char *default_filename)
Definition mlog.cpp:72
void mlog_set_log(const char *log)
Definition mlog.cpp:288
#define MAX_LOG_FILES
Definition misc_log_ex.h:39
#define ENDL
#define MINFO(x)
Definition misc_log_ex.h:75
void mlog_set_categories(const char *categories)
Definition mlog.cpp:238
#define MAX_LOG_FILE_SIZE
Definition misc_log_ex.h:38
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
const arg_descriptor< bool > arg_help
const arg_descriptor< bool > arg_version
bool is_arg_defaulted(const boost::program_options::variables_map &vm, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg)
bool handle_error_helper(const boost::program_options::options_description &desc, F parser)
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)
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
const command_line::arg_descriptor< std::string, false, true, 2 > arg_log_file
const command_line::arg_descriptor< std::size_t > arg_max_log_files
const command_line::arg_descriptor< std::string, false, true, 2 > arg_config_file
const command_line::arg_descriptor< unsigned > arg_max_concurrency
bool set_module_name_and_folder(const std::string &path_to_process_)
bool disable_core_dumps()
Definition util.cpp:748
void set_max_concurrency(unsigned n)
Definition util.cpp:857
void set_strict_default_file_permissions(bool strict)
Definition util.cpp:803
ssize_t get_lockable_memory()
Definition util.cpp:763
bool on_startup()
Definition util.cpp:778
const char *const ELECTRONEUM_RELEASE_NAME
const char *const ELECTRONEUM_VERSION_FULL
#define DEFAULT_MAX_CONCURRENCY
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tr()

const char * wallet_args::tr ( const char * str)

Definition at line 81 of file wallet_args.cpp.

82 {
83 return i18n_translate(str, "wallet_args");
84 }
const char * i18n_translate(const char *s, const std::string &context)
Definition i18n.cpp:323
Here is the call graph for this function:
Here is the caller graph for this function: