bitcoindevkit / bdk-ffi

Please consider this project *experimental*.
Other
98 stars 45 forks source link

Explore KMP as viable library #249

Open thunderbiscuit opened 2 years ago

thunderbiscuit commented 2 years ago

I'm quite confident we should be able to build a Kotlin Multiplatform using the bdk-android and bdk-swift libraries.

I'm starting to explore this a bit more and will share an example repo soon.

thunderbiscuit commented 2 years ago

Some interesting links:

  1. https://touchlab.github.io/KMMBridge/intro
  2. https://engineering.premise.com/kotlin-multiplatform-at-premise-b28d85825c9f
thunderbiscuit commented 1 year ago

Also relevant to this conversation: https://gitlab.com/trixnity/uniffi-kotlin-multiplatform-bindings

thunderbiscuit commented 1 year ago

I have something sorta working in this repo. Only Kotlin side at the moment. I'd love to pair program the iOS side of this if anyone is interested!

There is probably a few different ways to go about this (for example I have not tried trixnity's kmp bindings plugin yet.

A few small things I still need to figure out:

  1. It appears you can't use data classes directly (no big deal but it's a slight change from the standard bdk-android) You basically just transform data classes into normal classes. Attempting to use the expect/actual construct will throw
    expect data class ElectrumConfig {}
    // Modifier 'data' is incompatible with 'expect'
  2. You can't seem to use expect/actual on sealed classes. This is what gets used on the bdk-android side to represent enums variants that contain data structures. For example, the BlockchainConfig type in bdk-android is:
    // bdk-android
    sealed class BlockchainConfig {
    data class Electrum(val config: ElectrumConfig) : BlockchainConfig()
    data class Esplora(val config: EsploraConfig) : BlockchainConfig()
    data class Rpc(val config: RpcConfig) : BlockchainConfig()   
    }

    But I don't think you can use the expect/actual construct on inner classes

    // bdk-kmp
    // doesn't work: Modifier 'expect' is not applicable to 'nested class' 
    expect sealed class BlockchainConfig {
    expect class Electrum(val config: ElectrumConfig) : BlockchainConfig()
    expect class Esplora(val config: EsploraConfig) : BlockchainConfig()
    expect class Rpc(val config: RpcConfig) : BlockchainConfig()   
    }
thunderbiscuit commented 1 year ago

New link related to the plugin: https://github.com/wireapp/core-crypto/pull/214.

reez commented 7 months ago

I have something sorta working in this repo. Only Kotlin side at the moment. I'd love to pair program the iOS side of this if anyone is interested!

Happy to pair program the iOS side if this is still something you're interested in working on-