From fed24c3655e661796b98c09a9d89168db845b9f8 Mon Sep 17 00:00:00 2001 From: Nanocryk <nanocryk@gmail.com> Date: Wed, 8 Nov 2017 14:56:26 +0100 Subject: [PATCH] feature : wot creation with max_cert or from file. --- .gitignore | 2 ++ native/src/lib.rs | 52 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 0b3cb79..49b3073 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ native/artifacts.json **/*~ **/node_modules **/.DS_Store + +*.bk diff --git a/native/src/lib.rs b/native/src/lib.rs index 5b9929c..53b89a3 100644 --- a/native/src/lib.rs +++ b/native/src/lib.rs @@ -1,14 +1,48 @@ +//! `duniter-rs-wotb-js` is a crate providing Javascript bindings of `duniter-rs-wotb`. + +#![deny(missing_docs, +/*missing_debug_implementations, */ +missing_copy_implementations, + trivial_casts, trivial_numeric_casts, + unsafe_code, + unstable_features, + unused_import_braces, unused_qualifications)] + #[macro_use] extern crate neon; +extern crate duniter_rs_wotb; + +use neon::vm::Throw; +use neon::js::{JsInteger, JsString}; +use duniter_rs_wotb::WebOfTrust; + + +declare_types! { + /// JS class wrapping WebOfTrust struct. + pub class JsWebOfTrust for WebOfTrust { + init(call) { + let scope = call.scope; + let arg0 = try!(call.arguments.require(scope, 0)); + + if let Ok(max_cert) = arg0.check::<JsInteger>() { + let max_cert = max_cert.value(); -use neon::vm::{Call, JsResult}; -use neon::js::JsString; + match max_cert > 0 { + true => Ok(WebOfTrust::new(max_cert as usize)), + false => Err(Throw), + } -fn hello(call: Call) -> JsResult<JsString> { - let scope = call.scope; - Ok(JsString::new(scope, "hello node").unwrap()) -} + + } else if let Ok(path) = arg0.check::<JsString>() { + let path = path.value(); -register_module!(m, { - m.export("hello", hello) -}); + match WebOfTrust::from_file(path.as_str()) { + Some(wot) => Ok(wot), + None => Err(Throw), + } + } else { + Err(Throw) + } + } + } +} \ No newline at end of file -- GitLab