Browse Source

codding standards

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
4d70abf68a
  1. 15
      libdevcore/CommonJS.cpp
  2. 16
      libdevcore/CommonJS.h
  3. 4
      libethrpc/CMakeLists.txt
  4. 8
      libethrpc/CorsHttpServer.cpp
  5. 8
      libethrpc/CorsHttpServer.h
  6. 68
      libethrpc/WebThreeStubServer.cpp
  7. 60
      libethrpc/WebThreeStubServer.h
  8. 2
      libqethereum/QEthereum.cpp
  9. 16
      libqethereum/QEthereum.h
  10. 11
      test/jsonrpc.cpp

15
libdevcore/CommonJS.cpp

@ -1,19 +1,19 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 CommonJS.cpp
* @authors:
* Gav Wood <i@gavwood.com>
@ -23,7 +23,8 @@
#include "CommonJS.h"
namespace dev {
namespace dev
{
bytes jsToBytes(std::string const& _s)
{
@ -51,10 +52,10 @@ std::string jsPadded(std::string const& _s, unsigned _l, unsigned _r)
std::string jsPadded(std::string const& _s, unsigned _l)
{
if (_s.substr(0, 2) == "0x" || _s.find_first_not_of("0123456789") == std::string::npos)
// Numeric: pad to right
// Numeric: pad to right
return jsPadded(_s, _l, _l);
else
// Text: pad to the left
// Text: pad to the left
return jsPadded(_s, 0, _l);
}

16
libdevcore/CommonJS.h

@ -1,19 +1,19 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 CommonJS.h
* @authors:
* Gav Wood <i@gavwood.com>
@ -30,17 +30,21 @@
#include "Common.h"
#include "CommonData.h"
namespace dev {
namespace dev
{
template <unsigned S> std::string toJS(FixedHash<S> const& _h)
{
return "0x" + toHex(_h.ref());
}
template <unsigned N> std::string toJS(boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N, N, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>> const& _n)
{
return "0x" + toHex(toCompactBigEndian(_n));
}
inline std::string toJS(dev::bytes const& _n) {
inline std::string toJS(dev::bytes const& _n)
{
return "0x" + dev::toHex(_n);
}

4
libethrpc/CMakeLists.txt

@ -10,9 +10,9 @@ set(EXECUTABLE ethrpc)
file(GLOB HEADERS "*.h")
if(ETH_STATIC)
add_library(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS})
add_library(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS})
else()
add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS})
add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS})
endif()
target_link_libraries(${EXECUTABLE} webthree)

8
libethrpc/CorsHttpServer.cpp

@ -1,19 +1,19 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 CorsHttpServer.cpp
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2014

8
libethrpc/CorsHttpServer.h

@ -1,19 +1,19 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 CorsHttpServer.h
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2014

68
libethrpc/WebThreeStubServer.cpp

@ -33,7 +33,7 @@ using namespace std;
using namespace dev;
using namespace dev::eth;
static Json::Value toJson(const dev::eth::BlockInfo& bi)
static Json::Value toJson(dev::eth::BlockInfo const& bi)
{
Json::Value res;
res["hash"] = boost::lexical_cast<string>(bi.hash);
@ -53,7 +53,7 @@ static Json::Value toJson(const dev::eth::BlockInfo& bi)
return res;
}
static Json::Value toJson(const dev::eth::PastMessage& t)
static Json::Value toJson(dev::eth::PastMessage const& t)
{
Json::Value res;
res["input"] = jsFromBinary(t.input);
@ -73,16 +73,16 @@ static Json::Value toJson(const dev::eth::PastMessage& t)
return res;
}
static Json::Value toJson(const dev::eth::PastMessages& pms)
static Json::Value toJson(dev::eth::PastMessages const& pms)
{
Json::Value res;
for (dev::eth::PastMessage const & t: pms)
for (dev::eth::PastMessage const& t: pms)
res.append(toJson(t));
return res;
}
static Json::Value toJson(const dev::eth::Transaction& t)
static Json::Value toJson(dev::eth::Transaction const& t)
{
Json::Value res;
res["hash"] = toJS(t.sha3());
@ -107,12 +107,12 @@ dev::eth::Interface* WebThreeStubServer::client() const
return m_web3.ethereum();
}
std::string WebThreeStubServer::balanceAt(const string &address, const int& block)
std::string WebThreeStubServer::balanceAt(string const& address, int const& block)
{
return toJS(client()->balanceAt(jsToAddress(address), block));
}
dev::FixedHash<32> WebThreeStubServer::numberOrHash(Json::Value const &json) const
dev::FixedHash<32> WebThreeStubServer::numberOrHash(Json::Value const& json) const
{
dev::FixedHash<32> hash;
if (!json["hash"].empty())
@ -122,7 +122,7 @@ dev::FixedHash<32> WebThreeStubServer::numberOrHash(Json::Value const &json) con
return hash;
}
Json::Value WebThreeStubServer::block(const Json::Value &params)
Json::Value WebThreeStubServer::block(Json::Value const& params)
{
if (!client())
return "";
@ -131,7 +131,7 @@ Json::Value WebThreeStubServer::block(const Json::Value &params)
return toJson(client()->blockInfo(hash));
}
static TransactionJS toTransaction(const Json::Value &json)
static TransactionJS toTransaction(Json::Value const& json)
{
TransactionJS ret;
if (!json.isObject() || json.empty()){
@ -169,7 +169,7 @@ static TransactionJS toTransaction(const Json::Value &json)
return ret;
}
std::string WebThreeStubServer::call(const Json::Value &json)
std::string WebThreeStubServer::call(Json::Value const& json)
{
std::string ret;
if (!client())
@ -187,7 +187,7 @@ std::string WebThreeStubServer::call(const Json::Value &json)
return ret;
}
std::string WebThreeStubServer::codeAt(const string &address, const int& block)
std::string WebThreeStubServer::codeAt(string const& address, int const& block)
{
return client() ? jsFromBinary(client()->codeAt(jsToAddress(address), block)) : "";
}
@ -197,7 +197,7 @@ std::string WebThreeStubServer::coinbase()
return client() ? toJS(client()->address()) : "";
}
double WebThreeStubServer::countAt(const string &address, const int& block)
double WebThreeStubServer::countAt(string const& address, int const& block)
{
return client() ? (double)(uint64_t)client()->countAt(jsToAddress(address), block) : 0;
}
@ -207,12 +207,12 @@ int WebThreeStubServer::defaultBlock()
return client() ? client()->getDefault() : 0;
}
std::string WebThreeStubServer::fromAscii(const int& padding, const std::string& s)
std::string WebThreeStubServer::fromAscii(int const& padding, std::string const& s)
{
return jsFromBinary(s, padding);
}
double WebThreeStubServer::fromFixed(const string &s)
double WebThreeStubServer::fromFixed(string const& s)
{
return jsFromFixed(s);
}
@ -247,12 +247,12 @@ Json::Value WebThreeStubServer::keys()
return ret;
}
std::string WebThreeStubServer::lll(const string &s)
std::string WebThreeStubServer::lll(string const& s)
{
return toJS(dev::eth::compileLLL(s));
}
static dev::eth::MessageFilter toMessageFilter(const Json::Value &json)
static dev::eth::MessageFilter toMessageFilter(Json::Value const& json)
{
dev::eth::MessageFilter filter;
if (!json.isObject() || json.empty()){
@ -295,12 +295,12 @@ static dev::eth::MessageFilter toMessageFilter(const Json::Value &json)
filter.altered(jsToAddress(json["altered"]["id"].asString()), jsToU256(json["altered"]["at"].asString()));
else
filter.altered(jsToAddress(json["altered"].asString()));
}
}
return filter;
}
Json::Value WebThreeStubServer::messages(const Json::Value &json)
Json::Value WebThreeStubServer::messages(Json::Value const& json)
{
Json::Value res;
if (!client())
@ -313,7 +313,7 @@ int WebThreeStubServer::number()
return client() ? client()->number() + 1 : 0;
}
std::string WebThreeStubServer::offset(const int& o, const std::string& s)
std::string WebThreeStubServer::offset(int const & o, std::string const& s)
{
return toJS(jsToU256(s) + o);
}
@ -323,18 +323,18 @@ int WebThreeStubServer::peerCount()
return m_web3.peerCount();
}
std::string WebThreeStubServer::secretToAddress(const string &s)
std::string WebThreeStubServer::secretToAddress(string const& s)
{
return toJS(KeyPair(jsToSecret(s)).address());
}
bool WebThreeStubServer::setCoinbase(const std::string &address)
bool WebThreeStubServer::setCoinbase(std::string const& address)
{
client()->setAddress(jsToAddress(address));
return true;
}
bool WebThreeStubServer::setListening(const bool &listening)
bool WebThreeStubServer::setListening(bool const& listening)
{
if (listening)
m_web3.startNetwork();
@ -343,7 +343,7 @@ bool WebThreeStubServer::setListening(const bool &listening)
return true;
}
bool WebThreeStubServer::setMining(const bool &mining)
bool WebThreeStubServer::setMining(bool const& mining)
{
if (!client())
return Json::nullValue;
@ -355,32 +355,32 @@ bool WebThreeStubServer::setMining(const bool &mining)
return true;
}
std::string WebThreeStubServer::sha3(const string &s)
std::string WebThreeStubServer::sha3(string const& s)
{
return toJS(dev::eth::sha3(jsToBytes(s)));
}
std::string WebThreeStubServer::stateAt(const string &address, const int& block, const string &storage)
std::string WebThreeStubServer::stateAt(string const& address, int const& block, string const& storage)
{
return client() ? toJS(client()->stateAt(jsToAddress(address), jsToU256(storage), block)) : "";
}
std::string WebThreeStubServer::toAscii(const string &s)
std::string WebThreeStubServer::toAscii(string const& s)
{
return jsToBinary(s);
}
std::string WebThreeStubServer::toDecimal(const string &s)
std::string WebThreeStubServer::toDecimal(string const& s)
{
return jsToDecimal(s);
}
std::string WebThreeStubServer::toFixed(const double &s)
std::string WebThreeStubServer::toFixed(double const& s)
{
return jsToFixed(s);
}
std::string WebThreeStubServer::transact(const Json::Value &json)
std::string WebThreeStubServer::transact(Json::Value const& json)
{
std::string ret;
if (!client())
@ -406,7 +406,7 @@ std::string WebThreeStubServer::transact(const Json::Value &json)
return ret;
}
Json::Value WebThreeStubServer::transaction(const int &i, const Json::Value &params)
Json::Value WebThreeStubServer::transaction(int const& i, Json::Value const& params)
{
if (!client())
return "";
@ -415,7 +415,7 @@ Json::Value WebThreeStubServer::transaction(const int &i, const Json::Value &par
return toJson(client()->transaction(hash, i));
}
Json::Value WebThreeStubServer::uncle(const int &i, const Json::Value &params)
Json::Value WebThreeStubServer::uncle(int const& i, Json::Value const& params)
{
if (!client())
return "";
@ -424,7 +424,7 @@ Json::Value WebThreeStubServer::uncle(const int &i, const Json::Value &params)
return toJson(client()->uncle(hash, i));
}
int WebThreeStubServer::watch(const string &json)
int WebThreeStubServer::watch(string const& json)
{
unsigned ret = -1;
if (!client())
@ -444,14 +444,14 @@ int WebThreeStubServer::watch(const string &json)
return ret;
}
bool WebThreeStubServer::check(const int& id)
bool WebThreeStubServer::check(int const& id)
{
if (!client())
return false;
return client()->checkWatch(id);
}
bool WebThreeStubServer::killWatch(const int& id)
bool WebThreeStubServer::killWatch(int const& id)
{
if (!client())
return false;

60
libethrpc/WebThreeStubServer.h

@ -1,19 +1,19 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 WebThreeStubServer.h
* @authors:
* Gav Wood <i@gavwood.com>
@ -38,45 +38,45 @@ class WebThreeStubServer: public AbstractWebThreeStubServer
public:
WebThreeStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3);
virtual std::string balanceAt(const std::string& address, const int& block);
virtual Json::Value block(const Json::Value& params);
virtual std::string call(const Json::Value& json);
virtual std::string codeAt(const std::string& address, const int& block);
virtual std::string balanceAt(std::string const& address, int const& block);
virtual Json::Value block(Json::Value const& params);
virtual std::string call(Json::Value const& json);
virtual std::string codeAt(std::string const& address, int const& block);
virtual std::string coinbase();
virtual double countAt(const std::string& address, const int& block);
virtual double countAt(std::string const& address, int const& block);
virtual int defaultBlock();
virtual std::string fromAscii(const int& padding, const std::string& s);
virtual double fromFixed(const std::string& s);
virtual std::string fromAscii(int const& padding, std::string const& s);
virtual double fromFixed(std::string const& s);
virtual std::string gasPrice();
virtual bool listening();
virtual bool mining();
virtual std::string key();
virtual Json::Value keys();
virtual std::string lll(const std::string& s);
virtual Json::Value messages(const Json::Value& json);
virtual std::string lll(std::string const& s);
virtual Json::Value messages(Json::Value const& json);
virtual int number();
virtual std::string offset(const int& o, const std::string& s);
virtual std::string offset(int const& o, std::string const& s);
virtual int peerCount();
virtual std::string secretToAddress(const std::string& s);
virtual bool setCoinbase(const std::string& address);
virtual bool setListening(const bool& listening);
virtual bool setMining(const bool& mining);
virtual std::string sha3(const std::string& s);
virtual std::string stateAt(const std::string& address, const int& block, const std::string& storage);
virtual std::string toAscii(const std::string& s);
virtual std::string toDecimal(const std::string& s);
virtual std::string toFixed(const double& s);
virtual std::string transact(const Json::Value& json);
virtual Json::Value transaction(const int& i, const Json::Value& params);
virtual Json::Value uncle(const int& i, const Json::Value &params);
virtual int watch(const std::string& json);
virtual bool check(const int& id);
virtual bool killWatch(const int& id);
virtual std::string secretToAddress(std::string const& s);
virtual bool setCoinbase(std::string const& address);
virtual bool setListening(bool const& listening);
virtual bool setMining(bool const& mining);
virtual std::string sha3(std::string const& s);
virtual std::string stateAt(std::string const& address, int const& block, std::string const& storage);
virtual std::string toAscii(std::string const& s);
virtual std::string toDecimal(std::string const& s);
virtual std::string toFixed(double const& s);
virtual std::string transact(Json::Value const & json);
virtual Json::Value transaction(int const& i, Json::Value const& params);
virtual Json::Value uncle(int const& i, Json::Value const& params);
virtual int watch(std::string const& json);
virtual bool check(int const& id);
virtual bool killWatch(int const& id);
void setKeys(std::vector<dev::KeyPair> _keys) { m_keys = _keys; }
private:
dev::eth::Interface* client() const;
dev::WebThreeDirect& m_web3;
std::vector<dev::KeyPair> m_keys;
dev::FixedHash<32> numberOrHash(Json::Value const &_json) const;
dev::FixedHash<32> numberOrHash(Json::Value const& _json) const;
};

2
libqethereum/QEthereum.cpp

@ -400,7 +400,7 @@ static QString toJson(dev::eth::Transaction const& _bi)
return QString::fromUtf8(QJsonDocument(v).toJson());
}
dev::FixedHash<32> QEthereum::numberOrHash(QString const &_json) const
dev::FixedHash<32> QEthereum::numberOrHash(QString const& _json) const
{
QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object();
dev::FixedHash<32> hash;

16
libqethereum/QEthereum.h

@ -6,14 +6,18 @@
#include <libdevcore/CommonIO.h>
#include <libethcore/CommonEth.h>
namespace dev {
namespace eth {
namespace dev
{
namespace eth
{
class Interface;
}
namespace shh {
namespace shh
{
class Interface;
}
namespace p2p {
namespace p2p
{
class Host;
}
}
@ -199,12 +203,12 @@ private:
Q_PROPERTY(QString key READ key NOTIFY keysChanged)
Q_PROPERTY(QStringList keys READ keys NOTIFY keysChanged)
Q_PROPERTY(int defaultBlock READ getDefault WRITE setDefault)
Q_PROPERTY(unsigned number READ number NOTIFY watchChanged)
Q_PROPERTY(unsigned number READ number NOTIFY watchChanged)
dev::eth::Interface* m_client;
std::vector<unsigned> m_watches;
QList<dev::KeyPair> m_accounts;
dev::FixedHash<32> numberOrHash(QString const &_json) const;
dev::FixedHash<32> numberOrHash(QString const& _json) const;
};
class QPeer2Peer : public QObject

11
test/jsonrpc.cpp

@ -1,19 +1,19 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 jsonrpc.cpp
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2014
@ -41,7 +41,8 @@ using namespace dev;
using namespace dev::eth;
namespace js = json_spirit;
namespace jsonrpc_tests {
namespace jsonrpc_tests
{
string name = "Ethereum(++) tests";
string dbPath;

Loading…
Cancel
Save