Skip to content

Instantly share code, notes, and snippets.

@lucasfernog
Created May 12, 2020 01:00
Show Gist options
  • Save lucasfernog/406e719b031fc38987ca576bcc08f239 to your computer and use it in GitHub Desktop.
Save lucasfernog/406e719b031fc38987ca576bcc08f239 to your computer and use it in GitHub Desktop.
iota.rs wasm
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
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