diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 14fbf003f..18b327999 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -49,6 +50,7 @@ using namespace std; using namespace dev; using namespace dev::p2p; using namespace dev::eth; +namespace js = json_spirit; static void initUnits(QComboBox* _b) { @@ -573,10 +575,29 @@ void Main::on_importKey_triggered() void Main::on_importKeyFile_triggered() { QString s = QFileDialog::getOpenFileName(this, "Import Account", QDir::homePath(), "JSON Files (*.json);;All Files (*)"); - bytes b = fromHex(s.toStdString()); - if (b.size() == 32) + try { - auto k = KeyPair(h256(b)); + js::mValue val; + json_spirit::read_string(asString(contents(s.toStdString())), val); + js::mObject obj = val.get_obj(); + KeyPair k; + + if (obj["encseed"].type() == js::str_type) + { + string encseedstr = obj["encseed"].get_str(); + bytes encseed = fromHex(encseedstr); + Secret sec = sha3(encseed); + k = KeyPair(sec); + if (obj["ethaddr"].type() == js::str_type) + { + Address a(obj["ethaddr"].get_str()); + Address b = k.address(); + if (a != b && QMessageBox::warning(this, "Key File Invalid", "Could not import the secret key: it doesn't agree with the given address.\nWould you like to attempt to import anyway?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) + return; + } + } + else + throw 0; if (std::find(m_myKeys.begin(), m_myKeys.end(), k) == m_myKeys.end()) { m_myKeys.append(k); @@ -586,8 +607,10 @@ void Main::on_importKeyFile_triggered() else QMessageBox::warning(this, "Already Have Key", "Could not import the secret key: we already own this account."); } - else - QMessageBox::warning(this, "Invalid Entry", "Could not import the secret key; invalid key entered. Make sure it is 64 hex characters (0-9 or A-F)."); + catch (...) + { + QMessageBox::warning(this, "Key File Invalid", "Could not find secret key definition. This is probably not an Ethereum key file."); + } } void Main::on_exportKey_triggered() diff --git a/libethereum/DownloadMan.cpp b/libethereum/DownloadMan.cpp index 09a3bcc00..3c8dae58e 100644 --- a/libethereum/DownloadMan.cpp +++ b/libethereum/DownloadMan.cpp @@ -50,7 +50,7 @@ h256Set DownloadSub::nextFetch(unsigned _n) m_indices.clear(); m_remaining.clear(); - if (!m_man) + if (!m_man || m_man->chain().empty()) return h256Set(); m_asked = (~(m_man->taken() + m_attempted)).lowest(_n); diff --git a/libethereum/EthereumPeer.cpp b/libethereum/EthereumPeer.cpp index fb2558d57..99ff41bad 100644 --- a/libethereum/EthereumPeer.cpp +++ b/libethereum/EthereumPeer.cpp @@ -176,12 +176,12 @@ bool EthereumPeer::interpret(RLP const& _r) unsigned limit = _r[2].toInt(); clogS(NetMessageSummary) << "GetBlockHashes (" << limit << "entries," << later.abridged() << ")"; - unsigned c = min(max(1, host()->m_chain.number(later)) - 1, limit); + unsigned c = min(host()->m_chain.number(later), limit); RLPStream s; prep(s).appendList(1 + c).append(BlockHashesPacket); h256 p = host()->m_chain.details(later).parent; - for (unsigned i = 0; i < c; ++i, p = host()->m_chain.details(p).parent) + for (unsigned i = 0; i < c && p; ++i, p = host()->m_chain.details(p).parent) s << p; sealAndSend(s); break; diff --git a/test/rlp.cpp b/test/rlp.cpp index b51f3a225..c3f9dda2f 100644 --- a/test/rlp.cpp +++ b/test/rlp.cpp @@ -22,12 +22,12 @@ #include #include -#include "JsonSpiritHeaders.h" #include #include #include #include #include +#include "JsonSpiritHeaders.h" using namespace std; using namespace dev;