Browse Source

Refactor AlethSero project into dev::az namespace.

cl-refactor
Gav Wood 10 years ago
parent
commit
5a3064c166
  1. 3
      alethzero/Connect.cpp
  2. 14
      alethzero/Connect.h
  3. 15
      alethzero/Context.cpp
  4. 10
      alethzero/Context.h
  5. 2
      alethzero/DappHost.cpp
  6. 8
      alethzero/DappHost.h
  7. 8
      alethzero/DappLoader.cpp
  8. 11
      alethzero/DappLoader.h
  9. 3
      alethzero/Debugger.cpp
  10. 9
      alethzero/Debugger.h
  11. 5
      alethzero/DownloadView.cpp
  12. 13
      alethzero/DownloadView.h
  13. 6
      alethzero/ExportState.cpp
  14. 16
      alethzero/ExportState.h
  15. 2
      alethzero/LogPanel.cpp
  16. 2
      alethzero/LogPanel.h
  17. 8
      alethzero/Main.ui
  18. 52
      alethzero/MainWin.cpp
  19. 71
      alethzero/MainWin.h
  20. 7
      alethzero/MiningView.cpp
  21. 15
      alethzero/MiningView.h
  22. 3
      alethzero/NatspecHandler.cpp
  23. 8
      alethzero/NatspecHandler.h
  24. 3
      alethzero/OurWebThreeStubServer.cpp
  25. 31
      alethzero/OurWebThreeStubServer.h
  26. 8
      alethzero/Transact.cpp
  27. 15
      alethzero/Transact.h
  28. 4
      alethzero/WebPage.cpp
  29. 13
      alethzero/WebPage.h
  30. 2
      alethzero/main.cpp

3
alethzero/Connect.cpp

@ -20,9 +20,10 @@
*/
#include "Connect.h"
#include <libp2p/Host.h>
#include "ui_Connect.h"
using namespace dev;
using namespace az;
Connect::Connect(QWidget *parent) :
QDialog(parent),

14
alethzero/Connect.h

@ -25,9 +25,16 @@
#include <QList>
namespace Ui { class Connect; }
namespace dev { namespace p2p { class Host; } }
class Connect : public QDialog
namespace dev
{
namespace p2p { class Host; }
namespace az
{
class Connect: public QDialog
{
Q_OBJECT
@ -53,3 +60,6 @@ public:
private:
Ui::Connect* ui;
};
}
}

15
alethzero/Context.cpp

@ -25,7 +25,8 @@
#include <libethcore/Common.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace eth;
using namespace az;
NatSpecFace::~NatSpecFace()
{
@ -35,7 +36,7 @@ Context::~Context()
{
}
void setValueUnits(QComboBox* _units, QSpinBox* _value, u256 _v)
void dev::az::setValueUnits(QComboBox* _units, QSpinBox* _value, u256 _v)
{
initUnits(_units);
_units->setCurrentIndex(0);
@ -47,30 +48,30 @@ void setValueUnits(QComboBox* _units, QSpinBox* _value, u256 _v)
_value->setValue((unsigned)_v);
}
u256 fromValueUnits(QComboBox* _units, QSpinBox* _value)
u256 dev::az::fromValueUnits(QComboBox* _units, QSpinBox* _value)
{
return _value->value() * units()[units().size() - 1 - _units->currentIndex()].first;
}
void initUnits(QComboBox* _b)
void dev::az::initUnits(QComboBox* _b)
{
for (auto n = (unsigned)units().size(); n-- != 0; )
_b->addItem(QString::fromStdString(units()[n].second), n);
}
vector<KeyPair> keysAsVector(QList<KeyPair> const& keys)
vector<KeyPair> dev::az::keysAsVector(QList<KeyPair> const& keys)
{
auto list = keys.toStdList();
return {begin(list), end(list)};
}
bool sourceIsSolidity(string const& _source)
bool dev::az::sourceIsSolidity(string const& _source)
{
// TODO: Improve this heuristic
return (_source.substr(0, 8) == "contract" || _source.substr(0, 5) == "//sol");
}
bool sourceIsSerpent(string const& _source)
bool dev::az::sourceIsSerpent(string const& _source)
{
// TODO: Improve this heuristic
return (_source.substr(0, 5) == "//ser");

10
alethzero/Context.h

@ -30,7 +30,13 @@
class QComboBox;
class QSpinBox;
namespace dev { namespace eth { struct StateDiff; class KeyManager; } }
namespace dev
{
namespace eth { struct StateDiff; class KeyManager; }
namespace az
{
#define ETH_HTML_SMALL "font-size: small; "
#define ETH_HTML_MONO "font-family: Ubuntu Mono, Monospace, Lucida Console, Courier New; font-weight: bold; "
@ -74,3 +80,5 @@ public:
virtual dev::u256 gasPrice() const = 0;
};
}
}

2
alethzero/DappHost.cpp

@ -24,8 +24,8 @@
#include <microhttpd.h>
#include <boost/algorithm/string.hpp>
#include <libdevcore/Common.h>
using namespace dev;
using namespace az;
DappHost::DappHost(int _port, int _threads):
m_port(_port),

8
alethzero/DappHost.h

@ -29,6 +29,12 @@
struct MHD_Daemon;
struct MHD_Connection;
namespace dev
{
namespace az
{
/// DApp web server. Servers web content, resolves paths by hashes
class DappHost
{
@ -60,3 +66,5 @@ private:
std::map<QString, ManifestEntry const*> m_entriesByPath;
};
}
}

8
alethzero/DappLoader.cpp

@ -34,12 +34,12 @@
#include <libethereum/Client.h>
#include <libwebthree/WebThree.h>
#include "DappLoader.h"
using namespace dev;
using namespace dev::eth;
using namespace dev::crypto;
using namespace az;
using namespace eth;
using namespace crypto;
QString contentsOfQResource(std::string const& res);
namespace dev { namespace az { QString contentsOfQResource(std::string const& res); } }
DappLoader::DappLoader(QObject* _parent, WebThreeDirect* _web3, Address _nameReg):
QObject(_parent), m_web3(_web3), m_nameReg(_nameReg)

11
alethzero/DappLoader.h

@ -33,9 +33,12 @@
namespace dev
{
class WebThreeDirect;
class RLP;
}
class WebThreeDirect;
class RLP;
namespace az
{
struct ManifestEntry
{
@ -104,3 +107,5 @@ private:
std::string m_sessionKey;
};
}
}

3
alethzero/Debugger.cpp

@ -29,7 +29,8 @@
#include "ui_Debugger.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace az;
using namespace eth;
Debugger::Debugger(Context* _c, QWidget* _parent):
QDialog(_parent),

9
alethzero/Debugger.h

@ -32,6 +32,12 @@
namespace Ui { class Debugger; }
namespace dev
{
namespace az
{
struct WorldState
{
uint64_t steps;
@ -101,3 +107,6 @@ private:
DebugSession m_session;
Context* m_context;
};
}
}

5
alethzero/DownloadView.cpp

@ -20,15 +20,14 @@
*/
#include "DownloadView.h"
#include <QtWidgets>
#include <QtCore>
#include <libethereum/DownloadMan.h>
#include "Grapher.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace az;
using namespace eth;
SyncView::SyncView(QWidget* _p): QWidget(_p)
{

13
alethzero/DownloadView.h

@ -31,9 +31,13 @@
#include <libethereum/Client.h>
#endif
namespace dev { namespace eth {
class Client;
}}
namespace dev
{
namespace eth { class Client; }
namespace az
{
class SyncView: public QWidget
{
@ -54,3 +58,6 @@ private:
unsigned m_lastSyncCount = 0;
bool m_wasEstimate = false;
};
}
}

6
alethzero/ExportState.cpp

@ -25,10 +25,10 @@
#include <libethereum/Client.h>
#include "MainWin.h"
#include "ui_ExportState.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace az;
using namespace eth;
ExportStateDialog::ExportStateDialog(Main* _parent):
QDialog(_parent),
@ -46,7 +46,7 @@ ExportStateDialog::~ExportStateDialog()
{
}
dev::eth::Client* ExportStateDialog::ethereum() const
Client* ExportStateDialog::ethereum() const
{
return m_main->ethereum();
}

16
alethzero/ExportState.h

@ -26,7 +26,14 @@
#include <libethcore/Common.h>
namespace Ui { class ExportState; }
namespace dev { namespace eth { class Client; } }
namespace dev
{
namespace eth { class Client; }
namespace az
{
class Main;
@ -44,7 +51,7 @@ private slots:
void on_saveButton_clicked();
private:
dev::eth::Client* ethereum() const;
eth::Client* ethereum() const;
void fillBlocks();
void fillContracts();
void generateJSON();
@ -53,5 +60,8 @@ private:
std::unique_ptr<Ui::ExportState> ui;
Main* m_main;
int m_recentBlocks = 0;
dev::eth::BlockNumber m_block = dev::eth::LatestBlock;
eth::BlockNumber m_block = eth::LatestBlock;
};
}
}

2
alethzero/LogPanel.cpp

@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file LogPanel.h
/** @file LogPanel.cpp
* @author Gav Wood <i@gavwood.com>
* @date 2015
*/

2
alethzero/LogPanel.h

@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file AllAccounts.h
/** @file LogPanel.h
* @author Gav Wood <i@gavwood.com>
* @date 2015
*/

8
alethzero/Main.ui

@ -641,7 +641,7 @@
<number>0</number>
</property>
<item>
<widget class="MiningView" name="miningView" native="true"/>
<widget class="dev::az::MiningView" name="miningView" native="true"/>
</item>
</layout>
</widget>
@ -940,7 +940,7 @@ font-size: 14pt</string>
<number>0</number>
</property>
<item>
<widget class="SyncView" name="downloadView" native="true"/>
<widget class="dev::az::SyncView" name="downloadView" native="true"/>
</item>
</layout>
</widget>
@ -1617,13 +1617,13 @@ font-size: 14pt</string>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>MiningView</class>
<class>dev::az::MiningView</class>
<extends>QWidget</extends>
<header>MiningView.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>SyncView</class>
<class>dev::az::SyncView</class>
<extends>QWidget</extends>
<header>DownloadView.h</header>
<container>1</container>

52
alethzero/MainWin.cpp

@ -87,32 +87,7 @@ using namespace p2p;
using namespace eth;
namespace js = json_spirit;
string Main::fromRaw(h256 _n, unsigned* _inc)
{
if (_n)
{
string s((char const*)_n.data(), 32);
auto l = s.find_first_of('\0');
if (!l)
return string();
if (l != string::npos)
{
auto p = s.find_first_not_of('\0', l);
if (!(p == string::npos || (_inc && p == 31)))
return string();
if (_inc)
*_inc = (byte)s[31];
s.resize(l);
}
for (auto i: s)
if (i < 32)
return string();
return s;
}
return string();
}
QString contentsOfQResource(string const& res)
QString dev::az::contentsOfQResource(string const& res)
{
QFile file(QString::fromStdString(res));
if (!file.open(QFile::ReadOnly))
@ -309,6 +284,31 @@ Main::~Main()
writeSettings();
}
string Main::fromRaw(h256 const&_n, unsigned* _inc)
{
if (_n)
{
string s((char const*)_n.data(), 32);
auto l = s.find_first_of('\0');
if (!l)
return string();
if (l != string::npos)
{
auto p = s.find_first_not_of('\0', l);
if (!(p == string::npos || (_inc && p == 31)))
return string();
if (_inc)
*_inc = (byte)s[31];
s.resize(l);
}
for (auto i: s)
if (i < 32)
return string();
return s;
}
return string();
}
bool Main::confirm() const
{
return ui->natSpec->isChecked();

71
alethzero/MainWin.h

@ -50,16 +50,24 @@ namespace Ui {
class Main;
}
namespace dev { namespace eth {
class Client;
class State;
}}
namespace jsonrpc {
class HttpServer;
}
class QWebEnginePage;
namespace dev
{
namespace eth
{
class Client;
class State;
}
namespace az
{
class OurWebThreeStubServer;
class DappLoader;
class DappHost;
@ -67,7 +75,7 @@ struct Dapp;
QString contentsOfQResource(std::string const& res);
class Main: public dev::az::MainFace
class Main: public MainFace
{
Q_OBJECT
@ -75,28 +83,28 @@ public:
explicit Main(QWidget *parent = 0);
~Main();
dev::WebThreeDirect* web3() const override { return m_webThree.get(); }
dev::eth::Client* ethereum() const override { return m_webThree->ethereum(); }
std::shared_ptr<dev::shh::WhisperHost> whisper() const override { return m_webThree->whisper(); }
WebThreeDirect* web3() const override { return m_webThree.get(); }
eth::Client* ethereum() const override { return m_webThree->ethereum(); }
std::shared_ptr<shh::WhisperHost> whisper() const override { return m_webThree->whisper(); }
bool confirm() const;
NatSpecFace* natSpec() { return &m_natSpecDB; }
std::string pretty(dev::Address const& _a) const override;
std::string prettyU256(dev::u256 const& _n) const override;
std::string prettyU256(u256 const& _n) const override;
std::string render(dev::Address const& _a) const override;
std::pair<dev::Address, dev::bytes> fromString(std::string const& _a) const override;
std::string renderDiff(dev::eth::StateDiff const& _d) const override;
std::pair<Address, bytes> fromString(std::string const& _a) const override;
std::string renderDiff(eth::StateDiff const& _d) const override;
QList<dev::KeyPair> owned() const { return m_myIdentities; }
QList<KeyPair> owned() const { return m_myIdentities; }
dev::u256 gasPrice() const override;
u256 gasPrice() const override;
dev::eth::KeyManager& keyManager() override { return m_keyManager; }
eth::KeyManager& keyManager() override { return m_keyManager; }
void noteKeysChanged() override { refreshBalances(); }
bool doConfirm();
dev::Secret retrieveSecret(dev::Address const& _address) const override;
Secret retrieveSecret(Address const& _address) const override;
public slots:
void load(QString _file);
@ -200,18 +208,18 @@ signals:
void poll();
private:
template <class P> void loadPlugin() { dev::az::Plugin* p = new P(this); initPlugin(p); }
void initPlugin(dev::az::Plugin* _p);
void finalisePlugin(dev::az::Plugin* _p);
template <class P> void loadPlugin() { Plugin* p = new P(this); initPlugin(p); }
void initPlugin(Plugin* _p);
void finalisePlugin(Plugin* _p);
void unloadPlugin(std::string const& _name);
void debugDumpState(int _add);
dev::p2p::NetworkPreferences netPrefs() const;
p2p::NetworkPreferences netPrefs() const;
QString lookup(QString const& _n) const;
dev::Address getNameReg() const;
dev::Address getCurrencies() const;
Address getNameReg() const;
Address getCurrencies() const;
void updateFee();
void readSettings(bool _skipGeometry = false);
@ -219,8 +227,8 @@ private:
void setPrivateChain(QString const& _private, bool _forceConfigure = false);
unsigned installWatch(dev::eth::LogFilter const& _tf, dev::az::WatchHandler const& _f) override;
unsigned installWatch(dev::h256 const& _tf, dev::az::WatchHandler const& _f) override;
unsigned installWatch(eth::LogFilter const& _tf, WatchHandler const& _f) override;
unsigned installWatch(h256 const& _tf, WatchHandler const& _f) override;
void uninstallWatch(unsigned _w);
void keysChanged();
@ -248,22 +256,22 @@ private:
void refreshBlockCount();
void refreshBalances();
void setBeneficiary(dev::Address const& _b);
void setBeneficiary(Address const& _b);
std::string getPassword(std::string const& _title, std::string const& _for, std::string* _hint = nullptr, bool* _ok = nullptr);
std::unique_ptr<Ui::Main> ui;
std::unique_ptr<dev::WebThreeDirect> m_webThree;
std::unique_ptr<WebThreeDirect> m_webThree;
std::map<unsigned, dev::az::WatchHandler> m_handlers;
std::map<unsigned, WatchHandler> m_handlers;
unsigned m_nameRegFilter = (unsigned)-1;
unsigned m_currenciesFilter = (unsigned)-1;
unsigned m_balancesFilter = (unsigned)-1;
QByteArray m_networkConfig;
QStringList m_servers;
QList<dev::KeyPair> m_myIdentities;
dev::eth::KeyManager m_keyManager;
QList<KeyPair> m_myIdentities;
eth::KeyManager m_keyManager;
QString m_privateChain;
dev::Address m_nameReg;
dev::Address m_beneficiary;
@ -275,7 +283,7 @@ private:
std::unique_ptr<jsonrpc::HttpServer> m_httpConnector;
std::unique_ptr<OurWebThreeStubServer> m_server;
static std::string fromRaw(dev::h256 _n, unsigned* _inc = nullptr);
static std::string fromRaw(h256 const& _n, unsigned* _inc = nullptr);
NatspecHandler m_natSpecDB;
Transact* m_transact;
@ -285,3 +293,6 @@ private:
Connect m_connect;
};
}
}

7
alethzero/MiningView.cpp

@ -28,17 +28,12 @@
using namespace std;
using namespace lb;
// do *not* use eth since unsigned conflicts with Qt's global unit definition
// using namespace dev;
using namespace dev::az;
using namespace dev::eth;
// types
using dev::eth::MineInfo;
using dev::eth::WorkingProgress;
// functions
using dev::toString;
using dev::trimFront;

15
alethzero/MiningView.h

@ -31,9 +31,16 @@
#include <libethereum/Client.h>
#endif
namespace dev { namespace eth {
namespace dev
{
namespace eth
{
struct MineInfo;
}}
}
namespace az
{
class MiningView: public QWidget
{
@ -59,3 +66,7 @@ private:
double m_lastBest = 1e31;
bool m_haveReset = false;
};
}
}

3
alethzero/NatspecHandler.cpp

@ -30,7 +30,8 @@
#include <libdevcore/SHA3.h>
#include <libethereum/Defaults.h>
using namespace dev;
using namespace dev::eth;
using namespace az;
using namespace eth;
using namespace std;
namespace fs = boost::filesystem;

8
alethzero/NatspecHandler.h

@ -27,6 +27,11 @@
#include <libdevcore/FixedHash.h>
#include "Context.h"
namespace dev
{
namespace az
{
class NatspecHandler: public NatSpecFace
{
public:
@ -52,3 +57,6 @@ class NatspecHandler: public NatSpecFace
ldb::DB* m_db = nullptr;
Json::Reader m_reader;
};
}
}

3
alethzero/OurWebThreeStubServer.cpp

@ -27,7 +27,8 @@
#include "MainWin.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace az;
using namespace eth;
OurWebThreeStubServer::OurWebThreeStubServer(
jsonrpc::AbstractServerConnector& _conn,

31
alethzero/OurWebThreeStubServer.h

@ -27,9 +27,15 @@
#include <libweb3jsonrpc/WebThreeStubServer.h>
#include <libweb3jsonrpc/AccountHolder.h>
namespace dev
{
namespace az
{
class Main;
class OurAccountHolder: public QObject, public dev::eth::AccountHolder
class OurAccountHolder: public QObject, public eth::AccountHolder
{
Q_OBJECT
@ -47,27 +53,24 @@ protected:
private:
bool showAuthenticationPopup(std::string const& _title, std::string const& _text);
bool showCreationNotice(dev::eth::TransactionSkeleton const& _t, bool _toProxy);
bool showSendNotice(dev::eth::TransactionSkeleton const& _t, bool _toProxy);
bool showUnknownCallNotice(dev::eth::TransactionSkeleton const& _t, bool _toProxy);
bool showCreationNotice(eth::TransactionSkeleton const& _t, bool _toProxy);
bool showSendNotice(eth::TransactionSkeleton const& _t, bool _toProxy);
bool showUnknownCallNotice(eth::TransactionSkeleton const& _t, bool _toProxy);
bool validateTransaction(dev::eth::TransactionSkeleton const& _t, bool _toProxy);
bool validateTransaction(eth::TransactionSkeleton const& _t, bool _toProxy);
std::queue<dev::eth::TransactionSkeleton> m_queued;
dev::Mutex x_queued;
std::queue<eth::TransactionSkeleton> m_queued;
Mutex x_queued;
Main* m_main;
};
class OurWebThreeStubServer: public QObject, public dev::WebThreeStubServer
class OurWebThreeStubServer: public QObject, public WebThreeStubServer
{
Q_OBJECT
public:
OurWebThreeStubServer(
jsonrpc::AbstractServerConnector& _conn,
Main* main
);
OurWebThreeStubServer(jsonrpc::AbstractServerConnector& _conn, Main* main);
virtual std::string shh_newIdentity() override;
@ -77,3 +80,7 @@ signals:
private:
Main* m_main;
};
}
}

8
alethzero/Transact.cpp

@ -41,7 +41,6 @@
#include <libethereum/Client.h>
#include <libethereum/Utility.h>
#include <libethcore/KeyManager.h>
#if ETH_SERPENT
#include <libserpent/funcs.h>
#include <libserpent/util.h>
@ -50,7 +49,8 @@
#include "ui_Transact.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
using namespace az;
using namespace eth;
Transact::Transact(Context* _c, QWidget* _parent):
QDialog(_parent),
@ -206,7 +206,7 @@ void Transact::on_copyUnsigned_clicked()
qApp->clipboard()->setText(QString::fromStdString(toHex(t.rlp())));
}
static std::string toString(TransactionException _te)
/*static std::string toString(TransactionException _te)
{
switch (_te)
{
@ -223,7 +223,7 @@ static std::string toString(TransactionException _te)
case TransactionException::StackUnderflow: return "VM Error: Stack underflow";
default:; return std::string();
}
}
}*/
#if ETH_SOLIDITY
static string getFunctionHashes(dev::solidity::CompilerStack const& _compiler, string const& _contractName)

15
alethzero/Transact.h

@ -30,8 +30,15 @@
#include "Context.h"
namespace Ui { class Transact; }
namespace dev { namespace eth { class Client; } }
namespace dev { namespace solidity { class CompilerStack; } }
namespace dev
{
namespace eth { class Client; }
namespace solidity { class CompilerStack; }
namespace az
{
struct GasRequirements
{
@ -99,3 +106,7 @@ private:
NatSpecFace* m_natSpecDB = nullptr;
bool m_allGood = false;
};
}
}

4
alethzero/WebPage.cpp

@ -20,8 +20,10 @@
*/
#include "WebPage.h"
using namespace dev;
using namespace az;
void WebPage::javaScriptConsoleMessage(QWebEnginePage::JavaScriptConsoleMessageLevel _level, const QString& _message, int _lineNumber, const QString& _sourceID)
void WebPage::javaScriptConsoleMessage(QWebEnginePage::JavaScriptConsoleMessageLevel _level, QString const& _message, int _lineNumber, QString const& _sourceID)
{
QString prefix = _level == QWebEnginePage::ErrorMessageLevel ? "error" : _level == QWebEnginePage::WarningMessageLevel ? "warning" : "";
emit consoleMessage(QString("%1(%2:%3):%4").arg(prefix).arg(_sourceID).arg(_lineNumber).arg(_message));

13
alethzero/WebPage.h

@ -27,14 +27,25 @@
#include <QtWebEngineWidgets/QWebEnginePage>
#pragma GCC diagnostic pop
namespace dev
{
namespace az
{
class WebPage: public QWebEnginePage
{
Q_OBJECT
public:
WebPage(QObject* _parent): QWebEnginePage(_parent) { }
WebPage(QObject* _parent): QWebEnginePage(_parent) {}
signals:
void consoleMessage(QString const& _msg);
protected:
void javaScriptConsoleMessage(QWebEnginePage::JavaScriptConsoleMessageLevel _level, const QString& _message, int _lineNumber, const QString& _sourceID) override;
};
}
}

2
alethzero/main.cpp

@ -5,7 +5,7 @@ int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Q_INIT_RESOURCE(js);
Main w;
dev::az::Main w;
w.show();
return a.exec();

Loading…
Cancel
Save