Created
May 12, 2020 01:00
-
-
Save lucasfernog/406e719b031fc38987ca576bcc08f239 to your computer and use it in GitHub Desktop.
iota.rs wasm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wasm = import('./pkg/iota_wasm') | |
class Client { | |
constructor(uri) { | |
this.clientConfig = { | |
uri | |
} | |
} | |
getNodeInfo() { | |
return wasm().then(({ get_node_info, ClientConfig }) => { | |
return get_node_info(new ClientConfig(this.clientConfig.uri)) | |
}) | |
} | |
} | |
module.exports = Client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use wasm_bindgen::prelude::*; | |
use iota::client::response::{GetNodeInfoResponse}; | |
#[wasm_bindgen] | |
pub struct ClientConfig { | |
uri: String | |
} | |
#[wasm_bindgen] | |
impl ClientConfig { | |
#[wasm_bindgen(constructor)] | |
pub fn new(uri: String) -> Self { | |
ClientConfig { uri } | |
} | |
} | |
#[wasm_bindgen] | |
pub async fn get_node_info(client_config: ClientConfig) -> Result<JsValue, JsValue> { | |
let client = iota::Client::new(&client_config.uri); | |
let node_info = client.get_node_info() | |
.await | |
.map_err(|e| JsValue::from(e.to_string()))?; | |
let res = JsValue::from_serde(&node_info) | |
.map_err(|e| JsValue::from(e.to_string()))?; | |
Ok(res) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment