Skip to content

refactor!: Sans-io Client + bitreq feature#27

Merged
ValuedMammal merged 3 commits into
bitcoindevkit:masterfrom
ValuedMammal:sans_io_impl
May 18, 2026
Merged

refactor!: Sans-io Client + bitreq feature#27
ValuedMammal merged 3 commits into
bitcoindevkit:masterfrom
ValuedMammal:sans_io_impl

Conversation

@ValuedMammal

@ValuedMammal ValuedMammal commented Feb 2, 2026

Copy link
Copy Markdown
Collaborator

Description

Refactors the library to a layered, sans-io architecture. The previous Client owned a jsonrpc::Client<BitreqHttpTransport> directly, coupling all users to the bitreq HTTP transport. This PR separates concerns:

  • Client: A transport-agnostic type that manages JSON-RPC request building and ID tracking. Callers supply the transport at each call site via a send_fn: Fn(Request) -> Result<Response, E> closure.

  • bitreq::Client (behind the bitreq feature): A batteries-included HTTP client backed by jsonrpc's bitreq_http transport. Owns a Box<dyn Transport> and exposes all Bitcoin Core RPC methods. Auth, cookie-file parsing, and with_auth_timeout live here.

  • Rpc enum: Strongly-typed RPC method names whose Display impl produces the exact lowercase method string expected by Bitcoin Core.

Additional cleanup:

  • Error variants that are only reachable through bitreq code are now gated behind #[cfg(feature = "bitreq")].
  • corepc-types is now an optional dependency, only pulled in by bitreq.
  • with_auth now accepts an explicit timeout: Duration parameter instead of a hardcoded 60-second value.

Notes to the reviewers

The bitreq feature is included in default, so existing users who don't configure features explicitly will see no change in the available API surface (the bitreq::Client replaces the old top-level Client 1:1 for the common case). The new sans-io Client is an additive API available to users who need a custom transport.

Changelog notice

Added

  • Rpc enum for strongly-typed RPC method names.

Changed

  • crate::Client is now a transport-agnostic core; callers supply the transport per call via a send_fn closure.
  • bitreq::Client replaces the old Client as the HTTP client (requires bitreq feature, enabled by default).
  • Client::with_auth renamed to bitreq::Client::with_auth_timeout and now takes an explicit timeout: core::time::Duration parameter.
  • corepc-types is now an optional dependency (required by bitreq feature).

@tvpeter

tvpeter commented Feb 3, 2026

Copy link
Copy Markdown
Collaborator

The separation of concerns sounds excellent.

@tvpeter tvpeter mentioned this pull request Feb 3, 2026
5 tasks
@ValuedMammal ValuedMammal changed the title RFC: sans-io Client and async example using bitreq refactor!: Sans-io Client + bitreq feature May 12, 2026
@ValuedMammal ValuedMammal force-pushed the sans_io_impl branch 2 times, most recently from 55abb04 to 6a0f8ff Compare May 12, 2026 01:45
@ValuedMammal ValuedMammal marked this pull request as ready for review May 12, 2026 01:48
@ValuedMammal ValuedMammal force-pushed the sans_io_impl branch 2 times, most recently from 25a61fc to e44188c Compare May 12, 2026 02:10

@tvpeter tvpeter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK e44188c

Thank you @ValuedMammal, for introducing sans-io architecture into the library.

I have left a few suggestions.

Thank you.

Comment thread src/rpc.rs
Comment thread src/client.rs
Previously, enabling `--all-features` would cause the lowest
version feature to take precedence, which is counter-intuitive
and incorrect for CI.

Make the features additive so that `--all-features` implies
the latest version feature.

Each version feature explicitly enables the previous one. This
means `--all-features` now correctly activates the highest
version. Feature cfgs are updated throughout the library and
integration tests to match the new behavior.

`default` is now the minimum supported version (`28_0`), so that
additional features can be given without conflict.
The previous Client owned a `jsonrpc::Client<BitreqHttpTransport>`
directly, coupling all users to the bitreq HTTP transport.

Introduce a layered architecture:

`crate::Client`: transport-agnostic type that manages request
building and ID tracking. Callers supply a `send_fn` closure per
call.

`bitreq::Client`: batteries-included HTTP client behind the `bitreq`
feature flag (included in default). Owns a `Box<dyn Transport>` and
exposes all RPC methods. Auth and cookie-file parsing live here.
`with_auth` now accepts an explicit `timeout: Duration` and is
renamed to `with_auth_timeout`.

`corepc-types` is now an optional dependency pulled in by `bitreq`.

Error variants only reachable through bitreq code are gated behind
`bitreq` feature.
@ValuedMammal

Copy link
Copy Markdown
Collaborator Author
  • Fixed response id validation in Client::call
  • Changed with_auth to with_auth_timeout
  • Updated README.md, let me know if I missed something

@tvpeter tvpeter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK f85b4d2

Comment thread src/bitreq/v28.rs
@@ -1,15 +1,17 @@
// SPDX-License-Identifier: MIT OR Apache-2.0

//! [`Client`] methods for Bitcoin Core v28.0 and earlier.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "and earlier" belongs here.

Suggested change
//! [`Client`] methods for Bitcoin Core v28.0 and earlier.
//! [`Client`] methods for Bitcoin Core v28.0.

Comment thread src/error.rs

use core::fmt;
use core::num::TryFromIntError;
#[cfg(feature = "bitreq")]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of #[cfg(feature = "bitreq"] in the error module which is annoying, don't know if it'd be worth implementing a separate bitreq::Error 🤔

@ValuedMammal ValuedMammal merged commit 7e7c56c into bitcoindevkit:master May 18, 2026
9 checks passed
@ValuedMammal ValuedMammal deleted the sans_io_impl branch May 22, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants