SatoshiPortal / boltz-rust

Boltz client rust crate
https://docs.boltz.exchange
30 stars 19 forks source link

Re-export common libs #49

Closed ok300 closed 4 months ago

ok300 commented 4 months ago

This PR re-exports common libs bitcoin, elements and lightning_invoice.

TLDR: This allows callers, if necessary, to use structs from these libs without having to worry about having an incompatible lib version.

For example, without this PR, a caller would have access to lightning_invoice::Bolt11Invoice as boltz_client::Bolt11Invoice, but not to lightning_invoice::Bolt11InvoiceDescription since this is not re-exported at the moment. If the caller would import the lightning_invoice dependency to get access to this, they may run into compatibility issues if they use e.g. Bolt11Invoice::from_str(..)?.description() with the import from boltz_client and Bolt11InvoiceDescription from their own dependency.

With the new re-exports, callers can access all structs from boltz_client's specific versions of bitcoin, elements and lightning_invoice.

i5hi commented 4 months ago

It maybe an overkill to re-export the entire library. Instead we should be looking to only re-export those structs that we use as inputs and outputs in our code.

i5hi commented 4 months ago

Bolt11Invoice for example is already re-exported so you can already use:

boltz_client::Bolt11Invoice

ok300 commented 4 months ago

It maybe an overkill to re-export the entire library

Well, it doesn't hurt boltz-client to do it, but could help the projects integrating it.

Bolt11Invoice for example is already re-exported

Yes, but for anything more advanced, for example matching on the description, which is of type Bolt11InvoiceDescription, the caller now has to import the precise correct version of lightning_invoice crate. If its a different version, best case the compiler accepts it and the project now carries 2 dependency trees of 2 versions of lightning_invoice, worst case the compiler says the structs are incompatible. If they use any other dependency, which also uses e.g. lightning_invoice but with a different version, it becomes exponentially more difficult trying to bring the different modules to integrate with each other. Being able to use a dependency's specific e.g. lightning_invoice version massively simplifies that.

Especially for utility libraries, IMO it makes sense to export them, as projects using the boltz crate will likely need to use those utility libraries as well, so they will likely run in the above conundrum.

In the end its your call, but re-exporting them would be greatly appreciated.

i5hi commented 4 months ago

makes sense.

i5hi commented 4 months ago

Thanks for the PR @ok300 !