aboutsummaryrefslogtreecommitdiff
path: root/src/simplewallet
diff options
context:
space:
mode:
Diffstat (limited to 'src/simplewallet')
-rw-r--r--src/simplewallet/simplewallet.cpp81
-rw-r--r--src/simplewallet/simplewallet.h1
2 files changed, 42 insertions, 40 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 321f2b137..049125268 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -370,6 +370,33 @@ bool simple_wallet::seed_set_language(const std::vector<std::string> &args/* = s
return true;
}
+bool simple_wallet::change_password(const std::vector<std::string> &args)
+{
+ const auto orig_pwd_container = get_and_verify_password();
+
+ if(orig_pwd_container == boost::none)
+ {
+ fail_msg_writer() << tr("Your original password was incorrect.");
+ return false;
+ }
+
+ // prompts for a new password, this is not a new wallet so pass in false.
+ const auto pwd_container = tools::wallet2::password_prompt(false);
+
+ try
+ {
+ m_wallet->rewrite(m_wallet_file, pwd_container->password());
+ m_wallet->store();
+ }
+ catch (const wallet_logic_error& e)
+ {
+ fail_msg_writer() << tr("Error with wallet rewrite: ") << e.what();
+ return false;
+ }
+
+ return true;
+}
+
bool simple_wallet::set_always_confirm_transfers(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
const auto pwd_container = get_and_verify_password();
@@ -898,33 +925,6 @@ void simple_wallet::print_seed(std::string seed)
//----------------------------------------------------------------------------------------------------
static bool is_local_daemon(const std::string &address)
{
- // extract host
- epee::net_utils::http::url_content u_c;
- if (!epee::net_utils::parse_url(address, u_c))
- {
- LOG_PRINT_L1("Failed to determine whether daemon is local, assuming not");
- return false;
- }
- if (u_c.host.empty())
- {
- LOG_PRINT_L1("Failed to determine whether daemon is local, assuming not");
- return false;
- }
-
- // resolve to IP
- boost::asio::io_service io_service;
- boost::asio::ip::tcp::resolver resolver(io_service);
- boost::asio::ip::tcp::resolver::query query(u_c.host, "");
- boost::asio::ip::tcp::resolver::iterator i = resolver.resolve(query);
- while (i != boost::asio::ip::tcp::resolver::iterator())
- {
- const boost::asio::ip::tcp::endpoint &ep = *i;
- if (ep.address().is_loopback())
- return true;
- ++i;
- }
-
- return false;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::init(const boost::program_options::variables_map& vm)
@@ -1188,14 +1188,15 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
// set --trusted-daemon if local
try
{
- if (is_local_daemon(m_wallet->get_daemon_address()))
+ if (tools::is_local_address(m_wallet->get_daemon_address()))
{
- LOG_PRINT_L1(tr("Daemon is local, assuming trusted"));
+ MINFO(tr("Daemon is local, assuming trusted"));
m_trusted_daemon = true;
}
}
catch (const std::exception &e) { }
+ m_http_client.set_server(m_wallet->get_daemon_address());
m_wallet->callback(this);
return true;
}
@@ -1593,7 +1594,7 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args)
}
COMMAND_RPC_START_MINING::response res;
- bool r = net_utils::invoke_http_json_remote_command2(m_wallet->get_daemon_address() + "/start_mining", req, res, m_http_client);
+ bool r = net_utils::invoke_http_json("/start_mining", req, res, m_http_client);
std::string err = interpret_rpc_response(r, res.status);
if (err.empty())
success_msg_writer() << tr("Mining started in daemon");
@@ -1610,7 +1611,7 @@ bool simple_wallet::stop_mining(const std::vector<std::string>& args)
assert(m_wallet);
COMMAND_RPC_STOP_MINING::request req;
COMMAND_RPC_STOP_MINING::response res;
- bool r = net_utils::invoke_http_json_remote_command2(m_wallet->get_daemon_address() + "/stop_mining", req, res, m_http_client);
+ bool r = net_utils::invoke_http_json("/stop_mining", req, res, m_http_client);
std::string err = interpret_rpc_response(r, res.status);
if (err.empty())
success_msg_writer() << tr("Mining stopped in daemon");
@@ -1627,7 +1628,7 @@ bool simple_wallet::save_bc(const std::vector<std::string>& args)
assert(m_wallet);
COMMAND_RPC_SAVE_BC::request req;
COMMAND_RPC_SAVE_BC::response res;
- bool r = net_utils::invoke_http_json_remote_command2(m_wallet->get_daemon_address() + "/save_bc", req, res, m_http_client);
+ bool r = net_utils::invoke_http_json("/save_bc", req, res, m_http_client);
std::string err = interpret_rpc_response(r, res.status);
if (err.empty())
success_msg_writer() << tr("Blockchain saved");
@@ -1916,7 +1917,7 @@ uint64_t simple_wallet::get_daemon_blockchain_height(std::string& err)
COMMAND_RPC_GET_HEIGHT::request req;
COMMAND_RPC_GET_HEIGHT::response res = boost::value_initialized<COMMAND_RPC_GET_HEIGHT::response>();
- bool r = net_utils::invoke_http_json_remote_command2(m_wallet->get_daemon_address() + "/getheight", req, res, m_http_client);
+ bool r = net_utils::invoke_http_json("/getheight", req, res, m_http_client);
err = interpret_rpc_response(r, res.status);
return res.height;
}
@@ -2027,7 +2028,7 @@ bool simple_wallet::print_ring_members(const std::vector<tools::wallet2::pending
req.outputs[j].index = absolute_offsets[j];
}
COMMAND_RPC_GET_OUTPUTS_BIN::response res = AUTO_VAL_INIT(res);
- bool r = net_utils::invoke_http_bin_remote_command2(m_wallet->get_daemon_address() + "/get_outs.bin", req, res, m_http_client);
+ bool r = net_utils::invoke_http_bin("/get_outs.bin", req, res, m_http_client);
err = interpret_rpc_response(r, res.status);
if (!err.empty())
{
@@ -2177,7 +2178,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
cryptonote::tx_destination_entry de;
bool has_payment_id;
crypto::hash8 new_payment_id;
- if (!tools::dns_utils::get_account_address_from_str_or_url(de.addr, has_payment_id, new_payment_id, m_wallet->testnet(), local_args[i]))
+ if (!cryptonote::get_account_address_from_str_or_url(de.addr, has_payment_id, new_payment_id, m_wallet->testnet(), local_args[i]))
return true;
if (has_payment_id)
@@ -2672,7 +2673,7 @@ bool simple_wallet::sweep_all(const std::vector<std::string> &args_)
bool has_payment_id;
crypto::hash8 new_payment_id;
cryptonote::account_public_address address;
- if (!tools::dns_utils::get_account_address_from_str_or_url(address, has_payment_id, new_payment_id, m_wallet->testnet(), local_args[0]))
+ if (!cryptonote::get_account_address_from_str_or_url(address, has_payment_id, new_payment_id, m_wallet->testnet(), local_args[0]))
return true;
if (has_payment_id)
@@ -3226,7 +3227,7 @@ bool simple_wallet::check_tx_key(const std::vector<std::string> &args_)
cryptonote::account_public_address address;
bool has_payment_id;
crypto::hash8 payment_id;
- if(!tools::dns_utils::get_account_address_from_str_or_url(address, has_payment_id, payment_id, m_wallet->testnet(), local_args[2]))
+ if(!cryptonote::get_account_address_from_str_or_url(address, has_payment_id, payment_id, m_wallet->testnet(), local_args[2]))
{
fail_msg_writer() << tr("failed to parse address");
return true;
@@ -3235,7 +3236,7 @@ bool simple_wallet::check_tx_key(const std::vector<std::string> &args_)
COMMAND_RPC_GET_TRANSACTIONS::request req;
COMMAND_RPC_GET_TRANSACTIONS::response res;
req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid));
- if (!net_utils::invoke_http_json_remote_command2(m_wallet->get_daemon_address() + "/gettransactions", req, res, m_http_client) ||
+ if (!net_utils::invoke_http_json("/gettransactions", req, res, m_http_client) ||
(res.txs.size() != 1 && res.txs_as_hex.size() != 1))
{
fail_msg_writer() << tr("failed to get transaction from daemon");
@@ -3774,7 +3775,7 @@ bool simple_wallet::address_book(const std::vector<std::string> &args/* = std::v
cryptonote::account_public_address address;
bool has_payment_id;
crypto::hash8 payment_id8;
- if(!tools::dns_utils::get_account_address_from_str_or_url(address, has_payment_id, payment_id8, m_wallet->testnet(), args[1]))
+ if(!cryptonote::get_account_address_from_str_or_url(address, has_payment_id, payment_id8, m_wallet->testnet(), args[1]))
{
fail_msg_writer() << tr("failed to parse address");
return true;
@@ -3965,7 +3966,7 @@ bool simple_wallet::verify(const std::vector<std::string> &args)
cryptonote::account_public_address address;
bool has_payment_id;
crypto::hash8 payment_id;
- if(!tools::dns_utils::get_account_address_from_str_or_url(address, has_payment_id, payment_id, m_wallet->testnet(), address_string))
+ if(!cryptonote::get_account_address_from_str_or_url(address, has_payment_id, payment_id, m_wallet->testnet(), address_string))
{
fail_msg_writer() << tr("failed to parse address");
return true;
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index 7139cdea2..ce0a24be7 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -163,6 +163,7 @@ namespace cryptonote
bool export_outputs(const std::vector<std::string> &args);
bool import_outputs(const std::vector<std::string> &args);
bool show_transfer(const std::vector<std::string> &args);
+ bool change_password(const std::vector<std::string>& args);
uint64_t get_daemon_blockchain_height(std::string& err);
bool try_connect_to_daemon(bool silent = false, uint32_t* version = nullptr);