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

Document best approach for working with Java apps #244

Closed
notmandatory opened this issue Apr 5, 2022 · 8 comments
Closed

Document best approach for working with Java apps #244

notmandatory opened this issue Apr 5, 2022 · 8 comments
Assignees
Labels
discussion Issue requires some discussion first documentation Improvements or additions to documentation

Comments

@notmandatory
Copy link
Member

Reported by SeverinAlexB on discord. See also:

https://github.com/SeverinAlexB/bdk-java-ulong-bug

@notmandatory notmandatory added the discussion Issue requires some discussion first label Apr 5, 2022
@thunderbiscuit
Copy link
Member

@SeverinAlexB

@artfuldev
Copy link
Contributor

artfuldev commented Apr 5, 2022

I think ULong is the stricter type-safe API for Kotlin consumers but Java doesn't have the concept of unsigned numbers. I'm not sure if we're just targeting Kotlin consumers though. The way to solve this in a Java project is to just use Kotlin's libraries (which are JVM compatible) so we can either make that part of our documentation, or decide to weaken our type-safety in the APIs.

Refer: kotlin package in kotlin-stdlib, for example (for ULong) https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-u-long/

@thunderbiscuit
Copy link
Member

thunderbiscuit commented Apr 5, 2022

Yeah I'm not sure where the bug is coming from, but for some reason this Kotlin/Java compatibility breaks here for ULong (shouldn't it just work out of the box? that's what I would have assumed).

Also of interest (not sure how related) is the fact that on the Java side, the ElectrumConfig is private (even though it's a public data class).

Keeping these here for archives (issue was discussed on the #ffi-bindings channel a bit more):

If you use incorrect syntax on the Java side, the IDE will suggest something, and the tooltip box shows a public data class:
public

If you accept the changes proposed (adding the new keyword), now you get an error telling you the constructor for ElectrumConfig is private:
private

@thunderbiscuit
Copy link
Member

Notice in the second picture the type for timeout is kotlin.UByte, whereas the type for retry and stopGap are byte and long respectively...

@SeverinAlexB
Copy link

Hey guys, thanks for taking this on

I saw another issue I can't explain. For some reason, I can't call methods that are available in Kotlin. For example, sync or getBalance are just not available. As always, it works with a custom Kotlin wrapper.
image

All methods that are available in Java:
CleanShot 2022-04-06 at 11 02 45@2x

@artfuldev
Copy link
Contributor

I'll take a deeper look at this, thanks!

@artfuldev artfuldev self-assigned this Apr 6, 2022
@thunderbiscuit
Copy link
Member

Will attempt to keep track of the known issues and some hacks/fixes to get around them for the time being here.

@thunderbiscuit thunderbiscuit transferred this issue from bitcoindevkit/bdk-kotlin Nov 15, 2022
@notmandatory notmandatory changed the title Determine best approach for working with Java apps Document best approach for working with Java apps Nov 17, 2022
@notmandatory notmandatory added the documentation Improvements or additions to documentation label Nov 17, 2022
@thunderbiscuit
Copy link
Member

thunderbiscuit commented Mar 9, 2023

This issue has been further investigated, and I want to provide links for people stumbling on this. The core problem is that unsigned types are inline classes, and their names get mangled. The primary fix is to write small Kotlin wrapper classes, but I will expand on different approaches in a separate issue, #322.

Links:

  1. Kotlin YouTrack Issue
  2. Mangling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Issue requires some discussion first documentation Improvements or additions to documentation
Projects
No open projects
Status: Done
Development

No branches or pull requests

4 participants