Browse Source

Revert webtech changes that should never have been in.

cl-refactor
Gav Wood 11 years ago
parent
commit
495dac1d33
  1. 30
      alethzero/Main.ui
  2. 176
      alethzero/MainWin.cpp
  3. 142
      alethzero/MainWin.h
  4. 2
      libethereum/Common.h

30
alethzero/Main.ui

@ -36,29 +36,6 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<widget class="QWidget" name="tabWidgetPage1">
<attribute name="title">
<string/>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLineEdit" name="urlEdit"/>
</item>
<item>
<widget class="QWebView" name="webView">
<property name="url">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
@ -869,13 +846,6 @@
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QWebView</class>
<extends>QWidget</extends>
<header>QtWebKitWidgets/QWebView</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>destination</tabstop>
<tabstop>calculatedName</tabstop>

176
alethzero/MainWin.cpp

@ -52,152 +52,6 @@ using eth::g_logPost;
using eth::g_logVerbosity;
using eth::c_instructionInfo;
// Horrible global for the mainwindow. Needed for the QEthereums to find the Main window which acts as multiplexer for now.
// Can get rid of this once we've sorted out ITC for signalling & multiplexed querying.
Main* g_main = nullptr;
QEthereum::QEthereum(QObject* _p): QObject(_p)
{
connect(g_main, SIGNAL(changed()), SIGNAL(changed()));
}
QEthereum::~QEthereum()
{
}
Client* QEthereum::client() const
{
return g_main->client();
}
Address QEthereum::coinbase() const
{
return client()->address();
}
Address QEthereum::account() const
{
if (g_main->owned().empty())
return Address();
return g_main->owned()[0].address();
}
QVector<Address> QEthereum::accounts() const
{
QVector<Address> ret;
for (auto i: g_main->owned())
ret.push_back(i.address());
return ret;
}
void QEthereum::setCoinbase(Address _a)
{
if (client()->address() != _a)
{
client()->setAddress(_a);
changed();
}
}
QAccount::QAccount(QObject*)
{
}
QAccount::~QAccount()
{
}
void QAccount::setEthereum(QEthereum* _eth)
{
if (m_eth == _eth)
return;
if (m_eth)
disconnect(m_eth, SIGNAL(changed()), this, SIGNAL(changed()));
m_eth = _eth;
if (m_eth)
connect(m_eth, SIGNAL(changed()), this, SIGNAL(changed()));
ethChanged();
changed();
}
u256 QAccount::balance() const
{
if (m_eth)
return m_eth->balanceAt(m_address);
return 0;
}
double QAccount::txCount() const
{
if (m_eth)
return m_eth->txCountAt(m_address);
return 0;
}
bool QAccount::isContract() const
{
if (m_eth)
return m_eth->isContractAt(m_address);
return 0;
}
u256 QEthereum::balanceAt(Address _a) const
{
return client()->postState().balance(_a);
}
bool QEthereum::isContractAt(Address _a) const
{
return client()->postState().isContractAddress(_a);
}
bool QEthereum::isMining() const
{
return client()->isMining();
}
bool QEthereum::isListening() const
{
return client()->haveNetwork();
}
void QEthereum::setMining(bool _l)
{
if (_l)
client()->startMining();
else
client()->stopMining();
}
void QEthereum::setListening(bool _l)
{
if (_l)
client()->startNetwork();
else
client()->stopNetwork();
}
double QEthereum::txCountAt(Address _a) const
{
return (double)client()->postState().transactionsFrom(_a);
}
unsigned QEthereum::peerCount() const
{
return (unsigned)client()->peerCount();
}
void QEthereum::transact(Secret _secret, u256 _amount, u256 _gasPrice, u256 _gas, QByteArray _code, QByteArray _init)
{
client()->transact(_secret, _amount, bytes(_code.data(), _code.data() + _code.size()), bytes(_init.data(), _init.data() + _init.size()), _gas, _gasPrice);
}
void QEthereum::transact(Secret _secret, Address _dest, u256 _amount, u256 _gasPrice, u256 _gas, QByteArray _data)
{
client()->transact(_secret, _amount, _dest, bytes(_data.data(), _data.data() + _data.size()), _gas, _gasPrice);
}
static void initUnits(QComboBox* _b)
{
for (auto n = (::uint)units().size(); n-- != 0; )
@ -233,20 +87,11 @@ Main::Main(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Main)
{
g_main = this;
setWindowFlags(Qt::Window);
ui->setupUi(this);
g_logPost = [=](std::string const& s, char const* c) { simpleDebugOut(s, c); ui->log->addItem(QString::fromStdString(s)); };
m_client.reset(new Client("AlethZero"));
qRegisterMetaType<eth::u256>("eth::u256");
qRegisterMetaType<eth::KeyPair>("eth::KeyPair");
qRegisterMetaType<eth::Secret>("eth::Secret");
qRegisterMetaType<eth::Address>("eth::Address");
qRegisterMetaType<QAccount*>("QAccount*");
qRegisterMetaType<QEthereum*>("QEthereum*");
m_refresh = new QTimer(this);
connect(m_refresh, SIGNAL(timeout()), SLOT(refresh()));
m_refresh->start(100);
@ -291,18 +136,6 @@ Main::Main(QWidget *parent) :
statusBar()->addPermanentWidget(ui->peerCount);
statusBar()->addPermanentWidget(ui->blockCount);
connect(ui->webView, &QWebView::titleChanged, [=]()
{
ui->tabWidget->setTabText(0, ui->webView->title());
});
QWebFrame* f = ui->webView->page()->currentFrame();
connect(f, &QWebFrame::javaScriptWindowObjectCleared, [=](){
f->addToJavaScriptWindowObject("eth", new QEthereum, QWebFrame::ScriptOwnership);
f->addToJavaScriptWindowObject("u256", new U256Helper, QWebFrame::ScriptOwnership);
f->addToJavaScriptWindowObject("key", new KeyHelper, QWebFrame::ScriptOwnership);
});
readSettings();
refresh();
@ -405,8 +238,6 @@ void Main::writeSettings()
s.setValue("peers", m_peers);
s.setValue("nameReg", ui->nameReg->text());
s.setValue("url", ui->urlEdit->text());
s.setValue("geometry", saveGeometry());
s.setValue("windowState", saveState());
}
@ -438,8 +269,6 @@ void Main::readSettings()
ui->idealPeers->setValue(s.value("idealPeers", ui->idealPeers->value()).toInt());
ui->port->setValue(s.value("port", ui->port->value()).toInt());
ui->nameReg->setText(s.value("NameReg", "").toString());
ui->urlEdit->setText(s.value("url", "file:///home/gav/gavcoin.html").toString());
on_urlEdit_editingFinished();
}
void Main::on_nameReg_textChanged()
@ -569,11 +398,6 @@ void Main::refresh(bool _override)
m_client->unlock();
}
void Main::on_urlEdit_editingFinished()
{
ui->webView->setUrl(ui->urlEdit->text());
}
void Main::ourAccountsRowsMoved()
{
QVector<KeyPair> myKeys;

142
alethzero/MainWin.h

@ -23,145 +23,6 @@ class QJSEngine;
class QEthereum;
class QAccount;
Q_DECLARE_METATYPE(eth::u256)
Q_DECLARE_METATYPE(eth::Address)
Q_DECLARE_METATYPE(eth::Secret)
Q_DECLARE_METATYPE(eth::KeyPair)
Q_DECLARE_METATYPE(QEthereum*)
Q_DECLARE_METATYPE(QAccount*)
class U256Helper: public QObject
{
Q_OBJECT
public:
U256Helper(QObject* _p = nullptr): QObject(_p) {}
Q_INVOKABLE eth::u256 add(eth::u256 _a, eth::u256 _b) const { return _a + _b; }
Q_INVOKABLE eth::u256 sub(eth::u256 _a, eth::u256 _b) const { return _a - _b; }
Q_INVOKABLE eth::u256 mul(eth::u256 _a, int _b) const { return _a * _b; }
Q_INVOKABLE eth::u256 mul(int _a, eth::u256 _b) const { return _a * _b; }
Q_INVOKABLE eth::u256 div(eth::u256 _a, int _b) const { return _a / _b; }
Q_INVOKABLE eth::u256 wei(double _s) const { return (eth::u256)_s; }
Q_INVOKABLE eth::u256 szabo(double _s) const { return (eth::u256)(_s * (double)eth::szabo); }
Q_INVOKABLE eth::u256 finney(double _s) const { return (eth::u256)(_s * (double)eth::finney); }
Q_INVOKABLE eth::u256 ether(double _s) const { return (eth::u256)(_s * (double)eth::ether); }
Q_INVOKABLE eth::u256 wei(unsigned _s) const { return (eth::u256)_s; }
Q_INVOKABLE eth::u256 szabo(unsigned _s) const { return (eth::u256)(_s * eth::szabo); }
Q_INVOKABLE eth::u256 finney(unsigned _s) const { return (eth::u256)(_s * eth::finney); }
Q_INVOKABLE eth::u256 ether(unsigned _s) const { return (eth::u256)(_s * eth::ether); }
Q_INVOKABLE double toWei(eth::u256 _t) const { return (double)_t; }
Q_INVOKABLE double toSzabo(eth::u256 _t) const { return toWei(_t) / (double)eth::szabo; }
Q_INVOKABLE double toFinney(eth::u256 _t) const { return toWei(_t) / (double)eth::finney; }
Q_INVOKABLE double toEther(eth::u256 _t) const { return toWei(_t) / (double)eth::ether; }
Q_INVOKABLE double value(eth::u256 _t) const { return (double)_t; }
Q_INVOKABLE QString stringOf(eth::u256 _t) const { return QString::fromStdString(eth::formatBalance(_t)); }
Q_INVOKABLE QString testy() const { return "TEST"; }
};
class KeyHelper: public QObject
{
Q_OBJECT
public:
KeyHelper(QObject* _p = nullptr): QObject(_p) {}
Q_INVOKABLE eth::KeyPair create() const { return eth::KeyPair::create(); }
Q_INVOKABLE eth::Address address(eth::KeyPair _p) const { return _p.address(); }
Q_INVOKABLE eth::Secret secret(eth::KeyPair _p) const { return _p.secret(); }
Q_INVOKABLE eth::KeyPair keypair(eth::Secret _k) const { return eth::KeyPair(_k); }
Q_INVOKABLE bool isNull(eth::Address _a) const { return !_a; }
Q_INVOKABLE eth::Address addressOf(QString _s) const { return eth::Address(_s.toStdString()); }
Q_INVOKABLE QString stringOf(eth::Address _a) const { return QString::fromStdString(eth::toHex(_a.asArray())); }
Q_INVOKABLE QString toAbridged(eth::Address _a) const { return QString::fromStdString(_a.abridged()); }
};
class QAccount: public QObject
{
Q_OBJECT
public:
QAccount(QObject* _p = nullptr);
virtual ~QAccount();
Q_INVOKABLE QEthereum* ethereum() const { return m_eth; }
Q_INVOKABLE eth::u256 balance() const;
Q_INVOKABLE double txCount() const;
Q_INVOKABLE bool isContract() const;
// TODO: past transactions models.
public slots:
void setEthereum(QEthereum* _eth);
signals:
void changed();
void ethChanged();
private:
QEthereum* m_eth = nullptr;
eth::Address m_address;
Q_PROPERTY(eth::u256 balance READ balance NOTIFY changed STORED false)
Q_PROPERTY(double txCount READ txCount NOTIFY changed STORED false)
Q_PROPERTY(bool isContract READ isContract NOTIFY changed STORED false)
Q_PROPERTY(eth::Address address MEMBER m_address NOTIFY changed)
Q_PROPERTY(QEthereum* ethereum READ ethereum WRITE setEthereum NOTIFY ethChanged)
};
class QEthereum: public QObject
{
Q_OBJECT
public:
QEthereum(QObject* _p = nullptr);
virtual ~QEthereum();
eth::Client* client() const;
Q_INVOKABLE eth::Address coinbase() const;
Q_INVOKABLE bool isListening() const;
Q_INVOKABLE bool isMining() const;
Q_INVOKABLE eth::u256 balanceAt(eth::Address _a) const;
Q_INVOKABLE double txCountAt(eth::Address _a) const;
Q_INVOKABLE bool isContractAt(eth::Address _a) const;
Q_INVOKABLE QString ethTest() const { return "Hello world!"; }
Q_INVOKABLE eth::Address account() const;
Q_INVOKABLE QVector<eth::Address> accounts() const;
Q_INVOKABLE unsigned peerCount() const;
Q_INVOKABLE QEthereum* self() { return this; }
public slots:
void transact(eth::Secret _secret, eth::Address _dest, eth::u256 _amount, eth::u256 _gasPrice, eth::u256 _gas, QByteArray _data);
void transact(eth::Secret _secret, eth::u256 _amount, eth::u256 _gasPrice, eth::u256 _gas, QByteArray _code, QByteArray _init);
void setCoinbase(eth::Address);
void setMining(bool _l);
void setListening(bool _l);
signals:
void changed();
// void netChanged();
// void miningChanged();
private:
Q_PROPERTY(eth::Address coinbase READ coinbase WRITE setCoinbase NOTIFY changed)
Q_PROPERTY(bool listening READ isListening WRITE setListening)
Q_PROPERTY(bool mining READ isMining WRITE setMining)
};
class Main : public QMainWindow
{
Q_OBJECT
@ -200,7 +61,6 @@ private slots:
void on_nameReg_textChanged();
void on_preview_triggered() { refresh(true); }
void on_quit_triggered() { close(); }
void on_urlEdit_editingFinished();
void refresh(bool _override = false);
void refreshNetwork();
@ -241,8 +101,6 @@ private:
unsigned m_backupGas;
QNetworkAccessManager m_webCtrl;
QEthereum* m_ethereum;
};
#endif // MAIN_H

2
libethereum/Common.h

@ -24,7 +24,7 @@
#pragma once
// define version
#define ETH_VERSION 0.4.2
#define ETH_VERSION 0.4.3
// way to many uint to size_t warnings in 32 bit build
#ifdef _M_IX86

Loading…
Cancel
Save