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.cpp108
1 files changed, 95 insertions, 13 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 08f0a20f4..69f7aebab 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -1423,7 +1423,6 @@ bool simple_wallet::set_ring(const std::vector<std::string> &args)
}
ring.push_back(offset);
ptr += read;
- MGINFO("read offset: " << offset);
}
if (!valid)
continue;
@@ -1826,6 +1825,7 @@ bool simple_wallet::set_auto_refresh(const std::vector<std::string> &args/* = st
if (pwd_container)
{
parse_bool_and_use(args[1], [&](bool auto_refresh) {
+ m_auto_refresh_enabled.store(false, std::memory_order_relaxed);
m_wallet->auto_refresh(auto_refresh);
m_idle_mutex.lock();
m_auto_refresh_enabled.store(auto_refresh, std::memory_order_relaxed);
@@ -2092,6 +2092,19 @@ bool simple_wallet::set_segregation_height(const std::vector<std::string> &args/
return true;
}
+bool simple_wallet::set_ignore_fractional_outputs(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
+{
+ const auto pwd_container = get_and_verify_password();
+ if (pwd_container)
+ {
+ parse_bool_and_use(args[1], [&](bool r) {
+ m_wallet->ignore_fractional_outputs(r);
+ m_wallet->rewrite(m_wallet_file, pwd_container->password());
+ });
+ }
+ return true;
+}
+
bool simple_wallet::help(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
if(args.empty())
@@ -2157,6 +2170,10 @@ simple_wallet::simple_wallet()
boost::bind(&simple_wallet::locked_transfer, this, _1),
tr("locked_transfer [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] <addr> <amount> <lockblocks> [<payment_id>]"),
tr("Transfer <amount> to <address> and lock it for <lockblocks> (max. 1000000). If the parameter \"index=<N1>[,<N2>,...]\" is specified, the wallet uses outputs received by addresses of those indices. If omitted, the wallet randomly chooses address indices to be used. In any case, it tries its best not to combine outputs across multiple addresses. <priority> is the priority of the transaction. The higher the priority, the higher the transaction fee. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \"set priority\") is used. <ring_size> is the number of inputs to include for untraceability. Multiple payments can be made at once by adding <address_2> <amount_2> etcetera (before the payment ID, if it's included)"));
+ m_cmd_binder.set_handler("locked_sweep_all",
+ boost::bind(&simple_wallet::locked_sweep_all, this, _1),
+ tr("locked_sweep_all [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] <address> <lockblocks> [<payment_id>]"),
+ tr("Send all unlocked balance to an address and lock it for <lockblocks> (max. 1000000). If the parameter \"index<N1>[,<N2>,...]\" is specified, the wallet sweeps outputs received by those address indices. If omitted, the wallet randomly chooses an address index to be used. <priority> is the priority of the sweep. The higher the priority, the higher the transaction fee. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \"set priority\") is used. <ring_size> is the number of inputs to include for untraceability."));
m_cmd_binder.set_handler("sweep_unmixable",
boost::bind(&simple_wallet::sweep_unmixable, this, _1),
tr("Send all unmixable outputs to yourself with ring_size 1"));
@@ -2479,6 +2496,7 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
const std::pair<size_t, size_t> lookahead = m_wallet->get_subaddress_lookahead();
success_msg_writer() << "subaddress-lookahead = " << lookahead.first << ":" << lookahead.second;
success_msg_writer() << "segregation-height = " << m_wallet->segregation_height();
+ success_msg_writer() << "ignore-fractional-outputs = " << m_wallet->ignore_fractional_outputs();
return true;
}
else
@@ -2533,6 +2551,7 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
CHECK_SIMPLE_VARIABLE("key-reuse-mitigation2", set_key_reuse_mitigation2, tr("0 or 1"));
CHECK_SIMPLE_VARIABLE("subaddress-lookahead", set_subaddress_lookahead, tr("<major>:<minor>"));
CHECK_SIMPLE_VARIABLE("segregation-height", set_segregation_height, tr("unsigned integer"));
+ CHECK_SIMPLE_VARIABLE("ignore-fractional-outputs", set_ignore_fractional_outputs, tr("0 or 1"));
}
fail_msg_writer() << tr("set: unrecognized argument(s)");
return true;
@@ -3955,6 +3974,24 @@ void simple_wallet::on_money_received(uint64_t height, const crypto::hash &txid,
tr("txid ") << txid << ", " <<
print_money(amount) << ", " <<
tr("idx ") << subaddr_index;
+
+ const uint64_t warn_height = m_wallet->nettype() == TESTNET ? 1000000 : m_wallet->nettype() == STAGENET ? 50000 : 1650000;
+ if (height >= warn_height)
+ {
+ std::vector<tx_extra_field> tx_extra_fields;
+ parse_tx_extra(tx.extra, tx_extra_fields); // failure ok
+ tx_extra_nonce extra_nonce;
+ if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce))
+ {
+ crypto::hash8 payment_id8 = crypto::null_hash8;
+ if (get_encrypted_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id8))
+ message_writer() <<
+ tr("NOTE: this transaction uses an encrypted payment ID: consider using subaddresses instead");
+ else
+ message_writer(console_color_red, false) <<
+ tr("WARNING: this transaction uses an unencrypted payment ID: consider using subaddresses instead");
+ }
+ }
if (m_auto_refresh_refreshing)
m_cmd_binder.print_prompt();
else
@@ -4278,12 +4315,7 @@ uint64_t simple_wallet::get_daemon_blockchain_height(std::string& err)
{
throw std::runtime_error("simple_wallet null wallet");
}
-
- COMMAND_RPC_GET_HEIGHT::request req;
- COMMAND_RPC_GET_HEIGHT::response res = boost::value_initialized<COMMAND_RPC_GET_HEIGHT::response>();
- bool r = m_wallet->invoke_http_json("/getheight", req, res);
- err = interpret_rpc_response(r, res.status);
- return res.height;
+ return m_wallet->get_daemon_blockchain_height(err);
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::show_blockchain_height(const std::vector<std::string>& args)
@@ -4553,6 +4585,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
return true;
}
payment_id_seen = true;
+ message_writer() << tr("Unencrypted payment IDs are bad for privacy: ask the recipient to use subaddresses instead");
}
uint64_t locked_blocks = 0;
@@ -4861,6 +4894,11 @@ bool simple_wallet::locked_transfer(const std::vector<std::string> &args_)
return transfer_main(TransferLocked, args_);
}
//----------------------------------------------------------------------------------------------------
+bool simple_wallet::locked_sweep_all(const std::vector<std::string> &args_)
+{
+ return sweep_main(0, true, args_);
+}
+//----------------------------------------------------------------------------------------------------
bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
{
@@ -4968,12 +5006,16 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
return true;
}
//----------------------------------------------------------------------------------------------------
-bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &args_)
+bool simple_wallet::sweep_main(uint64_t below, bool locked, const std::vector<std::string> &args_)
{
- // sweep_all [index=<N1>[,<N2>,...]] [<ring_size>] <address> [<payment_id>]
+ auto print_usage = [below]()
+ {
+ fail_msg_writer() << boost::format(tr("usage: %s [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] <address> [<payment_id>]")) % (below ? "sweep_below" : "sweep_all");
+ };
if (args_.size() == 0)
{
fail_msg_writer() << tr("No address given");
+ print_usage();
return true;
}
@@ -4987,7 +5029,10 @@ bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &a
if (local_args.size() > 0 && local_args[0].substr(0, 6) == "index=")
{
if (!parse_subaddress_indices(local_args[0], subaddr_indices))
+ {
+ print_usage();
return true;
+ }
local_args.erase(local_args.begin());
}
@@ -5024,9 +5069,44 @@ bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &a
return true;
}
+ uint64_t unlock_block = 0;
+ if (locked) {
+ uint64_t locked_blocks = 0;
+
+ if (local_args.size() < 2) {
+ fail_msg_writer() << tr("missing lockedblocks parameter");
+ return true;
+ }
+
+ try
+ {
+ locked_blocks = boost::lexical_cast<uint64_t>(local_args[1]);
+ }
+ catch (const std::exception &e)
+ {
+ fail_msg_writer() << tr("bad locked_blocks parameter");
+ return true;
+ }
+ if (locked_blocks > 1000000)
+ {
+ fail_msg_writer() << tr("Locked blocks too high, max 1000000 (˜4 yrs)");
+ return true;
+ }
+ std::string err;
+ uint64_t bc_height = get_daemon_blockchain_height(err);
+ if (!err.empty())
+ {
+ fail_msg_writer() << tr("failed to get blockchain height: ") << err;
+ return true;
+ }
+ unlock_block = bc_height + locked_blocks;
+
+ local_args.erase(local_args.begin() + 1);
+ }
+
std::vector<uint8_t> extra;
bool payment_id_seen = false;
- if (2 >= local_args.size())
+ if (local_args.size() >= 2)
{
std::string payment_id_str = local_args.back();
@@ -5055,6 +5135,7 @@ bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &a
if(!r && local_args.size() == 3)
{
fail_msg_writer() << tr("payment id has invalid format, expected 16 or 64 character hex string: ") << payment_id_str;
+ print_usage();
return true;
}
if (payment_id_seen)
@@ -5065,6 +5146,7 @@ bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &a
if (!cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), local_args[0], oa_prompter))
{
fail_msg_writer() << tr("failed to parse address");
+ print_usage();
return true;
}
@@ -5106,7 +5188,7 @@ bool simple_wallet::sweep_main(uint64_t below, const std::vector<std::string> &a
try
{
// figure out what tx will be necessary
- auto ptx_vector = m_wallet->create_transactions_all(below, info.address, info.is_subaddress, fake_outs_count, 0 /* unlock_time */, priority, extra, m_current_subaddress_account, subaddr_indices, is_daemon_trusted());
+ auto ptx_vector = m_wallet->create_transactions_all(below, info.address, info.is_subaddress, fake_outs_count, unlock_block /* unlock_time */, priority, extra, m_current_subaddress_account, subaddr_indices, is_daemon_trusted());
if (ptx_vector.empty())
{
@@ -5402,7 +5484,7 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::sweep_all(const std::vector<std::string> &args_)
{
- return sweep_main(0, args_);
+ return sweep_main(0, false, args_);
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::sweep_below(const std::vector<std::string> &args_)
@@ -5418,7 +5500,7 @@ bool simple_wallet::sweep_below(const std::vector<std::string> &args_)
fail_msg_writer() << tr("invalid amount threshold");
return true;
}
- return sweep_main(below, std::vector<std::string>(++args_.begin(), args_.end()));
+ return sweep_main(below, false, std::vector<std::string>(++args_.begin(), args_.end()));
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::donate(const std::vector<std::string> &args_)