aboutsummaryrefslogtreecommitdiff
path: root/src/simplewallet
diff options
context:
space:
mode:
Diffstat (limited to 'src/simplewallet')
-rw-r--r--src/simplewallet/simplewallet.cpp316
1 files changed, 207 insertions, 109 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 397614328..16866a80d 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -90,8 +90,6 @@ typedef cryptonote::simple_wallet sw;
#define MIN_RING_SIZE 7 // Used to inform user about min ring size -- does not track actual protocol
-#define OUTPUT_EXPORT_FILE_MAGIC "Monero output export\003"
-
#define LOCK_IDLE_SCOPE() \
bool auto_refresh_enabled = m_auto_refresh_enabled.load(std::memory_order_relaxed); \
m_auto_refresh_enabled.store(false, std::memory_order_relaxed); \
@@ -381,21 +379,10 @@ namespace
boost::optional<std::pair<uint32_t, uint32_t>> parse_subaddress_lookahead(const std::string& str)
{
- auto pos = str.find(":");
- bool r = pos != std::string::npos;
- uint32_t major;
- r = r && epee::string_tools::get_xtype_from_string(major, str.substr(0, pos));
- uint32_t minor;
- r = r && epee::string_tools::get_xtype_from_string(minor, str.substr(pos + 1));
- if (r)
- {
- return std::make_pair(major, minor);
- }
- else
- {
+ auto r = tools::parse_subaddress_lookahead(str);
+ if (!r)
fail_msg_writer() << tr("invalid format for subaddress lookahead; must be <major>:<minor>");
- return {};
- }
+ return r;
}
void handle_transfer_exception(const std::exception_ptr &e, bool trusted_daemon)
@@ -508,7 +495,7 @@ namespace
}
if (warn_of_possible_attack)
- fail_msg_writer() << tr("There was an error, which could mean the node may be trying to get you to retry creating a transaction, and zero in on which outputs you own. Or it could be a bona fide error. It may be prudent to disconnect from this node, and not try to send a tranasction immediately. Alternatively, connect to another node so the original node cannot correlate information.");
+ fail_msg_writer() << tr("There was an error, which could mean the node may be trying to get you to retry creating a transaction, and zero in on which outputs you own. Or it could be a bona fide error. It may be prudent to disconnect from this node, and not try to send a transaction immediately. Alternatively, connect to another node so the original node cannot correlate information.");
}
bool check_file_overwrite(const std::string &filename)
@@ -1371,9 +1358,117 @@ bool simple_wallet::print_ring(const std::vector<std::string> &args)
bool simple_wallet::set_ring(const std::vector<std::string> &args)
{
crypto::key_image key_image;
+
+ // try filename first
+ if (args.size() == 1)
+ {
+ if (!epee::file_io_utils::is_file_exist(args[0]))
+ {
+ fail_msg_writer() << tr("File doesn't exist");
+ return true;
+ }
+
+ char str[4096];
+ std::unique_ptr<FILE, tools::close_file> f(fopen(args[0].c_str(), "r"));
+ if (f)
+ {
+ while (!feof(f.get()))
+ {
+ if (!fgets(str, sizeof(str), f.get()))
+ break;
+ const size_t len = strlen(str);
+ if (len > 0 && str[len - 1] == '\n')
+ str[len - 1] = 0;
+ if (!str[0])
+ continue;
+ char key_image_str[65], type_str[9];
+ int read_after_key_image = 0, read = 0;
+ int fields = sscanf(str, "%64[abcdefABCDEF0123456789] %n%8s %n", key_image_str, &read_after_key_image, type_str, &read);
+ if (fields != 2)
+ {
+ fail_msg_writer() << tr("Invalid ring specification: ") << str;
+ continue;
+ }
+ key_image_str[64] = 0;
+ type_str[8] = 0;
+ crypto::key_image key_image;
+ if (read_after_key_image == 0 || !epee::string_tools::hex_to_pod(key_image_str, key_image))
+ {
+ fail_msg_writer() << tr("Invalid key image: ") << str;
+ continue;
+ }
+ if (read == read_after_key_image+8 || (strcmp(type_str, "absolute") && strcmp(type_str, "relative")))
+ {
+ fail_msg_writer() << tr("Invalid ring type, expected relative or abosolute: ") << str;
+ continue;
+ }
+ bool relative = !strcmp(type_str, "relative");
+ if (read < 0 || (size_t)read > strlen(str))
+ {
+ fail_msg_writer() << tr("Error reading line: ") << str;
+ continue;
+ }
+ bool valid = true;
+ std::vector<uint64_t> ring;
+ const char *ptr = str + read;
+ while (*ptr)
+ {
+ unsigned long offset;
+ int elements = sscanf(ptr, "%lu %n", &offset, &read);
+ if (elements == 0 || read <= 0 || (size_t)read > strlen(str))
+ {
+ fail_msg_writer() << tr("Error reading line: ") << str;
+ valid = false;
+ break;
+ }
+ ring.push_back(offset);
+ ptr += read;
+ MGINFO("read offset: " << offset);
+ }
+ if (!valid)
+ continue;
+ if (ring.empty())
+ {
+ fail_msg_writer() << tr("Invalid ring: ") << str;
+ continue;
+ }
+ if (relative)
+ {
+ for (size_t n = 1; n < ring.size(); ++n)
+ {
+ if (ring[n] <= 0)
+ {
+ fail_msg_writer() << tr("Invalid relative ring: ") << str;
+ valid = false;
+ break;
+ }
+ }
+ }
+ else
+ {
+ for (size_t n = 1; n < ring.size(); ++n)
+ {
+ if (ring[n] <= ring[n-1])
+ {
+ fail_msg_writer() << tr("Invalid absolute ring: ") << str;
+ valid = false;
+ break;
+ }
+ }
+ }
+ if (!valid)
+ continue;
+ if (!m_wallet->set_ring(key_image, ring, relative))
+ fail_msg_writer() << tr("Failed to set ring for key image: ") << key_image << ". " << tr("Continuing.");
+ }
+ f.reset();
+ }
+ return true;
+ }
+
if (args.size() < 3)
{
- fail_msg_writer() << tr("usage: set_ring <key_image> absolute|relative <index> [<index>...]");
+ fail_msg_writer() << tr("usage: set_ring <filename> | ( <key_image> absolute|relative <index> [<index>...] )");
return true;
}
@@ -2028,7 +2123,7 @@ simple_wallet::simple_wallet()
tr("Stop mining in the daemon."));
m_cmd_binder.set_handler("set_daemon",
boost::bind(&simple_wallet::set_daemon, this, _1),
- tr("set_daemon <host>[:<port>]"),
+ tr("set_daemon <host>[:<port>] [trusted|untrusted]"),
tr("Set another daemon to connect to."));
m_cmd_binder.set_handler("save_bc",
boost::bind(&simple_wallet::save_bc, this, _1),
@@ -2082,8 +2177,8 @@ simple_wallet::simple_wallet()
tr("Donate <amount> to the development team (donate.getmonero.org)."));
m_cmd_binder.set_handler("sign_transfer",
boost::bind(&simple_wallet::sign_transfer, this, _1),
- tr("sign_transfer [export]"),
- tr("Sign a transaction from a file."));
+ tr("sign_transfer [export_raw]"),
+ tr("Sign a transaction from a file. If the parameter \"export_raw\" is specified, transaction raw hex data suitable for the daemon RPC /sendrawtransaction is exported."));
m_cmd_binder.set_handler("submit_transfer",
boost::bind(&simple_wallet::submit_transfer, this, _1),
tr("Submit a signed transaction from a file."));
@@ -2153,7 +2248,7 @@ simple_wallet::simple_wallet()
"refresh-type <full|optimize-coinbase|no-coinbase|default>\n "
" Set the wallet's refresh behaviour.\n "
"priority [0|1|2|3|4]\n "
- " Set the fee too default/unimportant/normal/elevated/priority.\n "
+ " Set the fee to default/unimportant/normal/elevated/priority.\n "
"confirm-missing-payment-id <1|0>\n "
"ask-password <1|0>\n "
"unit <monero|millinero|micronero|nanonero|piconero>\n "
@@ -2325,7 +2420,7 @@ simple_wallet::simple_wallet()
tr("Print the ring(s) used to spend a given key image or transaction (if the ring size is > 1)"));
m_cmd_binder.set_handler("set_ring",
boost::bind(&simple_wallet::set_ring, this, _1),
- tr("set_ring <key_image> absolute|relative <index> [<index>...]"),
+ tr("set_ring <filename> | ( <key_image> absolute|relative <index> [<index>...] )"),
tr("Set the ring used for a given key image, so it can be reused in a fork"));
m_cmd_binder.set_handler("save_known_rings",
boost::bind(&simple_wallet::save_known_rings, this, _1),
@@ -2451,8 +2546,24 @@ bool simple_wallet::set_log(const std::vector<std::string> &args)
fail_msg_writer() << tr("usage: set_log <log_level_number_0-4> | <categories>");
return true;
}
- if (!args.empty())
- mlog_set_log(args[0].c_str());
+ if(!args.empty())
+ {
+ uint16_t level = 0;
+ if(epee::string_tools::get_xtype_from_string(level, args[0]))
+ {
+ if(4 < level)
+ {
+ fail_msg_writer() << tr("wrong number range, use: set_log <log_level_number_0-4> | <categories>");
+ return true;
+ }
+ mlog_set_log_level(level);
+ }
+ else
+ {
+ mlog_set_log(args[0].c_str());
+ }
+ }
+
success_msg_writer() << "New log categories: " << mlog_get_categories();
return true;
}
@@ -3123,6 +3234,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
{
try
{
+ m_trusted_daemon = false;
if (tools::is_local_address(m_wallet->get_daemon_address()))
{
MINFO(tr("Daemon is local, assuming trusted"));
@@ -3685,7 +3797,6 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args)
req.miner_address = m_wallet->get_account().get_public_address_str(m_wallet->nettype());
bool ok = true;
- size_t max_mining_threads_count = (std::max)(tools::get_max_concurrency(), static_cast<unsigned>(2));
size_t arg_size = args.size();
if(arg_size >= 3)
{
@@ -3701,7 +3812,7 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args)
{
uint16_t num = 1;
ok = string_tools::get_xtype_from_string(num, args[0]);
- ok = ok && (1 <= num && num <= max_mining_threads_count);
+ ok = ok && 1 <= num;
req.threads_count = num;
}
else
@@ -3711,8 +3822,7 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args)
if (!ok)
{
- fail_msg_writer() << tr("invalid arguments. Please use start_mining [<number_of_threads>] [do_bg_mining] [ignore_battery], "
- "<number_of_threads> should be from 1 to ") << max_mining_threads_count;
+ fail_msg_writer() << tr("invalid arguments. Please use start_mining [<number_of_threads>] [do_bg_mining] [ignore_battery]");
return true;
}
@@ -3771,13 +3881,40 @@ bool simple_wallet::set_daemon(const std::vector<std::string>& args)
// If no port has been provided, use the default from config
if (!match[3].length())
{
- int daemon_port = m_wallet->nettype() == cryptonote::TESTNET ? config::testnet::RPC_DEFAULT_PORT : m_wallet->nettype() == cryptonote::STAGENET ? config::stagenet::RPC_DEFAULT_PORT : config::RPC_DEFAULT_PORT;
+ int daemon_port = get_config(m_wallet->nettype()).RPC_DEFAULT_PORT;
daemon_url = match[1] + match[2] + std::string(":") + std::to_string(daemon_port);
} else {
daemon_url = args[0];
}
LOCK_IDLE_SCOPE();
m_wallet->init(daemon_url);
+
+ if (args.size() == 2)
+ {
+ if (args[1] == "trusted")
+ m_trusted_daemon = true;
+ else if (args[1] == "untrusted")
+ m_trusted_daemon = false;
+ else
+ {
+ fail_msg_writer() << tr("Expected trusted or untrusted, got ") << args[1] << ": assuming untrusted";
+ m_trusted_daemon = false;
+ }
+ }
+ else
+ {
+ m_trusted_daemon = false;
+ try
+ {
+ if (tools::is_local_address(m_wallet->get_daemon_address()))
+ {
+ MINFO(tr("Daemon is local, assuming trusted"));
+ m_trusted_daemon = true;
+ }
+ }
+ catch (const std::exception &e) { }
+ }
+ success_msg_writer() << boost::format("Daemon set to %s, %s") % daemon_url % (*m_trusted_daemon ? tr("trusted") : tr("untrusted"));
} else {
fail_msg_writer() << tr("This does not seem to be a valid daemon URL.");
}
@@ -3869,7 +4006,7 @@ bool simple_wallet::refresh_main(uint64_t start_height, bool reset, bool is_init
{
m_in_manual_refresh.store(true, std::memory_order_relaxed);
epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){m_in_manual_refresh.store(false, std::memory_order_relaxed);});
- m_wallet->refresh(start_height, fetched_blocks);
+ m_wallet->refresh(is_daemon_trusted(), start_height, fetched_blocks);
ok = true;
// Clear line "Height xxx of xxx"
std::cout << "\r \r";
@@ -3941,6 +4078,8 @@ bool simple_wallet::show_balance_unlocked(bool detailed)
std::string extra;
if (m_wallet->has_multisig_partial_key_images())
extra = tr(" (Some owned outputs have partial key images - import_multisig_info needed)");
+ else if (m_wallet->has_unknown_key_images())
+ extra += tr(" (Some owned outputs have missing key images - import_key_images needed)");
success_msg_writer() << tr("Currently selected account: [") << m_current_subaddress_account << tr("] ") << m_wallet->get_subaddress_label({m_current_subaddress_account, 0});
const std::string tag = m_wallet->get_account_tags().second[m_current_subaddress_account];
success_msg_writer() << tr("Tag: ") << (tag.empty() ? std::string{tr("(No tag assigned)")} : tag);
@@ -4437,6 +4576,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
}
vector<cryptonote::tx_destination_entry> dsts;
+ size_t num_subaddresses = 0;
for (size_t i = 0; i < local_args.size(); i += 2)
{
cryptonote::address_parse_info info;
@@ -4448,6 +4588,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
}
de.addr = info.address;
de.is_subaddress = info.is_subaddress;
+ num_subaddresses += info.is_subaddress;
if (info.has_payment_id)
{
@@ -4480,7 +4621,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
}
// prompt is there is no payment id and confirmation is required
- if (!payment_id_seen && m_wallet->confirm_missing_payment_id())
+ if (!payment_id_seen && m_wallet->confirm_missing_payment_id() && dsts.size() > num_subaddresses)
{
std::string accepted = input_line(tr("No payment id is included with this transaction. Is this okay? (Y/Yes/N/No): "));
if (std::cin.eof())
@@ -4800,6 +4941,20 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
commit_or_save(ptx_vector, m_do_not_relay);
}
}
+ catch (const tools::error::not_enough_unlocked_money& e)
+ {
+ fail_msg_writer() << tr("Not enough money in unlocked balance");
+ std::string accepted = input_line((boost::format(tr("Discarding %s of unmixable outputs that cannot be spent, which can be undone by \"rescan_spent\". Is this okay? (Y/Yes/N/No): ")) % print_money(e.available())).str());
+ if (std::cin.eof())
+ return true;
+ if (command_line::is_yes(accepted))
+ {
+ try
+ {
+ m_wallet->discard_unmixable_outputs(is_daemon_trusted());
+ } catch (...) {}
+ }
+ }
catch (const std::exception &e)
{
handle_transfer_exception(std::current_exception(), is_daemon_trusted());
@@ -4933,7 +5088,7 @@ bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &a
}
// prompt is there is no payment id and confirmation is required
- if (!payment_id_seen && m_wallet->confirm_missing_payment_id())
+ if (!payment_id_seen && m_wallet->confirm_missing_payment_id() && !info.is_subaddress)
{
std::string accepted = input_line(tr("No payment id is included with this transaction. Is this okay? (Y/Yes/N/No): "));
if (std::cin.eof())
@@ -5146,7 +5301,7 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
}
// prompt if there is no payment id and confirmation is required
- if (!payment_id_seen && m_wallet->confirm_missing_payment_id())
+ if (!payment_id_seen && m_wallet->confirm_missing_payment_id() && !info.is_subaddress)
{
std::string accepted = input_line(tr("No payment id is included with this transaction. Is this okay? (Y/Yes/N/No): "));
if (std::cin.eof())
@@ -5299,7 +5454,7 @@ bool simple_wallet::donate(const std::vector<std::string> &args_)
local_args.push_back(amount_str);
if (!payment_id_str.empty())
local_args.push_back(payment_id_str);
- message_writer() << tr("Donating ") << amount_str << " to The Monero Project (donate.getmonero.org or "<< MONERO_DONATION_ADDR <<").";
+ message_writer() << (boost::format(tr("Donating %s %s to The Monero Project (donate.getmonero.org or %s).")) % amount_str % cryptonote::get_unit(cryptonote::get_default_decimal_point()) % MONERO_DONATION_ADDR).str();
transfer_new(local_args);
return true;
}
@@ -5469,9 +5624,9 @@ bool simple_wallet::sign_transfer(const std::vector<std::string> &args_)
fail_msg_writer() << tr("This is a watch only wallet");
return true;
}
- if (args_.size() > 1 || (args_.size() == 1 && args_[0] != "export"))
+ if (args_.size() > 1 || (args_.size() == 1 && args_[0] != "export_raw"))
{
- fail_msg_writer() << tr("usage: sign_transfer [export]");
+ fail_msg_writer() << tr("usage: sign_transfer [export_raw]");
return true;
}
if (m_wallet->ask_password() && !get_and_verify_password()) { return true; }
@@ -6016,10 +6171,7 @@ static std::string get_human_readable_timestamp(uint64_t ts)
#endif
uint64_t now = time(NULL);
uint64_t diff = ts > now ? ts - now : now - ts;
- if (diff > 24*3600)
- strftime(buffer, sizeof(buffer), "%Y-%m-%d", &tm);
- else
- strftime(buffer, sizeof(buffer), "%I:%M:%S %p", &tm);
+ strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &tm);
return std::string(buffer);
}
//----------------------------------------------------------------------------------------------------
@@ -6131,7 +6283,7 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
if (payment_id.substr(16).find_first_not_of('0') == std::string::npos)
payment_id = payment_id.substr(0,16);
std::string note = m_wallet->get_tx_note(pd.m_tx_hash);
- output.insert(std::make_pair(pd.m_block_height, std::make_pair(true, (boost::format("%16.16s %20.20s %s %s %d %s %s") % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount) % string_tools::pod_to_hex(pd.m_tx_hash) % payment_id % pd.m_subaddr_index.minor % "-" % note).str())));
+ output.insert(std::make_pair(pd.m_block_height, std::make_pair(true, (boost::format("%25.25s %20.20s %s %s %d %s %s") % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount) % string_tools::pod_to_hex(pd.m_tx_hash) % payment_id % pd.m_subaddr_index.minor % "-" % note).str())));
}
}
@@ -6164,7 +6316,7 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
if (payment_id.substr(16).find_first_not_of('0') == std::string::npos)
payment_id = payment_id.substr(0,16);
std::string note = m_wallet->get_tx_note(i->first);
- output.insert(std::make_pair(pd.m_block_height, std::make_pair(false, (boost::format("%16.16s %20.20s %s %s %14.14s %s %s - %s") % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount_in - change - fee) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee) % dests % print_subaddr_indices(pd.m_subaddr_indices) % note).str())));
+ output.insert(std::make_pair(pd.m_block_height, std::make_pair(false, (boost::format("%25.25s %20.20s %s %s %14.14s %s %s - %s") % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount_in - change - fee) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee) % dests % print_subaddr_indices(pd.m_subaddr_indices) % note).str())));
}
}
@@ -6190,7 +6342,7 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
std::string double_spend_note;
if (i->second.m_double_spend_seen)
double_spend_note = tr("[Double spend seen on the network: this transaction may or may not end up being mined] ");
- message_writer() << (boost::format("%8.8s %6.6s %16.16s %20.20s %s %s %d %s %s%s") % "pool" % "in" % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount) % string_tools::pod_to_hex(pd.m_tx_hash) % payment_id % pd.m_subaddr_index.minor % "-" % note % double_spend_note).str();
+ message_writer() << (boost::format("%8.8s %6.6s %25.25s %20.20s %s %s %d %s %s%s") % "pool" % "in" % get_human_readable_timestamp(pd.m_timestamp) % print_money(pd.m_amount) % string_tools::pod_to_hex(pd.m_tx_hash) % payment_id % pd.m_subaddr_index.minor % "-" % note % double_spend_note).str();
}
}
catch (const std::exception& e)
@@ -6213,7 +6365,7 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
std::string note = m_wallet->get_tx_note(i->first);
bool is_failed = pd.m_state == tools::wallet2::unconfirmed_transfer_details::failed;
if ((failed && is_failed) || (!is_failed && pending)) {
- message_writer() << (boost::format("%8.8s %6.6s %16.16s %20.20s %s %s %14.14s %s - %s") % (is_failed ? tr("failed") : tr("pending")) % tr("out") % get_human_readable_timestamp(pd.m_timestamp) % print_money(amount - pd.m_change - fee) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee) % print_subaddr_indices(pd.m_subaddr_indices) % note).str();
+ message_writer() << (boost::format("%8.8s %6.6s %25.25s %20.20s %s %s %14.14s %s - %s") % (is_failed ? tr("failed") : tr("pending")) % tr("out") % get_human_readable_timestamp(pd.m_timestamp) % print_money(amount - pd.m_change - fee) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee) % print_subaddr_indices(pd.m_subaddr_indices) % note).str();
}
}
}
@@ -6380,7 +6532,7 @@ void simple_wallet::wallet_idle_thread()
{
uint64_t fetched_blocks;
if (try_connect_to_daemon(true))
- m_wallet->refresh(0, fetched_blocks);
+ m_wallet->refresh(is_daemon_trusted(), 0, fetched_blocks);
}
catch(...) {}
m_auto_refresh_refreshing = false;
@@ -7182,19 +7334,8 @@ bool simple_wallet::export_outputs(const std::vector<std::string> &args)
LOCK_IDLE_SCOPE();
try
{
- std::vector<tools::wallet2::transfer_details> outs = m_wallet->export_outputs();
-
- std::stringstream oss;
- boost::archive::portable_binary_oarchive ar(oss);
- ar << outs;
-
- std::string magic(OUTPUT_EXPORT_FILE_MAGIC, strlen(OUTPUT_EXPORT_FILE_MAGIC));
- const cryptonote::account_public_address &keys = m_wallet->get_account().get_keys().m_account_address;
- std::string header;
- header += std::string((const char *)&keys.m_spend_public_key, sizeof(crypto::public_key));
- header += std::string((const char *)&keys.m_view_public_key, sizeof(crypto::public_key));
- std::string ciphertext = m_wallet->encrypt_with_view_secret_key(header + oss.str());
- bool r = epee::file_io_utils::save_string_to_file(filename, magic + ciphertext);
+ std::string data = m_wallet->export_outputs_to_str();
+ bool r = epee::file_io_utils::save_string_to_file(filename, data);
if (!r)
{
fail_msg_writer() << tr("failed to save file ") << filename;
@@ -7233,63 +7374,16 @@ bool simple_wallet::import_outputs(const std::vector<std::string> &args)
fail_msg_writer() << tr("failed to read file ") << filename;
return true;
}
- const size_t magiclen = strlen(OUTPUT_EXPORT_FILE_MAGIC);
- if (data.size() < magiclen || memcmp(data.data(), OUTPUT_EXPORT_FILE_MAGIC, magiclen))
- {
- fail_msg_writer() << "Bad output export file magic in " << filename;
- return true;
- }
-
- try
- {
- data = m_wallet->decrypt_with_view_secret_key(std::string(data, magiclen));
- }
- catch (const std::exception &e)
- {
- fail_msg_writer() << "Failed to decrypt " << filename << ": " << e.what();
- return true;
- }
-
- const size_t headerlen = 2 * sizeof(crypto::public_key);
- if (data.size() < headerlen)
- {
- fail_msg_writer() << "Bad data size from file " << filename;
- return true;
- }
- 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 cryptonote::account_public_address &keys = m_wallet->get_account().get_keys().m_account_address;
- if (public_spend_key != keys.m_spend_public_key || public_view_key != keys.m_view_public_key)
- {
- fail_msg_writer() << "Outputs from " << filename << " are for a different account";
- return true;
- }
try
{
- std::string body(data, headerlen);
- std::stringstream iss;
- iss << body;
- std::vector<tools::wallet2::transfer_details> outputs;
- try
- {
- boost::archive::portable_binary_iarchive ar(iss);
- ar >> outputs;
- }
- catch (...)
- {
- iss.str("");
- iss << body;
- boost::archive::binary_iarchive ar(iss);
- ar >> outputs;
- }
LOCK_IDLE_SCOPE();
- size_t n_outputs = m_wallet->import_outputs(outputs);
+ size_t n_outputs = m_wallet->import_outputs_from_str(data);
success_msg_writer() << boost::lexical_cast<std::string>(n_outputs) << " outputs imported";
}
catch (const std::exception &e)
{
- fail_msg_writer() << "Failed to import outputs: " << e.what();
+ fail_msg_writer() << "Failed to import outputs " << filename << ": " << e.what();
return true;
}
@@ -7331,8 +7425,12 @@ bool simple_wallet::show_transfer(const std::vector<std::string> &args)
if (pd.m_unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER)
{
uint64_t bh = std::max(pd.m_unlock_time, pd.m_block_height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE);
+ uint64_t last_block_reward = m_wallet->get_last_block_reward();
+ uint64_t suggested_threshold = last_block_reward ? (pd.m_amount + last_block_reward - 1) / last_block_reward : 0;
if (bh >= last_block_height)
success_msg_writer() << "Locked: " << (bh - last_block_height) << " blocks to unlock";
+ else if (suggested_threshold > 0)
+ success_msg_writer() << std::to_string(last_block_height - bh) << " confirmations (" << suggested_threshold << " suggested threshold)";
else
success_msg_writer() << std::to_string(last_block_height - bh) << " confirmations";
}
@@ -7529,7 +7627,7 @@ int main(int argc, char* argv[])
std::tie(vm, should_terminate) = wallet_args::main(
argc, argv,
"monero-wallet-cli [--wallet-file=<file>|--generate-new-wallet=<file>] [<COMMAND>]",
- sw::tr("This is the command line monero wallet. It needs to connect to a monero\ndaemon to work correctly.\nWARNING: Do not reuse your Monero keys on an another fork, UNLESS this fork has key reuse mitigations built in. Doing so will harm your privacy."),
+ sw::tr("This is the command line monero wallet. It needs to connect to a monero\ndaemon to work correctly.\nWARNING: Do not reuse your Monero keys on another fork, UNLESS this fork has key reuse mitigations built in. Doing so will harm your privacy."),
desc_params,
positional_options,
[](const std::string &s, bool emphasis){ tools::scoped_message_writer(emphasis ? epee::console_color_white : epee::console_color_default, true) << s; },