From f36c16b8a9a1b300b94ef69ea6ea2f814c5e5378 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 3 May 2014 20:06:07 +0100 Subject: [PATCH] Protocol changes for PoC-5 plus JS APIs. --- libethereum/CommonEth.cpp | 2 ++ libethereum/CommonEth.h | 3 +++ libethereum/PeerServer.cpp | 2 +- libqethereum/QEthereum.cpp | 1 + libqethereum/QEthereum.h | 7 +++++++ 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libethereum/CommonEth.cpp b/libethereum/CommonEth.cpp index a6f7a09bc..f65519a35 100644 --- a/libethereum/CommonEth.cpp +++ b/libethereum/CommonEth.cpp @@ -28,6 +28,8 @@ using namespace eth; //#define ETH_ADDRESS_DEBUG 1 +const unsigned eth::c_protocolVersion = 14; + static const vector> g_units = { {((((u256(1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000) * 1000000000, "Uether"}, diff --git a/libethereum/CommonEth.h b/libethereum/CommonEth.h index fd9b7a0ac..b58b6af20 100644 --- a/libethereum/CommonEth.h +++ b/libethereum/CommonEth.h @@ -29,6 +29,9 @@ namespace eth { +/// Current protocol version. +extern const unsigned c_protocolVersion; + /// A secret key: 32 bytes. /// @NOTE This is not endian-specific; it's just a bunch of bytes. using Secret = h256; diff --git a/libethereum/PeerServer.cpp b/libethereum/PeerServer.cpp index e86289d2c..8b3644aa5 100644 --- a/libethereum/PeerServer.cpp +++ b/libethereum/PeerServer.cpp @@ -115,7 +115,7 @@ PeerServer::~PeerServer() unsigned PeerServer::protocolVersion() { - return 13; + return c_protocolVersion; } void PeerServer::determinePublic(string const& _publicAddress, bool _upnp) diff --git a/libqethereum/QEthereum.cpp b/libqethereum/QEthereum.cpp index 4de1a89a1..8b5490770 100644 --- a/libqethereum/QEthereum.cpp +++ b/libqethereum/QEthereum.cpp @@ -255,6 +255,7 @@ void QEthereum::setup(QWebFrame* _e) _e->evaluateJavaScript("String.prototype.bin = function() { return eth.toBinary(this) }"); _e->evaluateJavaScript("String.prototype.unbin = function(l) { return eth.fromBinary(this) }"); _e->evaluateJavaScript("String.prototype.unpad = function(l) { return eth.unpad(this) }"); + _e->evaluateJavaScript("String.prototype.dec = function() { return eth.toDecimal(this) }"); } void QEthereum::teardown(QWebFrame*) diff --git a/libqethereum/QEthereum.h b/libqethereum/QEthereum.h index bc0e90467..5b79dbc88 100644 --- a/libqethereum/QEthereum.h +++ b/libqethereum/QEthereum.h @@ -304,6 +304,7 @@ inline QString asQString(eth::bytes const& _s) } eth::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); @@ -345,6 +346,11 @@ inline QString toBinary(QString const& _s) return asQString(toBytes(_s)); } +inline QString toDecimal(QString const& _s) +{ + return QString::fromStdString(eth::toString(toU256(_s))); +} + inline QString fromBinary(QString const& _s) { return QString::fromStdString("0x" + eth::toHex(asBytes(_s))); @@ -373,6 +379,7 @@ public: Q_INVOKABLE QString unpad(QString _s) const { return unpadded(_s); } Q_INVOKABLE QString toBinary(QString _s) const { return ::toBinary(_s); } Q_INVOKABLE QString fromBinary(QString _s) const { return ::fromBinary(_s); } + Q_INVOKABLE QString toDecimal(QString _s) const { return ::toDecimal(_s); } Q_INVOKABLE QString/*eth::u256*/ balanceAt(QString/*eth::Address*/ _a) const; Q_INVOKABLE QString/*eth::u256*/ storageAt(QString/*eth::Address*/ _a, QString/*eth::u256*/ _p) const;