Skip to content

feat(wasm-dpp): implement function to produce generics from JsValue #712

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

Merged
merged 2 commits into from
Jan 13, 2023

Conversation

markin-io
Copy link
Collaborator

@markin-io markin-io commented Jan 6, 2023

Issue being fixed or feature implemented

This utility function helps to produce generics from JsValue in the situations where we don't really know what is exactly passed to the function. (E.g. we can have either InstantAssetLockProof or ChainAssetLockProof)

Usage sample:

use wasm_bindgen::__rt::Ref;
use crate::utils::{generic_of_js_val};

struct Internal {
    value: u8,
}

#[wasm_bindgen(js_name=jsValueToGeneric)]
pub async fn js_value_to_generic(
    js_value: JsValue, 
) -> Result<JsValue, JsValue> {
    let internal: Ref<Internal> = generic_of_js_val::<Internal>(&js_value, "Internal")?;
    let internal_instance = internal.clone();
    ...
}

What was done?

Applied workaround as explained here rustwasm/wasm-bindgen#2231 (comment)

How Has This Been Tested?

Locally on relevant code sample

Breaking Changes

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

@markin-io markin-io added this to the v0.24.0 milestone Jan 6, 2023
@markin-io markin-io changed the title feat(wasm-dpp): implement function to produce generic from JsValue feat(wasm-dpp): implement function to produce generics from JsValue Jan 6, 2023
qrayven
qrayven previously approved these changes Jan 6, 2023
Copy link
Member

@shumkov shumkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be helpful to have a test?

@markin-io
Copy link
Collaborator Author

markin-io commented Jan 9, 2023

@shumkov this function will be used in bindings tests.
I just submitted it is as a standalone PR because others might need it as well

@markin-io markin-io force-pushed the feat/implement-jsvalue-to-generic-conversion branch from 93a0cce to 5423748 Compare January 13, 2023 10:30
Copy link
Collaborator

@antouhou antouhou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@markin-io markin-io merged commit d238160 into v0.24-dev Jan 13, 2023
@markin-io markin-io deleted the feat/implement-jsvalue-to-generic-conversion branch January 13, 2023 18:49
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.

4 participants