Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fpelliccioni committed Jul 9, 2023
1 parent 0c8151b commit 8ec573a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
7 changes: 7 additions & 0 deletions include/kth/js-native/helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ kth_start_modules_t start_modules_to_cpp(v8::Isolate* isolate, v8::Local<v8::Val
return res;
}

inline
kth_db_mode_t db_mode_to_cpp(v8::Isolate* isolate, v8::Local<v8::Value> const& x) {
auto val = x->IntegerValue(isolate->GetCurrentContext()).ToChecked();
kth_db_mode_t res = kth_db_mode_t(val);
return res;
}

} // namespace kth::js_native

#endif // KTH_JS_NATIVE_HELPER_HPP_
8 changes: 2 additions & 6 deletions src/config/database_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ v8::Local<v8::Object> config_database_settings_to_js(Isolate* isolate, kth_datab
auto ctx = isolate->GetCurrentContext();
auto res = v8::Object::New(isolate);
auto setr = res->Set(ctx, string_to_js(isolate, "directory"), string_to_js(isolate, setts.directory));
setr = res->Set(ctx, string_to_js(isolate, "flushWrites"), Boolean::New(isolate, setts.flush_writes != 0));
setr = res->Set(ctx, string_to_js(isolate, "fileGrowthRate"), Number::New(isolate, setts.file_growth_rate));
setr = res->Set(ctx, string_to_js(isolate, "indexStartHeight"), Number::New(isolate, setts.index_start_height));
setr = res->Set(ctx, string_to_js(isolate, "dbMode"), Number::New(isolate, setts.db_mode));
setr = res->Set(ctx, string_to_js(isolate, "reorgPoolLimit"), Number::New(isolate, setts.reorg_pool_limit));
setr = res->Set(ctx, string_to_js(isolate, "dbMaxSize"), Number::New(isolate, setts.db_max_size));
setr = res->Set(ctx, string_to_js(isolate, "safeMode"), Boolean::New(isolate, setts.safe_mode != 0));
Expand All @@ -54,9 +52,7 @@ kth_database_settings config_database_settings_to_cpp(Isolate* isolate, v8::Loca
setts->Get(ctx, string_to_js(isolate, "directory")).ToLocalChecked()->ToString(ctx).ToLocalChecked(),
&res.directory);

res.flush_writes = bool_to_cpp(isolate, setts->Get(ctx, string_to_js(isolate, "flushWrites")).ToLocalChecked());
res.file_growth_rate = setts->Get(ctx, string_to_js(isolate, "fileGrowthRate")).ToLocalChecked()->IntegerValue(ctx).ToChecked();
res.index_start_height = setts->Get(ctx, string_to_js(isolate, "indexStartHeight")).ToLocalChecked()->IntegerValue(ctx).ToChecked();
res.db_mode = db_mode_to_cpp(isolate, setts->Get(ctx, string_to_js(isolate, "dbMode")).ToLocalChecked());
res.reorg_pool_limit = setts->Get(ctx, string_to_js(isolate, "reorgPoolLimit")).ToLocalChecked()->IntegerValue(ctx).ToChecked();
res.db_max_size = setts->Get(ctx, string_to_js(isolate, "dbMaxSize")).ToLocalChecked()->IntegerValue(ctx).ToChecked();
res.safe_mode = bool_to_cpp(isolate, setts->Get(ctx, string_to_js(isolate, "safeMode")).ToLocalChecked());
Expand Down
11 changes: 9 additions & 2 deletions src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,19 @@ void node_currency(FunctionCallbackInfo<Value> const& args) {
void node_db_type(FunctionCallbackInfo<Value> const& args) {
Isolate* isolate = args.GetIsolate();

if (args.Length() != 0) {
if (args.Length() != 1) {
throw_exception(isolate, "Wrong number of arguments");
return;
}

char const* res = kth_node_db_type();
if ( ! args[1]->IsNumber()) {
throw_exception(isolate, "Wrong arguments, 1");
return;
}

kth_db_mode_t mode = db_mode_to_cpp(isolate, args[1]);

char const* res = kth_node_db_type(mode);
args.GetReturnValue().Set(string_to_js(isolate, res));
}

Expand Down
9 changes: 4 additions & 5 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ function print_settings(setts) {
console.log(setts.chain.asertHalfLife);
// ------------------------------------------------------------------------------------
console.log(setts.database.directory);
console.log(setts.database.flushWrites);
console.log(setts.database.fileGrowthRate);
console.log(setts.database.indexStartHeight);
console.log(setts.database.dbMode);
console.log(setts.database.reorgPoolLimit);
console.log(setts.database.dbMaxSize);
console.log(setts.database.safeMode);
Expand Down Expand Up @@ -143,13 +141,14 @@ function test_encoding() {

async function main() {
test_encoding();
return;

const mainnet = 0;
const justChain = 1;
const setts = kth.config_settings_default(mainnet);
setts.database.dbMaxSize = 2 * 1024 * 1024; // 2MiB
// console.log(setts);
console.log(setts);
print_settings(setts);
return;

let node = kth.node_construct(setts, true);
kth.node_init_run_and_wait_for_signal(node, justChain, function (err) {
Expand Down

0 comments on commit 8ec573a

Please sign in to comment.