Merge pull request 'wallet stuff' (#408) from wowario/wownero:wallet into master
Reviewed-on: https://git.wownero.com/wownero/wownero/pulls/408
This commit is contained in:
commit
d30de97e5e
|
@ -368,110 +368,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 << "Invalid syntax: At least one parameter expected. For more details, use the help command." << 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 << "Invalid syntax: Target account address has wrong format. For more details, use the help command." << 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)
|
|
||||||
{
|
|
||||||
std::cout << "Invalid syntax: Too many parameters. For more details, use the help command." << std::endl;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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")
|
|
||||||
{
|
|
||||||
std::cout << "Invalid syntax: Invalid combination of parameters. For more details, use the help command." << std::endl;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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")
|
|
||||||
{
|
|
||||||
std::cout << "Invalid syntax: Invalid combination of parameters. For more details, use the help command." << std::endl;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3186,6 +3186,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.");
|
||||||
|
@ -4766,9 +4767,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.");
|
||||||
|
@ -5342,34 +5340,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()
|
||||||
|
@ -5462,60 +5433,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;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -8672,12 +8672,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
|
||||||
const uint64_t amount = td.is_rct() ? 0 : td.amount();
|
const uint64_t amount = td.is_rct() ? 0 : td.amount();
|
||||||
std::unordered_set<uint64_t> seen_indices;
|
std::unordered_set<uint64_t> seen_indices;
|
||||||
// request more for rct in base recent (locked) coinbases are picked, since they're locked for longer
|
// request more for rct in base recent (locked) coinbases are picked, since they're locked for longer
|
||||||
uint64_t approx_blockchain_height = m_nettype == TESTNET ? 0 : (time(NULL) - 1522624244)/311;
|
size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2 - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE : 0);
|
||||||
uint64_t unlock_height = td.m_block_height + std::max<uint64_t>(CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE, CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS);
|
|
||||||
if (td.m_tx.unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER && td.m_tx.unlock_time > unlock_height)
|
|
||||||
unlock_height = td.m_tx.unlock_time;
|
|
||||||
uint64_t blocks_to_unlock = unlock_height > approx_blockchain_height ? unlock_height - approx_blockchain_height : 0;
|
|
||||||
size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? blocks_to_unlock - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE : 0) + 288;
|
|
||||||
size_t start = req.outputs.size();
|
size_t start = req.outputs.size();
|
||||||
bool use_histogram = amount != 0 || !has_rct_distribution;
|
bool use_histogram = amount != 0 || !has_rct_distribution;
|
||||||
|
|
||||||
|
@ -8993,12 +8988,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
|
||||||
for(size_t idx: selected_transfers)
|
for(size_t idx: selected_transfers)
|
||||||
{
|
{
|
||||||
const transfer_details &td = m_transfers[idx];
|
const transfer_details &td = m_transfers[idx];
|
||||||
uint64_t approx_blockchain_height = m_nettype == TESTNET ? 0 : (time(NULL) - 1522624244)/311;
|
size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2 - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE : 0);
|
||||||
uint64_t unlock_height = td.m_block_height + std::max<uint64_t>(CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE, CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS);
|
|
||||||
if (td.m_tx.unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER && td.m_tx.unlock_time > unlock_height)
|
|
||||||
unlock_height = td.m_tx.unlock_time;
|
|
||||||
uint64_t blocks_to_unlock = unlock_height > approx_blockchain_height ? unlock_height - approx_blockchain_height : 0;
|
|
||||||
size_t requested_outputs_count = base_requested_outputs_count + (td.is_rct() ? blocks_to_unlock - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE : 0) + 288;
|
|
||||||
outs.push_back(std::vector<get_outs_entry>());
|
outs.push_back(std::vector<get_outs_entry>());
|
||||||
outs.back().reserve(fake_outputs_count + 1);
|
outs.back().reserve(fake_outputs_count + 1);
|
||||||
const rct::key mask = td.is_rct() ? rct::commit(td.amount(), td.m_mask) : rct::zeroCommit(td.amount());
|
const rct::key mask = td.is_rct() ? rct::commit(td.amount(), td.m_mask) : rct::zeroCommit(td.amount());
|
||||||
|
|
Loading…
Reference in New Issue