lightning icon indicating copy to clipboard operation
lightning copied to clipboard

cln-rpc: API improvements

Open elsirion opened this issue 3 years ago • 0 comments

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 Error for RpcError so that ? works with anyhow
  • Implement a "typed" version of call that knows which return type it expects, so users don't need to match over the entire Response enum
  • Use bitcoin_hashes and secp256k1 instead of custom implementations (that are lacking a lot of convenience methods already present in these crates)
  • Implement Debug for the client struct
  • Make more types Copy
  • Add arithmetic functions to the Amount type. I'm not sure what's the best way. Ideally we would implement overflow-checked versions, but there aren't traits for that in std and 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 Outpoint with rust-bitcoin's implementation. This would require either pulling in the entirety of rust-bitcoin or 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.

elsirion avatar May 13 '22 22:05 elsirion