merkletree-rs icon indicating copy to clipboard operation
merkletree-rs copied to clipboard

error[E0583]: file not found for module `constants`

Open Alakazam03 opened this issue 6 years ago • 8 comments

how to compile the code? I want to use smt in my other cargo package? Please can someone tell me how to do it?

Alakazam03 avatar Sep 10 '19 10:09 Alakazam03

Also, how can I call db from main as it is private?

Alakazam03 avatar Sep 10 '19 11:09 Alakazam03

Hi, I've published this lib as crate, and updated the README.md example. Hope that now is more usable

arnaucube avatar Sep 10 '19 16:09 arnaucube

Thanks for the help. I am new to rust and i am using your crate in my APIs to make and maintain a Merkle tree. i want to initialize the mt once and use it across all related API created using rocket.

  1. I tried using lazy_static but couldn't figure out lifetime parameter for mekletree.
  2. used once_cell but found impl comlpex
  3. also, used rocket manage but then inside sto rusty_leveldb can not be sent between threads safely. Please can you suggest something?

Alakazam03 avatar Sep 12 '19 06:09 Alakazam03

if you create a new merkletree and pass to it the same database used in the old iteration, the new merkletree will have the state of the old merkletree. So, in this way, you can have merkletree struct in the memory of the server, but when server stops and starts again, will load the old merkletree and continue from the same state

arnaucube avatar Sep 12 '19 06:09 arnaucube

can you please give an example. As i am initiating it in first call or main function. either way how to access it mt again? #[get("//")] pub fn register_customer(number : String, name : String) -> String { let phone_number : String = number.to_string(); let mut val: TestValue = TestValue { bytes: phone_number.as_bytes().to_vec(), index_length: 10, }; mt.add(&val).unwrap(); }

fn generate_proof(val : &TestValue, mt: &mut MerkleTree ) -> bool { // want to use the same mt here }

Alakazam03 avatar Sep 12 '19 07:09 Alakazam03

hope that these links help:

  • https://rocket.rs/v0.4/guide/state/#state
  • https://stackoverflow.com/questions/55384204/how-can-i-pass-a-variable-initialized-in-main-to-a-rocket-route-handler

arnaucube avatar Sep 12 '19 08:09 arnaucube

I have tried this as i mentioned in previous comment.

pub struct MyTree<'a>(MerkleTree<'a>); fn main() { println!("Starting filtering service.."); let mut sto = (db::Db::new("test".to_string(), true)); let mt = MyTree(MerkleTree::new(&mut sto, 140 as u32)); rocket::ignite() .manage(mt) .mount("/", routes![smt_number::register_customer, smt_number::set_reminders]) .launch();

}

i get this error as rusty_leveldb is not managed for thread safety.

image

Alakazam03 avatar Sep 12 '19 09:09 Alakazam03

I have created a static for db as static sto. I have also used Arc and mutex for thread safety but it gives an error. error[E0277]: std::rc::Rc<std::boxed::Box<(dyn rusty_leveldb::cmp::Cmp + 'static)>> cannot be sent between threads safely error[E0277]: std::rc::Rc<std::cell::RefCell<rusty_leveldb::table_cache::TableCache>> cannot be sent between threads safely @arnaucube Please can you help?

Alakazam03 avatar Sep 17 '19 05:09 Alakazam03