Electroneum
Loading...
Searching...
No Matches
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 <secp256k1/include/secp256k1.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()
#define PRINT_USAGE(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:
do \
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)
#define tr(x)

◆ DEFAULT_MIX

#define DEFAULT_MIX   0

Definition at line 98 of file simplewallet.cpp.

◆ ELECTRONEUM_DEFAULT_LOG_CATEGORY

#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "wallet.simplewallet"

Definition at line 94 of file simplewallet.cpp.

◆ EXTENDED_LOGS_FILE

#define EXTENDED_LOGS_FILE   "wallet_details.log"

Definition at line 96 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 103 of file simplewallet.cpp.

103#define LOCK_IDLE_SCOPE() \
104 bool auto_refresh_enabled = m_auto_refresh_enabled.load(std::memory_order_relaxed); \
105 m_auto_refresh_enabled.store(false, std::memory_order_relaxed); \
106 /* stop any background refresh, and take over */ \
107 m_wallet->stop(); \
108 boost::unique_lock<boost::mutex> lock(m_idle_mutex); \
109 m_idle_cond.notify_all(); \
110 epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){ \
111 m_auto_refresh_enabled.store(auto_refresh_enabled, std::memory_order_relaxed); \
112 })

◆ 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 124 of file simplewallet.cpp.

124#define LONG_PAYMENT_ID_SUPPORT_CHECK() \
125 do { \
126 if (!m_long_payment_id_support) { \
127 fail_msg_writer() << tr("Warning: Long payment IDs are obsolete."); \
128 fail_msg_writer() << tr("Long payment IDs are not encrypted on the blockchain, and will harm your privacy."); \
129 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."); \
130 return true; \
131 } \
132 } while(0)

◆ MIN_RING_SIZE

#define MIN_RING_SIZE   1

Definition at line 100 of file simplewallet.cpp.

◆ OUTPUT_EXPORT_FILE_MAGIC

#define OUTPUT_EXPORT_FILE_MAGIC   "Electroneum output export\003"

Definition at line 101 of file simplewallet.cpp.

◆ PRINT_USAGE

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

Definition at line 122 of file simplewallet.cpp.

◆ SCOPED_WALLET_UNLOCK

#define SCOPED_WALLET_UNLOCK ( )
Value:
#define SCOPED_WALLET_UNLOCK_ON_BAD_PASSWORD(code)

Definition at line 120 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 114 of file simplewallet.cpp.

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

Typedef Documentation

◆ sw

Definition at line 91 of file simplewallet.cpp.

Enumeration Type Documentation

◆ TransferType

Enumerator
Transfer 
TransferLocked 

Definition at line 134 of file simplewallet.cpp.

134 {
135 Transfer,
137};
@ Transfer
@ TransferLocked

Function Documentation

◆ join_priority_strings()

std::string join_priority_strings ( const char * delimiter)

Definition at line 663 of file simplewallet.cpp.

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

◆ main()

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

Definition at line 9608 of file simplewallet.cpp.

9609{
9610 TRY_ENTRY();
9611
9612#ifdef WIN32
9613 // Activate UTF-8 support for Boost filesystem classes on Windows
9614 std::locale::global(boost::locale::generator().generate(""));
9615 boost::filesystem::path::imbue(std::locale());
9616#endif
9617 // READ IN OPTIONS FROM COMMAND LINE
9618 po::options_description desc_params(wallet_args::tr("Wallet options"));
9619 tools::wallet2::init_options(desc_params);
9620 command_line::add_arg(desc_params, arg_wallet_file);
9621 command_line::add_arg(desc_params, arg_generate_new_wallet);
9622 command_line::add_arg(desc_params, arg_generate_from_device);
9623 command_line::add_arg(desc_params, arg_generate_from_view_key);
9624 command_line::add_arg(desc_params, arg_generate_from_spend_key);
9625 command_line::add_arg(desc_params, arg_generate_from_keys);
9626 command_line::add_arg(desc_params, arg_generate_from_multisig_keys);
9627 command_line::add_arg(desc_params, arg_generate_from_json);
9628 command_line::add_arg(desc_params, arg_mnemonic_language);
9629 command_line::add_arg(desc_params, arg_command);
9630
9631 command_line::add_arg(desc_params, arg_restore_deterministic_wallet );
9632 command_line::add_arg(desc_params, arg_restore_multisig_wallet );
9633 command_line::add_arg(desc_params, arg_non_deterministic );
9634 command_line::add_arg(desc_params, arg_electrum_seed );
9635 command_line::add_arg(desc_params, arg_allow_mismatched_daemon_version);
9636 command_line::add_arg(desc_params, arg_restore_height);
9637 command_line::add_arg(desc_params, arg_restore_date);
9638 command_line::add_arg(desc_params, arg_do_not_relay);
9639 command_line::add_arg(desc_params, arg_create_address_file);
9640 command_line::add_arg(desc_params, arg_subaddress_lookahead);
9641 command_line::add_arg(desc_params, arg_use_english_language_names);
9642 command_line::add_arg(desc_params, arg_long_payment_id_support);
9643 command_line::add_arg(desc_params, arg_account_major_offset);
9646 po::positional_options_description positional_options;
9647 positional_options.add(arg_command.name, -1);
9648
9649 boost::optional<po::variables_map> vm;
9650 bool should_terminate = false;
9651 std::tie(vm, should_terminate) = wallet_args::main(
9652 argc, argv,
9653 "electroneum-wallet-cli [--wallet-file=<filename>|--generate-new-wallet=<filename>] [<COMMAND>]",
9654 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."),
9655 desc_params,
9656 positional_options,
9657 [](const std::string &s, bool emphasis){ tools::scoped_message_writer(emphasis ? epee::console_color_white : epee::console_color_default, true) << s; },
9658 "electroneum-wallet-cli.log"
9659 );
9660
9661 if (!vm)
9662 {
9663 return 1;
9664 }
9665
9666 if (should_terminate)
9667 {
9668 return 0;
9669 }
9670
9671
9672 // INITIALISE THE WALLET AND OPEN IT UP (.init)
9674 const bool r = w.init(*vm);
9675 CHECK_AND_ASSERT_MES(r, 1, sw::tr("Failed to initialize wallet"));
9676
9677 std::vector<std::string> command = command_line::get_arg(*vm, arg_command);
9678 if (!command.empty())
9679 {
9680 if (!w.process_command(command))
9681 fail_msg_writer() << sw::tr("Unknown command: ") << command.front();
9682 w.stop();
9683 w.deinit();
9684 }
9685 else
9686 {
9687 tools::signal_handler::install([&w](int type) {
9689 {
9690 // must be prompting for password so return and let the signal stop prompt
9691 return;
9692 }
9693#ifdef WIN32
9694 if (type == CTRL_C_EVENT)
9695#else
9696 if (type == SIGINT)
9697#endif
9698 {
9699 // if we're pressing ^C when refreshing, just stop refreshing
9700 w.interrupt();
9701 }
9702 else
9703 {
9704 w.stop();
9705 }
9706 });
9707
9708 // FINALLY, RUN THE WALLET
9709 w.run();
9710
9711 // CLOSE WALLET DOWN WHEN CONTROL RETURNS FROM w.run()
9712 w.deinit();
9713 }
9714 return 0;
9715 CATCH_ENTRY_L0("main", 1);
9716}
Manages wallet operations. This is the most abstracted wallet class.
bool init(const boost::program_options::variables_map &vm)
static const char * tr(const char *str)
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:1193
#define CATCH_ENTRY_L0(lacation, return_val)
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
#define TRY_ENTRY()
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)
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
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
@ console_color_white
scoped_message_writer fail_msg_writer()
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)
Here is the call graph for this function:

◆ parse_priority()

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

Definition at line 650 of file simplewallet.cpp.

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