lightning
lightning copied to clipboard
cln-rpc: API improvements
While using the rust RPC library I noticed a few unidiomatic/unergonomic API details. This PR proposes fixes to some of them that I'd like to discuss. If you think certain changes should be merged and wish to split them up that should be easily possible.
Changes:
- Implement
ErrorforRpcErrorso that?works withanyhow - Implement a "typed" version of
callthat knows which return type it expects, so users don't need to match over the entireResponseenum - Use
bitcoin_hashesandsecp256k1instead of custom implementations (that are lacking a lot of convenience methods already present in these crates) - Implement
Debugfor the client struct - Make more types
Copy - Add arithmetic functions to the
Amounttype. I'm not sure what's the best way. Ideally we would implement overflow-checked versions, but there aren't traits for that instdand it's inconvenient to use. For convenience one would also like to have floating point division/multiplication but that's also a footgun. The scope this change should have is very unclear to me.
Changes I'm holding off on for now:
- Replacing
Outpointwithrust-bitcoin's implementation. This would require either pulling in the entirety ofrust-bitcoinor splitting it into multiple crates (see rust-bitcoin/rust-bitcoin#550)
For now I haven't fixed any breakage in any of the sister crates, this will be the next step.