Browse Source

fixed #763, changes in CommonJS

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
63fc3cb4ac
  1. 22
      libdevcore/CommonJS.h
  2. 10
      libweb3jsonrpc/WebThreeStubServerBase.cpp

22
libdevcore/CommonJS.h

@ -41,9 +41,11 @@ template <unsigned N> std::string toJS(boost::multiprecision::number<boost::mult
return "0x" + toHex(toCompactBigEndian(_n, 1));
}
inline std::string toJS(bytes const& _n)
inline std::string toJS(bytes const& _n, std::size_t _padding = 0)
{
return "0x" + toHex(_n);
bytes n = _n;
n.resize(std::max<unsigned>(n.size(), _padding));
return "0x" + toHex(n);
}
template< typename T >std::string toJS( T const& i )
@ -109,20 +111,4 @@ inline std::string jsToDecimal(std::string const& _s)
return toString(jsToU256(_s));
}
inline std::string jsFromBinary(bytes _s, unsigned _padding = 32)
{
_s.resize(std::max<unsigned>(_s.size(), _padding));
return "0x" + toHex(_s);
}
inline std::string jsFromBinary(std::string const& _s, unsigned _padding = 32)
{
return jsFromBinary(asBytes(_s), _padding);
}
inline double jsFromFixed(std::string const& _s)
{
return (double)jsToU256(_s) / (double)(u256(1) << 128);
}
}

10
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -60,7 +60,7 @@ static Json::Value toJson(dev::eth::BlockInfo const& _bi)
res["number"] = toJS(_bi.number);
res["gasLimit"] = toJS(_bi.gasLimit);
res["timestamp"] = toJS(_bi.timestamp);
res["extraData"] = jsFromBinary(_bi.extraData);
res["extraData"] = toJS(_bi.extraData);
res["nonce"] = toJS(_bi.nonce);
return res;
}
@ -69,7 +69,7 @@ static Json::Value toJson(dev::eth::Transaction const& _t)
{
Json::Value res;
res["hash"] = toJS(_t.sha3());
res["input"] = jsFromBinary(_t.data());
res["input"] = toJS(_t.data());
res["to"] = toJS(_t.receiveAddress());
res["from"] = toJS(_t.safeSender());
res["gas"] = toJS(_t.gas());
@ -105,7 +105,7 @@ static Json::Value toJson(dev::eth::TransactionSkeleton const& _t)
res["gas"] = toJS(_t.gas);
res["gasPrice"] = toJS(_t.gasPrice);
res["value"] = toJS(_t.value);
res["data"] = jsFromBinary(_t.data);
res["data"] = toJS(_t.data, 32);
return res;
}
@ -113,7 +113,7 @@ static Json::Value toJson(dev::eth::LocalisedLogEntry const& _e)
{
Json::Value res;
res["data"] = jsFromBinary(_e.data);
res["data"] = toJS(_e.data);
res["address"] = toJS(_e.address);
res["topics"] = Json::Value(Json::arrayValue);
for (auto const& t: _e.topics)
@ -461,7 +461,7 @@ string WebThreeStubServerBase::eth_getData(string const& _address, string const&
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS));
}
return jsFromBinary(client()->codeAt(address, number));
return toJS(client()->codeAt(address, number));
}
static TransactionSkeleton toTransaction(Json::Value const& _json)

Loading…
Cancel
Save