-
Notifications
You must be signed in to change notification settings - Fork 39
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
Expose Interface for FFI #44
Comments
@Kixunil had a comment on this topic over email
This idea sounds right to me. Plainly I'm not sure what the best way to go about this is because I have not exposed rust via FFI before. |
My last project actually had WASM bindings so I have a fresh experience. :) What I ended up doing is to wrap the types used by the internal Rust library in a higher-level API that is easier to use from JS. E.g: #[wasm_bindgen]
pub struct Invoice(bip21::Uri /* checked, no extras */);
#[wasm_bindgen]
impl Invoice {
pub fn link(&self) -> String {
self.0.to_string()
}
pub fn qr_code_data(&self) -> String {
format!("{:#}", self.0)
}
} |
I agree with the sentiment that binding should live in separate repositories. There is a fair amount of wrapping that often needs to take place no matter what technique/tool is used. Easier to treat the Rust library as an internal implementation detail of the bindings lib. |
@BitcoinZavior now that https://github.com/LtbLightning/payjoin-ffi exists, is this issue closed? |
pure functions which take bytes as arguments and return bytes are simple to bind to. Right now we use rust typestate which is easy to reason about but hard to bind to. Perhaps static functions could be exposed as a feature, and the typestate could be built off of the static functions to make this library easy to consume downstream.
The BDK approach to FFI is documented here https://hackmd.io/@bdk/bindings-everywhere
After talking to @thunderbiscuit, it sounds like UniFFI handles callback interfaces without too much problem. They don't necessarily need to be static. The biggest bindings want with that approach is to support WASM bindings (like this example) in combination with the bitcoin-frontier demonstratedg mobile/python UniFFI bindings.
see: LtbLightning/payjoin-ffi#1
The text was updated successfully, but these errors were encountered: