diff --git a/alethzero/Main.ui b/alethzero/Main.ui index 52e973fe8..d5653f8ca 100644 --- a/alethzero/Main.ui +++ b/alethzero/Main.ui @@ -132,7 +132,7 @@ 0 0 1617 - 22 + 24 @@ -188,7 +188,6 @@ - @@ -1387,6 +1386,11 @@ font-size: 14pt Dump &Block State as JSON... + + + &Bulk Inject Transactions... + + diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 1fb84dddc..f4aebe28f 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -668,9 +668,10 @@ std::string Main::render(dev::Address const& _a) const if (p.size() == 9 && p.find_first_not_of("QWERYUOPASDFGHJKLZXCVBNM1234567890") == string::npos) p = ICAP(p, "XREG").encoded(); else - DEV_IGNORE_EXCEPTIONS(n = ICAP(_a).encoded()); - if (n.empty()) - n = _a.abridged(); + DEV_IGNORE_EXCEPTIONS(n = ICAP(_a).encoded().substr(0, 8)); + if (!n.empty()) + n += " "; + n += _a.abridged(); return p.empty() ? n : (p + " " + n); } @@ -1593,25 +1594,6 @@ void Main::on_transactionQueue_currentItemChanged() ui->pendingInfo->moveCursor(QTextCursor::Start); } -void Main::on_inject_triggered() -{ - QString s = QInputDialog::getText(this, "Inject Transaction", "Enter transaction dump in hex"); - try - { - bytes b = fromHex(s.toStdString(), WhenError::Throw); - ethereum()->injectTransaction(b); - } - catch (BadHexCharacter& _e) - { - cwarn << "invalid hex character, transaction rejected"; - cwarn << boost::diagnostic_information(_e); - } - catch (...) - { - cwarn << "transaction rejected"; - } -} - void Main::on_injectBlock_triggered() { QString s = QInputDialog::getText(this, "Inject Block", "Enter block dump in hex"); diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index db9298704..74ca7b5b0 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -180,7 +180,6 @@ private slots: void on_paranoia_triggered(); void on_killBlockchain_triggered(); void on_clearPending_triggered(); - void on_inject_triggered(); void on_injectBlock_triggered(); void on_forceMining_triggered(); void on_usePrivate_triggered(); diff --git a/alethzero/plugins/namers/OtherAccounts.cpp b/alethzero/plugins/namers/OtherAccounts.cpp index fc2d518bc..19b602b91 100644 --- a/alethzero/plugins/namers/OtherAccounts.cpp +++ b/alethzero/plugins/namers/OtherAccounts.cpp @@ -21,6 +21,7 @@ #include "OtherAccounts.h" #include +#include #include #include #include @@ -46,12 +47,22 @@ void OtherAccounts::import() if (d.exec() == QDialog::Accepted) { QStringList sl = u.accounts->toPlainText().split("\n"); + unsigned line = 1; for (QString const& s: sl) { - Address addr = dev::eth::toAddress(s.section(QRegExp("[ \\0\\t]+"), 0, 0).toStdString()); - string name = s.section(QRegExp("[ \\0\\t]+"), 1).toStdString(); - m_toName[addr] = name; - m_toAddress[name] = addr; + try + { + Address addr = dev::eth::toAddress(s.section(QRegExp("[ \\0\\t]+"), 0, 0).trimmed().toStdString()); + string name = s.section(QRegExp("[ \\0\\t]+"), 1).trimmed().toStdString(); + m_toName[addr] = name; + m_toAddress[name] = addr; + } + catch (...) + { + if (QMessageBox::warning(&d, "Invalid Line Format", "Line format or address given on line " + QString::number(line) + " is invalid:\n" + s, QMessageBox::Abort, QMessageBox::Ignore) == QMessageBox::Abort) + break; + } + line++; } main()->noteSettingsChanged(); noteKnownChanged(); diff --git a/alethzero/plugins/special/InjectTransactions.cpp b/alethzero/plugins/special/InjectTransactions.cpp new file mode 100644 index 000000000..f1535f56e --- /dev/null +++ b/alethzero/plugins/special/InjectTransactions.cpp @@ -0,0 +1,87 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file InjectTransactions.h + * @author Gav Wood + * @date 2015 + */ + +#include "InjectTransactions.h" +#include +#include +#include +#include +#include "ui_InjectTransactions.h" +using namespace std; +using namespace dev; +using namespace az; +using namespace eth; + +DEV_AZ_NOTE_PLUGIN(InjectTransactions); + +InjectTransactions::InjectTransactions(MainFace* _m): + Plugin(_m, "InjectTransactions") +{ + connect(addMenuItem("Inject Transaction...", "menuSpecial", true), SIGNAL(triggered()), SLOT(injectOne())); + connect(addMenuItem("Bulk Inject Transactions...", "menuSpecial", false), SIGNAL(triggered()), SLOT(injectBulk())); +} + +InjectTransactions::~InjectTransactions() +{ +} + +void InjectTransactions::injectOne() +{ + bool ok; + QString s = QInputDialog::getText(main(), "Inject Transaction", "Enter transaction dump in hex", QLineEdit::Normal, QString(), &ok); + if (ok) + doInject(s); +} + +void InjectTransactions::injectBulk() +{ + QDialog d; + Ui_InjectTransactions u; + u.setupUi(&d); + d.setWindowTitle("Bulk Inject Transactions"); + if (d.exec() == QDialog::Accepted) + for (QString const& s: u.transactions->toPlainText().split("\n")) + doInject(s); +} + +void InjectTransactions::doInject(QString _txHex) +{ + try + { + bytes b = fromHex(_txHex.toStdString(), WhenError::Throw); + main()->ethereum()->injectTransaction(b); + } + catch (BadHexCharacter& _e) + { + if (QMessageBox::warning(main(), "Invalid Transaction Hex", "Invalid hex character in:\n" + _txHex + "\nTransaction rejected.", QMessageBox::Ignore, QMessageBox::Abort) == QMessageBox::Abort) + return; + } + catch (Exception& _e) + { + if (QMessageBox::warning(main(), "Transaction Rejected", "Invalid transaction; due to" + QString::fromStdString(_e.what()) + "\n" + _txHex + "\nTransaction rejected.", QMessageBox::Ignore, QMessageBox::Abort) == QMessageBox::Abort) + return; + } + catch (...) + { + // Should not happen under normal circumstances. + return; + } +} diff --git a/alethzero/plugins/special/InjectTransactions.h b/alethzero/plugins/special/InjectTransactions.h new file mode 100644 index 000000000..76941027d --- /dev/null +++ b/alethzero/plugins/special/InjectTransactions.h @@ -0,0 +1,48 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file InjectTransactions.h + * @author Gav Wood + * @date 2015 + */ + +#pragma once + +#include "MainFace.h" + +namespace dev +{ +namespace az +{ + +class InjectTransactions: public QObject, public Plugin +{ + Q_OBJECT + +public: + InjectTransactions(MainFace* _m); + ~InjectTransactions(); + +private slots: + void injectOne(); + void injectBulk(); + +private: + void doInject(QString _txHex); +}; + +} +} diff --git a/alethzero/plugins/special/InjectTransactions.ui b/alethzero/plugins/special/InjectTransactions.ui new file mode 100644 index 000000000..e135130eb --- /dev/null +++ b/alethzero/plugins/special/InjectTransactions.ui @@ -0,0 +1,95 @@ + + + InjectTransactions + + + + 0 + 0 + 511 + 508 + + + + Dialog + + + + + + Write the transactions you wish to inject here, in hex, one per line. + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cancel + + + + + + + &Import + + + true + + + + + + + + + + + inject + clicked() + InjectTransactions + accept() + + + 462 + 484 + + + 449 + 504 + + + + + cancel + clicked() + InjectTransactions + reject() + + + 381 + 483 + + + 351 + 506 + + + + +