aboutsummaryrefslogtreecommitdiff
path: root/src/simplewallet
diff options
context:
space:
mode:
Diffstat (limited to 'src/simplewallet')
-rw-r--r--src/simplewallet/CMakeLists.txt3
-rw-r--r--src/simplewallet/password_container.cpp2
-rw-r--r--src/simplewallet/password_container.h2
-rw-r--r--src/simplewallet/simplewallet.cpp123
-rw-r--r--src/simplewallet/simplewallet.h14
5 files changed, 124 insertions, 20 deletions
diff --git a/src/simplewallet/CMakeLists.txt b/src/simplewallet/CMakeLists.txt
index 14f877907..a33ed0f32 100644
--- a/src/simplewallet/CMakeLists.txt
+++ b/src/simplewallet/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014, The Monero Project
+# Copyright (c) 2014-2015, The Monero Project
#
# All rights reserved.
#
@@ -50,6 +50,7 @@ target_link_libraries(simplewallet
crypto
common
mnemonics
+ p2p
${UNBOUND_LIBRARY}
${UPNP_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
diff --git a/src/simplewallet/password_container.cpp b/src/simplewallet/password_container.cpp
index 1c4aee453..e5fb933bb 100644
--- a/src/simplewallet/password_container.cpp
+++ b/src/simplewallet/password_container.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014, The Monero Project
+// Copyright (c) 2014-2015, The Monero Project
//
// All rights reserved.
//
diff --git a/src/simplewallet/password_container.h b/src/simplewallet/password_container.h
index b39fa1fe4..8a4191c7a 100644
--- a/src/simplewallet/password_container.h
+++ b/src/simplewallet/password_container.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014, The Monero Project
+// Copyright (c) 2014-2015, The Monero Project
//
// All rights reserved.
//
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 4f7df2d3a..9ac80fa9e 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014, The Monero Project
+// Copyright (c) 2014-2015, The Monero Project
//
// All rights reserved.
//
@@ -67,6 +67,9 @@ namespace po = boost::program_options;
#define EXTENDED_LOGS_FILE "wallet_details.log"
+unsigned int epee::g_test_dbg_lock_sleep = 0;
+
+#define DEFAULT_MIX 3
namespace
{
@@ -81,6 +84,7 @@ namespace
const command_line::arg_descriptor<int> arg_daemon_port = {"daemon-port", "Use daemon instance at port <arg> instead of 8081", 0};
const command_line::arg_descriptor<uint32_t> arg_log_level = {"set_log", "", 0, true};
const command_line::arg_descriptor<bool> arg_testnet = {"testnet", "Used to deploy test nets. The daemon must be launched with --testnet flag", false};
+ const command_line::arg_descriptor<bool> arg_restricted = {"restricted-rpc", "Restricts RPC to view only commands", false};
const command_line::arg_descriptor< std::vector<std::string> > arg_command = {"command", ""};
@@ -231,6 +235,36 @@ bool simple_wallet::seed(const std::vector<std::string> &args/* = std::vector<st
return true;
}
+bool simple_wallet::seed_set_language(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
+{
+ bool success = false;
+ if (!m_wallet->is_deterministic())
+ {
+ fail_msg_writer() << "This wallet is non-deterministic and doesn't have a seed.";
+ return true;
+ }
+ tools::password_container pwd_container;
+ success = pwd_container.read_password();
+ if (!success)
+ {
+ fail_msg_writer() << "failed to read wallet password";
+ return true;
+ }
+
+ /* verify password before using so user doesn't accidentally set a new password for rewritten wallet */
+ success = m_wallet->verify_password(pwd_container.password());
+ if (!success)
+ {
+ fail_msg_writer() << "invalid password";
+ return true;
+ }
+
+ std::string mnemonic_language = get_mnemonic_language();
+ m_wallet->set_seed_language(mnemonic_language);
+ m_wallet->rewrite(m_wallet_file, pwd_container.password());
+ return true;
+}
+
bool simple_wallet::help(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
success_msg_writer() << get_commands_str();
@@ -249,15 +283,45 @@ simple_wallet::simple_wallet()
m_cmd_binder.set_handler("incoming_transfers", boost::bind(&simple_wallet::show_incoming_transfers, this, _1), "incoming_transfers [available|unavailable] - Show incoming transfers - all of them or filter them by availability");
m_cmd_binder.set_handler("payments", boost::bind(&simple_wallet::show_payments, this, _1), "payments <payment_id_1> [<payment_id_2> ... <payment_id_N>] - Show payments <payment_id_1>, ... <payment_id_N>");
m_cmd_binder.set_handler("bc_height", boost::bind(&simple_wallet::show_blockchain_height, this, _1), "Show blockchain height");
- m_cmd_binder.set_handler("transfer", boost::bind(&simple_wallet::transfer, this, _1), "transfer <mixin_count> <addr_1> <amount_1> [<addr_2> <amount_2> ... <addr_N> <amount_N>] [payment_id] - Transfer <amount_1>,... <amount_N> to <address_1>,... <address_N>, respectively. <mixin_count> is the number of transactions yours is indistinguishable from (from 0 to maximum available)");
+ m_cmd_binder.set_handler("transfer", boost::bind(&simple_wallet::transfer, this, _1), "transfer [<mixin_count>] <addr_1> <amount_1> [<addr_2> <amount_2> ... <addr_N> <amount_N>] [payment_id] - Transfer <amount_1>,... <amount_N> to <address_1>,... <address_N>, respectively. <mixin_count> is the number of transactions yours is indistinguishable from (from 0 to maximum available)");
m_cmd_binder.set_handler("set_log", boost::bind(&simple_wallet::set_log, this, _1), "set_log <level> - Change current log detalization level, <level> is a number 0-4");
m_cmd_binder.set_handler("address", boost::bind(&simple_wallet::print_address, this, _1), "Show current wallet public address");
m_cmd_binder.set_handler("save", boost::bind(&simple_wallet::save, this, _1), "Save wallet synchronized data");
m_cmd_binder.set_handler("viewkey", boost::bind(&simple_wallet::viewkey, this, _1), "Get viewkey");
m_cmd_binder.set_handler("seed", boost::bind(&simple_wallet::seed, this, _1), "Get deterministic seed");
+ m_cmd_binder.set_handler("set", boost::bind(&simple_wallet::set_variable, this, _1), "available options: seed language - Set wallet seed langage");
m_cmd_binder.set_handler("help", boost::bind(&simple_wallet::help, this, _1), "Show this help");
}
//----------------------------------------------------------------------------------------------------
+bool simple_wallet::set_variable(const std::vector<std::string> &args)
+{
+ if (args.empty())
+ {
+ fail_msg_writer() << "set: needs an argument. available options: seed";
+ return true;
+ }
+ else
+ {
+ if (args[0] == "seed")
+ {
+ if (args.size() == 1)
+ {
+ fail_msg_writer() << "set seed: needs an argument. available options: language";
+ return true;
+ }
+ else if (args[1] == "language")
+ {
+ std::vector<std::string> local_args = args;
+ local_args.erase(local_args.begin(), local_args.begin()+2);
+ seed_set_language(local_args);
+ return true;
+ }
+ }
+ }
+ fail_msg_writer() << "set: unrecognized argument(s)";
+ return true;
+}
+//----------------------------------------------------------------------------------------------------
bool simple_wallet::set_log(const std::vector<std::string> &args)
{
if(args.size() != 1)
@@ -285,14 +349,28 @@ bool simple_wallet::ask_wallet_create_if_needed()
{
std::string wallet_path;
- wallet_path = command_line::input_line(
- "Specify wallet file name (e.g., wallet.bin). If the wallet doesn't exist, it will be created.\n"
- "Wallet file name: "
- );
+ bool valid_path = false;
+ do {
+ wallet_path = command_line::input_line(
+ "Specify wallet file name (e.g., wallet.bin). If the wallet doesn't exist, it will be created.\n"
+ "Wallet file name: "
+ );
+ valid_path = tools::wallet2::wallet_valid_path_format(wallet_path);
+ if (!valid_path)
+ {
+ fail_msg_writer() << "wallet file path not valid: " << wallet_path;
+ }
+ }
+ while (!valid_path);
bool keys_file_exists;
bool wallet_file_exists;
tools::wallet2::wallet_exists(wallet_path, keys_file_exists, wallet_file_exists);
+ LOG_PRINT_L3("wallet_path: " << wallet_path << "");
+ LOG_PRINT_L3("keys_file_exists: " << std::boolalpha << keys_file_exists << std::noboolalpha
+ << " wallet_file_exists: " << std::boolalpha << wallet_file_exists << std::noboolalpha);
+
+ LOG_PRINT_L1("Loading wallet...");
// add logic to error out if new wallet requested but named wallet file exists
if (keys_file_exists || wallet_file_exists)
@@ -575,6 +653,12 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string
//----------------------------------------------------------------------------------------------------
bool simple_wallet::open_wallet(const string &wallet_file, const std::string& password, bool testnet)
{
+ if (!tools::wallet2::wallet_valid_path_format(wallet_file))
+ {
+ fail_msg_writer() << "wallet file path not valid: " << wallet_file;
+ return false;
+ }
+
m_wallet_file = wallet_file;
m_wallet.reset(new tools::wallet2(testnet));
m_wallet->callback(this);
@@ -986,19 +1070,24 @@ bool simple_wallet::transfer(const std::vector<std::string> &args_)
return true;
std::vector<std::string> local_args = args_;
- if(local_args.size() < 3)
- {
- fail_msg_writer() << "wrong number of arguments, expected at least 3, got " << local_args.size();
- return true;
- }
size_t fake_outs_count;
- if(!epee::string_tools::get_xtype_from_string(fake_outs_count, local_args[0]))
+ if(local_args.size() > 0) {
+ if(!epee::string_tools::get_xtype_from_string(fake_outs_count, local_args[0]))
+ {
+ fake_outs_count = DEFAULT_MIX;
+ }
+ else
+ {
+ local_args.erase(local_args.begin());
+ }
+ }
+
+ if(local_args.size() < 2)
{
- fail_msg_writer() << "mixin_count should be non-negative integer, got " << local_args[0];
- return true;
+ fail_msg_writer() << "wrong number of arguments";
+ return true;
}
- local_args.erase(local_args.begin());
std::vector<uint8_t> extra;
if (1 == local_args.size() % 2)
@@ -1256,6 +1345,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_params, arg_non_deterministic );
command_line::add_arg(desc_params, arg_electrum_seed );
command_line::add_arg(desc_params, arg_testnet);
+ command_line::add_arg(desc_params, arg_restricted);
tools::wallet_rpc_server::init_options(desc_params);
po::positional_options_description positional_options;
@@ -1326,6 +1416,7 @@ int main(int argc, char* argv[])
}
bool testnet = command_line::get_arg(vm, arg_testnet);
+ bool restricted = command_line::get_arg(vm, arg_restricted);
std::string wallet_file = command_line::get_arg(vm, arg_wallet_file);
std::string wallet_password = command_line::get_arg(vm, arg_password);
std::string daemon_address = command_line::get_arg(vm, arg_daemon_address);
@@ -1338,7 +1429,7 @@ int main(int argc, char* argv[])
if (daemon_address.empty())
daemon_address = std::string("http://") + daemon_host + ":" + std::to_string(daemon_port);
- tools::wallet2 wal(testnet);
+ tools::wallet2 wal(testnet,restricted);
try
{
LOG_PRINT_L0("Loading wallet...");
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index ebc85ed17..a8fe78414 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014, The Monero Project
+// Copyright (c) 2014-2015, The Monero Project
//
// All rights reserved.
//
@@ -81,6 +81,17 @@ namespace cryptonote
bool viewkey(const std::vector<std::string> &args = std::vector<std::string>());
bool seed(const std::vector<std::string> &args = std::vector<std::string>());
+
+ /*!
+ * \brief Sets seed language.
+ *
+ * interactive
+ * - prompts for password so wallet can be rewritten
+ * - calls get_mnemonic_language() which prompts for language
+ *
+ * \return success status
+ */
+ bool seed_set_language(const std::vector<std::string> &args = std::vector<std::string>());
bool help(const std::vector<std::string> &args = std::vector<std::string>());
bool start_mining(const std::vector<std::string> &args);
bool stop_mining(const std::vector<std::string> &args);
@@ -96,6 +107,7 @@ namespace cryptonote
);
bool print_address(const std::vector<std::string> &args = std::vector<std::string>());
bool save(const std::vector<std::string> &args);
+ bool set_variable(const std::vector<std::string> &args);
bool set_log(const std::vector<std::string> &args);
uint64_t get_daemon_blockchain_height(std::string& err);