Commit fed24c36 authored by nanocryk's avatar nanocryk
Browse files

feature : wot creation with max_cert or from file.

parent bf28fd74
......@@ -4,3 +4,5 @@ native/artifacts.json
**/*~
**/node_modules
**/.DS_Store
*.bk
//! `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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment