aboutsummaryrefslogtreecommitdiff
path: root/src/simplewallet/simplewallet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/simplewallet/simplewallet.cpp')
-rw-r--r--src/simplewallet/simplewallet.cpp154
1 files changed, 141 insertions, 13 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 0d27f8acc..234f071d1 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -1369,9 +1369,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;
}
@@ -2323,7 +2431,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),
@@ -2449,8 +2557,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;
}
@@ -6014,10 +6138,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);
}
//----------------------------------------------------------------------------------------------------
@@ -6129,7 +6250,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())));
}
}
@@ -6162,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(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())));
}
}
@@ -6188,7 +6309,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)
@@ -6211,7 +6332,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();
}
}
}
@@ -7464,7 +7585,9 @@ int main(int argc, char* argv[])
po::positional_options_description positional_options;
positional_options.add(arg_command.name, -1);
- const auto vm = wallet_args::main(
+ boost::optional<po::variables_map> vm;
+ bool should_terminate = false;
+ 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."),
@@ -7479,6 +7602,11 @@ int main(int argc, char* argv[])
return 1;
}
+ if (should_terminate)
+ {
+ return 0;
+ }
+
cryptonote::simple_wallet w;
const bool r = w.init(*vm);
CHECK_AND_ASSERT_MES(r, 1, sw::tr("Failed to initialize wallet"));