Electroneum
simplewallet.cpp File Reference

Source file that defines simple_wallet class. More...

#include <boost/bind.hpp>
#include <thread>
#include <iostream>
#include <sstream>
#include <fstream>
#include <ctype.h>
#include <boost/lexical_cast.hpp>
#include <boost/program_options.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/format.hpp>
#include <boost/regex.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include "include_base_utils.h"
#include "common/i18n.h"
#include "common/command_line.h"
#include "common/util.h"
#include "common/dns_utils.h"
#include "common/base58.h"
#include "common/scoped_message_writer.h"
#include "cryptonote_protocol/cryptonote_protocol_handler.h"
#include "simplewallet.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "storages/http_abstract_invoke.h"
#include "rpc/core_rpc_server_commands_defs.h"
#include "crypto/crypto.h"
#include "mnemonics/electrum-words.h"
#include "rapidjson/document.h"
#include "common/json_util.h"
#include "ringct/rctSigs.h"
#include "multisig/multisig.h"
#include "wallet/wallet_args.h"
#include "version.h"
#include <stdexcept>
#include "wallet/message_store.h"
Include dependency graph for simplewallet.cpp:

Go to the source code of this file.

Macros

#define BOOST_BIND_GLOBAL_PLACEHOLDERS   1
 
#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "wallet.simplewallet"
 
#define EXTENDED_LOGS_FILE   "wallet_details.log"
 
#define DEFAULT_MIX   0
 
#define MIN_RING_SIZE   1
 
#define OUTPUT_EXPORT_FILE_MAGIC   "Electroneum output export\003"
 
#define LOCK_IDLE_SCOPE()
 
#define SCOPED_WALLET_UNLOCK_ON_BAD_PASSWORD(code)
 
#define SCOPED_WALLET_UNLOCK()   SCOPED_WALLET_UNLOCK_ON_BAD_PASSWORD(return true;)
 
#define PRINT_USAGE(usage_help)   fail_msg_writer() << boost::format(tr("usage: %s")) % usage_help;
 
#define LONG_PAYMENT_ID_SUPPORT_CHECK()
 
#define CHECK_SIMPLE_VARIABLE(name, f, help)
 

Typedefs

typedef cryptonote::simple_wallet sw
 

Enumerations

enum  TransferType { Transfer , TransferLocked }
 

Functions

bool parse_priority (const std::string &arg, uint32_t &priority)
 
std::string join_priority_strings (const char *delimiter)
 
int main (int argc, char *argv[])
 

Detailed Description

Source file that defines simple_wallet class.

Definition in file simplewallet.cpp.

Macro Definition Documentation

◆ BOOST_BIND_GLOBAL_PLACEHOLDERS

#define BOOST_BIND_GLOBAL_PLACEHOLDERS   1

Definition at line 39 of file simplewallet.cpp.

◆ CHECK_SIMPLE_VARIABLE

#define CHECK_SIMPLE_VARIABLE (   name,
  f,
  help 
)
Value:
if (args[0] == name) { \
if (args.size() <= 1) \
{ \
fail_msg_writer() << "set " << #name << ": " << tr("needs an argument") << " (" << help << ")"; \
return true; \
} \
else \
{ \
f(args); \
return true; \
} \
} while(0)
else if(0==res)
#define tr(x)
Definition: common_defines.h:4
const char * name

◆ DEFAULT_MIX

#define DEFAULT_MIX   0

Definition at line 97 of file simplewallet.cpp.

◆ ELECTRONEUM_DEFAULT_LOG_CATEGORY

#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "wallet.simplewallet"

Definition at line 93 of file simplewallet.cpp.

◆ EXTENDED_LOGS_FILE

#define EXTENDED_LOGS_FILE   "wallet_details.log"

Definition at line 95 of file simplewallet.cpp.

◆ LOCK_IDLE_SCOPE

#define LOCK_IDLE_SCOPE ( )
Value:
bool auto_refresh_enabled = m_auto_refresh_enabled.load(std::memory_order_relaxed); \
m_auto_refresh_enabled.store(false, std::memory_order_relaxed); \
/* stop any background refresh, and take over */ \
m_wallet->stop(); \
boost::unique_lock<boost::mutex> lock(m_idle_mutex); \
m_idle_cond.notify_all(); \
m_auto_refresh_enabled.store(auto_refresh_enabled, std::memory_order_relaxed); \
})
boost::shared_ptr< call_befor_die_base > auto_scope_leave_caller
auto_scope_leave_caller create_scope_leave_handler(t_scope_leave_handler f)

Definition at line 102 of file simplewallet.cpp.

◆ LONG_PAYMENT_ID_SUPPORT_CHECK

#define LONG_PAYMENT_ID_SUPPORT_CHECK ( )
Value:
do { \
if (!m_long_payment_id_support) { \
fail_msg_writer() << tr("Warning: Long payment IDs are obsolete."); \
fail_msg_writer() << tr("Long payment IDs are not encrypted on the blockchain, and will harm your privacy."); \
fail_msg_writer() << tr("Use --long-payment-id-support-bad-for-privacy if you really must use one, and warn the recipient they are using an obsolete feature that will disappear in the future."); \
return true; \
} \
} while(0)

Definition at line 123 of file simplewallet.cpp.

◆ MIN_RING_SIZE

#define MIN_RING_SIZE   1

Definition at line 99 of file simplewallet.cpp.

◆ OUTPUT_EXPORT_FILE_MAGIC

#define OUTPUT_EXPORT_FILE_MAGIC   "Electroneum output export\003"

Definition at line 100 of file simplewallet.cpp.

◆ PRINT_USAGE

#define PRINT_USAGE (   usage_help)    fail_msg_writer() << boost::format(tr("usage: %s")) % usage_help;

Definition at line 121 of file simplewallet.cpp.

◆ SCOPED_WALLET_UNLOCK

#define SCOPED_WALLET_UNLOCK ( )    SCOPED_WALLET_UNLOCK_ON_BAD_PASSWORD(return true;)

Definition at line 119 of file simplewallet.cpp.

◆ SCOPED_WALLET_UNLOCK_ON_BAD_PASSWORD

#define SCOPED_WALLET_UNLOCK_ON_BAD_PASSWORD (   code)
Value:
boost::optional<tools::password_container> pwd_container = boost::none; \
if (m_wallet->ask_password() && !(pwd_container = get_and_verify_password())) { code; } \
tools::wallet_keys_unlocker unlocker(*m_wallet, pwd_container);
#define LOCK_IDLE_SCOPE()

Definition at line 113 of file simplewallet.cpp.

Typedef Documentation

◆ sw

Definition at line 90 of file simplewallet.cpp.

Enumeration Type Documentation

◆ TransferType

Enumerator
Transfer 
TransferLocked 

Definition at line 133 of file simplewallet.cpp.

133  {
134  Transfer,
136 };
@ Transfer
@ TransferLocked

Function Documentation

◆ join_priority_strings()

std::string join_priority_strings ( const char *  delimiter)

Definition at line 662 of file simplewallet.cpp.

663 {
664  std::string s;
665  for (size_t n = 0; n < allowed_priority_strings.size(); ++n)
666  {
667  if (!s.empty())
668  s += delimiter;
669  s += allowed_priority_strings[n];
670  }
671  return s;
672 }
::std::string string
Definition: gtest-port.h:1097

◆ main()

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

Definition at line 9564 of file simplewallet.cpp.

9565 {
9566  TRY_ENTRY();
9567 
9568 #ifdef WIN32
9569  // Activate UTF-8 support for Boost filesystem classes on Windows
9570  std::locale::global(boost::locale::generator().generate(""));
9571  boost::filesystem::path::imbue(std::locale());
9572 #endif
9573  // READ IN OPTIONS FROM COMMAND LINE
9574  po::options_description desc_params(wallet_args::tr("Wallet options"));
9575  tools::wallet2::init_options(desc_params);
9576  command_line::add_arg(desc_params, arg_wallet_file);
9577  command_line::add_arg(desc_params, arg_generate_new_wallet);
9578  command_line::add_arg(desc_params, arg_generate_from_device);
9579  command_line::add_arg(desc_params, arg_generate_from_view_key);
9580  command_line::add_arg(desc_params, arg_generate_from_spend_key);
9581  command_line::add_arg(desc_params, arg_generate_from_keys);
9582  command_line::add_arg(desc_params, arg_generate_from_multisig_keys);
9584  command_line::add_arg(desc_params, arg_mnemonic_language);
9585  command_line::add_arg(desc_params, arg_command);
9586 
9587  command_line::add_arg(desc_params, arg_restore_deterministic_wallet );
9588  command_line::add_arg(desc_params, arg_restore_multisig_wallet );
9589  command_line::add_arg(desc_params, arg_non_deterministic );
9590  command_line::add_arg(desc_params, arg_electrum_seed );
9591  command_line::add_arg(desc_params, arg_allow_mismatched_daemon_version);
9592  command_line::add_arg(desc_params, arg_restore_height);
9593  command_line::add_arg(desc_params, arg_restore_date);
9594  command_line::add_arg(desc_params, arg_do_not_relay);
9595  command_line::add_arg(desc_params, arg_create_address_file);
9596  command_line::add_arg(desc_params, arg_subaddress_lookahead);
9597  command_line::add_arg(desc_params, arg_use_english_language_names);
9598  command_line::add_arg(desc_params, arg_long_payment_id_support);
9599  command_line::add_arg(desc_params, arg_account_major_offset);
9602  po::positional_options_description positional_options;
9603  positional_options.add(arg_command.name, -1);
9604 
9605  boost::optional<po::variables_map> vm;
9606  bool should_terminate = false;
9607  std::tie(vm, should_terminate) = wallet_args::main(
9608  argc, argv,
9609  "electroneum-wallet-cli [--wallet-file=<filename>|--generate-new-wallet=<filename>] [<COMMAND>]",
9610  sw::tr("This is the command line electroneum wallet. It needs to connect to a electroneum\ndaemon to work correctly.\nWARNING: Do not reuse your Electroneum keys on another fork, UNLESS this fork has key reuse mitigations built in. Doing so will harm your privacy."),
9611  desc_params,
9612  positional_options,
9613  [](const std::string &s, bool emphasis){ tools::scoped_message_writer(emphasis ? epee::console_color_white : epee::console_color_default, true) << s; },
9614  "electroneum-wallet-cli.log"
9615  );
9616 
9617  if (!vm)
9618  {
9619  return 1;
9620  }
9621 
9622  if (should_terminate)
9623  {
9624  return 0;
9625  }
9626 
9627 
9628  // INITIALISE THE WALLET AND OPEN IT UP (.init)
9630  const bool r = w.init(*vm);
9631  CHECK_AND_ASSERT_MES(r, 1, sw::tr("Failed to initialize wallet"));
9632 
9633  std::vector<std::string> command = command_line::get_arg(*vm, arg_command);
9634  if (!command.empty())
9635  {
9636  if (!w.process_command(command))
9637  fail_msg_writer() << sw::tr("Unknown command: ") << command.front();
9638  w.stop();
9639  w.deinit();
9640  }
9641  else
9642  {
9643  tools::signal_handler::install([&w](int type) {
9645  {
9646  // must be prompting for password so return and let the signal stop prompt
9647  return;
9648  }
9649 #ifdef WIN32
9650  if (type == CTRL_C_EVENT)
9651 #else
9652  if (type == SIGINT)
9653 #endif
9654  {
9655  // if we're pressing ^C when refreshing, just stop refreshing
9656  w.interrupt();
9657  }
9658  else
9659  {
9660  w.stop();
9661  }
9662  });
9663 
9664  // FINALLY, RUN THE WALLET
9665  w.run();
9666 
9667  // CLOSE WALLET DOWN WHEN CONTROL RETURNS FROM w.run()
9668  w.deinit();
9669  }
9670  return 0;
9671  CATCH_ENTRY_L0("main", 1);
9672 }
Manages wallet operations. This is the most abstracted wallet class.
Definition: simplewallet.h:68
static const char * tr(const char *str)
Definition: simplewallet.h:70
bool init(const boost::program_options::variables_map &vm)
bool process_command(const std::vector< std::string > &args)
static std::atomic< bool > is_prompting
Definition: password.h:55
static bool install(T t)
installs a signal handler
Definition: util.h:164
static void init_options(boost::program_options::options_description &desc_params)
Definition: wallet2.cpp:1192
#define CATCH_ENTRY_L0(lacation, return_val)
Definition: misc_log_ex.h:165
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
#define TRY_ENTRY()
Definition: misc_log_ex.h:151
void load(Archive &a, std::unordered_map< h_key, hval > &x, const boost::serialization::version_type ver)
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
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
Definition: command_line.h:271
const command_line::arg_descriptor< std::string > arg_fallback_to_pow_checkpoint_hash
const command_line::arg_descriptor< uint64_t > arg_fallback_to_pow_checkpoint_height
const command_line::arg_descriptor< std::vector< std::string > > arg_command
@ console_color_default
Definition: misc_log_ex.h:208
@ console_color_white
Definition: misc_log_ex.h:209
scoped_message_writer fail_msg_writer()
const char * tr(const char *str)
Definition: wallet_args.cpp:81
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
command_line::arg_descriptor< std::string > arg_generate_from_json()
Definition: wallet_args.cpp:72
command_line::arg_descriptor< std::string > arg_wallet_file()
Definition: wallet_args.cpp:76
Here is the call graph for this function:

◆ parse_priority()

bool parse_priority ( const std::string &  arg,
uint32_t priority 
)

Definition at line 649 of file simplewallet.cpp.

650 {
651  auto priority_pos = std::find(
652  allowed_priority_strings.begin(),
653  allowed_priority_strings.end(),
654  arg);
655  if(priority_pos != allowed_priority_strings.end()) {
656  priority = std::distance(allowed_priority_strings.begin(), priority_pos);
657  return true;
658  }
659  return false;
660 }