Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support wasm #48

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

support wasm #48

wants to merge 2 commits into from

Conversation

alanpoon
Copy link

@alanpoon alanpoon commented Dec 17, 2019

Breaking changes:

  • Added support for async/ await
  • At the moment, no intention to support for subscribe_events function
  • The websocket result is able to be read by nodejs and react using wasmpack
  • Change std::mpsc::sync::channel to future signals
  • Perform a quick hack on future signals to resolve BroadcasterSignal.second() Pauan/rust-signals#14
//Rust node_module
#[wasm_bindgen]
pub async fn k(url:String)->String{
    let mut api:Api<Pair> = Api::new(format!("ws://{}", url)).await;
    // get some plain storage value
    let result_str = api.get_storage("Balances", "TotalIssuance", None).await.unwrap();
    let result = hexstr_to_u256(result_str).unwrap();
    result
}

In javascript:

const wasm = await import('rust'); //your rust node_module
const resy =  await wasm.k("127.0.0.1:9944");
console.log("HHHHHHHHHHHHHHHHHH",resy);

@brenzi
Copy link
Contributor

brenzi commented Dec 17, 2019

@alanpoon thanks for this PR. As you're introducing breaking changes we won't be able to merge this before we made sure all our downstream projects can be easily migrated. We haven't even introduced semver so far.
This may take some time...

@S3bb1
Copy link

S3bb1 commented May 14, 2020

@alanpoon i wanted to use your branch to extend it to the current implementation. I'm now made it compile but stuck with your example

//Rust node_module
#[wasm_bindgen]
pub async fn k(url:String)->String{
    let mut api:Api<Pair> = Api::new(format!("ws://{}", url)).await;
    // get some plain storage value
    let result_str = api.get_storage("Balances", "TotalIssuance", None).await.unwrap();
    let result = hexstr_to_u256(result_str).unwrap();
    result
}

Do you have a working full example of it?

@alanpoon
Copy link
Author

@alanpoon i wanted to use your branch to extend it to the current implementation. I'm now made it compile but stuck with your example

//Rust node_module
#[wasm_bindgen]
pub async fn k(url:String)->String{
    let mut api:Api<Pair> = Api::new(format!("ws://{}", url)).await;
    // get some plain storage value
    let result_str = api.get_storage("Balances", "TotalIssuance", None).await.unwrap();
    let result = hexstr_to_u256(result_str).unwrap();
    result
}

Do you have a working full example of it?

You can look at this https://github.com/alanpoon/belanja_app/tree/developer
-There is shell script: https://github.com/alanpoon/belanja_app/blob/developer/wasm.sh
(my wasm-bindgen version is 0.2.47)
-package.json https://github.com/alanpoon/belanja_app/blob/developer/package.json#L92

-webpack.config https://github.com/alanpoon/belanja_app/blob/developer/webpack.config.js
-implementation: https://github.com/alanpoon/belanja_app/blob/developer/screens/WasmComponent.js

@haerdib haerdib mentioned this pull request Aug 29, 2022
@haerdib haerdib marked this pull request as draft December 15, 2022 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BroadcasterSignal.second()
3 participants