Browse Source

codding standards

cl-refactor
Marek Kotewicz 11 years ago
parent
commit
4d70abf68a
  1. 5
      libdevcore/CommonJS.cpp
  2. 10
      libdevcore/CommonJS.h
  3. 2
      libethrpc/CorsHttpServer.cpp
  4. 2
      libethrpc/CorsHttpServer.h
  5. 66
      libethrpc/WebThreeStubServer.cpp
  6. 54
      libethrpc/WebThreeStubServer.h
  7. 2
      libqethereum/QEthereum.cpp
  8. 14
      libqethereum/QEthereum.h
  9. 5
      test/jsonrpc.cpp

5
libdevcore/CommonJS.cpp

@ -13,7 +13,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file CommonJS.cpp /** @file CommonJS.cpp
* @authors: * @authors:
* Gav Wood <i@gavwood.com> * Gav Wood <i@gavwood.com>
@ -23,7 +23,8 @@
#include "CommonJS.h" #include "CommonJS.h"
namespace dev { namespace dev
{
bytes jsToBytes(std::string const& _s) bytes jsToBytes(std::string const& _s)
{ {

10
libdevcore/CommonJS.h

@ -13,7 +13,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file CommonJS.h /** @file CommonJS.h
* @authors: * @authors:
* Gav Wood <i@gavwood.com> * Gav Wood <i@gavwood.com>
@ -30,17 +30,21 @@
#include "Common.h" #include "Common.h"
#include "CommonData.h" #include "CommonData.h"
namespace dev { namespace dev
{
template <unsigned S> std::string toJS(FixedHash<S> const& _h) template <unsigned S> std::string toJS(FixedHash<S> const& _h)
{ {
return "0x" + toHex(_h.ref()); 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) 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)); 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); return "0x" + dev::toHex(_n);
} }

2
libethrpc/CorsHttpServer.cpp

@ -13,7 +13,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file CorsHttpServer.cpp /** @file CorsHttpServer.cpp
* @author Marek Kotewicz <marek@ethdev.com> * @author Marek Kotewicz <marek@ethdev.com>
* @date 2014 * @date 2014

2
libethrpc/CorsHttpServer.h

@ -13,7 +13,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file CorsHttpServer.h /** @file CorsHttpServer.h
* @author Marek Kotewicz <marek@ethdev.com> * @author Marek Kotewicz <marek@ethdev.com>
* @date 2014 * @date 2014

66
libethrpc/WebThreeStubServer.cpp

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

54
libethrpc/WebThreeStubServer.h

@ -13,7 +13,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file WebThreeStubServer.h /** @file WebThreeStubServer.h
* @authors: * @authors:
* Gav Wood <i@gavwood.com> * Gav Wood <i@gavwood.com>
@ -38,45 +38,45 @@ class WebThreeStubServer: public AbstractWebThreeStubServer
public: public:
WebThreeStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3); WebThreeStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3);
virtual std::string balanceAt(const std::string& address, const int& block); virtual std::string balanceAt(std::string const& address, int const& block);
virtual Json::Value block(const Json::Value& params); virtual Json::Value block(Json::Value const& params);
virtual std::string call(const Json::Value& json); virtual std::string call(Json::Value const& json);
virtual std::string codeAt(const std::string& address, const int& block); virtual std::string codeAt(std::string const& address, int const& block);
virtual std::string coinbase(); 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 int defaultBlock();
virtual std::string fromAscii(const int& padding, const std::string& s); virtual std::string fromAscii(int const& padding, std::string const& s);
virtual double fromFixed(const std::string& s); virtual double fromFixed(std::string const& s);
virtual std::string gasPrice(); virtual std::string gasPrice();
virtual bool listening(); virtual bool listening();
virtual bool mining(); virtual bool mining();
virtual std::string key(); virtual std::string key();
virtual Json::Value keys(); virtual Json::Value keys();
virtual std::string lll(const std::string& s); virtual std::string lll(std::string const& s);
virtual Json::Value messages(const Json::Value& json); virtual Json::Value messages(Json::Value const& json);
virtual int number(); 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 int peerCount();
virtual std::string secretToAddress(const std::string& s); virtual std::string secretToAddress(std::string const& s);
virtual bool setCoinbase(const std::string& address); virtual bool setCoinbase(std::string const& address);
virtual bool setListening(const bool& listening); virtual bool setListening(bool const& listening);
virtual bool setMining(const bool& mining); virtual bool setMining(bool const& mining);
virtual std::string sha3(const std::string& s); virtual std::string sha3(std::string const& s);
virtual std::string stateAt(const std::string& address, const int& block, const std::string& storage); virtual std::string stateAt(std::string const& address, int const& block, std::string const& storage);
virtual std::string toAscii(const std::string& s); virtual std::string toAscii(std::string const& s);
virtual std::string toDecimal(const std::string& s); virtual std::string toDecimal(std::string const& s);
virtual std::string toFixed(const double& s); virtual std::string toFixed(double const& s);
virtual std::string transact(const Json::Value& json); virtual std::string transact(Json::Value const & json);
virtual Json::Value transaction(const int& i, const Json::Value& params); virtual Json::Value transaction(int const& i, Json::Value const& params);
virtual Json::Value uncle(const int& i, const Json::Value &params); virtual Json::Value uncle(int const& i, Json::Value const& params);
virtual int watch(const std::string& json); virtual int watch(std::string const& json);
virtual bool check(const int& id); virtual bool check(int const& id);
virtual bool killWatch(const int& id); virtual bool killWatch(int const& id);
void setKeys(std::vector<dev::KeyPair> _keys) { m_keys = _keys; } void setKeys(std::vector<dev::KeyPair> _keys) { m_keys = _keys; }
private: private:
dev::eth::Interface* client() const; dev::eth::Interface* client() const;
dev::WebThreeDirect& m_web3; dev::WebThreeDirect& m_web3;
std::vector<dev::KeyPair> m_keys; 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()); 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(); QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object();
dev::FixedHash<32> hash; dev::FixedHash<32> hash;

14
libqethereum/QEthereum.h

@ -6,14 +6,18 @@
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include <libethcore/CommonEth.h> #include <libethcore/CommonEth.h>
namespace dev { namespace dev
namespace eth { {
namespace eth
{
class Interface; class Interface;
} }
namespace shh { namespace shh
{
class Interface; class Interface;
} }
namespace p2p { namespace p2p
{
class Host; class Host;
} }
} }
@ -204,7 +208,7 @@ private:
dev::eth::Interface* m_client; dev::eth::Interface* m_client;
std::vector<unsigned> m_watches; std::vector<unsigned> m_watches;
QList<dev::KeyPair> m_accounts; 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 class QPeer2Peer : public QObject

5
test/jsonrpc.cpp

@ -13,7 +13,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file jsonrpc.cpp /** @file jsonrpc.cpp
* @author Marek Kotewicz <marek@ethdev.com> * @author Marek Kotewicz <marek@ethdev.com>
* @date 2014 * @date 2014
@ -41,7 +41,8 @@ using namespace dev;
using namespace dev::eth; using namespace dev::eth;
namespace js = json_spirit; namespace js = json_spirit;
namespace jsonrpc_tests { namespace jsonrpc_tests
{
string name = "Ethereum(++) tests"; string name = "Ethereum(++) tests";
string dbPath; string dbPath;

Loading…
Cancel
Save