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

Add uniffi bindings #59

Merged
merged 8 commits into from
Apr 15, 2024
Merged

Add uniffi bindings #59

merged 8 commits into from
Apr 15, 2024

Conversation

ok300
Copy link
Contributor

@ok300 ok300 commented Mar 24, 2024

This PR:

  • creates a workspace around the library
  • adds a new uniffi package in the workspace for Kotlin, Python and Swift bindings

Part of #9

Binding generation can be tested with

cd lib/ls-sdk-bindings

cargo run --features=uniffi/cli --bin uniffi-bindgen generate src/ls_sdk.udl --no-format --language kotlin -o ffi/kotlin
cargo run --features=uniffi/cli --bin uniffi-bindgen generate src/ls_sdk.udl --no-format --language python -o ffi/python
cargo run --features=uniffi/cli --bin uniffi-bindgen generate src/ls_sdk.udl --no-format --language swift -o ffi/swift

which should generate bindings in lib/ls-sdk-bindings/ffi

@ok300 ok300 force-pushed the ok300-consolidate-rev-swap-onchain-amt branch from 1324935 to 7e5772e Compare March 26, 2024 05:11
Base automatically changed from ok300-consolidate-rev-swap-onchain-amt to main March 26, 2024 05:39
@ok300 ok300 changed the title [Draft] Add uniffi bindings Add uniffi bindings Apr 12, 2024
@ok300 ok300 requested review from hydra-yse and dangeross April 12, 2024 11:53
Copy link
Collaborator

@dangeross dangeross left a comment

Choose a reason for hiding this comment

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

Is a uniffi.toml file needed to set the bindings package/cdylib names?

lib/ls-sdk-bindings/README.md Outdated Show resolved Hide resolved
@ok300
Copy link
Contributor Author

ok300 commented Apr 12, 2024

I also added a uniffi.toml for the supported languages.

Copy link
Collaborator

@dangeross dangeross left a comment

Choose a reason for hiding this comment

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

LGTM

@ok300 ok300 merged commit e2ace48 into main Apr 15, 2024
2 checks passed
"PersistError",
"InvalidPreimage",
"AlreadyClaimed",
"BoltzError",
Copy link
Member

Choose a reason for hiding this comment

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

SwapperError ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's broader than that, it covers error kinds that can be thrown by the Boltz client (not the Boltz service) , like electrum errors, key parsing errors, HTTP errors, blinding/unblinding errors, etc.

https://github.com/SatoshiPortal/boltz-rust/blob/e55b8439f3311be7fcd18ec14a5747d0f3dbd74f/src/error.rs#L3-L26

BoltzError looks like a good enough umbrella-term IMO, until we start handling the sub-types differently.

Copy link
Member

Choose a reason for hiding this comment

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

But it leaks implementation details. When we move to other swappers it won't fit in there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then maybe it can default to a PaymentError::Generic and have the relevant sub-types be mapped to other relevant types.

dictionary WalletInfo {
u64 balance_sat;
string pubkey;
string active_address;
Copy link
Member

Choose a reason for hiding this comment

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

What is the active_address and why do we need it?

Copy link
Member

Choose a reason for hiding this comment

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

It is the address currently in use by the wallet, since we could also provide the interface for changing the derivation index. Can for now be renamed to address as that is not implemented yet, and I don't see a strong case as to it being necessary in the future.

Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to expose it?

Copy link
Member

Choose a reason for hiding this comment

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

No need, but in the future we could allow multiple addresses within the same wallet, handling swaps from each one. Not a priority for now.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, even if we allow multiple addresses I think the user doesn't need to know about it. We only want to expose the lightning ATM experience hiding the onchain experience as much as we can.
Since this is a first version, let's adapt and aggressive minimalistic approach so we will not regret later on exposing logic we didn't intend to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then maybe it's better to not expose it until then? Makes the interface cleaner.

Copy link
Member

Choose a reason for hiding this comment

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

@ok300 I am in favor of that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hydra-yse would you agree? Is there any other reason to keep it?

string active_address;
};

dictionary PreparePaymentResponse {
Copy link
Member

Choose a reason for hiding this comment

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

What is the purpose of PreparePaymentResponse and how the user gets it? I don't see any API to retrieve it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe you looked at an intermediary commit in the PR branch.

Here are all repo instances: https://github.com/search?q=repo%3Abreez%2Fbreez-sdk-liquid%20PreparePaymentResponse&type=code

PreparePaymentResponse is used as part of prepare_payment:

pub fn prepare_payment(&self, invoice: &str) -> Result<PreparePaymentResponse, PaymentError> {

};

dictionary ReceivePaymentRequest {
u64? invoice_amount_sat;
Copy link
Member

Choose a reason for hiding this comment

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

payer_amount ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in #90


dictionary ReceivePaymentRequest {
u64? invoice_amount_sat;
u64? onchain_amount_sat;
Copy link
Member

Choose a reason for hiding this comment

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

I think onchain shouldn't be here. perhaps receiver_amount ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in #90

@ok300 ok300 deleted the ok300-uniffi branch May 2, 2024 06:19
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