apoelstra/rust-jsonrpc

Proposal: Add a trait wrapping http calls to hook out in the wasm world

moneyball opened this issue · 6 comments

This would abstract users from a specific implementation so they could hook their own if required (eg WASM) or desired (eg use native HTTP client that comes with an OS/environment).

Motivation: There is a Rust crate https://github.com/lightningdevkit/rust-lightning/tree/main/lightning-transaction-sync that makes using LDK much easier as it handles a lot of tricky edge cases. However, it depends upon an HTTP client as it uses Esplora/Electrum. LDK also has extensive language bindings to support other languages but currently this create is not available to languages such as TypeScript/JavaScript in the browser as HTTP is not supported in WASM.

Additionally, other environments such as iOS or Android, an LDK user might wish to use the HTTP client available by the platform instead of taking on an extra dependency with a Rust HTTP client.

Hi @moneyball. Sorry for the delay, I have been letting Github notifications pile up this week.

RIght now we have the Transport trait which is close to what you're looking for. If somebody were to write a WasmTransport implementing this trait, and you were to use this in place of SimpleHttp or MinreqHttp or whatever, would that achieve your goals?

Largely, yes, but it would be substantially easier ecosystem-wide for the hook to be at the HTTP level rather than the request level. That would mean we can reuse it for bitcoind-REST, Electrum, Esplora, etc all in one trait.

Can you describe this trait? I don't understand what HTTP other than a series of requests.

The only difference would be the Request wouldn't be tied to JSON, but rather the request methods would take a URI, a "GET"/"POST"/etc method, and a body (which would be converted to string from JSON by the caller).

Ah, I understand! Concept ACK. Not sure when I'll be able to work on it myself.