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

Native usage library #267

Open
Milerius opened this issue Nov 22, 2021 · 7 comments
Open

Native usage library #267

Milerius opened this issue Nov 22, 2021 · 7 comments
Assignees

Comments

@Milerius
Copy link

Milerius commented Nov 22, 2021

Hello, I was curious if this library could be used in a native rust target that is not wasm or web.

For example to add light wallet functionality to a native rust target (amd64)

I was looking to potentially add Cardano support to https://github.com/KomodoPlatform/atomicDEX-API

The project is written in rust and supports all existing platforms: amd64, arm & wasm. But if I take a good look at this project, I feel like I can only use the wasm version currently, the documentation is not very clear on this.

@rooooooooob
Copy link
Contributor

You can use it directly from rust as well. The documentation was written more for web users as those comprise most of the people using the library but it's totally possible to use it from rust. Some of the APIs are a bit clunky from rust due to having to conform to wasm-bindgen though. We have a crate on cargo: https://crates.io/crates/cardano-serialization-lib/

@Milerius
Copy link
Author

Milerius commented Nov 23, 2021

You can use it directly from rust as well. The documentation was written more for web users as those comprise most of the people using the library but it's totally possible to use it from rust. Some of the APIs are a bit clunky from rust due to having to conform to wasm-bindgen though. We have a crate on cargo: https://crates.io/crates/cardano-serialization-lib/

I wonder how it's will look like on native target to deal with JsError from what I understand this type exist only if the target platform is wasm no ?

edit: I see that JsError is a string on native platform - all good.

I still think that few example in pure Rust would have been nice

@rooooooooob
Copy link
Contributor

Yeah, as you saw I guess with your edit we have

#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
pub type JsError = JsValue;

#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
#[derive(Debug, Clone)]
pub struct JsError {
    msg: String,
}

which isn't ideal but it at least won't panic in rust builds like JsValue/JsError from js_sys would. Hopefully one day wasm-bindgen will allow directly exposing rust error types or some kind of automatic conversion while preserving the rust error types for non-wasm builds. There's an open issue for that so maybe one day rustwasm/wasm-bindgen#1004 and some other related ones. Fingers crossed.

The JS examples should work almost the same you'll just need to replace things like Foo.bar() with Foo::bar() and handle Result/Option return values and reference parameters explicitly. We don't heavily use the more transformative wasm-bindgen renaming/changing things (e.g. to use new in JS) so it's pretty much 1:1.

@Milerius
Copy link
Author

Thanks for all those precious explanation, I may have some more questions later, is there any discord or telegram for dev?

@rooooooooob
Copy link
Contributor

Thanks for all those precious explanation, I may have some more questions later, is there any discord or telegram for dev?

@SebastienGllmt @vsubhuman

@Milerius
Copy link
Author

Thanks for all those precious explanations. I may have some more questions later. Is there any discord or telegram for dev?

@SebastienGllmt @vsubhuman

I joined the following Cardano Community Discord https://discord.gg/VQRHtDpJ would be nice if Emurgo team would have a channel to discuss possible light wallet integration, I'm curious and may have some questions regarding light node communication (How to fetch balance, transaction history, broadcasting a transaction)

I understand that the scope of cardano-serialization-lib is to create transactions, keypair and everything crypto-related. Still, I'm also curious to know more about the other parts for a full wallet integration.

@rooooooooob
Copy link
Contributor

I'm going to link to #276 here so that people inquiring about rust native usage can help tell us what they would like to see potentially.

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

No branches or pull requests

2 participants