aboutsummaryrefslogtreecommitdiff
path: root/src/simplewallet
diff options
context:
space:
mode:
Diffstat (limited to 'src/simplewallet')
-rw-r--r--src/simplewallet/simplewallet.cpp56
-rw-r--r--src/simplewallet/simplewallet.h1
2 files changed, 50 insertions, 7 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 503db7601..44af55949 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -97,6 +97,7 @@ namespace
const command_line::arg_descriptor<bool> arg_testnet = {"testnet", sw::tr("For testnet. Daemon must also be launched with --testnet flag"), false};
const command_line::arg_descriptor<bool> arg_restricted = {"restricted-rpc", sw::tr("Restricts RPC to view-only commands"), false};
const command_line::arg_descriptor<bool> arg_trusted_daemon = {"trusted-daemon", sw::tr("Enable commands which rely on a trusted daemon"), false};
+ const command_line::arg_descriptor<uint64_t> arg_restore_height = {"restore-height", sw::tr("Restore from specific blockchain height"), 0};
const command_line::arg_descriptor< std::vector<std::string> > arg_command = {"command", ""};
@@ -1137,6 +1138,22 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
return false;
}
}
+ if (!m_restore_height)
+ {
+ std::string heightstr = command_line::input_line("Restore from specific blockchain height (optional, default 0): ");
+ if (std::cin.eof())
+ return false;
+ if (heightstr.size())
+ {
+ try {
+ m_restore_height = boost::lexical_cast<uint64_t>(heightstr);
+ }
+ catch (boost::bad_lexical_cast &) {
+ fail_msg_writer() << tr("bad m_restore_height parameter:") << " " << heightstr;
+ return false;
+ }
+ }
+ }
if (!m_generate_from_view_key.empty())
{
// parse address
@@ -1307,6 +1324,7 @@ bool simple_wallet::handle_command_line(const boost::program_options::variables_
m_restore_deterministic_wallet = command_line::get_arg(vm, arg_restore_deterministic_wallet);
m_non_deterministic = command_line::get_arg(vm, arg_non_deterministic);
m_trusted_daemon = command_line::get_arg(vm, arg_trusted_daemon);
+ m_restore_height = command_line::get_arg(vm, arg_restore_height);
return true;
}
@@ -1411,6 +1429,15 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string
}
m_wallet->init(m_daemon_address);
+ // for a totally new account, we don't care about older blocks.
+ if (!m_restore_deterministic_wallet)
+ {
+ std::string err;
+ m_wallet->set_refresh_from_block_height(get_daemon_blockchain_height(err));
+ } else if (m_restore_height)
+ {
+ m_wallet->set_refresh_from_block_height(m_restore_height);
+ }
// convert rng value to electrum-style word list
std::string electrum_words;
@@ -1458,6 +1485,7 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string
}
m_wallet->init(m_daemon_address);
+ m_wallet->set_refresh_from_block_height(m_restore_height);
return true;
}
@@ -1483,6 +1511,7 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string
}
m_wallet->init(m_daemon_address);
+ m_wallet->set_refresh_from_block_height(m_restore_height);
return true;
}
@@ -2212,24 +2241,36 @@ bool simple_wallet::transfer_main(bool new_algorithm, const std::vector<std::str
if (m_wallet->always_confirm_transfers() || ptx_vector.size() > 1)
{
uint64_t total_fee = 0;
+ uint64_t dust_not_in_fee = 0;
+ uint64_t dust_in_fee = 0;
for (size_t n = 0; n < ptx_vector.size(); ++n)
{
total_fee += ptx_vector[n].fee;
+
+ if (ptx_vector[n].dust_added_to_fee)
+ dust_in_fee += ptx_vector[n].dust;
+ else
+ dust_not_in_fee += ptx_vector[n].dust;
}
- std::string prompt_str;
+ std::stringstream prompt;
if (ptx_vector.size() > 1)
{
- prompt_str = (boost::format(tr("Your transaction needs to be split into %llu transactions. "
- "This will result in a transaction fee being applied to each transaction, for a total fee of %s. Is this okay? (Y/Yes/N/No)")) %
- ((unsigned long long)ptx_vector.size()) % print_money(total_fee)).str();
+ prompt << boost::format(tr("Your transaction needs to be split into %llu transactions. "
+ "This will result in a transaction fee being applied to each transaction, for a total fee of %s")) %
+ ((unsigned long long)ptx_vector.size()) % print_money(total_fee);
}
else
{
- prompt_str = (boost::format(tr("The transaction fee is %s. Is this okay? (Y/Yes/N/No)")) %
- print_money(total_fee)).str();
+ prompt << boost::format(tr("The transaction fee is %s")) %
+ print_money(total_fee);
}
- std::string accepted = command_line::input_line(prompt_str);
+ if (dust_in_fee != 0) prompt << boost::format(tr(", of which %s is dust from change")) % print_money(dust_in_fee);
+ if (dust_not_in_fee != 0) prompt << tr(".") << ENDL << boost::format(tr("A total of %s from dust change will be sent to dust address"))
+ % print_money(dust_not_in_fee);
+ prompt << tr(".") << ENDL << tr("Is this okay? (Y/Yes/N/No)");
+
+ std::string accepted = command_line::input_line(prompt.str());
if (std::cin.eof())
return true;
if (accepted != "Y" && accepted != "y" && accepted != "Yes" && accepted != "yes")
@@ -3163,6 +3204,7 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_params, arg_testnet);
command_line::add_arg(desc_params, arg_restricted);
command_line::add_arg(desc_params, arg_trusted_daemon);
+ command_line::add_arg(desc_params, arg_restore_height);
tools::wallet_rpc_server::init_options(desc_params);
po::positional_options_description positional_options;
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index e7884155e..b825f71df 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -233,6 +233,7 @@ namespace cryptonote
bool m_restore_deterministic_wallet; // recover flag
bool m_non_deterministic; // old 2-random generation
bool m_trusted_daemon;
+ uint64_t m_restore_height; // optional
std::string m_daemon_address;
std::string m_daemon_host;