Browse Source

common changes

cl-refactor
Marek Kotewicz 11 years ago
parent
commit
178d80d5ef
  1. 16
      libdevcore/CommonJS.h
  2. 10
      libethrpc/CorsHttpServer.cpp
  3. 2
      libethrpc/EthStubServer.cpp
  4. 6
      test/jsonrpc.cpp

16
libdevcore/CommonJS.h

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <string>
#include <vector>
@ -10,9 +10,17 @@
namespace dev {
namespace eth {
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) { return "0x" + dev::toHex(_n); }
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) {
return "0x" + dev::toHex(_n);
}
bytes jsToBytes(std::string const& _s);
std::string jsPadded(std::string const& _s, unsigned _l, unsigned _r);

10
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;
}

2
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?

6
test/jsonrpc.cpp

@ -56,9 +56,9 @@ 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)

Loading…
Cancel
Save