wallet: move some scoped_message_writer calls from the libs
This commit is contained in:
parent
e89994e98f
commit
437421ce42
|
@ -1501,7 +1501,15 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
||||||
else if (!m_generate_from_json.empty())
|
else if (!m_generate_from_json.empty())
|
||||||
{
|
{
|
||||||
m_wallet_file = m_generate_from_json;
|
m_wallet_file = m_generate_from_json;
|
||||||
m_wallet = tools::wallet2::make_from_json(vm, m_wallet_file, password_prompter);
|
try
|
||||||
|
{
|
||||||
|
m_wallet = tools::wallet2::make_from_json(vm, m_wallet_file, password_prompter);
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
fail_msg_writer() << e.what();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (!m_wallet)
|
if (!m_wallet)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -5702,6 +5710,7 @@ int main(int argc, char* argv[])
|
||||||
"monero-wallet-cli [--wallet-file=<file>|--generate-new-wallet=<file>] [<COMMAND>]",
|
"monero-wallet-cli [--wallet-file=<file>|--generate-new-wallet=<file>] [<COMMAND>]",
|
||||||
desc_params,
|
desc_params,
|
||||||
positional_options,
|
positional_options,
|
||||||
|
[](const std::string &s, bool emphasis){ tools::scoped_message_writer(emphasis ? epee::console_color_white : epee::console_color_default, true) << s; },
|
||||||
"monero-wallet-cli.log"
|
"monero-wallet-cli.log"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -144,11 +144,8 @@ std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variabl
|
||||||
auto daemon_host = command_line::get_arg(vm, opts.daemon_host);
|
auto daemon_host = command_line::get_arg(vm, opts.daemon_host);
|
||||||
auto daemon_port = command_line::get_arg(vm, opts.daemon_port);
|
auto daemon_port = command_line::get_arg(vm, opts.daemon_port);
|
||||||
|
|
||||||
if (!daemon_address.empty() && !daemon_host.empty() && 0 != daemon_port)
|
THROW_WALLET_EXCEPTION_IF(!daemon_address.empty() && !daemon_host.empty() && 0 != daemon_port,
|
||||||
{
|
tools::error::wallet_internal_error, tools::wallet2::tr("can't specify daemon host or port more than once"));
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("can't specify daemon host or port more than once");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::optional<epee::net_utils::http::login> login{};
|
boost::optional<epee::net_utils::http::login> login{};
|
||||||
if (command_line::has_arg(vm, opts.daemon_login))
|
if (command_line::has_arg(vm, opts.daemon_login))
|
||||||
|
@ -184,8 +181,7 @@ boost::optional<tools::password_container> get_password(const boost::program_opt
|
||||||
{
|
{
|
||||||
if (command_line::has_arg(vm, opts.password) && command_line::has_arg(vm, opts.password_file))
|
if (command_line::has_arg(vm, opts.password) && command_line::has_arg(vm, opts.password_file))
|
||||||
{
|
{
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("can't specify more than one of --password and --password-file");
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("can't specify more than one of --password and --password-file"));
|
||||||
return boost::none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command_line::has_arg(vm, opts.password))
|
if (command_line::has_arg(vm, opts.password))
|
||||||
|
@ -198,11 +194,7 @@ boost::optional<tools::password_container> get_password(const boost::program_opt
|
||||||
std::string password;
|
std::string password;
|
||||||
bool r = epee::file_io_utils::load_file_to_string(command_line::get_arg(vm, opts.password_file),
|
bool r = epee::file_io_utils::load_file_to_string(command_line::get_arg(vm, opts.password_file),
|
||||||
password);
|
password);
|
||||||
if (!r)
|
THROW_WALLET_EXCEPTION_IF(!r, tools::error::wallet_internal_error, tools::wallet2::tr("the password file specified could not be read"));
|
||||||
{
|
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("the password file specified could not be read");
|
|
||||||
return boost::none;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove line breaks the user might have inserted
|
// Remove line breaks the user might have inserted
|
||||||
boost::trim_right_if(password, boost::is_any_of("\r\n"));
|
boost::trim_right_if(password, boost::is_any_of("\r\n"));
|
||||||
|
@ -223,22 +215,20 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
|
||||||
const auto do_generate = [&]() -> bool {
|
const auto do_generate = [&]() -> bool {
|
||||||
std::string buf;
|
std::string buf;
|
||||||
if (!epee::file_io_utils::load_file_to_string(json_file, buf)) {
|
if (!epee::file_io_utils::load_file_to_string(json_file, buf)) {
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("Failed to load file ") << json_file;
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, std::string(tools::wallet2::tr("Failed to load file ")) + json_file);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
rapidjson::Document json;
|
rapidjson::Document json;
|
||||||
if (json.Parse(buf.c_str()).HasParseError()) {
|
if (json.Parse(buf.c_str()).HasParseError()) {
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("Failed to parse JSON");
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("Failed to parse JSON"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, version, unsigned, Uint, true, 0);
|
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, version, unsigned, Uint, true, 0);
|
||||||
const int current_version = 1;
|
const int current_version = 1;
|
||||||
if (field_version > current_version) {
|
THROW_WALLET_EXCEPTION_IF(field_version > current_version, tools::error::wallet_internal_error,
|
||||||
tools::fail_msg_writer() << boost::format(tools::wallet2::tr("Version %u too new, we can only grok up to %u")) % field_version % current_version;
|
((boost::format(tools::wallet2::tr("Version %u too new, we can only grok up to %u")) % field_version % current_version)).str());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, filename, std::string, String, true, std::string());
|
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, filename, std::string, String, true, std::string());
|
||||||
|
|
||||||
|
@ -254,14 +244,12 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
|
||||||
cryptonote::blobdata viewkey_data;
|
cryptonote::blobdata viewkey_data;
|
||||||
if(!epee::string_tools::parse_hexstr_to_binbuff(field_viewkey, viewkey_data) || viewkey_data.size() != sizeof(crypto::secret_key))
|
if(!epee::string_tools::parse_hexstr_to_binbuff(field_viewkey, viewkey_data) || viewkey_data.size() != sizeof(crypto::secret_key))
|
||||||
{
|
{
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("failed to parse view key secret key");
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to parse view key secret key"));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
viewkey = *reinterpret_cast<const crypto::secret_key*>(viewkey_data.data());
|
viewkey = *reinterpret_cast<const crypto::secret_key*>(viewkey_data.data());
|
||||||
crypto::public_key pkey;
|
crypto::public_key pkey;
|
||||||
if (!crypto::secret_key_to_public_key(viewkey, pkey)) {
|
if (!crypto::secret_key_to_public_key(viewkey, pkey)) {
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("failed to verify view key secret key");
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to verify view key secret key"));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,14 +260,12 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
|
||||||
cryptonote::blobdata spendkey_data;
|
cryptonote::blobdata spendkey_data;
|
||||||
if(!epee::string_tools::parse_hexstr_to_binbuff(field_spendkey, spendkey_data) || spendkey_data.size() != sizeof(crypto::secret_key))
|
if(!epee::string_tools::parse_hexstr_to_binbuff(field_spendkey, spendkey_data) || spendkey_data.size() != sizeof(crypto::secret_key))
|
||||||
{
|
{
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("failed to parse spend key secret key");
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to parse spend key secret key"));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
spendkey = *reinterpret_cast<const crypto::secret_key*>(spendkey_data.data());
|
spendkey = *reinterpret_cast<const crypto::secret_key*>(spendkey_data.data());
|
||||||
crypto::public_key pkey;
|
crypto::public_key pkey;
|
||||||
if (!crypto::secret_key_to_public_key(spendkey, pkey)) {
|
if (!crypto::secret_key_to_public_key(spendkey, pkey)) {
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("failed to verify spend key secret key");
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to verify spend key secret key"));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,8 +277,7 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
|
||||||
{
|
{
|
||||||
if (!crypto::ElectrumWords::words_to_bytes(field_seed, recovery_key, old_language))
|
if (!crypto::ElectrumWords::words_to_bytes(field_seed, recovery_key, old_language))
|
||||||
{
|
{
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("Electrum-style word list failed verification");
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("Electrum-style word list failed verification"));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
restore_deterministic_wallet = true;
|
restore_deterministic_wallet = true;
|
||||||
|
|
||||||
|
@ -309,13 +294,11 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
|
||||||
// compatibility checks
|
// compatibility checks
|
||||||
if (!field_seed_found && !field_viewkey_found && !field_spendkey_found)
|
if (!field_seed_found && !field_viewkey_found && !field_spendkey_found)
|
||||||
{
|
{
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("At least one of Electrum-style word list and private view key and private spend key must be specified");
|
THROW_WALLET_EXCEPTION(tools::wallet2::tr("At least one of Electrum-style word list and private view key and private spend key must be specified"));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (field_seed_found && (field_viewkey_found || field_spendkey_found))
|
if (field_seed_found && (field_viewkey_found || field_spendkey_found))
|
||||||
{
|
{
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("Both Electrum-style word list and private key(s) specified");
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("Both Electrum-style word list and private key(s) specified"));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if an address was given, we check keys against it, and deduce the spend
|
// if an address was given, we check keys against it, and deduce the spend
|
||||||
|
@ -325,41 +308,34 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
|
||||||
cryptonote::address_parse_info info;
|
cryptonote::address_parse_info info;
|
||||||
if(!get_account_address_from_str(info, testnet, field_address))
|
if(!get_account_address_from_str(info, testnet, field_address))
|
||||||
{
|
{
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("invalid address");
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("invalid address"));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (field_viewkey_found)
|
if (field_viewkey_found)
|
||||||
{
|
{
|
||||||
crypto::public_key pkey;
|
crypto::public_key pkey;
|
||||||
if (!crypto::secret_key_to_public_key(viewkey, pkey)) {
|
if (!crypto::secret_key_to_public_key(viewkey, pkey)) {
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("failed to verify view key secret key");
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to verify view key secret key"));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (info.address.m_view_public_key != pkey) {
|
if (info.address.m_view_public_key != pkey) {
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("view key does not match standard address");
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("view key does not match standard address"));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (field_spendkey_found)
|
if (field_spendkey_found)
|
||||||
{
|
{
|
||||||
crypto::public_key pkey;
|
crypto::public_key pkey;
|
||||||
if (!crypto::secret_key_to_public_key(spendkey, pkey)) {
|
if (!crypto::secret_key_to_public_key(spendkey, pkey)) {
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("failed to verify spend key secret key");
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to verify spend key secret key"));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (info.address.m_spend_public_key != pkey) {
|
if (info.address.m_spend_public_key != pkey) {
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("spend key does not match standard address");
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("spend key does not match standard address"));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool deprecated_wallet = restore_deterministic_wallet && ((old_language == crypto::ElectrumWords::old_language_name) ||
|
const bool deprecated_wallet = restore_deterministic_wallet && ((old_language == crypto::ElectrumWords::old_language_name) ||
|
||||||
crypto::ElectrumWords::get_is_old_style_seed(field_seed));
|
crypto::ElectrumWords::get_is_old_style_seed(field_seed));
|
||||||
if (deprecated_wallet) {
|
THROW_WALLET_EXCEPTION_IF(deprecated_wallet, tools::error::wallet_internal_error,
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("Cannot create deprecated wallets from JSON");
|
tools::wallet2::tr("Cannot create deprecated wallets from JSON"));
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
wallet.reset(make_basic(vm, opts, password_prompter).release());
|
wallet.reset(make_basic(vm, opts, password_prompter).release());
|
||||||
wallet->set_refresh_from_block_height(field_scan_from_height);
|
wallet->set_refresh_from_block_height(field_scan_from_height);
|
||||||
|
@ -378,8 +354,7 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
|
||||||
{
|
{
|
||||||
cryptonote::account_public_address address;
|
cryptonote::account_public_address address;
|
||||||
if (!crypto::secret_key_to_public_key(viewkey, address.m_view_public_key)) {
|
if (!crypto::secret_key_to_public_key(viewkey, address.m_view_public_key)) {
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("failed to verify view key secret key");
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to verify view key secret key"));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field_spendkey.empty())
|
if (field_spendkey.empty())
|
||||||
|
@ -391,8 +366,7 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
|
||||||
cryptonote::address_parse_info info;
|
cryptonote::address_parse_info info;
|
||||||
if(!get_account_address_from_str(info, testnet, field_address))
|
if(!get_account_address_from_str(info, testnet, field_address))
|
||||||
{
|
{
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("failed to parse address: ") << field_address;
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, std::string(tools::wallet2::tr("failed to parse address: ")) + field_address);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
address.m_spend_public_key = info.address.m_spend_public_key;
|
address.m_spend_public_key = info.address.m_spend_public_key;
|
||||||
}
|
}
|
||||||
|
@ -406,8 +380,7 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!crypto::secret_key_to_public_key(spendkey, address.m_spend_public_key)) {
|
if (!crypto::secret_key_to_public_key(spendkey, address.m_spend_public_key)) {
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("failed to verify spend key secret key");
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to verify spend key secret key"));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
wallet->generate(field_filename, field_password, address, spendkey, viewkey);
|
wallet->generate(field_filename, field_password, address, spendkey, viewkey);
|
||||||
}
|
}
|
||||||
|
@ -415,8 +388,7 @@ std::unique_ptr<tools::wallet2> generate_from_json(const std::string& json_file,
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
tools::fail_msg_writer() << tools::wallet2::tr("failed to generate new wallet: ") << e.what();
|
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, std::string(tools::wallet2::tr("failed to generate new wallet: ")) + e.what());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -6513,16 +6485,12 @@ uint64_t wallet2::import_key_images(const std::string &filename, uint64_t &spent
|
||||||
std::string data;
|
std::string data;
|
||||||
bool r = epee::file_io_utils::load_file_to_string(filename, data);
|
bool r = epee::file_io_utils::load_file_to_string(filename, data);
|
||||||
|
|
||||||
if (!r)
|
THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, std::string(tr("failed to read file ")) + filename);
|
||||||
{
|
|
||||||
fail_msg_writer() << tr("failed to read file ") << filename;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
const size_t magiclen = strlen(KEY_IMAGE_EXPORT_FILE_MAGIC);
|
const size_t magiclen = strlen(KEY_IMAGE_EXPORT_FILE_MAGIC);
|
||||||
if (data.size() < magiclen || memcmp(data.data(), KEY_IMAGE_EXPORT_FILE_MAGIC, magiclen))
|
if (data.size() < magiclen || memcmp(data.data(), KEY_IMAGE_EXPORT_FILE_MAGIC, magiclen))
|
||||||
{
|
{
|
||||||
fail_msg_writer() << "Bad key image export file magic in " << filename;
|
THROW_WALLET_EXCEPTION(error::wallet_internal_error, std::string("Bad key image export file magic in ") + filename);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -6531,31 +6499,22 @@ uint64_t wallet2::import_key_images(const std::string &filename, uint64_t &spent
|
||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
fail_msg_writer() << "Failed to decrypt " << filename << ": " << e.what();
|
THROW_WALLET_EXCEPTION(error::wallet_internal_error, std::string("Failed to decrypt ") + filename + ": " + e.what());
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t headerlen = 2 * sizeof(crypto::public_key);
|
const size_t headerlen = 2 * sizeof(crypto::public_key);
|
||||||
if (data.size() < headerlen)
|
THROW_WALLET_EXCEPTION_IF(data.size() < headerlen, error::wallet_internal_error, std::string("Bad data size from file ") + filename);
|
||||||
{
|
|
||||||
fail_msg_writer() << "Bad data size from file " << filename;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
const crypto::public_key &public_spend_key = *(const crypto::public_key*)&data[0];
|
const crypto::public_key &public_spend_key = *(const crypto::public_key*)&data[0];
|
||||||
const crypto::public_key &public_view_key = *(const crypto::public_key*)&data[sizeof(crypto::public_key)];
|
const crypto::public_key &public_view_key = *(const crypto::public_key*)&data[sizeof(crypto::public_key)];
|
||||||
const cryptonote::account_public_address &keys = get_account().get_keys().m_account_address;
|
const cryptonote::account_public_address &keys = get_account().get_keys().m_account_address;
|
||||||
if (public_spend_key != keys.m_spend_public_key || public_view_key != keys.m_view_public_key)
|
if (public_spend_key != keys.m_spend_public_key || public_view_key != keys.m_view_public_key)
|
||||||
{
|
{
|
||||||
fail_msg_writer() << "Key images from " << filename << " are for a different account";
|
THROW_WALLET_EXCEPTION(error::wallet_internal_error, std::string( "Key images from ") + filename + " are for a different account");
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t record_size = sizeof(crypto::key_image) + sizeof(crypto::signature);
|
const size_t record_size = sizeof(crypto::key_image) + sizeof(crypto::signature);
|
||||||
if ((data.size() - headerlen) % record_size)
|
THROW_WALLET_EXCEPTION_IF((data.size() - headerlen) % record_size,
|
||||||
{
|
error::wallet_internal_error, std::string("Bad data size from file ") + filename);
|
||||||
fail_msg_writer() << "Bad data size from file " << filename;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
size_t nki = (data.size() - headerlen) / record_size;
|
size_t nki = (data.size() - headerlen) / record_size;
|
||||||
|
|
||||||
std::vector<std::pair<crypto::key_image, crypto::signature>> ski;
|
std::vector<std::pair<crypto::key_image, crypto::signature>> ski;
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
#include "common/i18n.h"
|
#include "common/i18n.h"
|
||||||
#include "common/scoped_message_writer.h"
|
|
||||||
#include "common/util.h"
|
#include "common/util.h"
|
||||||
#include "misc_log_ex.h"
|
#include "misc_log_ex.h"
|
||||||
#include "string_tools.h"
|
#include "string_tools.h"
|
||||||
|
@ -50,6 +49,20 @@
|
||||||
#define DEFAULT_MAX_CONCURRENCY 0
|
#define DEFAULT_MAX_CONCURRENCY 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
class Print
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Print(const std::function<void(const std::string&, bool)> &p, bool em = false): print(p), emphasis(em) {}
|
||||||
|
~Print() { print(ss.str(), emphasis); }
|
||||||
|
template<typename T> std::ostream &operator<<(const T &t) { ss << t; return ss; }
|
||||||
|
private:
|
||||||
|
const std::function<void(const std::string&, bool)> &print;
|
||||||
|
std::stringstream ss;
|
||||||
|
bool emphasis;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
namespace wallet_args
|
namespace wallet_args
|
||||||
{
|
{
|
||||||
|
@ -73,6 +86,7 @@ namespace wallet_args
|
||||||
const char* const usage,
|
const char* const usage,
|
||||||
boost::program_options::options_description desc_params,
|
boost::program_options::options_description desc_params,
|
||||||
const boost::program_options::positional_options_description& positional_options,
|
const boost::program_options::positional_options_description& positional_options,
|
||||||
|
const std::function<void(const std::string&, bool)> &print,
|
||||||
const char *default_log_name,
|
const char *default_log_name,
|
||||||
bool log_to_console)
|
bool log_to_console)
|
||||||
|
|
||||||
|
@ -118,16 +132,16 @@ namespace wallet_args
|
||||||
|
|
||||||
if (command_line::get_arg(vm, command_line::arg_help))
|
if (command_line::get_arg(vm, command_line::arg_help))
|
||||||
{
|
{
|
||||||
tools::msg_writer() << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")" << ENDL;
|
Print(print) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")" << ENDL;
|
||||||
tools::msg_writer() << wallet_args::tr("This is the command line monero wallet. It needs to connect to a monero\n"
|
Print(print) << wallet_args::tr("This is the command line monero wallet. It needs to connect to a monero\n"
|
||||||
"daemon to work correctly.") << ENDL;
|
"daemon to work correctly.") << ENDL;
|
||||||
tools::msg_writer() << wallet_args::tr("Usage:") << ENDL << " " << usage;
|
Print(print) << wallet_args::tr("Usage:") << ENDL << " " << usage;
|
||||||
tools::msg_writer() << desc_all;
|
Print(print) << desc_all;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (command_line::get_arg(vm, command_line::arg_version))
|
else if (command_line::get_arg(vm, command_line::arg_version))
|
||||||
{
|
{
|
||||||
tools::msg_writer() << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
|
Print(print) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +156,7 @@ namespace wallet_args
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tools::fail_msg_writer() << wallet_args::tr("Can't find config file ") << config;
|
MERROR(wallet_args::tr("Can't find config file ") << config);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,14 +181,15 @@ namespace wallet_args
|
||||||
if(command_line::has_arg(vm, arg_max_concurrency))
|
if(command_line::has_arg(vm, arg_max_concurrency))
|
||||||
tools::set_max_concurrency(command_line::get_arg(vm, arg_max_concurrency));
|
tools::set_max_concurrency(command_line::get_arg(vm, arg_max_concurrency));
|
||||||
|
|
||||||
tools::scoped_message_writer(epee::console_color_white, true) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
|
Print(print) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
|
||||||
|
|
||||||
if (!command_line::is_arg_defaulted(vm, arg_log_level))
|
if (!command_line::is_arg_defaulted(vm, arg_log_level))
|
||||||
MINFO("Setting log level = " << command_line::get_arg(vm, arg_log_level));
|
MINFO("Setting log level = " << command_line::get_arg(vm, arg_log_level));
|
||||||
else
|
else
|
||||||
MINFO("Setting log levels = " << getenv("MONERO_LOGS"));
|
MINFO("Setting log levels = " << getenv("MONERO_LOGS"));
|
||||||
MINFO(wallet_args::tr("Logging to: ") << log_path);
|
MINFO(wallet_args::tr("Logging to: ") << log_path);
|
||||||
tools::scoped_message_writer(epee::console_color_white, true) << boost::format(wallet_args::tr("Logging to %s")) % log_path;
|
|
||||||
|
Print(print) << boost::format(wallet_args::tr("Logging to %s")) % log_path;
|
||||||
|
|
||||||
return {std::move(vm)};
|
return {std::move(vm)};
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,5 +50,6 @@ namespace wallet_args
|
||||||
const char* const usage,
|
const char* const usage,
|
||||||
boost::program_options::options_description desc_params,
|
boost::program_options::options_description desc_params,
|
||||||
const boost::program_options::positional_options_description& positional_options,
|
const boost::program_options::positional_options_description& positional_options,
|
||||||
|
const std::function<void(const std::string&, bool)> &print,
|
||||||
const char *default_log_name, bool log_to_console = false);
|
const char *default_log_name, bool log_to_console = false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -765,6 +765,12 @@ namespace tools
|
||||||
#define STRINGIZE_DETAIL(x) #x
|
#define STRINGIZE_DETAIL(x) #x
|
||||||
#define STRINGIZE(x) STRINGIZE_DETAIL(x)
|
#define STRINGIZE(x) STRINGIZE_DETAIL(x)
|
||||||
|
|
||||||
|
#define THROW_WALLET_EXCEPTION(err_type, ...) \
|
||||||
|
do { \
|
||||||
|
LOG_ERROR("THROW EXCEPTION: " << #err_type); \
|
||||||
|
tools::error::throw_wallet_ex<err_type>(std::string(__FILE__ ":" STRINGIZE(__LINE__)), ## __VA_ARGS__); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#define THROW_WALLET_EXCEPTION_IF(cond, err_type, ...) \
|
#define THROW_WALLET_EXCEPTION_IF(cond, err_type, ...) \
|
||||||
if (cond) \
|
if (cond) \
|
||||||
{ \
|
{ \
|
||||||
|
|
|
@ -38,6 +38,7 @@ using namespace epee;
|
||||||
#include "wallet/wallet_args.h"
|
#include "wallet/wallet_args.h"
|
||||||
#include "common/command_line.h"
|
#include "common/command_line.h"
|
||||||
#include "common/i18n.h"
|
#include "common/i18n.h"
|
||||||
|
#include "common/scoped_message_writer.h"
|
||||||
#include "cryptonote_basic/cryptonote_format_utils.h"
|
#include "cryptonote_basic/cryptonote_format_utils.h"
|
||||||
#include "cryptonote_basic/account.h"
|
#include "cryptonote_basic/account.h"
|
||||||
#include "wallet_rpc_server_commands_defs.h"
|
#include "wallet_rpc_server_commands_defs.h"
|
||||||
|
@ -1981,6 +1982,7 @@ int main(int argc, char** argv) {
|
||||||
"monero-wallet-rpc [--wallet-file=<file>|--generate-from-json=<file>|--wallet-dir=<directory>] [--rpc-bind-port=<port>]",
|
"monero-wallet-rpc [--wallet-file=<file>|--generate-from-json=<file>|--wallet-dir=<directory>] [--rpc-bind-port=<port>]",
|
||||||
desc_params,
|
desc_params,
|
||||||
po::positional_options_description(),
|
po::positional_options_description(),
|
||||||
|
[](const std::string &s, bool emphasis){ tools::scoped_message_writer(emphasis ? epee::console_color_white : epee::console_color_default, true) << s; },
|
||||||
"monero-wallet-rpc.log",
|
"monero-wallet-rpc.log",
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
@ -2021,7 +2023,15 @@ int main(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wal = tools::wallet2::make_from_json(*vm, from_json, password_prompter);
|
try
|
||||||
|
{
|
||||||
|
wal = tools::wallet2::make_from_json(*vm, from_json, password_prompter);
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
MERROR("Error creating wallet: " << e.what());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!wal)
|
if (!wal)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue