Browse Source

Fixes and start on new JS API.

cl-refactor
Gav Wood 11 years ago
parent
commit
68fc84de91
  1. 18
      alethzero/Main.ui
  2. 18
      alethzero/MainWin.cpp
  3. 3
      alethzero/MainWin.h
  4. 2
      libethcore/Common.h
  5. 7
      libethereum/BlockInfo.cpp
  6. 2
      libethereum/Exceptions.h
  7. 2
      libethereum/Transaction.cpp
  8. 17
      libqethereum/QEthereum.cpp
  9. 7
      libqethereum/QEthereum.h

18
alethzero/Main.ui

@ -69,6 +69,21 @@
<string>Tab 1</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QLineEdit" name="urlEdit"/>
</item>
@ -81,6 +96,9 @@
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="jsInput"/>
</item>
</layout>
</widget>
</widget>

18
alethzero/MainWin.cpp

@ -186,7 +186,7 @@ Main::Main(QWidget *parent) :
else if (pocnumber == 4)
m_servers.push_back("54.72.31.55:30303");
else if (pocnumber == 5)
m_servers.push_back("54.201.28.117:30303");
m_servers.push_back("54.72.31.55:30305");
else
{
connect(&m_webCtrl, &QNetworkAccessManager::finished, [&](QNetworkReply* _r)
@ -226,10 +226,8 @@ Main::Main(QWidget *parent) :
QWebFrame* f = ui->webView->page()->currentFrame();
connect(f, &QWebFrame::javaScriptWindowObjectCleared, [=](){
f->addToJavaScriptWindowObject("eth", new QEthereum(this, m_client.get(), owned()), QWebFrame::ScriptOwnership);
f->addToJavaScriptWindowObject("u256", new U256Helper, QWebFrame::ScriptOwnership);
f->addToJavaScriptWindowObject("key", new KeyHelper, QWebFrame::ScriptOwnership);
f->addToJavaScriptWindowObject("bytes", new BytesHelper, QWebFrame::ScriptOwnership);
auto qe = new QEthereum(this, m_client.get(), owned());
qe->setup(f);
});
readSettings();
@ -251,6 +249,12 @@ Main::~Main()
writeSettings();
}
void Main::on_jsInput_returnPressed()
{
ui->jsInput->setText(ui->webView->page()->currentFrame()->evaluateJavaScript(ui->jsInput->text()).toString());
ui->jsInput->setSelection(0, ui->jsInput->text().size());
}
QString Main::pretty(eth::Address _a) const
{
h256 n;
@ -368,10 +372,10 @@ void Main::readSettings()
ui->port->setValue(s.value("port", ui->port->value()).toInt());
ui->nameReg->setText(s.value("NameReg", "").toString());
ui->urlEdit->setText(s.value("url", "http://gavwood.com/gavcoin.html").toString());
on_urlEdit_editingFinished();
on_urlEdit_returnPressed();
}
void Main::on_urlEdit_editingFinished()
void Main::on_urlEdit_returnPressed()
{
ui->webView->setUrl(ui->urlEdit->text());
}

3
alethzero/MainWin.h

@ -69,10 +69,11 @@ private slots:
void on_nameReg_textChanged();
void on_preview_triggered() { refresh(true); }
void on_quit_triggered() { close(); }
void on_urlEdit_editingFinished();
void on_urlEdit_returnPressed();
void on_debugStep_triggered();
void on_debug_clicked();
void on_debugTimeline_valueChanged();
void on_jsInput_returnPressed();
void refresh(bool _override = false);
void refreshNetwork();

2
libethcore/Common.h

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

7
libethereum/BlockInfo.cpp

@ -142,7 +142,7 @@ void BlockInfo::verifyInternals(bytesConstRef _block) const
{
RLP root(_block);
u256 mgp = 0;
u256 mgp = (u256)-1;
Overlay db;
GenericTrieDB<Overlay> t(&db);
@ -153,15 +153,14 @@ void BlockInfo::verifyInternals(bytesConstRef _block) const
bytes k = rlp(i);
t.insert(&k, tr.data());
u256 gp = tr[0][1].toInt<u256>();
if (!i || mgp > gp)
mgp = gp;
mgp = min(mgp, gp);
++i;
}
if (transactionsRoot != t.root())
throw InvalidTransactionsHash(t.root(), transactionsRoot);
if (minGasPrice > mgp)
throw InvalidMinGasPrice();
throw InvalidMinGasPrice(minGasPrice, mgp);
if (sha3Uncles != sha3(root[2].data()))
throw InvalidUnclesHash();

2
libethereum/Exceptions.h

@ -35,7 +35,7 @@ class InvalidTransactionsHash: public Exception { public: InvalidTransactionsHas
class InvalidTransaction: public Exception {};
class InvalidDifficulty: public Exception {};
class InvalidGasLimit: public Exception {};
class InvalidMinGasPrice: public Exception {};
class InvalidMinGasPrice: public Exception { public: InvalidMinGasPrice(u256 _provided = 0, u256 _limit = 0): provided(_provided), limit(_limit) {} u256 provided; u256 limit; virtual std::string description() const { return "Invalid minimum gas price (provided: " + toString(provided) + " limit:" + toString(limit) + ")"; } };
class InvalidTransactionGasUsed: public Exception {};
class InvalidTransactionStateRoot: public Exception {};
class InvalidTimestamp: public Exception {};

2
libethereum/Transaction.cpp

@ -123,6 +123,8 @@ void Transaction::fillStream(RLPStream& _s, bool _sig) const
h256 Transaction::kFromMessage(h256 _msg, h256 _priv)
{
// TODO!
// bytes v(32, 1);
// bytes k(32, 0);
/*
v = '\x01' * 32
k = '\x00' * 32

17
libqethereum/QEthereum.cpp

@ -1,5 +1,6 @@
#include <QtQml/QtQml>
#include <QtCore/QtCore>
#include <QtWebKitWidgets/QWebFrame>
#include <libethcore/FileSystem.h>
#include <libethereum/Dagger.h>
#include <libethereum/Client.h>
@ -192,6 +193,22 @@ QEthereum::~QEthereum()
{
}
void QEthereum::setup(QWebFrame* _e)
{
// disconnect
disconnect(SIGNAL(changed()));
_e->addToJavaScriptWindowObject("eth", this, QWebFrame::ScriptOwnership);
_e->addToJavaScriptWindowObject("u256", new U256Helper, QWebFrame::ScriptOwnership);
_e->addToJavaScriptWindowObject("key", new KeyHelper, QWebFrame::ScriptOwnership);
_e->addToJavaScriptWindowObject("bytes", new BytesHelper, QWebFrame::ScriptOwnership);
// _e->evaluateJavaScript("xeth = new Object({\"callback\": function(f) { eth.testcallback.connect(f) }})");
_e->evaluateJavaScript("eth.onChanged = function(f) { eth.changed.connect(f) }");
}
void QEthereum::teardown(QWebFrame* _e)
{
}
Client* QEthereum::client() const
{
return m_client;

7
libqethereum/QEthereum.h

@ -1,6 +1,7 @@
#pragma once
#include <QtCore/QAbstractListModel>
#include <QtQml>
#include <libethereum/CommonEth.h>
#include <libethcore/CommonIO.h>
@ -11,6 +12,7 @@ class State;
class QQmlEngine;
class QJSEngine;
class QWebFrame;
class QEthereum;
class QmlAccount;
@ -291,6 +293,9 @@ public:
eth::Client* client() const;
void setup(QWebFrame* _e);
void teardown(QWebFrame* _e);
Q_INVOKABLE QVariant/*eth::Address*/ coinbase() const;
Q_INVOKABLE bool isListening() const;
@ -304,6 +309,7 @@ public:
Q_INVOKABLE QVariant gasPrice() const { return toQJS(10 * eth::szabo); }
Q_INVOKABLE QString ethTest() const { return "Hello world!"; }
Q_INVOKABLE void ethTest2() { changed(); }
Q_INVOKABLE QVariant/*eth::KeyPair*/ key() const;
Q_INVOKABLE QList<QVariant/*eth::KeyPair*/> keys() const;
@ -329,6 +335,7 @@ public slots:
signals:
void changed();
void testcallback();
// void netChanged();
// void miningChanged();

Loading…
Cancel
Save