wallet: print tx overview on submit_transfer too

This is on the potentially compromised wallet, but still guards
against stupid mistakes.
This commit is contained in:
moneromooo-monero 2016-10-30 10:49:22 +00:00
parent 83b0511731
commit 1f9e6a46d8
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
4 changed files with 25 additions and 7 deletions

View file

@ -3111,16 +3111,16 @@ bool simple_wallet::sweep_all(const std::vector<std::string> &args_)
return true; return true;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
bool simple_wallet::accept_loaded_tx(const tools::wallet2::unsigned_tx_set &txs) 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)
{ {
// gather info to ask the user // gather info to ask the user
uint64_t amount = 0, amount_to_dests = 0, change = 0; uint64_t amount = 0, amount_to_dests = 0, change = 0;
size_t min_mixin = ~0; size_t min_mixin = ~0;
std::unordered_map<std::string, uint64_t> dests; std::unordered_map<std::string, uint64_t> dests;
const std::string wallet_address = m_wallet->get_account().get_public_address_str(m_wallet->testnet()); const std::string wallet_address = m_wallet->get_account().get_public_address_str(m_wallet->testnet());
for (size_t n = 0; n < txs.txes.size(); ++n) for (size_t n = 0; n < get_num_txes(); ++n)
{ {
const tools::wallet2::tx_construction_data &cd = txs.txes[n]; const tools::wallet2::tx_construction_data &cd = get_tx(n);
for (size_t s = 0; s < cd.sources.size(); ++s) for (size_t s = 0; s < cd.sources.size(); ++s)
{ {
amount += cd.sources[s].amount; amount += cd.sources[s].amount;
@ -3168,11 +3168,21 @@ bool simple_wallet::accept_loaded_tx(const tools::wallet2::unsigned_tx_set &txs)
dest_string = tr("with no destinations"); dest_string = tr("with no destinations");
uint64_t fee = amount - amount_to_dests; 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)txs.txes.size() % 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, 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 accepted = command_line::input_line(prompt_str); std::string accepted = command_line::input_line(prompt_str);
return is_it_true(accepted); 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];});
}
//----------------------------------------------------------------------------------------------------
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;});
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::sign_transfer(const std::vector<std::string> &args_) bool simple_wallet::sign_transfer(const std::vector<std::string> &args_)
{ {
if(m_wallet->watch_only()) if(m_wallet->watch_only())
@ -3208,7 +3218,7 @@ bool simple_wallet::submit_transfer(const std::vector<std::string> &args_)
try try
{ {
std::vector<tools::wallet2::pending_tx> ptx_vector; std::vector<tools::wallet2::pending_tx> ptx_vector;
bool r = m_wallet->load_tx("signed_monero_tx", ptx_vector); bool r = m_wallet->load_tx("signed_monero_tx", ptx_vector, [&](const tools::wallet2::signed_tx_set &tx){ return accept_loaded_tx(tx); });
if (!r) if (!r)
{ {
fail_msg_writer() << tr("Failed to load transaction from file"); fail_msg_writer() << tr("Failed to load transaction from file");

View file

@ -156,7 +156,9 @@ namespace cryptonote
uint64_t get_daemon_blockchain_height(std::string& err); uint64_t get_daemon_blockchain_height(std::string& err);
bool try_connect_to_daemon(bool silent = false); bool try_connect_to_daemon(bool silent = false);
bool ask_wallet_create_if_needed(); 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 tools::wallet2::unsigned_tx_set &txs); 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); bool get_address_from_str(const std::string &str, cryptonote::account_public_address &address, bool &has_payment_id, crypto::hash8 &payment_id);
/*! /*!

View file

@ -2678,7 +2678,7 @@ bool wallet2::sign_tx(const std::string &unsigned_filename, const std::string &s
return epee::file_io_utils::save_string_to_file(signed_filename, std::string(SIGNED_TX_PREFIX) + s); return epee::file_io_utils::save_string_to_file(signed_filename, std::string(SIGNED_TX_PREFIX) + s);
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
bool wallet2::load_tx(const std::string &signed_filename, std::vector<tools::wallet2::pending_tx> &ptx) bool wallet2::load_tx(const std::string &signed_filename, std::vector<tools::wallet2::pending_tx> &ptx, std::function<bool(const signed_tx_set&)> accept_func)
{ {
std::string s; std::string s;
boost::system::error_code errcode; boost::system::error_code errcode;
@ -2709,6 +2709,12 @@ bool wallet2::load_tx(const std::string &signed_filename, std::vector<tools::wal
LOG_PRINT_L0("Loaded signed tx data from binary: " << signed_txs.ptx.size() << " transactions"); LOG_PRINT_L0("Loaded signed tx data from binary: " << signed_txs.ptx.size() << " transactions");
for (auto &ptx: signed_txs.ptx) LOG_PRINT_L0(cryptonote::obj_to_json_str(ptx.tx)); for (auto &ptx: signed_txs.ptx) LOG_PRINT_L0(cryptonote::obj_to_json_str(ptx.tx));
if (accept_func && !accept_func(signed_txs))
{
LOG_PRINT_L1("Transactions rejected by callback");
return false;
}
ptx = signed_txs.ptx; ptx = signed_txs.ptx;
return true; return true;

View file

@ -357,7 +357,7 @@ namespace tools
void commit_tx(std::vector<pending_tx>& ptx_vector); void commit_tx(std::vector<pending_tx>& ptx_vector);
bool save_tx(const std::vector<pending_tx>& ptx_vector, const std::string &filename); bool save_tx(const std::vector<pending_tx>& ptx_vector, const std::string &filename);
bool sign_tx(const std::string &unsigned_filename, const std::string &signed_filename, std::function<bool(const unsigned_tx_set&)> accept_func = NULL); bool sign_tx(const std::string &unsigned_filename, const std::string &signed_filename, std::function<bool(const unsigned_tx_set&)> accept_func = NULL);
bool load_tx(const std::string &signed_filename, std::vector<tools::wallet2::pending_tx> &ptx); bool load_tx(const std::string &signed_filename, std::vector<tools::wallet2::pending_tx> &ptx, std::function<bool(const signed_tx_set&)> accept_func = NULL);
std::vector<pending_tx> create_transactions(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t> extra, bool trusted_daemon); std::vector<pending_tx> create_transactions(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t> extra, bool trusted_daemon);
std::vector<wallet2::pending_tx> create_transactions_2(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t> extra, bool trusted_daemon); std::vector<wallet2::pending_tx> create_transactions_2(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t> extra, bool trusted_daemon);
std::vector<wallet2::pending_tx> create_transactions_all(const cryptonote::account_public_address &address, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t> extra, bool trusted_daemon); std::vector<wallet2::pending_tx> create_transactions_all(const cryptonote::account_public_address &address, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t> extra, bool trusted_daemon);