Marek Kotewicz
10 years ago
13 changed files with 216 additions and 10 deletions
@ -0,0 +1,11 @@ |
|||||
|
console = {}; |
||||
|
console.log = function () { |
||||
|
}; |
||||
|
console.warn = function () { |
||||
|
}; |
||||
|
console.error = function () { |
||||
|
}; |
||||
|
|
||||
|
setTimeout = function () { |
||||
|
}; |
||||
|
|
@ -1,6 +1,8 @@ |
|||||
|
|
||||
|
set(web3 "${CMAKE_CURRENT_LIST_DIR}/../libjsqrc/ethereumjs/dist/web3.js") |
||||
set(pretty_print "${CMAKE_CURRENT_LIST_DIR}/PrettyPrint.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_NAME "JSEngineResources") |
||||
set(ETH_RESOURCE_LOCATION "${CMAKE_CURRENT_BINARY_DIR}") |
set(ETH_RESOURCE_LOCATION "${CMAKE_CURRENT_BINARY_DIR}") |
||||
set(ETH_RESOURCES "pretty_print") |
set(ETH_RESOURCES "web3" "pretty_print" "common") |
||||
|
@ -0,0 +1,79 @@ |
|||||
|
//
|
||||
|
// Created by Marek Kotewicz on 04/05/15.
|
||||
|
//
|
||||
|
|
||||
|
#include "libjsconsole/JSConsoleResources.hpp" |
||||
|
#include "JSV8RPC.h" |
||||
|
#include <assert.h> |
||||
|
|
||||
|
using namespace std; |
||||
|
using namespace dev; |
||||
|
using namespace dev::eth; |
||||
|
|
||||
|
namespace dev |
||||
|
{ |
||||
|
namespace eth |
||||
|
{ |
||||
|
|
||||
|
void JSV8RPCSend(v8::FunctionCallbackInfo<v8::Value> const& args) |
||||
|
{ |
||||
|
const char* tmp = R"( |
||||
|
{ |
||||
|
"id": 1, |
||||
|
"jsonrpc": "2.0", |
||||
|
"result": "0x9df33b35fbdd8dff5e557a0cce288614dbf7327c292f1ac5b9c6c0e672005f48" |
||||
|
} |
||||
|
)"; |
||||
|
|
||||
|
v8::Local<v8::String> JSON = v8::String::NewFromUtf8(args.GetIsolate(), "JSON"); |
||||
|
v8::Local<v8::String> parse = v8::String::NewFromUtf8(args.GetIsolate(), "parse"); |
||||
|
v8::Handle<v8::Object> jsonObject = v8::Handle<v8::Object>::Cast(args.GetIsolate()->GetCurrentContext()->Global()->Get(JSON)); |
||||
|
v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(jsonObject->Get(parse)); |
||||
|
|
||||
|
v8::Local<v8::Value> values[1] = {v8::String::NewFromUtf8(args.GetIsolate(), tmp)}; |
||||
|
args.GetReturnValue().Set(func->Call(func, 1, values)); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
JSV8RPC::JSV8RPC(JSV8Engine const &_engine): m_engine(_engine) {} |
||||
|
|
||||
|
JSV8RPC::~JSV8RPC() |
||||
|
{ |
||||
|
StopListening(); |
||||
|
} |
||||
|
|
||||
|
bool JSV8RPC::StartListening() |
||||
|
{ |
||||
|
v8::HandleScope scope(m_engine.context()->GetIsolate()); |
||||
|
v8::Local<v8::ObjectTemplate> rpcTemplate = v8::ObjectTemplate::New(m_engine.context()->GetIsolate()); |
||||
|
rpcTemplate->SetInternalFieldCount(1); |
||||
|
rpcTemplate->Set(v8::String::NewFromUtf8(m_engine.context()->GetIsolate(), "send"), |
||||
|
v8::FunctionTemplate::New(m_engine.context()->GetIsolate(), JSV8RPCSend)); |
||||
|
rpcTemplate->Set(v8::String::NewFromUtf8(m_engine.context()->GetIsolate(), "sendAsync"), |
||||
|
v8::FunctionTemplate::New(m_engine.context()->GetIsolate(), JSV8RPCSend)); |
||||
|
|
||||
|
v8::Local<v8::Object> obj = rpcTemplate->NewInstance(); |
||||
|
obj->SetInternalField(0, v8::External::New(m_engine.context()->GetIsolate(), this)); |
||||
|
|
||||
|
v8::Local<v8::String> web3 = v8::String::NewFromUtf8(m_engine.context()->GetIsolate(), "web3"); |
||||
|
v8::Local<v8::String> setProvider = v8::String::NewFromUtf8(m_engine.context()->GetIsolate(), "setProvider"); |
||||
|
v8::Handle<v8::Object> web3object = v8::Handle<v8::Object>::Cast(m_engine.context()->Global()->Get(web3)); |
||||
|
v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(web3object->Get(setProvider)); |
||||
|
v8::Local<v8::Value> values[1] = {obj}; |
||||
|
func->Call(func, 1, values); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
bool JSV8RPC::StopListening() |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
bool JSV8RPC::SendResponse(std::string const &_response, void *_addInfo) |
||||
|
{ |
||||
|
m_lastResponse = _response; |
||||
|
(void)_addInfo; |
||||
|
return true; |
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
//
|
||||
|
// Created by Marek Kotewicz on 04/05/15.
|
||||
|
//
|
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
//#include <jsonrpccpp/server/abstractserverconnector.h>
|
||||
|
#include <libjsengine/JSV8Engine.h> |
||||
|
|
||||
|
namespace dev |
||||
|
{ |
||||
|
namespace eth |
||||
|
{ |
||||
|
|
||||
|
class JSV8RPC |
||||
|
{ |
||||
|
public: |
||||
|
JSV8RPC(JSV8Engine const& _engine); |
||||
|
virtual ~JSV8RPC(); |
||||
|
|
||||
|
bool StartListening(); |
||||
|
|
||||
|
bool StopListening(); |
||||
|
|
||||
|
bool SendResponse(std::string const& _response, void* _addInfo = NULL); |
||||
|
|
||||
|
private: |
||||
|
JSV8Engine const& m_engine; |
||||
|
std::string m_lastResponse; |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
} |
Loading…
Reference in new issue