Browse Source

removed unused code, watched and polling not working yet

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
7de3f8aa8e
  1. 34
      alethzero/MainWin.cpp
  2. 6
      alethzero/MainWin.h
  3. 607
      libqethereum/QEthereum.cpp
  4. 275
      libqethereum/QEthereum.h

34
alethzero/MainWin.cpp

@ -136,10 +136,7 @@ Main::Main(QWidget *parent) :
connect(ui->webView, &QWebView::loadStarted, [this]()
{
// NOTE: no need to delete as QETH_INSTALL_JS_NAMESPACE adopts it.
m_dev = new QDev(this);
m_ethereum = new QEthereum(this, ethereum(), owned());
m_whisper = new QWhisper(this, whisper());
m_p2p = new QPeer2Peer(this, peer2peer());
QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
QWebFrame* f = ui->webView->page()->mainFrame();
@ -147,22 +144,19 @@ Main::Main(QWidget *parent) :
m_qweb = new QWebThree(this);
auto qdev = m_dev;
auto qeth = m_ethereum;
auto qshh = m_whisper;
auto qp2p = m_p2p;
auto qweb = m_qweb;
auto list = owned().toStdList();
jsonrpcServer = auto_ptr<WebThreeStubServer>(new WebThreeStubServer(new QWebThreeConnector(qweb), *web3(), {std::begin(list), std::end(list)}));
jsonrpcServer->StartListening();
m_server = auto_ptr<WebThreeStubServer>(new WebThreeStubServer(new QWebThreeConnector(qweb), *web3(), {std::begin(list), std::end(list)}));
m_server->StartListening();
connect(f, &QWebFrame::javaScriptWindowObjectCleared, QETH_INSTALL_JS_NAMESPACE(f, this, qdev, qeth, qshh, qp2p, qweb));
connect(f, &QWebFrame::javaScriptWindowObjectCleared, QETH_INSTALL_JS_NAMESPACE(f, this, qweb));
});
connect(ui->webView, &QWebView::loadFinished, [=]()
{
m_ethereum->poll();
// m_ethereum->poll();
});
connect(ui->webView, &QWebView::titleChanged, [=]()
@ -190,7 +184,7 @@ Main::~Main()
{
// Must do this here since otherwise m_ethereum'll be deleted (and therefore clearWatches() called by the destructor)
// *after* the client is dead.
m_ethereum->clientDieing();
// m_ethereum->clientDieing();
g_logPost = simpleDebugOut;
writeSettings();
@ -1011,8 +1005,8 @@ void Main::timerEvent(QTimerEvent*)
else
interval += 100;
if (m_ethereum)
m_ethereum->poll();
// if (m_ethereum)
// m_ethereum->poll();
for (auto const& i: m_handlers)
if (ethereum()->checkWatch(i.first))
@ -1135,8 +1129,12 @@ void Main::ourAccountsRowsMoved()
myKeys.push_back(i);
}
m_myKeys = myKeys;
if (m_ethereum)
m_ethereum->setAccounts(myKeys);
if (m_server.get())
{
auto list = owned().toStdList();
m_server->setAccounts({std::begin(list), std::end(list)});
}
}
void Main::on_inject_triggered()
@ -1522,7 +1520,7 @@ void Main::on_killBlockchain_triggered()
ui->net->setChecked(false);
web3()->stopNetwork();
ethereum()->killChain();
m_ethereum->setClient(ethereum());
// m_ethereum->setClient(ethereum());
readSettings(true);
installWatches();
refreshAll();

6
alethzero/MainWin.h

@ -249,10 +249,6 @@ private:
QString m_logHistory;
bool m_logChanged = true;
std::auto_ptr<WebThreeStubServer> jsonrpcServer;
QDev* m_dev = nullptr;
QEthereum* m_ethereum = nullptr;
QWhisper* m_whisper = nullptr;
QPeer2Peer* m_p2p = nullptr;
std::auto_ptr<WebThreeStubServer> m_server;
QWebThree* m_qweb = nullptr;
};

607
libqethereum/QEthereum.cpp

@ -7,615 +7,11 @@
#include <libethereum/EthereumHost.h>
#include <libp2p/Host.h>
#include "QEthereum.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
dev::bytes toBytes(QString const& _s)
{
if (_s.startsWith("0x"))
// Hex
return dev::fromHex(_s.mid(2).toStdString());
else if (!_s.contains(QRegExp("[^0-9]")))
// Decimal
return dev::toCompactBigEndian(dev::bigint(_s.toStdString()));
else
{
// Binary
cwarn << "THIS FUNCTIONALITY IS DEPRECATED. DO NOT ASSUME ASCII/BINARY-STRINGS WILL BE ACCEPTED. USE eth.fromAscii().";
return asBytes(_s);
}
}
QString padded(QString const& _s, unsigned _l, unsigned _r)
{
dev::bytes b = toBytes(_s);
while (b.size() < _l)
b.insert(b.begin(), 0);
while (b.size() < _r)
b.push_back(0);
return asQString(dev::asBytes(dev::asString(b).substr(b.size() - max(_l, _r))));
}
//"0xff".bin().unbin()
QString padded(QString const& _s, unsigned _l)
{
if (_s.startsWith("0x") || !_s.contains(QRegExp("[^0-9]")))
// Numeric: pad to right
return padded(_s, _l, _l);
else
// Text: pad to the left
return padded(_s, 0, _l);
}
QString unpadded(QString _s)
{
while (_s.size() && _s.endsWith(QChar(0)))
_s.chop(1);
return _s;
}
QEthereum::QEthereum(QObject* _p, eth::Interface* _c, QList<dev::KeyPair> _accounts):
QObject(_p), m_client(_c)
{
// required to prevent crash on osx when performing addto/evaluatejavascript calls
moveToThread(_p->thread());
setAccounts(_accounts);
}
QEthereum::~QEthereum()
{
clearWatches();
}
void QEthereum::clientDieing()
{
clearWatches();
m_client = nullptr;
}
void QEthereum::clearWatches()
{
if (m_client)
for (auto i: m_watches)
m_client->uninstallWatch(i);
m_watches.clear();
}
eth::Interface* QEthereum::client() const
{
return m_client;
}
QString QEthereum::lll(QString _s) const
{
return toQJS(dev::eth::compileLLL(_s.toStdString()));
}
QString QDev::sha3(QString _s) const
{
return toQJS(dev::sha3(toBytes(_s)));
}
QString QDev::sha3(QString _s1, QString _s2) const
{
return toQJS(dev::sha3(asBytes(padded(_s1, 32)) + asBytes(padded(_s2, 32))));
}
QString QDev::sha3(QString _s1, QString _s2, QString _s3) const
{
return toQJS(dev::sha3(asBytes(padded(_s1, 32)) + asBytes(padded(_s2, 32)) + asBytes(padded(_s3, 32))));
}
QString QDev::offset(QString _s, int _i) const
{
return toQJS(toU256(_s) + _i);
}
QString QEthereum::coinbase() const
{
return m_client ? toQJS(client()->address()) : "";
}
unsigned QEthereum::number() const
{
return client() ? client()->number() + 1 : 0;
}
QStringList QEthereum::accounts() const
{
QStringList ret;
for (auto i: m_accounts)
ret.push_back(toQJS(i.first));
return ret;
}
void QEthereum::setCoinbaseImpl(QString _a)
{
if (m_client && client()->address() != toAddress(_a))
{
client()->setAddress(toAddress(_a));
coinbaseChanged();
}
}
void QEthereum::setDefault(int _block)
{
if (m_client)
m_client->setDefault(_block);
}
int QEthereum::getDefault() const
{
return m_client ? m_client->getDefault() : 0;
}
QString QEthereum::balanceAt(QString _a) const
{
return m_client ? toQJS(client()->balanceAt(toAddress(_a))) : "";
}
QString QEthereum::balanceAt(QString _a, int _block) const
{
return m_client ? toQJS(client()->balanceAt(toAddress(_a), _block)) : "";
}
QString QEthereum::stateAt(QString _a, QString _p) const
{
return m_client ? toQJS(client()->stateAt(toAddress(_a), toU256(_p))) : "";
}
QString QEthereum::stateAt(QString _a, QString _p, int _block) const
{
return m_client ? toQJS(client()->stateAt(toAddress(_a), toU256(_p), _block)) : "";
}
QString QEthereum::codeAt(QString _a) const
{
return m_client ? ::fromBinary(client()->codeAt(toAddress(_a))) : "";
}
QString QEthereum::codeAt(QString _a, int _block) const
{
return m_client ? ::fromBinary(client()->codeAt(toAddress(_a), _block)) : "";
}
double QEthereum::countAt(QString _a) const
{
return m_client ? (double)(uint64_t)client()->countAt(toAddress(_a)) : 0;
}
double QEthereum::countAt(QString _a, int _block) const
{
return m_client ? (double)(uint64_t)client()->countAt(toAddress(_a), _block) : 0;
}
static dev::eth::MessageFilter toMessageFilter(QString _json)
{
dev::eth::MessageFilter filter;
QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object();
if (f.contains("earliest"))
filter.withEarliest(f["earliest"].toInt());
if (f.contains("latest"))
filter.withLatest(f["latest"].toInt());
if (f.contains("max"))
filter.withMax(f["max"].toInt());
if (f.contains("skip"))
filter.withSkip(f["skip"].toInt());
if (f.contains("from"))
{
if (f["from"].isArray())
for (auto i: f["from"].toArray())
filter.from(toAddress(i.toString()));
else
filter.from(toAddress(f["from"].toString()));
}
if (f.contains("to"))
{
if (f["to"].isArray())
for (auto i: f["to"].toArray())
filter.to(toAddress(i.toString()));
else
filter.to(toAddress(f["to"].toString()));
}
if (f.contains("altered"))
{
if (f["altered"].isArray())
for (auto i: f["altered"].toArray())
if (i.isObject())
filter.altered(toAddress(i.toObject()["id"].toString()), toU256(i.toObject()["at"].toString()));
else
filter.altered(toAddress(i.toString()));
else
if (f["altered"].isObject())
filter.altered(toAddress(f["altered"].toObject()["id"].toString()), toU256(f["altered"].toObject()["at"].toString()));
else
filter.altered(toAddress(f["altered"].toString()));
}
return filter;
}
struct TransactionSkeleton
{
Address from;
Address to;
u256 value;
bytes data;
u256 gas;
u256 gasPrice;
};
static TransactionSkeleton toTransaction(QString _json)
{
TransactionSkeleton ret;
QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object();
if (f.contains("from"))
ret.from = toAddress(f["from"].toString());
if (f.contains("to"))
ret.to = toAddress(f["to"].toString());
if (f.contains("value"))
ret.value = toU256(f["value"].toString());
if (f.contains("gas"))
ret.gas = toU256(f["gas"].toString());
if (f.contains("gasPrice"))
ret.gasPrice = toU256(f["gasPrice"].toString());
if (f.contains("data") || f.contains("code") || f.contains("dataclose"))
{
if (f["data"].isString())
ret.data = toBytes(f["data"].toString());
else if (f["code"].isString())
ret.data = toBytes(f["code"].toString());
else if (f["data"].isArray())
for (auto i: f["data"].toArray())
dev::operator +=(ret.data, asBytes(padded(i.toString(), 32)));
else if (f["code"].isArray())
for (auto i: f["code"].toArray())
dev::operator +=(ret.data, asBytes(padded(i.toString(), 32)));
else if (f["dataclose"].isArray())
for (auto i: f["dataclose"].toArray())
dev::operator +=(ret.data, toBytes(i.toString()));
}
return ret;
}
static QString toJson(dev::eth::PastMessages const& _pms)
{
QJsonArray jsonArray;
for (dev::eth::PastMessage const& t: _pms)
{
QJsonObject v;
v["input"] = ::fromBinary(t.input);
v["output"] = ::fromBinary(t.output);
v["to"] = toQJS(t.to);
v["from"] = toQJS(t.from);
v["origin"] = toQJS(t.origin);
v["timestamp"] = (int)t.timestamp;
v["coinbase"] = toQJS(t.coinbase);
v["block"] = toQJS(t.block);
QJsonArray path;
for (int i: t.path)
path.append(i);
v["path"] = path;
v["number"] = (int)t.number;
jsonArray.append(v);
}
return QString::fromUtf8(QJsonDocument(jsonArray).toJson());
}
static QString toJson(dev::eth::BlockInfo const& _bi, dev::eth::BlockDetails const& _bd)
{
QJsonObject v;
v["hash"] = toQJS(_bi.hash);
v["parentHash"] = toQJS(_bi.parentHash);
v["sha3Uncles"] = toQJS(_bi.sha3Uncles);
v["miner"] = toQJS(_bi.coinbaseAddress);
v["stateRoot"] = toQJS(_bi.stateRoot);
v["transactionsRoot"] = toQJS(_bi.transactionsRoot);
v["difficulty"] = toQJS(_bi.difficulty);
v["number"] = (int)_bi.number;
v["minGasPrice"] = toQJS(_bi.minGasPrice);
v["gasLimit"] = (int)_bi.gasLimit;
v["gasUsed"] = (int)_bi.gasUsed;
v["timestamp"] = (int)_bi.timestamp;
v["extraData"] = ::fromBinary(_bi.extraData);
v["nonce"] = toQJS(_bi.nonce);
QJsonArray children;
for (auto c: _bd.children)
children.append(toQJS(c));
v["children"] = children;
v["totalDifficulty"] = toQJS(_bd.totalDifficulty);
v["bloom"] = toQJS(_bd.bloom);
return QString::fromUtf8(QJsonDocument(v).toJson());
}
static QString toJson(dev::eth::BlockInfo const& _bi)
{
QJsonObject v;
v["hash"] = toQJS(_bi.hash);
v["parentHash"] = toQJS(_bi.parentHash);
v["sha3Uncles"] = toQJS(_bi.sha3Uncles);
v["miner"] = toQJS(_bi.coinbaseAddress);
v["stateRoot"] = toQJS(_bi.stateRoot);
v["transactionsRoot"] = toQJS(_bi.transactionsRoot);
v["difficulty"] = toQJS(_bi.difficulty);
v["number"] = (int)_bi.number;
v["minGasPrice"] = toQJS(_bi.minGasPrice);
v["gasLimit"] = (int)_bi.gasLimit;
v["gasUsed"] = (int)_bi.gasUsed;
v["timestamp"] = (int)_bi.timestamp;
v["extraData"] = ::fromBinary(_bi.extraData);
v["nonce"] = toQJS(_bi.nonce);
return QString::fromUtf8(QJsonDocument(v).toJson());
}
static QString toJson(dev::eth::Transaction const& _bi)
{
QJsonObject v;
v["hash"] = toQJS(_bi.sha3());
v["input"] = ::fromBinary(_bi.data);
v["to"] = toQJS(_bi.receiveAddress);
v["from"] = toQJS(_bi.sender());
v["gas"] = (int)_bi.gas;
v["gasPrice"] = toQJS(_bi.gasPrice);
v["nonce"] = (int)_bi.nonce;
v["value"] = toQJS(_bi.value);
return QString::fromUtf8(QJsonDocument(v).toJson());
}
static dev::FixedHash<32>toHash(QString const & _json, dev::eth::Interface* _client)
{
QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object();
dev::FixedHash<32> hash;
if (f.contains("hash"))
hash = ::toFixed<32>(f["hash"].toString());
else if (f.contains("number"))
hash =_client->hashFromNumber((unsigned)f["number"].toInt());
return hash;
}
QString QEthereum::getBlockImpl(QString _json) const
{
if (!client())
return "";
auto hash = toHash(_json, client());
return toJson(client()->blockInfo(hash), client()->blockDetails(hash));
}
QString QEthereum::getTransactionImpl(QString _json, int _i) const
{
if (!client())
return "";
auto hash = toHash(_json, client());
return toJson(client()->transaction(hash, _i));
}
QString QEthereum::getUncleImpl(QString _json, int _i) const
{
if (!client())
return "";
auto hash = toHash(_json, client());
return toJson(client()->uncle(hash, _i));
}
QString QEthereum::getMessagesImpl(QString _json) const
{
return m_client ? toJson(m_client->messages(toMessageFilter(_json))) : "";
}
bool QEthereum::isMining() const
{
return m_client ? client()->isMining() : false;
}
void QEthereum::setMiningImpl(bool _l)
{
if (m_client)
{
if (_l)
client()->startMining();
else
client()->stopMining();
}
}
void QEthereum::setAccounts(QList<dev::KeyPair> const& _l)
{
m_accounts.clear();
for (auto i: _l)
m_accounts[i.address()] = i.secret();
keysChanged();
}
QString QEthereum::doTransactImpl(QString _json)
{
QString ret;
if (!m_client)
return ret;
TransactionSkeleton t = toTransaction(_json);
if (!t.from && m_accounts.size())
{
auto b = m_accounts.begin()->first;
for (auto a: m_accounts)
if (client()->balanceAt(a.first) > client()->balanceAt(b))
b = a.first;
t.from = b;
}
if (!m_accounts.count(t.from))
return QString();
if (!t.gasPrice)
t.gasPrice = 10 * dev::eth::szabo;
if (!t.gas)
t.gas = min<u256>(client()->gasLimitRemaining(), client()->balanceAt(t.from) / t.gasPrice);
cwarn << "Silently signing transaction from address" << t.from.abridged() << ": User validation hook goes here.";
if (t.to)
// TODO: insert validification hook here.
client()->transact(m_accounts[t.from].secret(), t.value, t.to, t.data, t.gas, t.gasPrice);
else
ret = toQJS(client()->transact(m_accounts[t.from].secret(), t.value, t.data, t.gas, t.gasPrice));
client()->flushTransactions();
return ret;
}
QString QEthereum::doCallImpl(QString _json)
{
if (!m_client)
return QString();
TransactionSkeleton t = toTransaction(_json);
if (!t.from && m_accounts.size())
{
auto b = m_accounts.begin()->first;
for (auto a: m_accounts)
if (client()->balanceAt(a.first) > client()->balanceAt(b))
b = a.first;
t.from = b;
}
if (!m_accounts.count(t.from))
return QString();
if (!t.gasPrice)
t.gasPrice = 10 * dev::eth::szabo;
if (!t.gas)
t.gas = min<u256>(client()->gasLimitRemaining(), client()->balanceAt(t.from) / t.gasPrice);
bytes out = client()->call(m_accounts[t.from].secret(), t.value, t.to, t.data, t.gas, t.gasPrice);
return asQString(out);
}
unsigned QEthereum::newWatch(QString _json)
{
if (!m_client)
return (unsigned)-1;
unsigned ret;
if (_json == "chain")
ret = m_client->installWatch(dev::eth::ChainChangedFilter);
else if (_json == "pending")
ret = m_client->installWatch(dev::eth::PendingChangedFilter);
else
ret = m_client->installWatch(toMessageFilter(_json));
m_watches.push_back(ret);
return ret;
}
QString QEthereum::watchMessages(unsigned _w)
{
if (!m_client)
return "";
return toJson(m_client->messages(_w));
}
void QEthereum::killWatch(unsigned _w)
{
if (!m_client)
return;
m_client->uninstallWatch(_w);
std::remove(m_watches.begin(), m_watches.end(), _w);
}
void QEthereum::poll()
{
if (!m_client)
return;
for (auto w: m_watches)
if (m_client->checkWatch(w))
emit watchChanged(w);
}
QPeer2Peer::QPeer2Peer(QObject *_p, dev::p2p::Host *_p2p): QObject(_p), m_p2p(_p2p)
{
}
QPeer2Peer::~QPeer2Peer()
{
}
bool QPeer2Peer::isListening() const
{
return m_p2p ? m_p2p->isStarted() : false;
}
void QPeer2Peer::setListeningImpl(bool _l)
{
if (!m_p2p)
return;
if (_l)
m_p2p->start();
else
m_p2p->stop();
}
unsigned QPeer2Peer::peerCount() const
{
return m_p2p ? (unsigned)m_p2p->peerCount() : 0;
}
// TODO: repot and hook all these up.
QWhisper::QWhisper(QObject* _p, std::shared_ptr<dev::shh::Interface> const& _c): QObject(_p), m_face(_c)
{
}
QWhisper::~QWhisper()
{
}
// probably want a better way of doing this. somehow guarantee that the face() will always be available as long as this object is.
struct NoInterface: public Exception {};
std::shared_ptr<dev::shh::Interface> QWhisper::face() const
{
auto ret = m_face.lock();
if (!ret)
throw NoInterface();
return ret;
}
void QWhisper::faceDieing()
{
}
void QWhisper::send(QString /*dev::Address*/ _dest, QString /*ev::KeyPair*/ _from, QString /*dev::h256 const&*/ _topic, QString /*dev::bytes const&*/ _payload)
{
(void)_dest;
(void)_from;
(void)_topic;
(void)_payload;
}
unsigned QWhisper::newWatch(QString _json)
{
(void)_json;
return 0;
}
QString QWhisper::watchMessages(unsigned _w)
{
(void)_w;
return "";
}
void QWhisper::killWatch(unsigned _w)
{
(void)_w;
}
void QWhisper::clearWatches()
{
}
void QWhisper::poll()
{
}
QWebThree::QWebThree(QObject* _p): QObject(_p)
{
@ -624,7 +20,6 @@ QWebThree::QWebThree(QObject* _p): QObject(_p)
QWebThree::~QWebThree()
{
}
static QString toJsonRpcMessage(QString _json)

275
libqethereum/QEthereum.h

@ -7,269 +7,6 @@
#include <libethcore/CommonEth.h>
#include <jsonrpc/rpc.h>
namespace dev
{
namespace eth
{
class Interface;
}
namespace shh
{
class Interface;
}
namespace p2p
{
class Host;
}
}
class QJSEngine;
class QWebFrame;
class QEthereum;
inline dev::bytes asBytes(QString const& _s)
{
dev::bytes ret;
ret.reserve(_s.size());
for (QChar c: _s)
ret.push_back(c.cell());
return ret;
}
inline QString asQString(dev::bytes const& _s)
{
QString ret;
ret.reserve(_s.size());
for (auto c: _s)
ret.push_back(QChar(c, 0));
return ret;
}
dev::bytes toBytes(QString const& _s);
QString padded(QString const& _s, unsigned _l, unsigned _r);
QString padded(QString const& _s, unsigned _l);
QString unpadded(QString _s);
template <unsigned N> dev::FixedHash<N> toFixed(QString const& _s)
{
if (_s.startsWith("0x"))
// Hex
return dev::FixedHash<N>(_s.mid(2).toStdString());
else if (!_s.contains(QRegExp("[^0-9]")))
// Decimal
return (typename dev::FixedHash<N>::Arith)(_s.toStdString());
else
// Binary
return dev::FixedHash<N>(asBytes(padded(_s, N)));
}
template <unsigned N> inline boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>> toInt(QString const& _s);
inline dev::Address toAddress(QString const& _s) { return toFixed<20>(_s); }
inline dev::Secret toSecret(QString const& _s) { return toFixed<32>(_s); }
inline dev::u256 toU256(QString const& _s) { return toInt<32>(_s); }
template <unsigned S> QString toQJS(dev::FixedHash<S> const& _h) { return QString::fromStdString("0x" + toHex(_h.ref())); }
template <unsigned N> QString toQJS(boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N, N, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>> const& _n) { return QString::fromStdString("0x" + dev::toHex(dev::toCompactBigEndian(_n))); }
inline QString toQJS(dev::bytes const& _n) { return "0x" + QString::fromStdString(dev::toHex(_n)); }
inline QString toBinary(QString const& _s)
{
return unpadded(asQString(toBytes(_s)));
}
inline QString toDecimal(QString const& _s)
{
return QString::fromStdString(dev::toString(toU256(_s)));
}
inline double fromFixed(QString const& _s)
{
return (double)toU256(_s) / (double)(dev::u256(1) << 128);
}
inline QString toFixed(double _s)
{
return toQJS(dev::u256(_s * (double)(dev::u256(1) << 128)));
}
inline QString fromBinary(dev::bytes _s, unsigned _padding = 32)
{
_s.resize(std::max<unsigned>(_s.size(), _padding));
return QString::fromStdString("0x" + dev::toHex(_s));
}
inline QString fromBinary(QString const& _s, unsigned _padding = 32)
{
return fromBinary(asBytes(_s), _padding);
}
class QDev: public QObject
{
Q_OBJECT
public:
QDev(QObject* _p): QObject(_p) {}
virtual ~QDev() {}
Q_INVOKABLE QString sha3(QString _s) const;
Q_INVOKABLE QString sha3(QString _s1, QString _s2) const;
Q_INVOKABLE QString sha3(QString _s1, QString _s2, QString _s3) const;
Q_INVOKABLE QString offset(QString _s, int _offset) const;
Q_INVOKABLE QString toAscii(QString _s) const { return ::toBinary(_s); }
Q_INVOKABLE QString fromAscii(QString _s) const { return ::fromBinary(_s, 32); }
Q_INVOKABLE QString fromAscii(QString _s, unsigned _padding) const { return ::fromBinary(_s, _padding); }
Q_INVOKABLE QString toDecimal(QString _s) const { return ::toDecimal(_s); }
Q_INVOKABLE double fromFixed(QString _s) const { return ::fromFixed(_s); }
Q_INVOKABLE QString toFixed(double _d) const { return ::toFixed(_d); }
};
class QEthereum: public QObject
{
Q_OBJECT
public:
QEthereum(QObject* _p, dev::eth::Interface* _c, QList<dev::KeyPair> _accounts);
virtual ~QEthereum();
dev::eth::Interface* client() const;
void setClient(dev::eth::Interface* _c) { m_client = _c; }
/// Call when the client() is going to be deleted to make this object useless but safe.
void clientDieing();
void setAccounts(QList<dev::KeyPair> const& _l);
Q_INVOKABLE QEthereum* self() { return this; }
Q_INVOKABLE QString lll(QString _s) const;
// [NEW API] - Use this instead.
Q_INVOKABLE QString/*dev::u256*/ balanceAt(QString/*dev::Address*/ _a, int _block) const;
Q_INVOKABLE double countAt(QString/*dev::Address*/ _a, int _block) const;
Q_INVOKABLE QString/*dev::u256*/ stateAt(QString/*dev::Address*/ _a, QString/*dev::u256*/ _p, int _block) const;
Q_INVOKABLE QString/*dev::u256*/ codeAt(QString/*dev::Address*/ _a, int _block) const;
Q_INVOKABLE QString/*dev::u256*/ balanceAt(QString/*dev::Address*/ _a) const;
Q_INVOKABLE double countAt(QString/*dev::Address*/ _a) const;
Q_INVOKABLE QString/*dev::u256*/ stateAt(QString/*dev::Address*/ _a, QString/*dev::u256*/ _p) const;
Q_INVOKABLE QString/*dev::u256*/ codeAt(QString/*dev::Address*/ _a) const;
Q_INVOKABLE QString/*json*/ getBlockImpl(QString _json) const;
Q_INVOKABLE QString/*json*/ getTransactionImpl(QString _json, int _index) const;
Q_INVOKABLE QString/*json*/ getUncleImpl(QString _json, int _index) const;
Q_INVOKABLE QString/*json*/ getMessagesImpl(QString _attribs/*json*/) const;
Q_INVOKABLE QString doTransactImpl(QString _json);
Q_INVOKABLE QString doCallImpl(QString _json);
Q_INVOKABLE unsigned newWatch(QString _json);
Q_INVOKABLE QString watchMessages(unsigned _w);
Q_INVOKABLE void killWatch(unsigned _w);
void clearWatches();
bool isMining() const;
QString/*dev::Address*/ coinbase() const;
QString/*dev::u256*/ gasPrice() const { return toQJS(10 * dev::eth::szabo); }
unsigned/*dev::u256*/ number() const;
int getDefault() const;
QStringList/*list of dev::Address*/ accounts() const;
public slots:
void setCoinbaseImpl(QString/*dev::Address*/);
void setMiningImpl(bool _l);
void setDefault(int _block);
/// Check to see if anything has changed, fire off signals if so.
/// @note Must be called in the QObject's thread.
void poll();
signals:
void netChanged();
void watchChanged(unsigned _w);
void coinbaseChanged();
void keysChanged();
private:
Q_PROPERTY(QString coinbase READ coinbase WRITE setCoinbaseImpl NOTIFY coinbaseChanged)
Q_PROPERTY(bool mining READ isMining WRITE setMiningImpl NOTIFY netChanged)
Q_PROPERTY(QString gasPrice READ gasPrice)
Q_PROPERTY(QStringList accounts READ accounts NOTIFY keysChanged)
Q_PROPERTY(int defaultBlock READ getDefault WRITE setDefault)
Q_PROPERTY(unsigned number READ number NOTIFY watchChanged)
dev::eth::Interface* m_client;
std::vector<unsigned> m_watches;
std::map<dev::Address, dev::KeyPair> m_accounts;
};
class QPeer2Peer : public QObject
{
Q_OBJECT
public:
QPeer2Peer(QObject *_p, dev::p2p::Host *_p2p);
virtual ~QPeer2Peer();
bool isListening() const;
void setListeningImpl(bool _l);
unsigned peerCount() const;
signals:
void netChanged();
void miningChanged();
private:
Q_PROPERTY(bool listening READ isListening WRITE setListeningImpl NOTIFY netChanged)
Q_PROPERTY(unsigned peerCount READ peerCount NOTIFY miningChanged)
dev::p2p::Host* m_p2p;
};
class QWhisper: public QObject
{
Q_OBJECT
public:
QWhisper(QObject* _p, std::shared_ptr<dev::shh::Interface> const& _c);
virtual ~QWhisper();
std::shared_ptr<dev::shh::Interface> face() const;
void setFace(std::shared_ptr<dev::shh::Interface> const& _c) { m_face = _c; }
/// Call when the face() is going to be deleted to make this object useless but safe.
void faceDieing();
Q_INVOKABLE QWhisper* self() { return this; }
/// Basic message send.
Q_INVOKABLE void send(QString /*dev::Address*/ _dest, QString /*ev::KeyPair*/ _from, QString /*dev::h256 const&*/ _topic, QString /*dev::bytes const&*/ _payload);
// Watches interface
Q_INVOKABLE unsigned newWatch(QString _json);
Q_INVOKABLE QString watchMessages(unsigned _w);
Q_INVOKABLE void killWatch(unsigned _w);
void clearWatches();
public slots:
/// Check to see if anything has changed, fire off signals if so.
/// @note Must be called in the QObject's thread.
void poll();
signals:
void watchChanged(unsigned _w);
private:
std::weak_ptr<dev::shh::Interface> m_face;
std::vector<unsigned> m_watches;
};
class QWebThree: public QObject
{
Q_OBJECT
@ -277,22 +14,12 @@ class QWebThree: public QObject
public:
QWebThree(QObject* _p);
virtual ~QWebThree();
void installJSNamespace(QWebFrame* _f);
Q_INVOKABLE void postData(QString _json);
signals:
void processData(QString _json);
void send(QString _json);
private:
QObject* m_main = nullptr;
QWebFrame* m_frame = nullptr;
QDev* m_dev = nullptr;
QEthereum* m_ethereum = nullptr;
QWhisper* m_whisper = nullptr;
QPeer2Peer* m_p2p = nullptr;
};
class QWebThreeConnector: public QObject, public jsonrpc::AbstractServerConnector
@ -318,7 +45,7 @@ private:
// TODO: p2p object condition
#define QETH_INSTALL_JS_NAMESPACE(_frame, _env, _dev, _eth, _shh, _p2p, qweb) [_frame, _env, _dev, _eth, _shh, _p2p, qweb]() \
#define QETH_INSTALL_JS_NAMESPACE(_frame, _env, qweb) [_frame, _env, qweb]() \
{ \
_frame->disconnect(); \
_frame->addToJavaScriptWindowObject("_web3", qweb, QWebFrame::ScriptOwnership); \

Loading…
Cancel
Save