From 178d80d5ef10690540bb4999b8a275c77885c9da Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 14 Oct 2014 01:21:52 +0200 Subject: [PATCH] common changes --- libdevcore/CommonJS.h | 16 ++++++++++++---- libethrpc/CorsHttpServer.cpp | 10 ++-------- libethrpc/EthStubServer.cpp | 2 +- test/jsonrpc.cpp | 8 ++++---- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/libdevcore/CommonJS.h b/libdevcore/CommonJS.h index ceca1e01a..a67a308d5 100644 --- a/libdevcore/CommonJS.h +++ b/libdevcore/CommonJS.h @@ -1,4 +1,4 @@ -#pragma once + #pragma once #include #include @@ -10,9 +10,17 @@ namespace dev { namespace eth { -template std::string toJS(FixedHash const& _h) { return "0x" + toHex(_h.ref()); } -template std::string toJS(boost::multiprecision::number> const& _n) { return "0x" + toHex(toCompactBigEndian(_n)); } -inline std::string toJS(dev::bytes const& _n) { return "0x" + dev::toHex(_n); } +template std::string toJS(FixedHash const& _h) +{ + return "0x" + toHex(_h.ref()); +} +template std::string toJS(boost::multiprecision::number> const& _n) +{ + return "0x" + toHex(toCompactBigEndian(_n)); +} +inline std::string toJS(dev::bytes const& _n) { + return "0x" + dev::toHex(_n); +} bytes jsToBytes(std::string const& _s); std::string jsPadded(std::string const& _s, unsigned _l, unsigned _r); diff --git a/libethrpc/CorsHttpServer.cpp b/libethrpc/CorsHttpServer.cpp index 16e78af66..b612f503f 100644 --- a/libethrpc/CorsHttpServer.cpp +++ b/libethrpc/CorsHttpServer.cpp @@ -14,15 +14,9 @@ bool CorsHttpServer::SendResponse(const std::string &response, void *addInfo) "Access-Control-Allow-Headers: Content-Type\r\n" "\r\n" "%s",(int)response.length(), response.c_str()) > 0) - - - { return true; - } - else - { - return false; - } + + return false; } diff --git a/libethrpc/EthStubServer.cpp b/libethrpc/EthStubServer.cpp index 89cc14321..cb365fe7c 100644 --- a/libethrpc/EthStubServer.cpp +++ b/libethrpc/EthStubServer.cpp @@ -92,7 +92,7 @@ dev::eth::Interface* EthStubServer::client() const std::string EthStubServer::balanceAt(const string &a, const int& block) { - return toJS(client()->balanceAt(jsToAddress(a), block)); + return jsToDecimal(toJS(client()->balanceAt(jsToAddress(a), block))); } //TODO BlockDetails? diff --git a/test/jsonrpc.cpp b/test/jsonrpc.cpp index 4d486e60c..4a60ee060 100644 --- a/test/jsonrpc.cpp +++ b/test/jsonrpc.cpp @@ -50,15 +50,15 @@ struct JsonrpcFixture { cnote << "teardown jsonrpc"; } }; - + BOOST_GLOBAL_FIXTURE(JsonrpcFixture) BOOST_AUTO_TEST_CASE(jsonrpc_balanceAt) { cnote << "Testing jsonrpc balanceAt..."; - dev::KeyPair pair = keys[0]; -// string balance = jsonrpcClient->balanceAt(toJS(pair.address())); - + auto address = keys[0].address(); + string balance = jsonrpcClient->balanceAt(toJS(address), 0); + BOOST_CHECK_EQUAL(jsToDecimal(toJS(web3.ethereum()->balanceAt(address))), balance); } BOOST_AUTO_TEST_CASE(jsonrpc_block)