39 uint64_t thread_pool_size = 16;
48 std::unordered_map<MerkleTreeId, uint32_t> tree_height;
49 std::unordered_map<MerkleTreeId, index_t> tree_prefill;
52 MerkleTreeId::NULLIFIER_TREE, MerkleTreeId::NOTE_HASH_TREE, MerkleTreeId::PUBLIC_DATA_TREE,
53 MerkleTreeId::L1_TO_L2_MESSAGE_TREE, MerkleTreeId::ARCHIVE,
55 uint32_t initial_header_generator_point = 0;
57 Napi::Env env =
info.Env();
59 size_t data_dir_index = 0;
60 if (
info.Length() > data_dir_index &&
info[data_dir_index].IsString()) {
61 data_dir =
info[data_dir_index].As<Napi::String>();
63 throw Napi::TypeError::New(env,
"Directory needs to be a string");
66 size_t tree_height_index = 1;
67 if (
info.Length() > tree_height_index &&
info[tree_height_index].IsObject()) {
68 Napi::Object obj =
info[tree_height_index].As<Napi::Object>();
70 for (
auto tree_id : tree_ids) {
71 if (obj.Has(tree_id)) {
72 tree_height[tree_id] = obj.Get(tree_id).As<Napi::Number>().Uint32Value();
76 throw Napi::TypeError::New(env,
"Tree heights must be a map");
79 size_t tree_prefill_index = 2;
80 if (
info.Length() > tree_prefill_index &&
info[tree_prefill_index].IsObject()) {
81 Napi::Object obj =
info[tree_prefill_index].As<Napi::Object>();
83 for (
auto tree_id : tree_ids) {
84 if (obj.Has(tree_id)) {
85 tree_prefill[tree_id] = obj.Get(tree_id).As<Napi::Number>().Uint32Value();
89 throw Napi::TypeError::New(env,
"Tree prefill must be a map");
92 size_t prefilled_public_data_index = 3;
93 if (
info.Length() > prefilled_public_data_index &&
info[prefilled_public_data_index].IsArray()) {
94 Napi::Array arr =
info[prefilled_public_data_index].As<Napi::Array>();
95 for (uint32_t i = 0; i < arr.Length(); ++i) {
96 Napi::Array deserialized = arr.Get(i).As<Napi::Array>();
97 if (deserialized.Length() != 2 || !deserialized.Get(uint32_t(0)).IsBuffer() ||
98 !deserialized.Get(uint32_t(1)).IsBuffer()) {
99 throw Napi::TypeError::New(env,
"Prefilled public data value must be a buffer array of size 2");
101 Napi::Buffer<uint8_t> slot_buf = deserialized.Get(uint32_t(0)).As<Napi::Buffer<uint8_t>>();
102 Napi::Buffer<uint8_t> value_buf = deserialized.Get(uint32_t(1)).As<Napi::Buffer<uint8_t>>();
105 for (
size_t j = 0; j < 32; ++j) {
112 throw Napi::TypeError::New(env,
"Prefilled public data must be an array");
115 size_t initial_header_generator_point_index = 4;
116 if (
info.Length() > initial_header_generator_point_index &&
info[initial_header_generator_point_index].IsNumber()) {
117 initial_header_generator_point =
info[initial_header_generator_point_index].As<Napi::Number>().Uint32Value();
119 throw Napi::TypeError::New(env,
"Header generator point needs to be a number");
123 size_t map_size_index = 5;
124 if (
info.Length() > map_size_index) {
125 if (
info[map_size_index].IsObject()) {
126 Napi::Object obj =
info[map_size_index].As<Napi::Object>();
128 for (
auto tree_id : tree_ids) {
129 if (obj.Has(tree_id)) {
130 map_size[tree_id] = obj.Get(tree_id).As<Napi::Number>().Uint32Value();
133 }
else if (
info[map_size_index].IsNumber()) {
134 uint64_t size =
info[map_size_index].As<Napi::Number>().Uint32Value();
135 for (
auto tree_id : tree_ids) {
136 map_size[tree_id] = size;
139 throw Napi::TypeError::New(env,
"Map size must be a number or an object");
143 size_t thread_pool_size_index = 6;
144 if (
info.Length() > thread_pool_size_index) {
145 if (!
info[thread_pool_size_index].IsNumber()) {
146 throw Napi::TypeError::New(env,
"Thread pool size must be a number");
149 thread_pool_size =
info[thread_pool_size_index].As<Napi::Number>().Uint32Value();
157 prefilled_public_data,
158 initial_header_generator_point);
185 [
this](msgpack::object& obj, msgpack::sbuffer&
buffer) {
218 [
this](msgpack::object& obj, msgpack::sbuffer&
buffer) {
return commit(obj,
buffer); });
241 [
this](msgpack::object& obj, msgpack::sbuffer&
buffer) {
return unwind(obj,
buffer); });
252 [
this](msgpack::object& obj, msgpack::sbuffer&
buffer) {
return close(obj,
buffer); });