Skip to content

Commit

Permalink
add start module parameter to node launch
Browse files Browse the repository at this point in the history
  • Loading branch information
fpelliccioni committed Mar 10, 2021
1 parent 7dcc31c commit b6f0d76
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kth-bch-native",
"version": "0.20.0",
"version": "0.21.0",
"description": "Bitcoin Cash development platform for Javascript applications",
"repository": {
"type": "git",
Expand Down
11 changes: 8 additions & 3 deletions src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void node_init_run_and_wait_for_signal_handler(uv_async_t* handle) {
void node_init_run_and_wait_for_signal(FunctionCallbackInfo<Value> const& args) {
auto* isolate = args.GetIsolate();

if (args.Length() != 2) {
if (args.Length() != 3) {
throw_exception(isolate, "Wrong number of arguments");
return;
}
Expand All @@ -139,11 +139,16 @@ void node_init_run_and_wait_for_signal(FunctionCallbackInfo<Value> const& args)
return;
}

if ( ! args[1]->IsFunction()) {
if ( ! args[1]->IsNumber()) {
throw_exception(isolate, "Wrong arguments, 1");
return;
}

if ( ! args[2]->IsFunction()) {
throw_exception(isolate, "Wrong arguments, 2");
return;
}

// std::cout << std::this_thread::get_id() << '\n';
void* vptr = v8::External::Cast(*args[0])->Value();
kth_node_t node = (kth_node_t)vptr;
Expand All @@ -155,8 +160,8 @@ void node_init_run_and_wait_for_signal(FunctionCallbackInfo<Value> const& args)
context->async = &node_init_run_and_wait_for_signal_ah_;
context->callback = callback;

kth_start_modules_t mods = start_modules_to_cpp(isolate, args[1]);

kth_start_modules_t mods = kth_start_modules_all; //TODO(fernando): this is another parameter.
std::thread t([node, context, mods]() {
kth_node_init_run_and_wait_for_signal(node, context, mods, [](kth_node_t node, void* ctx, kth_error_code_t err) {
auto* context = static_cast<context_t*>(ctx);
Expand Down
3 changes: 2 additions & 1 deletion tests/test_native.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ async function main() {
// kth.node_initchain(node)
// kth.node_run_wait(node)

kth.node_init_run_and_wait_for_signal(node, function (err) {
let justChain = 1;
kth.node_init_run_and_wait_for_signal(node, justChain, function (err) {
console.log(err);
});

Expand Down

0 comments on commit b6f0d76

Please sign in to comment.