aboutsummaryrefslogtreecommitdiff
path: root/src/simplewallet
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2016-11-17 16:36:12 +0200
committerRiccardo Spagni <ric@spagni.net>2016-11-17 16:36:12 +0200
commit2988e1be8ced33d5196611539abaacbb2ac88aa6 (patch)
tree50f22dcd53acaefcc18916ac71f100e8e98462fa /src/simplewallet
parentMerge pull request #1337 (diff)
parentwallet: auto sync outputs and key images in cold signing files (diff)
downloadmonero-2988e1be8ced33d5196611539abaacbb2ac88aa6.tar.xz
Merge pull request #1344
a0131c8 wallet: auto sync outputs and key images in cold signing files (moneromooo-monero) f806611 wallet2: fill key image and pubkey maps when importing outputs (moneromooo-monero) 5fe363c wallet: cast indices to string in logs to be nice to CLANG (moneromooo-monero) 11ae187 wallet2: try all tx keys when scanning a new transaction (moneromooo-monero) 072d646 wallet2: fill in key image map when importing key images (moneromooo-monero) 23d80b1 core: remove any tx pubkey from extra before adding one (moneromooo-monero) d72376d simplewallet: add a verbose flag to incoming_transfers (moneromooo-monero) 47413a5 simplewallet: spell out change when signing a transfer (moneromooo-monero) 14cb088 simplewallet: print public keys too on spendkey/viewkey commands (moneromooo-monero) a99ab49 wallet: fix serialization of new m_key_image_known member (moneromooo-monero)
Diffstat (limited to 'src/simplewallet')
-rw-r--r--src/simplewallet/simplewallet.cpp72
-rw-r--r--src/simplewallet/simplewallet.h2
2 files changed, 58 insertions, 16 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 801df3400..515fc5b22 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -280,7 +280,8 @@ std::string simple_wallet::get_commands_str()
bool simple_wallet::viewkey(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
// don't log
- std::cout << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key) << std::endl;
+ std::cout << "secret: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key) << std::endl;
+ std::cout << "public: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_account_address.m_view_public_key) << std::endl;
return true;
}
@@ -288,7 +289,8 @@ bool simple_wallet::viewkey(const std::vector<std::string> &args/* = std::vector
bool simple_wallet::spendkey(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
// don't log
- std::cout << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_spend_secret_key) << std::endl;
+ std::cout << "secret: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_spend_secret_key) << std::endl;
+ std::cout << "public: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_account_address.m_spend_public_key) << std::endl;
return true;
}
@@ -1738,18 +1740,23 @@ bool simple_wallet::show_incoming_transfers(const std::vector<std::string>& args
bool filter = false;
bool available = false;
- if (!args.empty())
+ bool verbose = false;
+ for (const auto &arg: args)
{
- if (args[0] == "available")
+ if (arg == "available")
{
filter = true;
available = true;
}
- else if (args[0] == "unavailable")
+ else if (arg == "unavailable")
{
filter = true;
available = false;
}
+ else if (arg == "verbose")
+ {
+ verbose = true;
+ }
}
tools::wallet2::transfer_container transfers;
@@ -1762,17 +1769,24 @@ bool simple_wallet::show_incoming_transfers(const std::vector<std::string>& args
{
if (!transfers_found)
{
- message_writer() << boost::format("%21s%8s%12s%8s%16s%68s") % tr("amount") % tr("spent") % tr("unlocked") % tr("ringct") % tr("global index") % tr("tx id");
+ std::string verbose_string;
+ if (verbose)
+ verbose_string = (boost::format("%68s%68s") % tr("pubkey") % tr("key image")).str();
+ message_writer() << boost::format("%21s%8s%12s%8s%16s%68s%s") % tr("amount") % tr("spent") % tr("unlocked") % tr("ringct") % tr("global index") % tr("tx id") % verbose_string;
transfers_found = true;
}
+ std::string verbose_string;
+ if (verbose)
+ verbose_string = (boost::format("%68s%68s") % td.get_public_key() % (td.m_key_image_known ? epee::string_tools::pod_to_hex(td.m_key_image) : std::string('?', 64))).str();
message_writer(td.m_spent ? epee::log_space::console_color_magenta : epee::log_space::console_color_green, false) <<
- boost::format("%21s%8s%12s%8s%16u%68s") %
+ boost::format("%21s%8s%12s%8s%16u%68s%s") %
print_money(td.amount()) %
(td.m_spent ? tr("T") : tr("F")) %
(m_wallet->is_transfer_unlocked(td) ? tr("unlocked") : tr("locked")) %
(td.is_rct() ? tr("RingCT") : tr("-")) %
td.m_global_output_index %
- td.m_txid;
+ td.m_txid %
+ verbose_string;
}
}
@@ -2765,7 +2779,7 @@ bool simple_wallet::sweep_all(const std::vector<std::string> &args_)
return true;
}
//----------------------------------------------------------------------------------------------------
-bool simple_wallet::accept_loaded_tx(const std::function<size_t()> get_num_txes, const std::function<const tools::wallet2::tx_construction_data&(size_t)> &get_tx)
+bool simple_wallet::accept_loaded_tx(const std::function<size_t()> get_num_txes, const std::function<const tools::wallet2::tx_construction_data&(size_t)> &get_tx, const std::string &extra_message)
{
// gather info to ask the user
uint64_t amount = 0, amount_to_dests = 0, change = 0;
@@ -2806,7 +2820,12 @@ bool simple_wallet::accept_loaded_tx(const std::function<size_t()> get_num_txes,
fail_msg_writer() << tr("Claimed change is larger than payment to the change address");
return false;
}
- change = cd.change_dts.amount;
+ if (memcmp(&cd.change_dts.addr, &get_tx(0).change_dts.addr, sizeof(cd.change_dts.addr)))
+ {
+ fail_msg_writer() << tr("Change does to more than one address");
+ return false;
+ }
+ change += cd.change_dts.amount;
it->second -= cd.change_dts.amount;
if (it->second == 0)
dests.erase(get_account_address_as_str(m_wallet->testnet(), cd.change_dts.addr));
@@ -2823,20 +2842,35 @@ bool simple_wallet::accept_loaded_tx(const std::function<size_t()> get_num_txes,
if (dest_string.empty())
dest_string = tr("with no destinations");
+ std::string change_string;
+ if (change > 0)
+ {
+ std::string address = get_account_address_as_str(m_wallet->testnet(), get_tx(0).change_dts.addr);
+ change_string += (boost::format(tr("%s change to %s")) % print_money(change) % address).str();
+ }
+ else
+ change_string += tr("no change");
+
uint64_t fee = amount - amount_to_dests;
- std::string prompt_str = (boost::format(tr("Loaded %lu transactions, for %s, fee %s, change %s, %s, with min mixin %lu. Is this okay? (Y/Yes/N/No)")) % (unsigned long)get_num_txes() % print_money(amount) % print_money(fee) % print_money(change) % dest_string % (unsigned long)min_mixin).str();
+ std::string prompt_str = (boost::format(tr("Loaded %lu transactions, for %s, fee %s, %s, %s, with min mixin %lu. %sIs this okay? (Y/Yes/N/No)")) % (unsigned long)get_num_txes() % print_money(amount) % print_money(fee) % dest_string % change_string % (unsigned long)min_mixin % extra_message).str();
std::string accepted = command_line::input_line(prompt_str);
return is_it_true(accepted);
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::accept_loaded_tx(const tools::wallet2::unsigned_tx_set &txs)
{
- return accept_loaded_tx([&txs](){return txs.txes.size();}, [&txs](size_t n)->const tools::wallet2::tx_construction_data&{return txs.txes[n];});
+ std::string extra_message;
+ if (!txs.transfers.empty())
+ extra_message = (boost::format("%u outputs to import. ") % (unsigned)txs.transfers.size()).str();
+ return accept_loaded_tx([&txs](){return txs.txes.size();}, [&txs](size_t n)->const tools::wallet2::tx_construction_data&{return txs.txes[n];}, extra_message);
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::accept_loaded_tx(const tools::wallet2::signed_tx_set &txs)
{
- return accept_loaded_tx([&txs](){return txs.ptx.size();}, [&txs](size_t n)->const tools::wallet2::tx_construction_data&{return txs.ptx[n].construction_data;});
+ std::string extra_message;
+ if (!txs.key_images.empty())
+ extra_message = (boost::format("%u key images to import. ") % (unsigned)txs.key_images.size()).str();
+ return accept_loaded_tx([&txs](){return txs.ptx.size();}, [&txs](size_t n)->const tools::wallet2::tx_construction_data&{return txs.ptx[n].construction_data;}, extra_message);
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::sign_transfer(const std::vector<std::string> &args_)
@@ -2847,9 +2881,10 @@ bool simple_wallet::sign_transfer(const std::vector<std::string> &args_)
return true;
}
+ std::vector<tools::wallet2::pending_tx> ptx;
try
{
- bool r = m_wallet->sign_tx("unsigned_monero_tx", "signed_monero_tx", [&](const tools::wallet2::unsigned_tx_set &tx){ return accept_loaded_tx(tx); });
+ bool r = m_wallet->sign_tx("unsigned_monero_tx", "signed_monero_tx", ptx, [&](const tools::wallet2::unsigned_tx_set &tx){ return accept_loaded_tx(tx); });
if (!r)
{
fail_msg_writer() << tr("Failed to sign transaction");
@@ -2862,7 +2897,14 @@ bool simple_wallet::sign_transfer(const std::vector<std::string> &args_)
return true;
}
- success_msg_writer(true) << tr("Transaction successfully signed to file: ") << "signed_monero_tx";
+ std::string txids_as_text;
+ for (const auto &t: ptx)
+ {
+ if (!txids_as_text.empty())
+ txids_as_text += (", ");
+ txids_as_text += epee::string_tools::pod_to_hex(get_transaction_hash(t.tx));
+ }
+ success_msg_writer(true) << tr("Transaction successfully signed to file ") << "signed_monero_tx" << ", txid " << txids_as_text;
return true;
}
//----------------------------------------------------------------------------------------------------
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index 4fe1b0417..0d83f429b 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -155,7 +155,7 @@ namespace cryptonote
uint64_t get_daemon_blockchain_height(std::string& err);
bool try_connect_to_daemon(bool silent = false);
bool ask_wallet_create_if_needed();
- bool accept_loaded_tx(const std::function<size_t()> get_num_txes, const std::function<const tools::wallet2::tx_construction_data&(size_t)> &get_tx);
+ bool accept_loaded_tx(const std::function<size_t()> get_num_txes, const std::function<const tools::wallet2::tx_construction_data&(size_t)> &get_tx, const std::string &extra_message = std::string());
bool accept_loaded_tx(const tools::wallet2::unsigned_tx_set &txs);
bool accept_loaded_tx(const tools::wallet2::signed_tx_set &txs);
bool get_address_from_str(const std::string &str, cryptonote::account_public_address &address, bool &has_payment_id, crypto::hash8 &payment_id);