prevent mining within wallet and node

This commit is contained in:
wowario 2021-07-19 21:21:51 +03:00
parent e586e39936
commit 947c154cd1
2 changed files with 4 additions and 186 deletions

View file

@ -331,107 +331,7 @@ bool t_command_parser_executor::print_transaction_pool_stats(const std::vector<s
bool t_command_parser_executor::start_mining(const std::vector<std::string>& args) bool t_command_parser_executor::start_mining(const std::vector<std::string>& args)
{ {
if(!args.size()) std::cout << "You can't mine within wownerod. To mine, restart node like this: ./wownerod --start-mining YOUR-ADDRESS --spendkey SECRET-SPENDKEY" << std::endl;
{
std::cout << "Please specify a wallet address to mine for: start_mining <addr> [<threads>|auto]" << std::endl;
return true;
}
cryptonote::address_parse_info info;
cryptonote::network_type nettype = cryptonote::MAINNET;
if(!cryptonote::get_account_address_from_str(info, cryptonote::MAINNET, args.front()))
{
if(!cryptonote::get_account_address_from_str(info, cryptonote::TESTNET, args.front()))
{
if(!cryptonote::get_account_address_from_str(info, cryptonote::STAGENET, args.front()))
{
bool dnssec_valid;
std::string address_str = tools::dns_utils::get_account_address_as_str_from_url(args.front(), dnssec_valid,
[](const std::string &url, const std::vector<std::string> &addresses, bool dnssec_valid){return addresses[0];});
if(!cryptonote::get_account_address_from_str(info, cryptonote::MAINNET, address_str))
{
if(!cryptonote::get_account_address_from_str(info, cryptonote::TESTNET, address_str))
{
if(!cryptonote::get_account_address_from_str(info, cryptonote::STAGENET, address_str))
{
std::cout << "target account address has wrong format" << std::endl;
return true;
}
else
{
nettype = cryptonote::STAGENET;
}
}
else
{
nettype = cryptonote::TESTNET;
}
}
}
else
{
nettype = cryptonote::STAGENET;
}
}
else
{
nettype = cryptonote::TESTNET;
}
}
if (info.is_subaddress)
{
tools::fail_msg_writer() << "You can't use a subaddress to mine. You need to use your wallet's main address, which starts with \"Wo\"." << std::endl;
return true;
}
if(nettype != cryptonote::MAINNET)
std::cout << "Mining to a " << (nettype == cryptonote::TESTNET ? "testnet" : "stagenet") << " address, make sure this is intentional!" << std::endl;
uint64_t threads_count = 1;
bool do_background_mining = false;
bool ignore_battery = false;
if(args.size() > 4)
{
return false;
}
if(args.size() == 4)
{
if(args[3] == "true" || command_line::is_yes(args[3]) || args[3] == "1")
{
ignore_battery = true;
}
else if(args[3] != "false" && !command_line::is_no(args[3]) && args[3] != "0")
{
return false;
}
}
if(args.size() >= 3)
{
if(args[2] == "true" || command_line::is_yes(args[2]) || args[2] == "1")
{
do_background_mining = true;
}
else if(args[2] != "false" && !command_line::is_no(args[2]) && args[2] != "0")
{
return false;
}
}
if(args.size() >= 2)
{
if (args[1] == "auto" || args[1] == "autodetect")
{
threads_count = 0;
}
else
{
bool ok = epee::string_tools::get_xtype_from_string(threads_count, args[1]);
threads_count = (ok && 0 < threads_count) ? threads_count : 1;
}
}
m_executor.start_mining(info.address, threads_count, nettype, do_background_mining, ignore_battery);
return true; return true;
} }

View file

@ -3142,6 +3142,7 @@ bool simple_wallet::help(const std::vector<std::string> &args/* = std::vector<st
message_writer() << tr("\"transfer <address> <amount>\" - Send WOW to an address."); message_writer() << tr("\"transfer <address> <amount>\" - Send WOW to an address.");
message_writer() << tr("\"show_transfers [in|out|pending|failed|pool]\" - Show transactions."); message_writer() << tr("\"show_transfers [in|out|pending|failed|pool]\" - Show transactions.");
message_writer() << tr("\"sweep_all <address>\" - Send whole balance to another wallet."); message_writer() << tr("\"sweep_all <address>\" - Send whole balance to another wallet.");
message_writer() << tr("\"spendkey\" - Show secret spend key used for mining.");
message_writer() << tr("\"seed\" - Show secret 25 words that can be used to recover this wallet."); message_writer() << tr("\"seed\" - Show secret 25 words that can be used to recover this wallet.");
message_writer() << tr("\"refresh\" - Synchronize wallet with the Wownero network."); message_writer() << tr("\"refresh\" - Synchronize wallet with the Wownero network.");
message_writer() << tr("\"status\" - Check current status of wallet."); message_writer() << tr("\"status\" - Check current status of wallet.");
@ -4676,9 +4677,6 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
m_wallet->callback(this); m_wallet->callback(this);
bool skip_check_backround_mining = !command_line::get_arg(vm, arg_command).empty();
if (!skip_check_backround_mining)
check_background_mining(password);
if (welcome) if (welcome)
message_writer(console_color_yellow, true) << tr("If you are new to Wownero, type \"welcome\" for a brief overview."); message_writer(console_color_yellow, true) << tr("If you are new to Wownero, type \"welcome\" for a brief overview.");
@ -5247,34 +5245,7 @@ bool simple_wallet::save_watch_only(const std::vector<std::string> &args/* = std
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
void simple_wallet::start_background_mining() void simple_wallet::start_background_mining()
{ {
COMMAND_RPC_MINING_STATUS::request reqq; message_writer(console_color_red, false) << tr("Background mining not available.");
COMMAND_RPC_MINING_STATUS::response resq;
bool r = m_wallet->invoke_http_json("/mining_status", reqq, resq);
std::string err = interpret_rpc_response(r, resq.status);
if (!r)
return;
if (!err.empty())
{
fail_msg_writer() << tr("Failed to query mining status: ") << err;
return;
}
if (!resq.is_background_mining_enabled)
{
COMMAND_RPC_START_MINING::request req;
COMMAND_RPC_START_MINING::response res;
req.miner_address = m_wallet->get_account().get_public_address_str(m_wallet->nettype());
req.threads_count = 1;
req.do_background_mining = true;
req.ignore_battery = false;
bool r = m_wallet->invoke_http_json("/start_mining", req, res);
std::string err = interpret_rpc_response(r, res.status);
if (!err.empty())
{
fail_msg_writer() << tr("Failed to setup background mining: ") << err;
return;
}
}
success_msg_writer() << tr("Background mining enabled. Thank you for supporting the Wownero network.");
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
void simple_wallet::stop_background_mining() void simple_wallet::stop_background_mining()
@ -5367,60 +5338,7 @@ void simple_wallet::check_background_mining(const epee::wipeable_string &passwor
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
bool simple_wallet::start_mining(const std::vector<std::string>& args) bool simple_wallet::start_mining(const std::vector<std::string>& args)
{ {
if (!m_wallet->is_trusted_daemon()) fail_msg_writer() << tr("You can't mine within the wallet. To mine, restart node like this: ./wownerod --start-mining YOUR-ADDRESS --spendkey SECRET-SPENDKEY");
{
fail_msg_writer() << tr("this command requires a trusted daemon. Enable with --trusted-daemon");
return true;
}
if (!try_connect_to_daemon())
return true;
if (!m_wallet)
{
fail_msg_writer() << tr("wallet is null");
return true;
}
COMMAND_RPC_START_MINING::request req = AUTO_VAL_INIT(req);
req.miner_address = m_wallet->get_account().get_public_address_str(m_wallet->nettype());
bool ok = true;
size_t arg_size = args.size();
if(arg_size >= 3)
{
if (!parse_bool_and_use(args[2], [&](bool r) { req.ignore_battery = r; }))
return true;
}
if(arg_size >= 2)
{
if (!parse_bool_and_use(args[1], [&](bool r) { req.do_background_mining = r; }))
return true;
}
if(arg_size >= 1)
{
uint16_t num = 1;
ok = string_tools::get_xtype_from_string(num, args[0]);
ok = ok && 1 <= num;
req.threads_count = num;
}
else
{
req.threads_count = 1;
}
if (!ok)
{
PRINT_USAGE(USAGE_START_MINING);
return true;
}
COMMAND_RPC_START_MINING::response res;
bool r = m_wallet->invoke_http_json("/start_mining", req, res);
std::string err = interpret_rpc_response(r, res.status);
if (err.empty())
success_msg_writer() << tr("Mining started in daemon");
else
fail_msg_writer() << tr("mining has NOT been started: ") << err;
return true; return true;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------