Browse Source

retab

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
5001c19987
  1. 6
      eth/main.cpp
  2. 36
      libdevcore/CommonJS.cpp
  3. 26
      libdevcore/CommonJS.h

6
eth/main.cpp

@ -186,7 +186,7 @@ int main(int argc, char** argv)
unsigned peers = 5;
bool interactive = false;
#if ETH_JSONRPC
int jsonrpc = -1;
int jsonrpc = -1;
#endif
string publicIP;
bool bootstrap = false;
@ -340,7 +340,7 @@ int main(int argc, char** argv)
auto_ptr<EthStubServer> jsonrpcServer;
if (jsonrpc > -1)
{
jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::CorsHttpServer(jsonrpc), web3));
jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::CorsHttpServer(jsonrpc), web3));
jsonrpcServer->setKeys({us});
jsonrpcServer->StartListening();
}
@ -428,7 +428,7 @@ int main(int argc, char** argv)
{
if (jsonrpc < 0)
jsonrpc = 8080;
jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::CorsHttpServer(jsonrpc), web3));
jsonrpcServer = auto_ptr<EthStubServer>(new EthStubServer(new jsonrpc::CorsHttpServer(jsonrpc), web3));
jsonrpcServer->setKeys({us});
jsonrpcServer->StartListening();
}

36
libdevcore/CommonJS.cpp

@ -5,42 +5,42 @@ namespace eth {
bytes dev::eth::jsToBytes(std::string const& _s)
{
if (_s.substr(0, 2) == "0x")
// Hex
return fromHex(_s.substr(2));
if (_s.substr(0, 2) == "0x")
// Hex
return fromHex(_s.substr(2));
else if (_s.find_first_not_of("0123456789") == std::string::npos)
// Decimal
return toCompactBigEndian(bigint(_s));
return toCompactBigEndian(bigint(_s));
else
// Binary
return asBytes(_s);
return asBytes(_s);
}
std::string dev::eth::jsPadded(std::string const& _s, unsigned _l, unsigned _r)
{
bytes b = jsToBytes(_s);
while (b.size() < _l)
b.insert(b.begin(), 0);
while (b.size() < _r)
b.push_back(0);
return asString(b).substr(b.size() - std::max(_l, _r));
bytes b = jsToBytes(_s);
while (b.size() < _l)
b.insert(b.begin(), 0);
while (b.size() < _r)
b.push_back(0);
return asString(b).substr(b.size() - std::max(_l, _r));
}
std::string dev::eth::jsPadded(std::string const& _s, unsigned _l)
{
if (_s.substr(0, 2) == "0x" || _s.find_first_not_of("0123456789") == std::string::npos)
if (_s.substr(0, 2) == "0x" || _s.find_first_not_of("0123456789") == std::string::npos)
// Numeric: pad to right
return jsPadded(_s, _l, _l);
else
return jsPadded(_s, _l, _l);
else
// Text: pad to the left
return jsPadded(_s, 0, _l);
return jsPadded(_s, 0, _l);
}
std::string dev::eth::jsUnpadded(std::string _s)
{
auto p = _s.find_last_not_of((char)0);
_s.resize(p == std::string::npos ? 0 : (p + 1));
return _s;
auto p = _s.find_last_not_of((char)0);
_s.resize(p == std::string::npos ? 0 : (p + 1));
return _s;
}

26
libdevcore/CommonJS.h

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <string>
#include <vector>
@ -12,14 +12,14 @@ namespace eth {
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)
{
return "0x" + toHex(toCompactBigEndian(_n));
return "0x" + toHex(toCompactBigEndian(_n));
}
inline std::string toJS(dev::bytes const& _n) {
return "0x" + dev::toHex(_n);
return "0x" + dev::toHex(_n);
}
bytes jsToBytes(std::string const& _s);
@ -29,15 +29,15 @@ std::string jsUnpadded(std::string _s);
template <unsigned N> FixedHash<N> jsToFixed(std::string const& _s)
{
if (_s.substr(0, 2) == "0x")
// Hex
return FixedHash<N>(_s.substr(2));
else if (_s.find_first_not_of("0123456789") == std::string::npos)
// Decimal
return (typename FixedHash<N>::Arith)(_s);
else
// Binary
return FixedHash<N>(asBytes(jsPadded(_s, N)));
if (_s.substr(0, 2) == "0x")
// Hex
return FixedHash<N>(_s.substr(2));
else if (_s.find_first_not_of("0123456789") == std::string::npos)
// Decimal
return (typename FixedHash<N>::Arith)(_s);
else
// Binary
return FixedHash<N>(asBytes(jsPadded(_s, N)));
}
inline std::string jsToFixed(double _s)

Loading…
Cancel
Save