arkpar
10 years ago
26 changed files with 603 additions and 90 deletions
@ -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() |
|||
|
@ -0,0 +1,27 @@ |
|||
|
|||
#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 != 2) |
|||
{ |
|||
cout << "remote url not provided\n"; |
|||
cout << "using default:\n"; |
|||
cout << "./ethconsole http://localhost:8545\n"; |
|||
remote = "http://localhost:8545\n"; |
|||
} |
|||
else |
|||
remote = argv[1]; |
|||
|
|||
JSRemoteConsole console(remote); |
|||
while (true) |
|||
console.readExpression(); |
|||
|
|||
return 0; |
|||
} |
@ -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; |
|||
} |
@ -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(); |
|||
}; |
|||
|
|||
|
@ -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)); |
|||
} |
@ -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; |
|||
}; |
|||
|
|||
} |
|||
} |
@ -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" |
@ -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; |
|||
|
|||
}; |
|||
|
|||
} |
|||
} |
@ -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(); |
|||
} |
@ -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; |
|||
}; |
|||
|
|||
} |
|||
} |
@ -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") |
|||
|
@ -0,0 +1,101 @@ |
|||
/*
|
|||
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 keymanager.cpp
|
|||
* @author Christoph Jentzsch <cj@ethdev.com> |
|||
* @date 2015 |
|||
* Keymanager test functions. |
|||
*/ |
|||
|
|||
|
|||
#include <boost/test/unit_test.hpp> |
|||
#include <test/TestHelper.h> |
|||
#include <libdevcore/TransientDirectory.h> |
|||
#include <libethcore/KeyManager.h> |
|||
|
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
|
|||
BOOST_AUTO_TEST_SUITE(KeyManagerTests) |
|||
|
|||
BOOST_AUTO_TEST_CASE(KeyInfoDefaultConstructor) |
|||
{ |
|||
cnote << "KeyInfoDefaultConstructor"; |
|||
KeyInfo kiDefault; |
|||
BOOST_CHECK_EQUAL(kiDefault.accountName, ""); |
|||
BOOST_CHECK(kiDefault.passHash == h256()); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(KeyInfoConstructor) |
|||
{ |
|||
cnote << "KeyInfoConstructor"; |
|||
h256 passHash("0x2a"); |
|||
string accountName = "myAccount"; |
|||
KeyInfo ki(passHash, accountName); |
|||
BOOST_CHECK_EQUAL(ki.accountName, "myAccount"); |
|||
BOOST_CHECK(ki.passHash == h256("0x2a")); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(KeyManagerConstructor) |
|||
{ |
|||
cnote << "KeyManagerConstructor"; |
|||
KeyManager km; |
|||
BOOST_CHECK_EQUAL(km.keysFile(), km.defaultPath()); |
|||
BOOST_CHECK_EQUAL(km.defaultPath(), getDataDir("ethereum") + "/keys.info"); |
|||
BOOST_CHECK(km.store().keys() == SecretStore().keys()); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(KeyManagerKeysFile) |
|||
{ |
|||
cnote << "KeyManagerKeysFile"; |
|||
KeyManager km; |
|||
string password = "hardPassword"; |
|||
BOOST_CHECK(!km.load(password)); |
|||
|
|||
// set to valid path
|
|||
TransientDirectory tmpDir; |
|||
km.setKeysFile(tmpDir.path()); |
|||
BOOST_CHECK(!km.exists()); |
|||
BOOST_CHECK_THROW(km.create(password), FileError); |
|||
km.setKeysFile(tmpDir.path() + "/notExistingDir/keysFile.json"); |
|||
BOOST_CHECK_THROW(km.create(password), FileError); |
|||
BOOST_CHECK(!km.exists()); |
|||
km.setKeysFile(tmpDir.path() + "keysFile.json"); |
|||
BOOST_CHECK_NO_THROW(km.create(password)); |
|||
|
|||
km.save(password); |
|||
BOOST_CHECK(km.load(password)); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_CASE(KeyManagerHints) |
|||
{ |
|||
cnote << "KeyManagerHints"; |
|||
KeyManager km; |
|||
string password = "hardPassword"; |
|||
|
|||
// set to valid path
|
|||
TransientDirectory tmpDir; |
|||
km.setKeysFile(tmpDir.path() + "keysFile.json"); |
|||
km.create(password); |
|||
km.save(password); |
|||
|
|||
BOOST_CHECK(!km.haveHint(password + "2")); |
|||
km.notePassword(password); |
|||
BOOST_CHECK(km.haveHint(password)); |
|||
} |
|||
|
|||
BOOST_AUTO_TEST_SUITE_END() |
Loading…
Reference in new issue