aboutsummaryrefslogtreecommitdiff
path: root/src/simplewallet/simplewallet.cpp
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-01-15 20:32:57 -0500
committerRiccardo Spagni <ric@spagni.net>2017-01-15 20:32:57 -0500
commitab69d5b3670cc21a10aab9ad16919afdcc80fdba (patch)
treef0c009b9b943a570ee505f2881be2243c68e16cd /src/simplewallet/simplewallet.cpp
parentMerge pull request #1522 (diff)
parentspecify restore height by YYYY-MM-DD format (diff)
downloadmonero-ab69d5b3670cc21a10aab9ad16919afdcc80fdba.tar.xz
Merge pull request #1569
16b8b66a specify restore height by YYYY-MM-DD format (kenshi84)
Diffstat (limited to 'src/simplewallet/simplewallet.cpp')
-rw-r--r--src/simplewallet/simplewallet.cpp80
1 files changed, 64 insertions, 16 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 2637e8db5..68781dd73 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -939,22 +939,6 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
return false;
}
}
- if (!m_restore_height && m_restoring)
- {
- 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())
{
m_wallet_file = m_generate_from_view_key;
@@ -1095,6 +1079,70 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
bool r = new_wallet(vm, m_recovery_key, m_restore_deterministic_wallet, m_non_deterministic, old_language);
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
}
+ if (!m_restore_height && m_restoring)
+ {
+ uint32_t version;
+ bool connected = try_connect_to_daemon(false, &version);
+ while (true)
+ {
+ std::string heightstr;
+ if (!connected || version < MAKE_CORE_RPC_VERSION(1, 6))
+ heightstr = command_line::input_line("Restore from specific blockchain height (optional, default 0): ");
+ else
+ heightstr = command_line::input_line("Restore from specific blockchain height (optional, default 0),\nor alternatively from specific date (YYYY-MM-DD): ");
+ if (std::cin.eof())
+ return false;
+ if (heightstr.empty())
+ {
+ m_restore_height = 0;
+ break;
+ }
+ try
+ {
+ m_restore_height = boost::lexical_cast<uint64_t>(heightstr);
+ break;
+ }
+ catch (const boost::bad_lexical_cast &)
+ {
+ if (!connected || version < MAKE_CORE_RPC_VERSION(1, 6))
+ {
+ fail_msg_writer() << tr("bad m_restore_height parameter: ") << heightstr;
+ continue;
+ }
+ if (heightstr.size() != 10 || heightstr[4] != '-' || heightstr[7] != '-')
+ {
+ fail_msg_writer() << tr("date format must be YYYY-MM-DD");
+ continue;
+ }
+ uint16_t year;
+ uint8_t month; // 1, 2, ..., 12
+ uint8_t day; // 1, 2, ..., 31
+ try
+ {
+ year = boost::lexical_cast<uint16_t>(heightstr.substr(0,4));
+ // lexical_cast<uint8_t> won't work becasue uint8_t is treated as character type
+ month = boost::lexical_cast<uint16_t>(heightstr.substr(5,2));
+ day = boost::lexical_cast<uint16_t>(heightstr.substr(8,2));
+ m_restore_height = m_wallet->get_blockchain_height_by_date(year, month, day);
+ success_msg_writer() << tr("Restore height is: ") << m_restore_height;
+ std::string confirm = command_line::input_line(tr("Is this okay? (Y/Yes/N/No): "));
+ if (std::cin.eof())
+ return false;
+ if(command_line::is_yes(confirm))
+ break;
+ }
+ catch (const boost::bad_lexical_cast &)
+ {
+ fail_msg_writer() << tr("bad m_restore_height parameter: ") << heightstr;
+ }
+ catch (const std::runtime_error& e)
+ {
+ fail_msg_writer() << e.what();
+ }
+ }
+ }
+ m_wallet->set_refresh_from_block_height(m_restore_height);
+ }
}
else
{