Browse Source

Merge branch 'develop' of github.com:ethereum/cpp-ethereum into develop

cl-refactor
Gav Wood 10 years ago
parent
commit
096662a692
  1. 1
      CMakeLists.txt
  2. 16
      eth/main.cpp
  3. 31
      ethconsole/CMakeLists.txt
  4. 42
      ethconsole/main.cpp
  5. 2
      ethvm/main.cpp
  6. 6
      libdevcore/Common.cpp
  7. 19
      libdevcore/Common.h
  8. 6
      libethereum/BlockChain.cpp
  9. 2
      libethereum/Client.cpp
  10. 2
      libethereum/Executive.cpp
  11. 6
      libethereum/State.cpp
  12. 8
      libjsconsole/CMakeLists.txt
  13. 66
      libjsconsole/CURLRequest.cpp
  14. 58
      libjsconsole/CURLRequest.h
  15. 62
      libjsconsole/JSConsole.cpp
  16. 64
      libjsconsole/JSConsole.h
  17. 34
      libjsconsole/JSLocalConsole.cpp
  18. 50
      libjsconsole/JSLocalConsole.h
  19. 23
      libjsconsole/JSRemoteConsole.cpp
  20. 48
      libjsconsole/JSRemoteConsole.h
  21. 2
      libjsconsole/JSV8Connector.h
  22. 20
      libjsconsole/JSV8RemoteConnector.cpp
  23. 32
      libjsconsole/JSV8RemoteConnector.h
  24. 3
      libjsengine/JSResources.cmake
  25. 2
      libjsengine/JSV8Engine.cpp
  26. 3
      libjsengine/JSV8Engine.h
  27. 16
      libsolidity/Compiler.cpp
  28. 1
      libweb3jsonrpc/CMakeLists.txt
  29. 2
      test/libdevcrypto/trie.cpp

1
CMakeLists.txt

@ -394,6 +394,7 @@ endif ()
if (JSCONSOLE)
add_subdirectory(libjsengine)
add_subdirectory(libjsconsole)
add_subdirectory(ethconsole)
endif ()
add_subdirectory(secp256k1)

16
eth/main.cpp

@ -41,7 +41,7 @@
#include <libwebthree/WebThree.h>
#if ETH_JSCONSOLE || !ETH_TRUE
#include <libjsconsole/JSConsole.h>
#include <libjsconsole/JSLocalConsole.h>
#endif
#if ETH_READLINE || !ETH_TRUE
#include <readline/readline.h>
@ -1772,12 +1772,24 @@ int main(int argc, char** argv)
if (useConsole)
{
#if ETH_JSCONSOLE
JSConsole console(web3, make_shared<SimpleAccountHolder>([&](){return web3.ethereum();}, getAccountPassword, keyManager));
JSLocalConsole console;
jsonrpcServer = shared_ptr<dev::WebThreeStubServer>(new dev::WebThreeStubServer(*jsonrpcConnector.get(), web3, make_shared<SimpleAccountHolder>([&](){ return web3.ethereum(); }, getAccountPassword, keyManager), vector<KeyPair>(), keyManager, *gasPricer));
jsonrpcServer->setMiningBenefactorChanger([&](Address const& a) { beneficiary = a; });
jsonrpcServer->StartListening();
if (jsonAdmin.empty())
jsonAdmin = jsonrpcServer->newSession(SessionPermissions{{Priviledge::Admin}});
else
jsonrpcServer->addSession(jsonAdmin, SessionPermissions{{Priviledge::Admin}});
cout << "JSONRPC Admin Session Key: " << jsonAdmin << endl;
while (!g_exit)
{
console.readExpression();
stopMiningAfterXBlocks(c, n, mining);
}
jsonrpcServer->StopListening();
#endif
}
else

31
ethconsole/CMakeLists.txt

@ -0,0 +1,31 @@
cmake_policy(SET CMP0015 NEW)
set(CMAKE_AUTOMOC OFF)
aux_source_directory(. SRC_LIST)
include_directories(BEFORE ..)
include_directories(${JSON_RPC_CPP_INCLUDE_DIRS})
include_directories(${CURL_INCLUDE_DIRS})
include_directories(${V8_INCLUDE_DIRS})
set(EXECUTABLE ethconsole)
file(GLOB HEADERS "*.h")
add_executable(${EXECUTABLE} ${SRC_LIST} ${HEADERS})
target_link_libraries(${EXECUTABLE} ${Boost_REGEX_LIBRARIES})
target_link_libraries(${EXECUTABLE} ${READLINE_LIBRARIES})
target_link_libraries(${EXECUTABLE} ${CURL_LIBRARIES})
if (DEFINED WIN32 AND NOT DEFINED CMAKE_COMPILER_IS_MINGW)
eth_copy_dlls(${EXECUTABLE} CURL_DLLS)
endif()
target_link_libraries(${EXECUTABLE} jsconsole)
if (APPLE)
install(TARGETS ${EXECUTABLE} DESTINATION bin)
else()
eth_install_executable(${EXECUTABLE})
endif()

42
ethconsole/main.cpp

@ -0,0 +1,42 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file main.cpp
* @author Marek
* @date 2014
*/
#include <string>
#include <libjsconsole/JSRemoteConsole.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
int main(int argc, char** argv)
{
string remote;
if (argc == 1)
remote = "http://localhost:8545";
else if (argc == 2)
remote = argv[1];
JSRemoteConsole console(remote);
while (true)
console.readExpression();
return 0;
}

2
ethvm/main.cpp

@ -165,7 +165,7 @@ int main(int argc, char** argv)
executive.initialize(t);
executive.create(sender, value, gasPrice, gas, &data, origin);
boost::timer timer;
Timer timer;
executive.go(onOp);
double execTime = timer.elapsed();
executive.finalize();

6
libdevcore/Common.cpp

@ -48,9 +48,9 @@ const char* TimerChannel::name() { return EthRed " ⚡ "; }
TimerHelper::~TimerHelper()
{
auto e = m_t.elapsed();
if (!m_ms || e * 1000 > m_ms)
clog(TimerChannel) << m_id << e << "s";
auto e = std::chrono::high_resolution_clock::now() - m_t;
if (!m_ms || e > chrono::milliseconds(m_ms))
clog(TimerChannel) << m_id << chrono::duration_cast<chrono::milliseconds>(e).count() << "ms";
}
}

19
libdevcore/Common.h

@ -40,7 +40,7 @@
#include <unordered_set>
#include <functional>
#include <string>
#include <boost/timer.hpp>
#include <chrono>
#include <boost/functional/hash.hpp>
#pragma warning(push)
#pragma GCC diagnostic push
@ -193,15 +193,28 @@ private:
class TimerHelper
{
public:
TimerHelper(char const* _id, unsigned _msReportWhenGreater = 0): m_id(_id), m_ms(_msReportWhenGreater) {}
TimerHelper(char const* _id, unsigned _msReportWhenGreater = 0): m_t(std::chrono::high_resolution_clock::now()), m_id(_id), m_ms(_msReportWhenGreater) {}
~TimerHelper();
private:
boost::timer m_t;
std::chrono::high_resolution_clock::time_point m_t;
char const* m_id;
unsigned m_ms;
};
class Timer
{
public:
Timer() { restart(); }
std::chrono::high_resolution_clock::duration duration() const { return std::chrono::high_resolution_clock::now() - m_t; }
double elapsed() const { return std::chrono::duration_cast<std::chrono::microseconds>(duration()).count() / 1000000.0; }
void restart() { m_t = std::chrono::high_resolution_clock::now(); }
private:
std::chrono::high_resolution_clock::time_point m_t;
};
#define DEV_TIMED(S) for (::std::pair<::dev::TimerHelper, bool> __eth_t(#S, true); __eth_t.second; __eth_t.second = false)
#define DEV_TIMED_SCOPE(S) ::dev::TimerHelper __eth_t(S)
#if WIN32

6
libethereum/BlockChain.cpp

@ -239,7 +239,7 @@ void BlockChain::rebuild(std::string const& _path, std::function<void(unsigned,
m_extrasDB->Put(m_writeOptions, toSlice(m_lastBlockHash, ExtraDetails), (ldb::Slice)dev::ref(m_details[m_lastBlockHash].rlp()));
h256 lastHash = m_lastBlockHash;
boost::timer t;
Timer t;
for (unsigned d = 1; d < originalNumber; ++d)
{
if (!(d % 1000))
@ -412,13 +412,13 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const&
//@tidy This is a behemoth of a method - could do to be split into a few smaller ones.
#if ETH_TIMED_IMPORTS
boost::timer total;
Timer total;
double preliminaryChecks;
double enactment;
double collation;
double writing;
double checkBest;
boost::timer t;
Timer t;
#endif
// Check block doesn't already exist first!

2
libethereum/Client.cpp

@ -642,7 +642,7 @@ void Client::syncBlockQueue()
cwork << "BQ ==> CHAIN ==> STATE";
ImportRoute ir;
unsigned count;
boost::timer t;
Timer t;
tie(ir, m_syncBlockQueue, count) = m_bc.sync(m_bq, m_stateDB, m_syncAmount);
double elapsed = t.elapsed();

2
libethereum/Executive.cpp

@ -316,7 +316,7 @@ bool Executive::go(OnOpFunc const& _onOp)
if (m_ext)
{
#if ETH_TIMED_EXECUTIONS
boost::timer t;
Timer t;
#endif
try
{

6
libethereum/State.cpp

@ -139,7 +139,7 @@ PopulationStatistics State::populateFromChain(BlockChain const& _bc, h256 const&
// 2. Enact the block's transactions onto this state.
m_ourAddress = bi.coinbaseAddress;
boost::timer t;
Timer t;
auto vb = BlockChain::verifyBlock(b);
ret.verify = t.elapsed();
t.restart();
@ -401,7 +401,7 @@ bool State::sync(BlockChain const& _bc, h256 _block, BlockInfo const& _bi, Impor
u256 State::enactOn(VerifiedBlockRef const& _block, BlockChain const& _bc, ImportRequirements::value _ir)
{
#if ETH_TIMED_ENACTMENTS
boost::timer t;
Timer t;
double populateVerify;
double populateGrand;
double syncReset;
@ -507,7 +507,7 @@ pair<TransactionReceipts, bool> State::sync(BlockChain const& _bc, TransactionQu
{
if (i.second.gasPrice() >= _gp.ask(*this))
{
// boost::timer t;
// Timer t;
if (lh.empty())
lh = _bc.lastHashes();
execute(lh, i.second);

8
libjsconsole/CMakeLists.txt

@ -14,6 +14,7 @@ include_directories(BEFORE ${V8_INCLUDE_DIRS})
include_directories(BEFORE ..)
include_directories(${READLINE_INCLUDE_DIRS})
include_directories(${JSON_RPC_CPP_INCLUDE_DIRS})
include_directories(${CURL_INCLUDE_DIRS})
set(EXECUTABLE jsconsole)
@ -24,7 +25,12 @@ add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS})
target_link_libraries(${EXECUTABLE} jsengine)
target_link_libraries(${EXECUTABLE} devcore)
target_link_libraries(${EXECUTABLE} ${READLINE_LIBRARIES})
target_link_libraries(${EXECUTABLE} web3jsonrpc)
target_link_libraries(${EXECUTABLE} ${JSON_RPC_CPP_SERVER_LIBRARIES})
target_link_libraries(${EXECUTABLE} ${CURL_LIBRARIES})
if (DEFINED WIN32 AND NOT DEFINED CMAKE_COMPILER_IS_MINGW)
eth_copy_dlls(${EXECUTABLE} CURL_DLLS)
endif()
install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib )
install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} )

66
libjsconsole/CURLRequest.cpp

@ -0,0 +1,66 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file CURLRequest.cpp
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
* Ethereum client.
*/
#include "CURLRequest.h"
using namespace std;
static size_t write_data(void *buffer, size_t elementSize, size_t numberOfElements, void *userp)
{
static_cast<stringstream *>(userp)->write((const char *)buffer, elementSize * numberOfElements);
return elementSize * numberOfElements;
}
void CURLRequest::commonCURLPreparation()
{
m_resultBuffer.str("");
curl_easy_setopt(m_curl, CURLOPT_URL, (m_url + "?").c_str());
curl_easy_setopt(m_curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &m_resultBuffer);
}
std::tuple<long, string> CURLRequest::commonCURLPerform()
{
CURLcode res = curl_easy_perform(m_curl);
if (res != CURLE_OK) {
throw runtime_error(curl_easy_strerror(res));
}
long httpCode = 0;
curl_easy_getinfo(m_curl, CURLINFO_RESPONSE_CODE, &httpCode);
return make_tuple(httpCode, m_resultBuffer.str());
}
std::tuple<long, string> CURLRequest::post()
{
commonCURLPreparation();
curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, m_body.c_str());
struct curl_slist *headerList = NULL;
headerList = curl_slist_append(headerList, "Content-Type: application/json");
curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, headerList);
auto result = commonCURLPerform();
curl_slist_free_all(headerList);
return result;
}

58
libjsconsole/CURLRequest.h

@ -0,0 +1,58 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file CURLRequest.h
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
* Ethereum client.
*/
// based on http://stackoverflow.com/questions/1011339/how-do-you-make-a-http-request-with-c/27026683#27026683
#pragma once
#include <stdio.h>
#include <sstream>
#include <unordered_map>
#include <curl/curl.h>
class CURLRequest
{
public:
CURLRequest(): m_curl(curl_easy_init()) {}
~CURLRequest()
{
if (m_curl)
curl_easy_cleanup(m_curl);
}
void setUrl(std::string _url) { m_url = _url; }
void setBody(std::string _body) { m_body = _body; }
std::tuple<long, std::string> post();
private:
std::string m_url;
std::string m_body;
CURL* m_curl;
std::stringstream m_resultBuffer;
void commonCURLPreparation();
std::tuple<long, std::string> commonCURLPerform();
};

62
libjsconsole/JSConsole.cpp

@ -20,65 +20,5 @@
* Ethereum client.
*/
#include <iostream>
#include <libdevcore/Log.h>
#include <libweb3jsonrpc/WebThreeStubServer.h>
#include "JSConsole.h"
#include "JSV8Connector.h"
// TODO! make readline optional!
#include <readline/readline.h>
#include <readline/history.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
JSConsole::JSConsole(WebThreeDirect& _web3, shared_ptr<AccountHolder> const& _accounts):
m_engine(),
m_printer(m_engine)
{
m_jsonrpcConnector.reset(new JSV8Connector(m_engine));
(void)_web3; (void)_accounts;
// m_jsonrpcServer.reset(new WebThreeStubServer(*m_jsonrpcConnector.get(), _web3, _accounts, vector<KeyPair>()));
}
void JSConsole::readExpression() const
{
string cmd = "";
g_logPost = [](std::string const& a, char const*) { cout << "\r \r" << a << endl << flush; rl_forced_update_display(); };
bool isEmpty = true;
int openBrackets = 0;
do {
char* buff = readline(promptForIndentionLevel(openBrackets).c_str());
isEmpty = !(buff && *buff);
if (!isEmpty)
{
cmd += string(buff);
cmd += " ";
free(buff);
int open = count(cmd.begin(), cmd.end(), '{');
open += count(cmd.begin(), cmd.end(), '(');
int closed = count(cmd.begin(), cmd.end(), '}');
closed += count(cmd.begin(), cmd.end(), ')');
openBrackets = open - closed;
}
} while (openBrackets > 0);
if (!isEmpty)
{
add_history(cmd.c_str());
auto value = m_engine.eval(cmd.c_str());
string result = m_printer.prettyPrint(value).cstr();
cout << result << endl;
}
}
std::string JSConsole::promptForIndentionLevel(int _i) const
{
if (_i == 0)
return "> ";
return string((_i + 1) * 2, ' ');
}
#include "JSConsole.h"

64
libjsconsole/JSConsole.h

@ -22,32 +22,66 @@
#pragma once
#include <libjsengine/JSV8Engine.h>
#include <libjsengine/JSV8Printer.h>
namespace dev { class WebThreeStubServer; }
namespace jsonrpc { class AbstractServerConnector; }
#include <libdevcore/Log.h>
// TODO! make readline optional!
#include <readline/readline.h>
#include <readline/history.h>
namespace dev
{
namespace eth
{
class AccountHolder;
template<typename Engine, typename Printer>
class JSConsole
{
public:
JSConsole(WebThreeDirect& _web3, std::shared_ptr<AccountHolder> const& _accounts);
void readExpression() const;
JSConsole(): m_engine(Engine()), m_printer(Printer(m_engine)) {}
~JSConsole() {}
void readExpression() const
{
std::string cmd = "";
g_logPost = [](std::string const& a, char const*) { std::cout << "\r \r" << a << std::endl << std::flush; rl_forced_update_display(); };
bool isEmpty = true;
int openBrackets = 0;
do {
char* buff = readline(promptForIndentionLevel(openBrackets).c_str());
isEmpty = !(buff && *buff);
if (!isEmpty)
{
cmd += std::string(buff);
cmd += " ";
free(buff);
int open = std::count(cmd.begin(), cmd.end(), '{');
open += std::count(cmd.begin(), cmd.end(), '(');
int closed = std::count(cmd.begin(), cmd.end(), '}');
closed += std::count(cmd.begin(), cmd.end(), ')');
openBrackets = open - closed;
}
} while (openBrackets > 0);
private:
std::string promptForIndentionLevel(int _i) const;
if (!isEmpty)
{
add_history(cmd.c_str());
auto value = m_engine.eval(cmd.c_str());
std::string result = m_printer.prettyPrint(value).cstr();
std::cout << result << std::endl;
}
}
protected:
Engine m_engine;
Printer m_printer;
JSV8Engine m_engine;
JSV8Printer m_printer;
std::unique_ptr<dev::WebThreeStubServer> m_jsonrpcServer;
std::unique_ptr<jsonrpc::AbstractServerConnector> m_jsonrpcConnector;
virtual std::string promptForIndentionLevel(int _i) const
{
if (_i == 0)
return "> ";
return std::string((_i + 1) * 2, ' ');
}
};
}

34
libjsconsole/JSLocalConsole.cpp

@ -0,0 +1,34 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file JSLocalConsole.cpp
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
* Ethereum client.
*/
#include <iostream>
#include "JSLocalConsole.h"
#include "JSV8Connector.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
JSLocalConsole::JSLocalConsole()
{
m_jsonrpcConnector.reset(new JSV8Connector(m_engine));
}

50
libjsconsole/JSLocalConsole.h

@ -0,0 +1,50 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file JSLocalConsole.h
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
* Ethereum client.
*/
#pragma once
#include <libjsengine/JSV8Engine.h>
#include <libjsengine/JSV8Printer.h>
#include "JSConsole.h"
class WebThreeStubServer;
namespace jsonrpc { class AbstractServerConnector; }
namespace dev
{
namespace eth
{
class JSLocalConsole: public JSConsole<JSV8Engine, JSV8Printer>
{
public:
JSLocalConsole();
virtual ~JSLocalConsole() {}
jsonrpc::AbstractServerConnector* connector() { return m_jsonrpcConnector.get(); }
private:
std::unique_ptr<jsonrpc::AbstractServerConnector> m_jsonrpcConnector;
};
}
}

23
libjsconsole/JSRemoteConsole.cpp

@ -0,0 +1,23 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file JSRemoteConsole.cpp
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
* Ethereum client.
*/
#include "JSRemoteConsole.h"

48
libjsconsole/JSRemoteConsole.h

@ -0,0 +1,48 @@
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file JSRemoteConsole.h
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
* Ethereum client.
*/
#pragma once
#include <libjsengine/JSV8Engine.h>
#include <libjsengine/JSV8Printer.h>
#include "JSV8RemoteConnector.h"
#include "JSConsole.h"
namespace dev
{
namespace eth
{
class JSRemoteConsole: public JSConsole<JSV8Engine, JSV8Printer>
{
public:
JSRemoteConsole(std::string _url): m_connector(m_engine, _url) {}
virtual ~JSRemoteConsole() {}
private:
JSV8RemoteConnector m_connector;
};
}
}

2
libjsconsole/JSV8Connector.h

@ -43,7 +43,7 @@ public:
bool SendResponse(std::string const& _response, void* _addInfo = nullptr);
// implement JSV8RPC interface
void onSend(char const* payload);
void onSend(char const* _payload);
};
}

20
libjsconsole/JSV8RemoteConnector.cpp

@ -0,0 +1,20 @@
//
// Created by Marek Kotewicz on 15/06/15.
//
#include "JSV8RemoteConnector.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
void JSV8RemoteConnector::onSend(char const* _payload)
{
m_request.setUrl(m_url);
m_request.setBody(_payload);
long code;
string response;
tie(code, response) = m_request.post();
(void)code;
m_lastResponse = response.c_str();
}

32
libjsconsole/JSV8RemoteConnector.h

@ -0,0 +1,32 @@
//
// Created by Marek Kotewicz on 15/06/15.
//
#pragma once
#include <string>
#include <libjsengine/JSV8RPC.h>
#include "CURLRequest.h"
namespace dev
{
namespace eth
{
class JSV8RemoteConnector : public JSV8RPC
{
public:
JSV8RemoteConnector(JSV8Engine const& _engine, std::string _url): JSV8RPC(_engine), m_url(_url) {}
virtual ~JSV8RemoteConnector() {}
// implement JSV8RPC interface
void onSend(char const* _payload);
private:
std::string m_url;
CURLRequest m_request;
};
}
}

3
libjsengine/JSResources.cmake

@ -1,8 +1,9 @@
set(web3 "${CMAKE_CURRENT_LIST_DIR}/../libjsqrc/ethereumjs/dist/web3.js")
set(admin "${CMAKE_CURRENT_LIST_DIR}/../libjsqrc/admin.js")
set(pretty_print "${CMAKE_CURRENT_LIST_DIR}/PrettyPrint.js")
set(common "${CMAKE_CURRENT_LIST_DIR}/Common.js")
set(ETH_RESOURCE_NAME "JSEngineResources")
set(ETH_RESOURCE_LOCATION "${CMAKE_CURRENT_BINARY_DIR}")
set(ETH_RESOURCES "web3" "pretty_print" "common")
set(ETH_RESOURCES "web3" "pretty_print" "common" "admin")

2
libjsengine/JSV8Engine.cpp

@ -143,9 +143,11 @@ JSV8Engine::JSV8Engine(): m_scope(new JSV8Scope())
JSEngineResources resources;
string common = resources.loadResourceAsString("common");
string web3 = resources.loadResourceAsString("web3");
string admin = resources.loadResourceAsString("admin");
eval(common.c_str());
eval(web3.c_str());
eval("web3 = require('web3');");
eval(admin.c_str());
}
JSV8Engine::~JSV8Engine()

3
libjsengine/JSV8Engine.h

@ -22,7 +22,10 @@
#pragma once
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <v8.h>
#pragma clang diagnostic pop
#include "JSEngine.h"
namespace dev

16
libsolidity/Compiler.cpp

@ -165,10 +165,26 @@ void Compiler::appendConstructor(FunctionDefinition const& _constructor)
// copy constructor arguments from code to memory and then to stack, they are supplied after the actual program
if (!_constructor.getParameters().empty())
{
unsigned argumentSize = 0;
for (ASTPointer<VariableDeclaration> const& var: _constructor.getParameters())
if (var->getType()->isDynamicallySized())
{
argumentSize = 0;
break;
}
else
argumentSize += var->getType()->getCalldataEncodedSize();
CompilerUtils(m_context).fetchFreeMemoryPointer();
if (argumentSize == 0)
{
// argument size is dynamic, use CODESIZE to determine it
m_context.appendProgramSize(); // program itself
// CODESIZE is program plus manually added arguments
m_context << eth::Instruction::CODESIZE << eth::Instruction::SUB;
}
else
m_context << u256(argumentSize);
// stack: <memptr> <argument size>
m_context << eth::Instruction::DUP1;
m_context.appendProgramSize();

1
libweb3jsonrpc/CMakeLists.txt

@ -54,4 +54,3 @@ install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib L
install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} )
add_custom_target(aux_json SOURCES "spec.json")

2
test/libdevcrypto/trie.cpp

@ -585,7 +585,7 @@ template<typename Trie> void perfTestTrie(char const* _name)
d.init();
cnote << "TriePerf " << _name << p;
std::vector<h256> keys(1000);
boost::timer t;
Timer t;
size_t ki = 0;
for (size_t i = 0; i < p; ++i)
{

Loading…
Cancel
Save