Skip to content

Commit

Permalink
implement node settings
Browse files Browse the repository at this point in the history
  • Loading branch information
fpelliccioni committed Mar 6, 2021
1 parent 4104845 commit 609fa18
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/config/node_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ using v8::Function;
using v8::Uint8Array;
using v8::ArrayBuffer;

// typedef struct {
// uint32_t sync_peers;
// uint32_t sync_timeout_seconds;
// uint32_t block_latency_seconds;
// kth_bool_t refresh_transactions;
// kth_bool_t compact_blocks_high_bandwidth;
// } kth_node_settings;


v8::Local<v8::Object> config_node_settings_to_js(Isolate* isolate, kth_node_settings const& setts) {
auto ctx = isolate->GetCurrentContext();
auto res = v8::Object::New(isolate);
auto setr = res->Set(ctx, to_string(isolate, "syncPeers"), Number::New(isolate, setts.sync_peers));
setr = res->Set(ctx, to_string(isolate, "syncTimeoutSeconds"), Number::New(isolate, setts.sync_timeout_seconds));
setr = res->Set(ctx, to_string(isolate, "blockLatencySeconds"), Number::New(isolate, setts.block_latency_seconds));
setr = res->Set(ctx, to_string(isolate, "refreshTransactions"), Boolean::New(isolate, setts.refresh_transactions != 0));
setr = res->Set(ctx, to_string(isolate, "compactBlocksHighBandwidth"), Boolean::New(isolate, setts.compact_blocks_high_bandwidth != 0));
return res;
}

void config_node_settings_default(v8::FunctionCallbackInfo<v8::Value> const& args) {
Isolate* isolate = args.GetIsolate();

Expand All @@ -45,9 +65,8 @@ void config_node_settings_default(v8::FunctionCallbackInfo<v8::Value> const& arg
}

kth_network_t network = to_kth_network_t(isolate, args[0]);

kth_node_settings res = kth_config_node_settings_default(network);
args.GetReturnValue().Set(External::New(isolate, res));
args.GetReturnValue().Set(config_node_settings_to_js(isolate, res));
}

} // namespace kth::js_native

0 comments on commit 609fa18

Please sign in to comment.