Browse Source

Move CommonJS to libethcore. Split it up ready for refactoring into

libdevcore/libdevcrypto.
cl-refactor
Gav Wood 10 years ago
parent
commit
325ec15389
  1. 2
      alethzero/MainWin.cpp
  2. 4
      alethzero/OurWebThreeStubServer.h
  3. 51
      libethcore/CommonJS.cpp
  4. 40
      libethcore/CommonJS.h
  5. 2
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  6. 4
      libweb3jsonrpc/WebThreeStubServerBase.h
  7. 2
      mix/ClientModel.cpp
  8. 2
      mix/ContractCallDataEncoder.cpp
  9. 2
      mix/DebuggingStateWrapper.cpp
  10. 2
      mix/QBigInt.cpp
  11. 2
      mix/QBigInt.h
  12. 2
      mix/QVariableDefinition.cpp
  13. 5
      test/commonjs.cpp
  14. 2
      test/jsonrpc.cpp

2
alethzero/MainWin.cpp

@ -33,7 +33,7 @@
#include <libserpent/funcs.h> #include <libserpent/funcs.h>
#include <libserpent/util.h> #include <libserpent/util.h>
#include <libdevcrypto/FileSystem.h> #include <libdevcrypto/FileSystem.h>
#include <libdevcore/CommonJS.h> #include <libethcore/CommonJS.h>
#include <liblll/Compiler.h> #include <liblll/Compiler.h>
#include <liblll/CodeFragment.h> #include <liblll/CodeFragment.h>
#include <libsolidity/Scanner.h> #include <libsolidity/Scanner.h>

4
alethzero/OurWebThreeStubServer.h

@ -20,7 +20,7 @@
*/ */
#include <QtCore/QObject> #include <QtCore/QObject>
#include <libdevcore/CommonJS.h> #include <libethcore/CommonJS.h>
#include <libdevcrypto/Common.h> #include <libdevcrypto/Common.h>
#include <libweb3jsonrpc/WebThreeStubServer.h> #include <libweb3jsonrpc/WebThreeStubServer.h>
@ -35,7 +35,7 @@ public:
std::vector<dev::KeyPair> const& _accounts, Main* main); std::vector<dev::KeyPair> const& _accounts, Main* main);
virtual std::string shh_newIdentity() override; virtual std::string shh_newIdentity() override;
virtual bool authenticate(dev::TransactionSkeleton const& _t); virtual bool authenticate(dev::eth::TransactionSkeleton const& _t);
signals: signals:
void onNewId(QString _s); void onNewId(QString _s);

51
libdevcore/CommonJS.cpp → libethcore/CommonJS.cpp

@ -72,6 +72,31 @@ bytes unpadLeft(bytes _b)
return _b; return _b;
} }
std::string fromRaw(h256 _n, unsigned* _inc)
{
if (_n)
{
std::string s((char const*)_n.data(), 32);
auto l = s.find_first_of('\0');
if (!l)
return "";
if (l != std::string::npos)
{
auto p = s.find_first_not_of('\0', l);
if (!(p == std::string::npos || (_inc && p == 31)))
return "";
if (_inc)
*_inc = (byte)s[31];
s.resize(l);
}
for (auto i: s)
if (i < 32)
return "";
return s;
}
return "";
}
std::string prettyU256(u256 _n) std::string prettyU256(u256 _n)
{ {
unsigned inc = 0; unsigned inc = 0;
@ -98,31 +123,6 @@ std::string prettyU256(u256 _n)
return s.str(); return s.str();
} }
std::string fromRaw(h256 _n, unsigned* _inc)
{
if (_n)
{
std::string s((char const*)_n.data(), 32);
auto l = s.find_first_of('\0');
if (!l)
return "";
if (l != std::string::npos)
{
auto p = s.find_first_not_of('\0', l);
if (!(p == std::string::npos || (_inc && p == 31)))
return "";
if (_inc)
*_inc = (byte)s[31];
s.resize(l);
}
for (auto i: s)
if (i < 32)
return "";
return s;
}
return "";
}
Address fromString(std::string const& _sn) Address fromString(std::string const& _sn)
{ {
if (_sn.size() == 40) if (_sn.size() == 40)
@ -132,3 +132,4 @@ Address fromString(std::string const& _sn)
} }
} }

40
libdevcore/CommonJS.h → libethcore/CommonJS.h

@ -24,9 +24,11 @@
#pragma once #pragma once
#include <string> #include <string>
#include <libethereum/Interface.h> #include <libdevcore/Common.h>
#include "Common.h" #include <libdevcore/FixedHash.h>
#include "CommonData.h" #include <libdevcore/CommonData.h>
#include <libdevcore/CommonIO.h>
#include "CommonEth.h"
namespace dev namespace dev
{ {
@ -94,16 +96,8 @@ template <unsigned N> boost::multiprecision::number<boost::multiprecision::cpp_i
return 0; // FAIL return 0; // FAIL
} }
inline Address jsToAddress(std::string const& _s) { return jsToFixed<sizeof(dev::Address)>(_s); }
inline Public jsToPublic(std::string const& _s) { return jsToFixed<sizeof(dev::Public)>(_s); }
inline Secret jsToSecret(std::string const& _s) { return jsToFixed<sizeof(dev::Secret)>(_s); }
inline u256 jsToU256(std::string const& _s) { return jsToInt<32>(_s); } inline u256 jsToU256(std::string const& _s) { return jsToInt<32>(_s); }
inline std::string jsToBinary(std::string const& _s)
{
return dev::toString(unpadded(jsToBytes(_s)));
}
inline std::string jsToDecimal(std::string const& _s) inline std::string jsToDecimal(std::string const& _s)
{ {
return dev::toString(jsToU256(_s)); return dev::toString(jsToU256(_s));
@ -125,6 +119,29 @@ inline double jsFromFixed(std::string const& _s)
return (double)jsToU256(_s) / (double)(dev::u256(1) << 128); return (double)jsToU256(_s) / (double)(dev::u256(1) << 128);
} }
}
// devcrypto
#include <libdevcrypto/Common.h>
namespace dev
{
inline Public jsToPublic(std::string const& _s) { return jsToFixed<sizeof(dev::Public)>(_s); }
inline Secret jsToSecret(std::string const& _s) { return jsToFixed<sizeof(dev::Secret)>(_s); }
}
// ethcore
namespace dev
{
namespace eth
{
inline Address jsToAddress(std::string const& _s) { return jsToFixed<sizeof(dev::Address)>(_s); }
struct TransactionSkeleton struct TransactionSkeleton
{ {
Address from; Address from;
@ -136,3 +153,4 @@ struct TransactionSkeleton
}; };
} }
}

2
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -28,7 +28,7 @@
#include <liblll/Compiler.h> #include <liblll/Compiler.h>
#include <libethereum/Client.h> #include <libethereum/Client.h>
#include <libwebthree/WebThree.h> #include <libwebthree/WebThree.h>
#include <libdevcore/CommonJS.h> #include <libethcore/CommonJS.h>
#include <libwhisper/Message.h> #include <libwhisper/Message.h>
#include <libwhisper/WhisperHost.h> #include <libwhisper/WhisperHost.h>
#include <libserpent/funcs.h> #include <libserpent/funcs.h>

4
libweb3jsonrpc/WebThreeStubServerBase.h

@ -36,9 +36,9 @@ namespace dev
{ {
class WebThreeNetworkFace; class WebThreeNetworkFace;
class KeyPair; class KeyPair;
struct TransactionSkeleton;
namespace eth namespace eth
{ {
struct TransactionSkeleton;
class Interface; class Interface;
} }
namespace shh namespace shh
@ -122,7 +122,7 @@ public:
std::map<dev::Public, dev::Secret> const& ids() const { return m_ids; } std::map<dev::Public, dev::Secret> const& ids() const { return m_ids; }
protected: protected:
virtual bool authenticate(dev::TransactionSkeleton const& _t); virtual bool authenticate(dev::eth::TransactionSkeleton const& _t);
protected: protected:
virtual dev::eth::Interface* client() = 0; virtual dev::eth::Interface* client() = 0;

2
mix/ClientModel.cpp

@ -24,7 +24,7 @@
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QStandardPaths> #include <QStandardPaths>
#include <jsonrpccpp/server.h> #include <jsonrpccpp/server.h>
#include <libdevcore/CommonJS.h> #include <libethcore/CommonJS.h>
#include <libethereum/Transaction.h> #include <libethereum/Transaction.h>
#include "AppContext.h" #include "AppContext.h"
#include "DebuggingStateWrapper.h" #include "DebuggingStateWrapper.h"

2
mix/ContractCallDataEncoder.cpp

@ -23,7 +23,7 @@
#include <QDebug> #include <QDebug>
#include <QMap> #include <QMap>
#include <QStringList> #include <QStringList>
#include <libdevcore/CommonJS.h> #include <libethcore/CommonJS.h>
#include <libsolidity/AST.h> #include <libsolidity/AST.h>
#include "QVariableDeclaration.h" #include "QVariableDeclaration.h"
#include "QVariableDefinition.h" #include "QVariableDefinition.h"

2
mix/DebuggingStateWrapper.cpp

@ -26,7 +26,7 @@
#include <QQmlEngine> #include <QQmlEngine>
#include <QVariantList> #include <QVariantList>
#include <libevmcore/Instruction.h> #include <libevmcore/Instruction.h>
#include <libdevcore/CommonJS.h> #include <libethcore/CommonJS.h>
#include <libdevcrypto/Common.h> #include <libdevcrypto/Common.h>
#include <libevmcore/Instruction.h> #include <libevmcore/Instruction.h>
#include <libdevcore/Common.h> #include <libdevcore/Common.h>

2
mix/QBigInt.cpp

@ -21,7 +21,7 @@
#include <boost/variant/multivisitors.hpp> #include <boost/variant/multivisitors.hpp>
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <libdevcore/CommonJS.h> #include <libethcore/CommonJS.h>
#include "QBigInt.h" #include "QBigInt.h"
using namespace dev; using namespace dev;

2
mix/QBigInt.h

@ -26,7 +26,7 @@
#include "boost/variant/multivisitors.hpp" #include "boost/variant/multivisitors.hpp"
#include <QObject> #include <QObject>
#include <QQmlEngine> #include <QQmlEngine>
#include <libdevcore/CommonJS.h> #include <libethcore/CommonJS.h>
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
using namespace dev; using namespace dev;

2
mix/QVariableDefinition.cpp

@ -20,7 +20,7 @@
*/ */
#include <libdevcore/CommonData.h> #include <libdevcore/CommonData.h>
#include <libdevcore/CommonJS.h> #include <libethcore/CommonJS.h>
#include "QVariableDefinition.h" #include "QVariableDefinition.h"
using namespace dev::mix; using namespace dev::mix;

5
test/commonjs.cpp

@ -20,7 +20,8 @@
*/ */
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <libdevcore/CommonJS.h> #include <libdevcore/Log.h>
#include <libethcore/CommonJS.h>
BOOST_AUTO_TEST_SUITE(commonjs) BOOST_AUTO_TEST_SUITE(commonjs)
using namespace std; using namespace std;
@ -41,7 +42,7 @@ BOOST_AUTO_TEST_CASE(jsToAddress)
cnote << "Testing jsToPublic..."; cnote << "Testing jsToPublic...";
KeyPair kp = KeyPair::create(); KeyPair kp = KeyPair::create();
string string = toJS(kp.address()); string string = toJS(kp.address());
Address address = dev::jsToAddress(string); Address address = dev::eth::jsToAddress(string);
BOOST_CHECK_EQUAL(kp.address(), address); BOOST_CHECK_EQUAL(kp.address(), address);
} }

2
test/jsonrpc.cpp

@ -28,7 +28,7 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <libdevcore/Log.h> #include <libdevcore/Log.h>
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include <libdevcore/CommonJS.h> #include <libethcore/CommonJS.h>
#include <libwebthree/WebThree.h> #include <libwebthree/WebThree.h>
#include <libweb3jsonrpc/WebThreeStubServer.h> #include <libweb3jsonrpc/WebThreeStubServer.h>
#include <jsonrpccpp/server/connectors/httpserver.h> #include <jsonrpccpp/server/connectors/httpserver.h>

Loading…
Cancel
Save