diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptonote_core/cryptonote_core.cpp | 12 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_format_utils.cpp | 2 | ||||
-rw-r--r-- | src/daemon/protocol.h | 2 | ||||
-rw-r--r-- | src/p2p/net_node.inl | 5 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 42 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.h | 1 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 6 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 7 |
8 files changed, 74 insertions, 3 deletions
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 5ddedd6fd..900dc58ba 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -41,6 +41,7 @@ using namespace epee; #include "cryptonote_format_utils.h" #include "misc_language.h" #include <csignal> +#include <p2p/net_node.h> #include "cryptonote_core/checkpoints.h" #include "ringct/rctTypes.h" #include "blockchain_db/blockchain_db.h" @@ -258,8 +259,17 @@ namespace cryptonote m_fakechain = test_options != NULL; bool r = handle_command_line(vm); + bool testnet = command_line::get_arg(vm, command_line::arg_testnet_on); + auto p2p_bind_arg = testnet ? nodetool::arg_testnet_p2p_bind_port : nodetool::arg_p2p_bind_port; + std::string m_port = command_line::get_arg(vm, p2p_bind_arg); + std::string m_config_folder_mempool = m_config_folder; + + if ((!testnet && m_port != std::to_string(::config::P2P_DEFAULT_PORT)) + || (testnet && m_port != std::to_string(::config::testnet::P2P_DEFAULT_PORT))) { + m_config_folder_mempool = m_config_folder_mempool + "/" + m_port; + } - r = m_mempool.init(m_fakechain ? std::string() : m_config_folder); + r = m_mempool.init(m_fakechain ? std::string() : m_config_folder_mempool); CHECK_AND_ASSERT_MES(r, false, "Failed to initialize memory pool"); std::string db_type = command_line::get_arg(vm, command_line::arg_db_type); diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index 70ba7ee18..2e6917878 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -443,6 +443,8 @@ namespace cryptonote { if (!memcmp(&destinations[n].addr, &sender_keys.m_account_address, sizeof(destinations[0].addr))) continue; + if (destinations[n].amount == 0) + continue; if (memcmp(&destinations[n].addr, &destinations[0].addr, sizeof(destinations[0].addr))) return null_pkey; } diff --git a/src/daemon/protocol.h b/src/daemon/protocol.h index 5bcb83dcf..0b0f95988 100644 --- a/src/daemon/protocol.h +++ b/src/daemon/protocol.h @@ -33,6 +33,8 @@ #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "daemon" +#include "common/scoped_message_writer.h" + namespace daemonize { diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index d67c5dd93..7ab6a4894 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -505,6 +505,11 @@ namespace nodetool auto config_arg = testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir; m_config_folder = command_line::get_arg(vm, config_arg); + if ((!testnet && m_port != std::to_string(::config::P2P_DEFAULT_PORT)) + || (testnet && m_port != std::to_string(::config::testnet::P2P_DEFAULT_PORT))) { + m_config_folder = m_config_folder + "/" + m_port; + } + res = init_config(); CHECK_AND_ASSERT_MES(res, false, "Failed to init config."); diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 694838010..a8f1d177f 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -286,6 +286,7 @@ std::string simple_wallet::get_commands_str() bool simple_wallet::viewkey(const std::vector<std::string> &args/* = std::vector<std::string>()*/) { + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } // don't log std::cout << "secret: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key) << std::endl; std::cout << "public: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_account_address.m_view_public_key) << std::endl; @@ -295,6 +296,12 @@ bool simple_wallet::viewkey(const std::vector<std::string> &args/* = std::vector bool simple_wallet::spendkey(const std::vector<std::string> &args/* = std::vector<std::string>()*/) { + if (m_wallet->watch_only()) + { + fail_msg_writer() << tr("wallet is watch-only and has no spend key"); + return true; + } + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } // don't log std::cout << "secret: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_spend_secret_key) << std::endl; std::cout << "public: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_account_address.m_spend_public_key) << std::endl; @@ -312,6 +319,7 @@ bool simple_wallet::seed(const std::vector<std::string> &args/* = std::vector<st fail_msg_writer() << tr("wallet is watch-only and has no seed"); return true; } + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } if (m_wallet->is_deterministic()) { if (m_wallet->get_seed_language().empty()) @@ -571,6 +579,17 @@ bool simple_wallet::set_confirm_missing_payment_id(const std::vector<std::string return true; } +bool simple_wallet::set_ask_password(const std::vector<std::string> &args/* = std::vector<std::string>()*/) +{ + const auto pwd_container = get_and_verify_password(); + if (pwd_container) + { + m_wallet->ask_password(is_it_true(args[1])); + 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(); @@ -643,6 +662,7 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args) success_msg_writer() << "refresh-type = " << get_refresh_type_name(m_wallet->get_refresh_type()); success_msg_writer() << "priority = " << m_wallet->get_default_priority(); success_msg_writer() << "confirm-missing-payment-id = " << m_wallet->confirm_missing_payment_id(); + success_msg_writer() << "ask-password = " << m_wallet->ask_password(); return true; } else @@ -765,6 +785,19 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args) return true; } } + else if (args[0] == "ask-password") + { + if (args.size() <= 1) + { + fail_msg_writer() << tr("set ask-password: needs an argument (0 or 1)"); + return true; + } + else + { + set_ask_password(args); + return true; + } + } } fail_msg_writer() << tr("set: unrecognized argument(s)"); return true; @@ -2050,6 +2083,7 @@ bool simple_wallet::print_ring_members(const std::vector<tools::wallet2::pending //---------------------------------------------------------------------------------------------------- bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::string> &args_) { + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } if (!try_connect_to_daemon()) return true; @@ -2408,6 +2442,7 @@ bool simple_wallet::locked_transfer(const std::vector<std::string> &args_) bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_) { + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } if (!try_connect_to_daemon()) return true; @@ -2570,6 +2605,7 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_) //---------------------------------------------------------------------------------------------------- bool simple_wallet::sweep_all(const std::vector<std::string> &args_) { + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } if (!try_connect_to_daemon()) return true; @@ -2831,6 +2867,7 @@ bool simple_wallet::sweep_all(const std::vector<std::string> &args_) //---------------------------------------------------------------------------------------------------- bool simple_wallet::donate(const std::vector<std::string> &args_) { + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } std::vector<std::string> local_args = args_; if(local_args.empty() || local_args.size() > 3) { @@ -2971,6 +3008,7 @@ bool simple_wallet::sign_transfer(const std::vector<std::string> &args_) fail_msg_writer() << tr("This is a watch only wallet"); return true; } + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } std::vector<tools::wallet2::pending_tx> ptx; try @@ -3119,6 +3157,7 @@ bool simple_wallet::get_tx_key(const std::vector<std::string> &args_) fail_msg_writer() << tr("usage: get_tx_key <txid>"); return true; } + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } cryptonote::blobdata txid_data; if(!epee::string_tools::parse_hexstr_to_binbuff(local_args.front(), txid_data)) @@ -3887,6 +3926,7 @@ bool simple_wallet::sign(const std::vector<std::string> &args) fail_msg_writer() << tr("wallet is watch-only and cannot sign"); return true; } + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } std::string filename = args[0]; std::string data; bool r = epee::file_io_utils::load_file_to_string(filename, data); @@ -3952,6 +3992,7 @@ bool simple_wallet::export_key_images(const std::vector<std::string> &args) fail_msg_writer() << tr("wallet is watch-only and cannot export key images"); return true; } + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } std::string filename = args[0]; try @@ -4010,6 +4051,7 @@ bool simple_wallet::export_outputs(const std::vector<std::string> &args) fail_msg_writer() << tr("usage: export_outputs <filename>"); return true; } + if (m_wallet->ask_password() && !get_and_verify_password()) { return true; } std::string filename = args[0]; try diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 9918300df..ce0a24be7 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -115,6 +115,7 @@ namespace cryptonote bool set_auto_refresh(const std::vector<std::string> &args = std::vector<std::string>()); bool set_refresh_type(const std::vector<std::string> &args = std::vector<std::string>()); bool set_confirm_missing_payment_id(const std::vector<std::string> &args = std::vector<std::string>()); + bool set_ask_password(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); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 148fb9d52..9bdfc7b04 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1860,6 +1860,9 @@ bool wallet2::store_keys(const std::string& keys_file_name, const std::string& p value2.SetInt(m_confirm_missing_payment_id ? 1 :0); json.AddMember("confirm_missing_payment_id", value2, json.GetAllocator()); + value2.SetInt(m_ask_password ? 1 :0); + json.AddMember("ask_password", value2, json.GetAllocator()); + // Serialize the JSON object rapidjson::StringBuffer buffer; rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); @@ -1927,6 +1930,7 @@ bool wallet2::load_keys(const std::string& keys_file_name, const std::string& pa m_auto_refresh = true; m_refresh_type = RefreshType::RefreshDefault; m_confirm_missing_payment_id = true; + m_ask_password = true; } else { @@ -1987,6 +1991,8 @@ bool wallet2::load_keys(const std::string& keys_file_name, const std::string& pa m_refresh_from_block_height = field_refresh_height; GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, confirm_missing_payment_id, int, Int, false, true); m_confirm_missing_payment_id = field_confirm_missing_payment_id; + GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, ask_password, int, Int, false, true); + m_ask_password = field_ask_password; } const cryptonote::account_keys& keys = m_account.get_keys(); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 91d4db47e..567292d30 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -104,7 +104,7 @@ namespace tools }; private: - wallet2(const wallet2&) : m_run(true), m_callback(0), m_testnet(false), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true), m_node_rpc_proxy(m_http_client, m_daemon_rpc_mutex) {} + wallet2(const wallet2&) : m_run(true), m_callback(0), m_testnet(false), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true), m_ask_password(true), m_node_rpc_proxy(m_http_client, m_daemon_rpc_mutex) {} public: static const char* tr(const char* str); @@ -125,7 +125,7 @@ namespace tools //! Uses stdin and stdout. Returns a wallet2 and password for wallet with no file if no errors. static std::pair<std::unique_ptr<wallet2>, password_container> make_new(const boost::program_options::variables_map& vm); - wallet2(bool testnet = false, bool restricted = false) : m_run(true), m_callback(0), m_testnet(testnet), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true), m_restricted(restricted), is_old_file_format(false), m_node_rpc_proxy(m_http_client, m_daemon_rpc_mutex) {} + wallet2(bool testnet = false, bool restricted = false) : m_run(true), m_callback(0), m_testnet(testnet), m_always_confirm_transfers(true), m_print_ring_members(false), m_store_tx_info(true), m_default_mixin(0), m_default_priority(0), m_refresh_type(RefreshOptimizeCoinbase), m_auto_refresh(true), m_refresh_from_block_height(0), m_confirm_missing_payment_id(true), m_ask_password(true), m_restricted(restricted), is_old_file_format(false), m_node_rpc_proxy(m_http_client, m_daemon_rpc_mutex) {} struct transfer_details { uint64_t m_block_height; @@ -506,6 +506,8 @@ namespace tools void auto_refresh(bool r) { m_auto_refresh = r; } bool confirm_missing_payment_id() const { return m_confirm_missing_payment_id; } void confirm_missing_payment_id(bool always) { m_confirm_missing_payment_id = always; } + bool ask_password() const { return m_ask_password; } + void ask_password(bool always) { m_ask_password = always; } bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key) const; @@ -656,6 +658,7 @@ namespace tools bool m_auto_refresh; uint64_t m_refresh_from_block_height; bool m_confirm_missing_payment_id; + bool m_ask_password; NodeRPCProxy m_node_rpc_proxy; }; } |