diff --git a/.github/workflows/cron-daily-fuzz.yml b/.github/workflows/cron-daily-fuzz.yml index 6343f5e2..ca6569f0 100644 --- a/.github/workflows/cron-daily-fuzz.yml +++ b/.github/workflows/cron-daily-fuzz.yml @@ -18,7 +18,7 @@ jobs: # We only get 20 jobs at a time, we probably don't want to go # over that limit with fuzzing because of the hour run time. fuzz_target: [ - minreq_http, + bitreq_http, simple_http, ] steps: diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml index dfb7868d..72728a8b 100644 --- a/.github/workflows/rust.yaml +++ b/.github/workflows/rust.yaml @@ -70,7 +70,7 @@ jobs: run: ./maintainer-tools/ci/run_task.sh nightly MSRV: # 2 jobs, one per lock file. - name: Test - 1.63.0 toolchain + name: Test - 1.75.0 toolchain runs-on: ubuntu-latest strategy: fail-fast: false @@ -87,7 +87,7 @@ jobs: - name: "Select toolchain" uses: dtolnay/rust-toolchain@stable with: - toolchain: "1.63.0" + toolchain: "1.75.0" - name: "Set dependencies" run: cp Cargo-${{ matrix.dep }}.lock Cargo.lock - name: "Run test script" diff --git a/Cargo-minimal.lock b/Cargo-minimal.lock index b6d159d1..7e5296e7 100644 --- a/Cargo-minimal.lock +++ b/Cargo-minimal.lock @@ -156,7 +156,7 @@ checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" [[package]] name = "bitreq" -version = "0.1.0" +version = "0.2.0" dependencies = [ "base64 0.22.1", "chrono", @@ -279,11 +279,11 @@ version = "0.10.0" dependencies = [ "anyhow", "bitcoin_hashes", + "bitreq", "corepc-client", "env_logger", "flate2", "log", - "minreq", "serde_json", "tar", "tempfile", @@ -451,7 +451,7 @@ name = "jsonrpc" version = "0.18.0" dependencies = [ "base64 0.22.1", - "minreq", + "bitreq", "serde", "serde_json", "socks", @@ -501,21 +501,6 @@ dependencies = [ "adler2", ] -[[package]] -name = "minreq" -version = "2.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fdef521c74c2884a4f3570bcdb6d2a77b3c533feb6b27ac2ae72673cc221c64" -dependencies = [ - "log", - "once_cell", - "rustls", - "rustls-webpki", - "serde", - "serde_json", - "webpki-roots", -] - [[package]] name = "mio" version = "1.0.2" diff --git a/Cargo-recent.lock b/Cargo-recent.lock index 53897d05..7b900ba3 100644 --- a/Cargo-recent.lock +++ b/Cargo-recent.lock @@ -156,7 +156,7 @@ checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" [[package]] name = "bitreq" -version = "0.1.0" +version = "0.2.0" dependencies = [ "base64 0.22.1", "chrono", @@ -279,11 +279,11 @@ version = "0.10.0" dependencies = [ "anyhow", "bitcoin_hashes", + "bitreq", "corepc-client", "env_logger", "flate2", "log", - "minreq", "serde_json", "tar", "tempfile", @@ -456,7 +456,7 @@ name = "jsonrpc" version = "0.18.0" dependencies = [ "base64 0.22.1", - "minreq", + "bitreq", "serde", "serde_json", "socks", @@ -506,21 +506,6 @@ dependencies = [ "adler2", ] -[[package]] -name = "minreq" -version = "2.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0c420feb01b9fb5061f8c8f452534361dd783756dcf38ec45191ce55e7a161" -dependencies = [ - "log", - "once_cell", - "rustls", - "rustls-webpki", - "serde", - "serde_json", - "webpki-roots", -] - [[package]] name = "mio" version = "1.1.0" diff --git a/README.md b/README.md index ffce101c..88fa0e13 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,6 @@ Some code shamelessly stolen from `rust-bitcoincore-rpc` (credit to Steven). ## Minimum Supported Rust Version (MSRV) -This library should always compile with any combination of features on **Rust 1.63.0**. +This library should always compile with any combination of features on **Rust 1.75.0**. Use `Cargo-minimal.lock` to build the MSRV by copying to `Cargo.lock` and building. diff --git a/bitreq/.github/workflows/msrv.yml b/bitreq/.github/workflows/msrv.yml index c85713e8..aede3509 100644 --- a/bitreq/.github/workflows/msrv.yml +++ b/bitreq/.github/workflows/msrv.yml @@ -18,7 +18,7 @@ jobs: - name: Checkout Crate uses: actions/checkout@v3 - name: Checkout Toolchain - uses: dtolnay/rust-toolchain@1.63 + uses: dtolnay/rust-toolchain@1.75 - name: Running test script run: | cargo test diff --git a/bitreq/CHANGELOG.md b/bitreq/CHANGELOG.md index 4c01c877..a823071b 100644 --- a/bitreq/CHANGELOG.md +++ b/bitreq/CHANGELOG.md @@ -1,381 +1,12 @@ -# Changelog -All notable changes to this project will be documented in this file. +# 0.2.0 - 2025-10-31 -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +* Re-implement `json-using-serde` feature [#398](https://github.com/rust-bitcoin/corepc/pull/398) +* Update MSRV to Rust `v1.75.0` [#405](https://github.com/rust-bitcoin/corepc/pull/405/) -## [Unreleased] -### Changed -- `https-bundled`, `https-bundled-probe`: Removed almost all of the bundled - native-tls code (~1k LoC), only keeping the relevant part (~30 LoC). There - should be no change to the actual code that ends up being ran, but if you're - using these features, make sure to test that everything works as you expect, - something might have slipped. +# 0.1.0 - 2025-10-22 -### Fixed -- `https-*`: Refactored the TLS handling code a bit. This should have no visible - effect downstream, `src/connection.rs` is just a little bit more readable now. -- Removed `build.rs`, which turned out to be dead code. This should have no - effect, but if it does, it should also only affect the `https-bundled` and - `https-bundled-probe` features. +* Fork `minreq`, strip it down, and import it into the `corepc` repo. + Rename to `bitreq` while doing so. -## [2.13.4] - 2025-04-11 -### Fixed -- Updated the base64 dependency, only used by the `proxy` feature, to its newest - minor version. Thanks for the report, @Jackhr-arch! - ([#119](https://github.com/neonmoe/minreq/issues/119)) - -## [2.13.3] - 2025-03-11 -### Fixed -- Removed the `once_cell` dependency by making use of the new - `std::sync::OnceLock` type. This change only affects the rustls-based https - features. Thanks for the PR, @LyonSyonII! - ([#115](https://github.com/neonmoe/minreq/pull/115)) -- MSRV builds that got broken due to a `rustix` update. Now `tempfile` is pinned - as well. - -## [2.13.2] - 2025-01-29 -### Fixed -- Reverted a part of 2.13.1, accidentally removed some code that wasn't actually - dead code. - -## [2.13.1] - 2025-01-29 -### Fixed -- Usage of an openssl-probe function that's deprecated due to safety issues. See - [rustsec/advisory-db#2209](https://github.com/rustsec/advisory-db/pull/2209) - for further info. - -## [2.13.0] - 2024-12-04 -### Changed -- The `https-rustls-probe` feature no longer brings in the `webpki-roots` and - `rustls-webpki` crates. Thanks for the report, @polarathene! - ([#111](https://github.com/neonmoe/minreq/issues/111)) - -### Fixed -- Cleaned up an unnecessary `format!()` in `Connection::connect`. Thanks for the - PR, @melotic! ([#112](https://github.com/neonmoe/minreq/pull/112)) -- Fixed some msrv and lint issues introduced by libc and clippy updates - respectively. - -## [2.12.0] - 2024-07-16 -### Added -- Request::with_headers, to allow passing in many headers at a - time. Thanks for the idea and PR, @rawhuul! - ([#110](https://github.com/neonmoe/minreq/pull/110)) - -## [2.11.2] - 2024-04-26 -### Fixed -- The dev dependency tiny_http's version up to 0.12. Thanks for the - PR, @davide125! ([#107](https://github.com/neonmoe/minreq/pull/107)) - -## [2.11.1] - 2024-02-04 -### Fixed -- Unnecessary buffering causing performance problems. Thanks for the - PRs, @mrkline! ([#102](https://github.com/neonmoe/minreq/pull/102), - [#103](https://github.com/neonmoe/minreq/pull/103)) -- Connections failing if the first resolved address fails to connect - (even if there's more to try). Thanks for the PR, @darosior! - ([#106](https://github.com/neonmoe/minreq/pull/106)) - -## [2.11.0] - 2023-10-17 -### Changed -- Removed upper bounds on the `serde_json`, `log` and `chrono` - dependencies (dev-dependency in the case of `chrono`). If you were - depending on minreq compiling with the MSRV compiler without any - issues, check out the MSRV section in the readme, it's been updated - with additional instructions. Thanks for the report, @RCasatta! - ([#99](https://github.com/neonmoe/minreq/issues/99)) - -## [2.10.0] - 2023-09-05 -### Fixed -- Fragment handling, once again. Turns out you're not supposed to include - fragments in the request. This may break usage with servers that are written - with the wrong assumptions. Thanks for the report, @rawhuul! - ([#100](https://github.com/neonmoe/minreq/issues/100)) - -### Added -- `Response::url` and `ResponseLazy::url` fields, to contain the final URL after - redirects and fragment replacement semantics. - -## [2.9.1] - 2023-08-28 -### Changed -- Loosened the rustls version requirement from 0.21.6 to 0.21.1. - -## [2.9.0] - 2023-08-24 -### Changed -- From webpki to rustls-webpki. Thanks for the heads-up about webpki not - being maintained, @RCasatta! - ([#98](https://github.com/neonmoe/minreq/issues/98)) -- Updated rustls and webpki-roots to their most recent versions. -- Maximum versions for the following dependencies to keep minreq compiling on - Rust 1.48: - - serde_json (`>=1.0.0, <1.0.101`) - - log (`>=0.4.0, <0.4.19`) - - chrono (dev-dependency, `>=0.4.0, <0.4.24`) - -### Fixed -- Errors when using an IP address as the host with HTTPS (tested with - ). ([#34](https://github.com/neonmoe/minreq/issues/34)) - -## [2.8.1] - 2023-05-20 -### Fixed -- Proxy strings with the protocol included not working. Thanks for the report, - @tkkcc! ([#95](https://github.com/neonmoe/minreq/issues/95)) - -## [2.8.0] - 2023-05-13 -### Added -- Default proxy from environment variables when the `proxy` feature is - enabled, based on what curl does. Thanks for the PR, @krypt0nn! - ([#94](https://github.com/neonmoe/minreq/pull/94)) - -## [2.7.0] - 2023-03-19 -### Changed -- From lazy_static to once_cell for library internals. Thanks for the PR, - @alpha-tango-kilo! ([#80](https://github.com/neonmoe/minreq/pull/80)) - -### Added -- A Read impl for ResponseLazy. Thanks for the PR, @Luro02! - ([#81](https://github.com/neonmoe/minreq/pull/81)) -- Building with `--all-features`, with the `send_https` function defaulting to - the rustls-based implementation. Thanks for the PR, @tcharding! - ([#89](https://github.com/neonmoe/minreq/pull/89)) -- An explicit minimum supported rust version policy. The MSRV for versions 2.x - is 1.48. Thanks for the suggestion and PR, @tcharding! - ([#90](https://github.com/neonmoe/minreq/pull/90)) -- Performance improvements, test fixes, CI updates. - -## [2.6.0] - 2022-02-23 -### Changed -- The error returned when the request url does not start with - `https://` or `http://` now is now a slightly different IoError, - with a clearer message. This will be changed to a proper - minreq-specific error in 3.0, but for now it's an IoError to avoid - breaking the Error type. - -### Added -- The `urlencoding` feature for automatically percent-encoding - urls. Thanks for the idea and PR, @alpha-tango-kilo! - ([#67](https://github.com/neonmoe/minreq/issues/67), - [#68](https://github.com/neonmoe/minreq/pull/68)) - -## [2.5.1] - 2022-01-07 -### Fixed -- GitHub API requests without User-Agent returning an IoError. Thanks - for the report, @tech-ticks! - ([#66](https://github.com/neonmoe/minreq/issues/66)) - -## [2.5.0] - 2022-01-06 -### Fixed -- Returning the wrong status code when the response was missing a - status phrase. Thanks for the PR, @richarddd! - ([#64](https://github.com/neonmoe/minreq/issues/64)) -- Non-lazy requests crashing if the request had a very big - Content-Length header. Thanks for the report, @Shnatsel! - ([#63](https://github.com/neonmoe/minreq/issues/63)) - -## [2.4.2] - 2021-06-11 -### Fixed -- A regression in 2.4.1 where the port is no longer included in the - `Host`, even if it's a non-standard port. Now the port is always - included if it's in the request URL, and omitted if the port is - implied. Thanks for the report, @ollpu! - ([#61](https://github.com/neonmoe/minreq/issues/61)) - -## [2.4.1] - 2021-06-05 -### Fixed -- The port is no longer included in the `Host` header when sending - requests, and port handling was cleaned up overall. This fixes - issues with infinite redirections and https handshakes for some - websites. Thanks to @Shnatsel for reporting the issues, and @joeried - for debugging and figuring out the root cause of these problems! - ([#48](https://github.com/neonmoe/minreq/issues/48), - [#49](https://github.com/neonmoe/minreq/issues/49)) - -## [2.4.0] - 2021-05-27 -### Added -- `Request::with_param` for more ergonomic query parameter - usage. Thanks for the PR, @sjvignesh! - ([#54](https://github.com/neonmoe/minreq/pull/54)) -- `Request::with_max_headers_size` and - `Request::with_max_status_line_length` for avoiding DoS when the - server sends large headers or status lines. Thanks for the report, - @Shnatsel! ([#55](https://github.com/neonmoe/minreq/issues/55)) -- Support for the `rustls-native-certs` crate via a new - `https-rustls-probe` feature. Thanks for the PR, @joeried! - ([#59](https://github.com/neonmoe/minreq/pull/59)) - -### Fixed -- Chunk length handling for some servers with slightly off-spec chunk - lengths. Thanks for the report, @Shnatsel! - ([#50](https://github.com/neonmoe/minreq/issues/50)) -- Timeouts not always being properly enforced. Thanks for the report, - @Shnatsel! ([#52](https://github.com/neonmoe/minreq/issues/52)) - -## [2.3.1] - 2021-02-10 -### Fixed -- Removed some leftover printlns from the redirection update in 2.3.0 - and ensured there's no printlns in the library anymore. Thanks for - reporting the issue @Shnatsel! - [#45](https://github.com/neonmoe/minreq/issues/45) -- Fixed the timeout not being respected during the initial TCP - connect. Thanks for the report and fix @KarthikNedunchezhiyan! - [#46](https://github.com/neonmoe/minreq/issues/46), - [#47](https://github.com/neonmoe/minreq/pull/47) - -## [2.3.0] - 2021-01-04 -### Changed -- **Breaking (sort of):** the redirection code was improved to match - [RFC 7231 section - 7.1.2](https://tools.ietf.org/html/rfc7231#section-7.1.2), which - could subtly break some programs relying on very specific redirects, - which is why this should be investigated if you come across weird - behaviour after updating. No API changes though, so only a minor - version bump. The following two points are now fixed when - redirecting: - - Fragments, the bit after a #-character in the url. If the - redirecting url has a fragment, and the one in `Location` does - not, the original fragment should be included in the new url. If - `Location` does have a fragment, it should override the one in the - redirecting url. - - Relative urls. Minreq now properly redirects when `Location` is - relative, e.g. `/Foo.html` instead of - `https://example.com/Foo.html`. Thanks, @fjt523! - -### Fixed -- The `Content-Length: 0` header is now inserted into requests that - should have it. Thanks, @KarthikNedunchezhiyan! -- Status line parsing is now fixed, so "400 Bad Request" is not parsed - as "400 Bad". Thanks, @KarthikNedunchezhiyan! - -### Added -- M1 Mac support by bumping the ring dependency. Thanks, @ryanmcgrath! - -## [2.2.1] - 2020-08-22 -### Fixed -- Some documentation which has been long due for an update. I just - always forget when writing an actual update. No code changes! - -## [2.2.0] - 2020-06-18 -### Added -- Support for `native-tls` and `openssl-sys` via new features, in - addition to `rustls`. Thanks to @dubiousjim! - -## [2.1.1] - 2020-05-01 -### Fixed -- Handling of status codes 204 and 304. Thanks to @Mubelotix! - -## [2.1.0] - 2020-03-14 -### Added -- Proxy support via the `proxy` feature. Thanks to @rustysec! - -## [2.0.3] - 2020-01-15 -### Fixed -- Fixed regression in header parsing caused by 2.0.2, which was yanked. - -## [2.0.2] - 2020-01-15 -### Fixed -- Fixed a panic when sending a request to an invalid domain - via https. -- Fixed a panic when parsing headers that have >1 byte - unicode characters right after the ":" in the response. - -## [2.0.1] - 2020-01-11 -### Fixed -- Made timeouts work as described in the documentation. - Fixed issue #22. - -## [2.0.0] - 2019-11-23 -### Added -- API for loading the HTTP response body through an iterator, allowing - for processing of the data during the download. - - See the `ResponseLazy` documentation for more information. -- Error type for all the errors that this crate can run into for - easier `?` usage and better debuggability. -- Punycode support for non-ascii hostnames via the `punycode` feature. -- Trailer header support. -- Examples [`hello`](examples/hello.rs), - [`iterator`](examples/iterator.rs), and [`json`](examples/json.rs). - -### Changed -- **Breaking, will cause problems not detectable by the compiler:** - Response headers' field names are now in lowercase, as they are - case-insensitive and this makes getting header values easier. The - values are unaffected. So if your code has - `response.headers.get("Content-Type")`, you have to change it to - `response.headers.get("content-type")`, or it will not return what - you want. -- **Breaking**: Restructure the `Response` struct: - - Removed `bytes` and `body_bytes`. - - Added `as_bytes()`, `into_bytes()`, and `as_str()` in their place. -- **Breaking**: Changed the `with_body` parameter type to - `Into>` from `Into`. - - `String`s implement `Into>`, so this shouldn't cause any - problems, unless you're using some interesting types that - implement `Into` but not `Into>`. -- Clean up the crate internals overall. **Note**: This might cause - instability, if you're very concerned about stability, please hold - off upgrading for a while. -- Remove `panic!` when trying to make an `https://` request without - the `https` feature. The request will now return an error - instead. The library should not panic anymore. -- Audit the remaining `unwrap()`s from library code, none of them - should actually ever cause a panic now. - -### Removed -- `create_request` in favor of just using `Response::new`. - -## [1.4.1] - 2019-10-13 -### Changed -- Updated dependencies. - -### Fixed -- Tests on Windows by changing the ip in tests from `0.0.0.0` to - `localhost`. -- Reuse `rustls::ClientConfig` between requests. -- `Content-Length` and `Transfer-Encoding` detection failing because - of case-sensitiveness. - -## [1.4.0] - 2019-07-13 -### Added -- `json-using-serde` feature. - -## [1.3.0] - 2019-06-04 -### Added -- The `body_bytes` field to Response, containing the body in raw - bytes. - -### Fixed -- Some clippy warnings. -- Panic when getting a non-UTF-8 response, instead setting the `body` - string to an empty string, for now. - -## [1.2.1] - 2019-05-24 -### Fixed -- HTTP response body handling. - -## [1.2.0] - 2019-05-23 -### Added -- Support for the HTTP status codes 301, 302, 303, and 307. - -### Fixed -- Less .clones()s. - -## [1.1.2] - 2019-04-14 -### Fixed -- Fix response handling when `Transfer-Encoding` is `chunked`. - -## [1.1.1] - 2019-03-28 -### Changed -- Moved to 2018 edition. - -### Fixed -- HEAD requests and ones that receive a 1xx, 204, or 304 status code - as a response. - -## [1.1.0] - 2019-03-24 -### Changed -- Timeout made optional. -- Updated dependencies. - -### Fixed -- Improved performance for HTTP (not HTTPS) requests. +I forked `minreq` from the master branch 3 months ago and did not grab +the commit hash when forking, at the time the released version was 2.13.4 diff --git a/bitreq/Cargo.toml b/bitreq/Cargo.toml index bce0dfe6..68ddd0a6 100644 --- a/bitreq/Cargo.toml +++ b/bitreq/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bitreq" -version = "0.1.0" +version = "0.2.0" authors = ["Jens Pitkanen ", "Tobin C. Harding "] description = "Simple, minimal-dependency HTTP client" documentation = "https://docs.rs/bitreq" @@ -10,7 +10,7 @@ keywords = ["http", "https", "client", "request", "json"] categories = ["web-programming::http-client"] license = "ISC" edition = "2021" -rust-version = "1.74.0" +rust-version = "1.75.0" [badges] maintenance = { status = "experimental" } diff --git a/bitreq/README.md b/bitreq/README.md index 1815cd7d..90e940b3 100644 --- a/bitreq/README.md +++ b/bitreq/README.md @@ -40,7 +40,7 @@ We use an MSRV per major release, i.e., with a new major release we reserve the right to change the MSRV. The current major version of this library should always compile with -default features (i.e., `std`) on **Rust 1.63**. Other features may +default features (i.e., `std`) on **Rust 1.75**. Other features may require a higher MSRV. ## License diff --git a/bitreq/examples/wasm_example.rs b/bitreq/examples/wasm_example.rs deleted file mode 100644 index b2e5edc3..00000000 --- a/bitreq/examples/wasm_example.rs +++ /dev/null @@ -1,25 +0,0 @@ -//! WASM example demonstrating extern C function integration -//! -//! This example shows how to use bitreq with the `wasm` feature. -//! The actual HTTP requests are performed by JavaScript through extern C functions. - -fn main() { - // Example usage in WASM environment - let _request = - bitreq::get("https://httpbin.org/get").with_header("User-Agent", "bitreq-wasm/0.1.0"); - - // In a real WASM environment, this would call out to JavaScript - // The JavaScript implementation would need to provide: - // - bitreq_wasm_http_request - // - bitreq_wasm_get_status_code - // - bitreq_wasm_get_response_headers - - println!("Request prepared for WASM execution:"); - println!("URL: https://httpbin.org/get"); - println!("Method: GET"); - println!("Headers: User-Agent: bitreq-wasm/0.1.0"); - - // Note: This won't actually execute in non-WASM environments - // as the extern C functions aren't implemented - println!("To run this, compile to WASM and provide JavaScript implementations"); -} diff --git a/bitreq/src/connection.rs b/bitreq/src/connection.rs index 0a72066d..1595e2f6 100644 --- a/bitreq/src/connection.rs +++ b/bitreq/src/connection.rs @@ -87,7 +87,7 @@ pub struct AsyncConnection { impl AsyncConnection { /// Creates a new `AsyncConnection`. pub(crate) fn new(request: ParsedRequest) -> AsyncConnection { - let timeout = request.config.timeout.or_else(|| match env::var("MINREQ_TIMEOUT") { + let timeout = request.config.timeout.or_else(|| match env::var("BITREQ_TIMEOUT") { Ok(t) => t.parse::().ok(), Err(_) => None, }); @@ -128,7 +128,7 @@ impl Connection { /// Creates a new `Connection`. See [Request] and [ParsedRequest] /// for specifics about *what* is being sent. pub(crate) fn new(request: ParsedRequest) -> Connection { - let timeout = request.config.timeout.or_else(|| match env::var("MINREQ_TIMEOUT") { + let timeout = request.config.timeout.or_else(|| match env::var("BITREQ_TIMEOUT") { Ok(t) => t.parse::().ok(), Err(_) => None, }); diff --git a/bitreq/src/lib.rs b/bitreq/src/lib.rs index eda3bbe7..afa718de 100644 --- a/bitreq/src/lib.rs +++ b/bitreq/src/lib.rs @@ -1,4 +1,4 @@ -//! # Minreq +//! # Bitreq //! //! Simple, minimal-dependency HTTP client. The library has a very //! minimal API, so you'll probably know everything you need to after @@ -207,16 +207,16 @@ //! ```text,ignore //! bitreq::get("/").with_timeout(8).send(); //! ``` -//! - Set the environment variable `MINREQ_TIMEOUT` to the desired +//! - Set the environment variable `BITREQ_TIMEOUT` to the desired //! amount of seconds until timeout. Ie. if you have a program called //! `foo` that uses bitreq, and you want all the requests made by that //! program to timeout in 8 seconds, you launch the program like so: //! ```text,ignore -//! $ MINREQ_TIMEOUT=8 ./foo +//! $ BITREQ_TIMEOUT=8 ./foo //! ``` //! Or add the following somewhere before the requests in the code. //! ``` -//! std::env::set_var("MINREQ_TIMEOUT", "8"); +//! std::env::set_var("BITREQ_TIMEOUT", "8"); //! ``` //! If the timeout is set with `with_timeout`, the environment //! variable will be ignored. diff --git a/client/CHANGELOG.md b/client/CHANGELOG.md index 3e0835a5..abe79dff 100644 --- a/client/CHANGELOG.md +++ b/client/CHANGELOG.md @@ -1,8 +1,8 @@ -# 0.10.0 2025-10-07 +# 0.10.0 - 2025-10-07 - Update to use latest `types v0.10.0`. -# 0.9.0 2025-09-11 +# 0.9.0 - 2025-09-11 Add support for all the new methods added as part of the `types v0.9.0` release - that means **all** of the documented Core RPC methods. @@ -11,7 +11,7 @@ release - that means **all** of the documented Core RPC methods. - Integration test all methods (excl. two that have open issues). - Add support for Core `v28.2` [#279](https://github.com/rust-bitcoin/corepc/pull/279) -# 0.8.0 2025-05-21 +# 0.8.0 - 2025-05-21 - Add support for Bitcoin Core 29.0 [#131](https://github.com/rust-bitcoin/corepc/pull/131) - Add support for Bitcoin Core 28.1 [#184](https://github.com/rust-bitcoin/corepc/pull/184) @@ -24,7 +24,7 @@ release - that means **all** of the documented Core RPC methods. - Implement `verifychain` method and test [#155](https://github.com/rust-bitcoin/corepc/pull/155) - Implement `getnodeaddresses` method and test [#154](https://github.com/rust-bitcoin/corepc/pull/154) -# 0.7.0 2025-04-04 +# 0.7.0 - 2025-04-04 - Fix unloadwallet method [#110](https://github.com/rust-bitcoin/corepc/pull/110) - Implement methods from the mining section [#106](https://github.com/rust-bitcoin/corepc/pull/106) diff --git a/client/Cargo.toml b/client/Cargo.toml index 225a281f..08f9ec4a 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -9,7 +9,7 @@ categories = ["cryptography::cryptocurrencies"] keywords = ["bitcoin", "bitcoind", "json-rpc"] readme = "README.md" edition = "2021" -rust-version = "1.63.0" +rust-version = "1.75.0" exclude = ["tests", "contrib"] [package.metadata.docs.rs] @@ -27,6 +27,6 @@ serde = { version = "1.0.103", default-features = false, features = [ "derive", serde_json = { version = "1.0.117" } types = { package = "corepc-types", version = "0.10.0", path = "../types", default-features = false, features = ["std"] } -jsonrpc = { version = "0.18.0", path = "../jsonrpc", features = ["minreq_http"], optional = true } +jsonrpc = { version = "0.18.0", path = "../jsonrpc", features = ["bitreq_http"], optional = true } [dev-dependencies] diff --git a/client/README.md b/client/README.md index 0579950e..0c09dedd 100644 --- a/client/README.md +++ b/client/README.md @@ -5,7 +5,7 @@ is only a blocking client and is intended to be used in integration testing. ## Minimum Supported Rust Version (MSRV) -This library should always compile with any combination of features on **Rust 1.63.0**. +This library should always compile with any combination of features on **Rust 1.75.0**. ## Licensing diff --git a/client/src/client_sync/mod.rs b/client/src/client_sync/mod.rs index fc32d66b..bca9e954 100644 --- a/client/src/client_sync/mod.rs +++ b/client/src/client_sync/mod.rs @@ -55,9 +55,9 @@ impl Auth { } } -/// Defines a `jsonrpc::Client` using `minreq`. +/// Defines a `jsonrpc::Client` using `bitreq`. #[macro_export] -macro_rules! define_jsonrpc_minreq_client { +macro_rules! define_jsonrpc_bitreq_client { ($version:literal) => { use std::fmt; @@ -81,7 +81,7 @@ macro_rules! define_jsonrpc_minreq_client { impl Client { /// Creates a client to a bitcoind JSON-RPC server without authentication. pub fn new(url: &str) -> Self { - let transport = jsonrpc::http::minreq_http::Builder::new() + let transport = jsonrpc::http::bitreq_http::Builder::new() .url(url) .expect("jsonrpc v0.18, this function does not error") .timeout(std::time::Duration::from_secs(60)) @@ -98,7 +98,7 @@ macro_rules! define_jsonrpc_minreq_client { } let (user, pass) = auth.get_user_pass()?; - let transport = jsonrpc::http::minreq_http::Builder::new() + let transport = jsonrpc::http::bitreq_http::Builder::new() .url(url) .expect("jsonrpc v0.18, this function does not error") .timeout(std::time::Duration::from_secs(60)) diff --git a/client/src/client_sync/v17/blockchain.rs b/client/src/client_sync/v17/blockchain.rs index f0b037ca..810fa19b 100644 --- a/client/src/client_sync/v17/blockchain.rs +++ b/client/src/client_sync/v17/blockchain.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `getblockchaininfo`. #[macro_export] diff --git a/client/src/client_sync/v17/control.rs b/client/src/client_sync/v17/control.rs index b84bd7ce..ab50b2c8 100644 --- a/client/src/client_sync/v17/control.rs +++ b/client/src/client_sync/v17/control.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `getmemoryinfo`. #[macro_export] diff --git a/client/src/client_sync/v17/generating.rs b/client/src/client_sync/v17/generating.rs index c7e5f7b5..7f4bddb3 100644 --- a/client/src/client_sync/v17/generating.rs +++ b/client/src/client_sync/v17/generating.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `generatetoaddress`. #[macro_export] diff --git a/client/src/client_sync/v17/hidden.rs b/client/src/client_sync/v17/hidden.rs new file mode 100644 index 00000000..05e305da --- /dev/null +++ b/client/src/client_sync/v17/hidden.rs @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: CC0-1.0 + +//! Macros for implementing JSON-RPC methods on a client. +//! +//! Specifically this is `== Hidden ==` methods that are not listed in the +//! API docs of Bitcoin Core `v0.17`. +//! +//! All macros require `Client` to be in scope. +//! +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. + +/// Implements Bitcoin Core JSON-RPC API method `waitforblock`. +#[macro_export] +macro_rules! impl_client_v17__wait_for_block { + () => { + impl Client { + pub fn wait_for_block(&self, hash: &bitcoin::BlockHash) -> Result { + self.call("waitforblock", &[into_json(hash)?]) + } + } + }; +} + +/// Implements Bitcoin Core JSON-RPC API method `waitforblockheight`. +#[macro_export] +macro_rules! impl_client_v17__wait_for_block_height { + () => { + impl Client { + pub fn wait_for_block_height(&self, height: u64) -> Result { + self.call("waitforblockheight", &[into_json(height)?]) + } + } + }; +} + +/// Implements Bitcoin Core JSON-RPC API method `waitfornewblock`. +#[macro_export] +macro_rules! impl_client_v17__wait_for_new_block { + () => { + impl Client { + pub fn wait_for_new_block(&self) -> Result { + self.call("waitfornewblock", &[]) + } + } + }; +} diff --git a/client/src/client_sync/v17/mining.rs b/client/src/client_sync/v17/mining.rs index bc777030..80f50138 100644 --- a/client/src/client_sync/v17/mining.rs +++ b/client/src/client_sync/v17/mining.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `getblocktemplate`. #[macro_export] diff --git a/client/src/client_sync/v17/mod.rs b/client/src/client_sync/v17/mod.rs index 58215d5c..7921840d 100644 --- a/client/src/client_sync/v17/mod.rs +++ b/client/src/client_sync/v17/mod.rs @@ -7,6 +7,7 @@ pub mod blockchain; pub mod control; pub mod generating; +pub mod hidden; pub mod mining; pub mod network; pub mod raw_transactions; @@ -24,7 +25,7 @@ use serde::{Deserialize, Serialize, Serializer}; use crate::client_sync::into_json; use crate::types::v17::*; -crate::define_jsonrpc_minreq_client!("v17"); +crate::define_jsonrpc_bitreq_client!("v17"); crate::impl_client_check_expected_server_version!({ [170200] }); // == Blockchain == @@ -64,6 +65,11 @@ crate::impl_client_v17__generate_to_address!(); crate::impl_client_v17__generate!(); crate::impl_client_v17__invalidate_block!(); +// == Hidden == +crate::impl_client_v17__wait_for_block!(); +crate::impl_client_v17__wait_for_block_height!(); +crate::impl_client_v17__wait_for_new_block!(); + // == Mining == crate::impl_client_v17__get_block_template!(); crate::impl_client_v17__get_mining_info!(); diff --git a/client/src/client_sync/v17/network.rs b/client/src/client_sync/v17/network.rs index 41645ff3..59edfe12 100644 --- a/client/src/client_sync/v17/network.rs +++ b/client/src/client_sync/v17/network.rs @@ -7,7 +7,7 @@ //! Specifically this is methods found under the `== Network ==` section of the //! API docs of Bitcoin Core `v0.17`. //! -//! See, or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See, or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `addnode`. #[macro_export] diff --git a/client/src/client_sync/v17/raw_transactions.rs b/client/src/client_sync/v17/raw_transactions.rs index c108e055..2a7425f4 100644 --- a/client/src/client_sync/v17/raw_transactions.rs +++ b/client/src/client_sync/v17/raw_transactions.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `combinepsbt`. #[macro_export] diff --git a/client/src/client_sync/v17/util.rs b/client/src/client_sync/v17/util.rs index a55c09a7..169aadf9 100644 --- a/client/src/client_sync/v17/util.rs +++ b/client/src/client_sync/v17/util.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `createmultisig`. #[macro_export] diff --git a/client/src/client_sync/v17/wallet.rs b/client/src/client_sync/v17/wallet.rs index 2ca38780..c1db0027 100644 --- a/client/src/client_sync/v17/wallet.rs +++ b/client/src/client_sync/v17/wallet.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `abandontransaction`. #[macro_export] diff --git a/client/src/client_sync/v18/control.rs b/client/src/client_sync/v18/control.rs index a42efc11..10e32674 100644 --- a/client/src/client_sync/v18/control.rs +++ b/client/src/client_sync/v18/control.rs @@ -5,7 +5,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `getrpcinfo`. #[macro_export] diff --git a/client/src/client_sync/v18/mining.rs b/client/src/client_sync/v18/mining.rs index 9d688e9e..b331a1ab 100644 --- a/client/src/client_sync/v18/mining.rs +++ b/client/src/client_sync/v18/mining.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `submitheader`. #[macro_export] diff --git a/client/src/client_sync/v18/mod.rs b/client/src/client_sync/v18/mod.rs index 7a806ccd..73a4f048 100644 --- a/client/src/client_sync/v18/mod.rs +++ b/client/src/client_sync/v18/mod.rs @@ -29,7 +29,7 @@ pub use crate::client_sync::{ }; // This publicly re-exports `Client`. -crate::define_jsonrpc_minreq_client!("v18"); +crate::define_jsonrpc_bitreq_client!("v18"); crate::impl_client_check_expected_server_version!({ [180100] }); // == Blockchain == @@ -70,6 +70,11 @@ crate::impl_client_v17__generate_to_address!(); crate::impl_client_v17__generate!(); crate::impl_client_v17__invalidate_block!(); +// == Hidden == +crate::impl_client_v17__wait_for_block!(); +crate::impl_client_v17__wait_for_block_height!(); +crate::impl_client_v17__wait_for_new_block!(); + // == Mining == crate::impl_client_v17__get_block_template!(); crate::impl_client_v17__get_mining_info!(); diff --git a/client/src/client_sync/v18/network.rs b/client/src/client_sync/v18/network.rs index 6e0049b4..2c3b5090 100644 --- a/client/src/client_sync/v18/network.rs +++ b/client/src/client_sync/v18/network.rs @@ -7,7 +7,7 @@ //! Specifically this is methods found under the `== Network ==` section of the //! API docs of Bitcoin Core `v0.18`. //! -//! See, or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See, or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `getnodeaddresses`. #[macro_export] diff --git a/client/src/client_sync/v18/raw_transactions.rs b/client/src/client_sync/v18/raw_transactions.rs index 5211495f..80bc7146 100644 --- a/client/src/client_sync/v18/raw_transactions.rs +++ b/client/src/client_sync/v18/raw_transactions.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `analyzepsbt`. #[macro_export] diff --git a/client/src/client_sync/v18/util.rs b/client/src/client_sync/v18/util.rs index 8fee92e0..594db166 100644 --- a/client/src/client_sync/v18/util.rs +++ b/client/src/client_sync/v18/util.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `deriveaddresses`. #[macro_export] diff --git a/client/src/client_sync/v18/wallet.rs b/client/src/client_sync/v18/wallet.rs index ee517385..e3f96a07 100644 --- a/client/src/client_sync/v18/wallet.rs +++ b/client/src/client_sync/v18/wallet.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `getreceivedbylabel`. #[macro_export] macro_rules! impl_client_v18__get_received_by_label { diff --git a/client/src/client_sync/v19/blockchain.rs b/client/src/client_sync/v19/blockchain.rs index 6eab4652..d82bc623 100644 --- a/client/src/client_sync/v19/blockchain.rs +++ b/client/src/client_sync/v19/blockchain.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `getblockfilter`. #[macro_export] diff --git a/client/src/client_sync/v19/mod.rs b/client/src/client_sync/v19/mod.rs index 7cf1d16e..8bed0e35 100644 --- a/client/src/client_sync/v19/mod.rs +++ b/client/src/client_sync/v19/mod.rs @@ -24,7 +24,7 @@ pub use crate::client_sync::{ }, }; -crate::define_jsonrpc_minreq_client!("v19"); +crate::define_jsonrpc_bitreq_client!("v19"); crate::impl_client_check_expected_server_version!({ [190100] }); // == Blockchain == @@ -65,6 +65,11 @@ crate::impl_client_v17__uptime!(); crate::impl_client_v17__generate_to_address!(); crate::impl_client_v17__invalidate_block!(); +// == Hidden == +crate::impl_client_v17__wait_for_block!(); +crate::impl_client_v17__wait_for_block_height!(); +crate::impl_client_v17__wait_for_new_block!(); + // == Mining == crate::impl_client_v17__get_block_template!(); crate::impl_client_v17__get_mining_info!(); diff --git a/client/src/client_sync/v19/wallet.rs b/client/src/client_sync/v19/wallet.rs index c940124a..7c4920ff 100644 --- a/client/src/client_sync/v19/wallet.rs +++ b/client/src/client_sync/v19/wallet.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `getbalances`. #[macro_export] diff --git a/client/src/client_sync/v20/generating.rs b/client/src/client_sync/v20/generating.rs index a7ee33bb..6533f651 100644 --- a/client/src/client_sync/v20/generating.rs +++ b/client/src/client_sync/v20/generating.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `generatetodescriptor`. #[macro_export] diff --git a/client/src/client_sync/v20/mod.rs b/client/src/client_sync/v20/mod.rs index 21424320..067caf4c 100644 --- a/client/src/client_sync/v20/mod.rs +++ b/client/src/client_sync/v20/mod.rs @@ -23,7 +23,7 @@ pub use crate::client_sync::{ }, }; -crate::define_jsonrpc_minreq_client!("v20"); +crate::define_jsonrpc_bitreq_client!("v20"); crate::impl_client_check_expected_server_version!({ [200200] }); // == Blockchain == @@ -65,6 +65,11 @@ crate::impl_client_v17__generate_to_address!(); crate::impl_client_v20__generate_to_descriptor!(); crate::impl_client_v17__invalidate_block!(); +// == Hidden == +crate::impl_client_v17__wait_for_block!(); +crate::impl_client_v17__wait_for_block_height!(); +crate::impl_client_v17__wait_for_new_block!(); + // == Mining == crate::impl_client_v17__get_block_template!(); crate::impl_client_v17__get_mining_info!(); diff --git a/client/src/client_sync/v21/generating.rs b/client/src/client_sync/v21/generating.rs index 690e3eba..e9ec1b80 100644 --- a/client/src/client_sync/v21/generating.rs +++ b/client/src/client_sync/v21/generating.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `generateblock`. #[macro_export] diff --git a/client/src/client_sync/v21/hidden.rs b/client/src/client_sync/v21/hidden.rs index fc867510..8e6c9751 100644 --- a/client/src/client_sync/v21/hidden.rs +++ b/client/src/client_sync/v21/hidden.rs @@ -2,12 +2,12 @@ //! Macros for implementing JSON-RPC methods on a client. //! -//! Specifically this is methods found under the `== Generating ==` section of the +//! Specifically this is `== Hidden ==` methods that are not listed in the //! API docs of Bitcoin Core `v0.21`. //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `addpeeraddress`. #[macro_export] diff --git a/client/src/client_sync/v21/mod.rs b/client/src/client_sync/v21/mod.rs index 58b9d0a8..029a1c94 100644 --- a/client/src/client_sync/v21/mod.rs +++ b/client/src/client_sync/v21/mod.rs @@ -27,7 +27,7 @@ pub use crate::client_sync::{ }, }; -crate::define_jsonrpc_minreq_client!("v21"); +crate::define_jsonrpc_bitreq_client!("v21"); crate::impl_client_check_expected_server_version!({ [210200] }); // == Blockchain == @@ -72,6 +72,9 @@ crate::impl_client_v17__invalidate_block!(); // == Hidden == crate::impl_client_v21__add_peer_address!(); +crate::impl_client_v17__wait_for_block!(); +crate::impl_client_v17__wait_for_block_height!(); +crate::impl_client_v17__wait_for_new_block!(); // == Mining == crate::impl_client_v17__get_block_template!(); diff --git a/client/src/client_sync/v21/util.rs b/client/src/client_sync/v21/util.rs index 2ed6864f..eca84998 100644 --- a/client/src/client_sync/v21/util.rs +++ b/client/src/client_sync/v21/util.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `getindexinfo`. #[macro_export] diff --git a/client/src/client_sync/v21/wallet.rs b/client/src/client_sync/v21/wallet.rs index 43f344b5..8fe15229 100644 --- a/client/src/client_sync/v21/wallet.rs +++ b/client/src/client_sync/v21/wallet.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `createwallet`. #[macro_export] diff --git a/client/src/client_sync/v22/mod.rs b/client/src/client_sync/v22/mod.rs index 6d32b66f..75658cb4 100644 --- a/client/src/client_sync/v22/mod.rs +++ b/client/src/client_sync/v22/mod.rs @@ -25,7 +25,7 @@ pub use crate::client_sync::{ v21::ImportDescriptorsRequest, }; -crate::define_jsonrpc_minreq_client!("v22"); +crate::define_jsonrpc_bitreq_client!("v22"); crate::impl_client_check_expected_server_version!({ [220100] }); // == Blockchain == @@ -70,6 +70,9 @@ crate::impl_client_v17__invalidate_block!(); // == Hidden == crate::impl_client_v21__add_peer_address!(); +crate::impl_client_v17__wait_for_block!(); +crate::impl_client_v17__wait_for_block_height!(); +crate::impl_client_v17__wait_for_new_block!(); // == Mining == crate::impl_client_v17__get_block_template!(); diff --git a/client/src/client_sync/v22/signer.rs b/client/src/client_sync/v22/signer.rs index 384a2ea1..09551754 100644 --- a/client/src/client_sync/v22/signer.rs +++ b/client/src/client_sync/v22/signer.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `enumeratesigners` #[macro_export] diff --git a/client/src/client_sync/v22/wallet.rs b/client/src/client_sync/v22/wallet.rs index 92dffca5..2a6e4b00 100644 --- a/client/src/client_sync/v22/wallet.rs +++ b/client/src/client_sync/v22/wallet.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `listdescriptors`. #[macro_export] diff --git a/client/src/client_sync/v23/blockchain.rs b/client/src/client_sync/v23/blockchain.rs index 4c33a3f9..ec6194b2 100644 --- a/client/src/client_sync/v23/blockchain.rs +++ b/client/src/client_sync/v23/blockchain.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `getblockfrompeer`. #[macro_export] diff --git a/client/src/client_sync/v23/mod.rs b/client/src/client_sync/v23/mod.rs index 8cc0102e..f6bed4b9 100644 --- a/client/src/client_sync/v23/mod.rs +++ b/client/src/client_sync/v23/mod.rs @@ -26,7 +26,7 @@ pub use crate::client_sync::{ v21::ImportDescriptorsRequest, }; -crate::define_jsonrpc_minreq_client!("v23"); +crate::define_jsonrpc_bitreq_client!("v23"); crate::impl_client_check_expected_server_version!({ [230200] }); // == Blockchain == @@ -73,6 +73,9 @@ crate::impl_client_v17__invalidate_block!(); // == Hidden == crate::impl_client_v21__add_peer_address!(); +crate::impl_client_v17__wait_for_block!(); +crate::impl_client_v17__wait_for_block_height!(); +crate::impl_client_v17__wait_for_new_block!(); // == Mining == crate::impl_client_v17__get_block_template!(); diff --git a/client/src/client_sync/v23/wallet.rs b/client/src/client_sync/v23/wallet.rs index f1d0b3de..c615a7d1 100644 --- a/client/src/client_sync/v23/wallet.rs +++ b/client/src/client_sync/v23/wallet.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `createwallet`. #[macro_export] diff --git a/client/src/client_sync/v24/blockchain.rs b/client/src/client_sync/v24/blockchain.rs index d3db015a..df7bb4c6 100644 --- a/client/src/client_sync/v24/blockchain.rs +++ b/client/src/client_sync/v24/blockchain.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `gettxspendingprevout` #[macro_export] diff --git a/client/src/client_sync/v24/mod.rs b/client/src/client_sync/v24/mod.rs index 49f4a804..427250df 100644 --- a/client/src/client_sync/v24/mod.rs +++ b/client/src/client_sync/v24/mod.rs @@ -26,7 +26,7 @@ pub use crate::client_sync::{ v23::AddressType, }; -crate::define_jsonrpc_minreq_client!("v24"); +crate::define_jsonrpc_bitreq_client!("v24"); crate::impl_client_check_expected_server_version!({ [240200] }); // == Blockchain == @@ -74,6 +74,9 @@ crate::impl_client_v17__invalidate_block!(); // == Hidden == crate::impl_client_v21__add_peer_address!(); +crate::impl_client_v17__wait_for_block!(); +crate::impl_client_v17__wait_for_block_height!(); +crate::impl_client_v17__wait_for_new_block!(); // == Mining == crate::impl_client_v17__get_block_template!(); diff --git a/client/src/client_sync/v24/wallet.rs b/client/src/client_sync/v24/wallet.rs index 8e030aa4..d259f99f 100644 --- a/client/src/client_sync/v24/wallet.rs +++ b/client/src/client_sync/v24/wallet.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `migratewallet`. #[macro_export] diff --git a/client/src/client_sync/v25/blockchain.rs b/client/src/client_sync/v25/blockchain.rs index 8592352c..9b998eef 100644 --- a/client/src/client_sync/v25/blockchain.rs +++ b/client/src/client_sync/v25/blockchain.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `scanblocks` #[macro_export] diff --git a/client/src/client_sync/v25/generating.rs b/client/src/client_sync/v25/generating.rs index 3aad1314..3b19a19b 100644 --- a/client/src/client_sync/v25/generating.rs +++ b/client/src/client_sync/v25/generating.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `generateblock`. #[macro_export] diff --git a/client/src/client_sync/v25/mod.rs b/client/src/client_sync/v25/mod.rs index 36ecc2cc..d4fa9aca 100644 --- a/client/src/client_sync/v25/mod.rs +++ b/client/src/client_sync/v25/mod.rs @@ -26,7 +26,7 @@ pub use crate::client_sync::{ v23::AddressType, }; -crate::define_jsonrpc_minreq_client!("v25"); +crate::define_jsonrpc_bitreq_client!("v25"); crate::impl_client_check_expected_server_version!({ [250200] }); // == Blockchain == @@ -75,6 +75,9 @@ crate::impl_client_v17__invalidate_block!(); // == Hidden == crate::impl_client_v21__add_peer_address!(); +crate::impl_client_v17__wait_for_block!(); +crate::impl_client_v17__wait_for_block_height!(); +crate::impl_client_v17__wait_for_new_block!(); // == Mining == crate::impl_client_v17__get_block_template!(); diff --git a/client/src/client_sync/v26/blockchain.rs b/client/src/client_sync/v26/blockchain.rs index e44ce04b..d9f30f0b 100644 --- a/client/src/client_sync/v26/blockchain.rs +++ b/client/src/client_sync/v26/blockchain.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `dumptxoutset`. #[macro_export] diff --git a/client/src/client_sync/v26/mining.rs b/client/src/client_sync/v26/mining.rs index 2e58a9ef..4a92b5f8 100644 --- a/client/src/client_sync/v26/mining.rs +++ b/client/src/client_sync/v26/mining.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `getprioritisedtransactions`. #[macro_export] diff --git a/client/src/client_sync/v26/mod.rs b/client/src/client_sync/v26/mod.rs index f7fd02f2..d06fefc7 100644 --- a/client/src/client_sync/v26/mod.rs +++ b/client/src/client_sync/v26/mod.rs @@ -28,7 +28,7 @@ pub use crate::client_sync::{ v23::AddressType, }; -crate::define_jsonrpc_minreq_client!("v26"); +crate::define_jsonrpc_bitreq_client!("v26"); crate::impl_client_check_expected_server_version!({ [260000, 260100, 260200] }); // == Blockchain == @@ -81,6 +81,9 @@ crate::impl_client_v17__invalidate_block!(); // == Hidden == crate::impl_client_v21__add_peer_address!(); +crate::impl_client_v17__wait_for_block!(); +crate::impl_client_v17__wait_for_block_height!(); +crate::impl_client_v17__wait_for_new_block!(); // == Mining == crate::impl_client_v17__get_block_template!(); diff --git a/client/src/client_sync/v26/network.rs b/client/src/client_sync/v26/network.rs index af5cf918..39acb5c5 100644 --- a/client/src/client_sync/v26/network.rs +++ b/client/src/client_sync/v26/network.rs @@ -7,7 +7,7 @@ //! Specifically this is methods found under the `== Network ==` section of the //! API docs of Bitcoin Core `v26`. //! -//! See, or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See, or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `getaddrmaninfo`. #[macro_export] diff --git a/client/src/client_sync/v26/raw_transactions.rs b/client/src/client_sync/v26/raw_transactions.rs index e173b10c..19cf74bb 100644 --- a/client/src/client_sync/v26/raw_transactions.rs +++ b/client/src/client_sync/v26/raw_transactions.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `submitpackage`. #[macro_export] diff --git a/client/src/client_sync/v27/mod.rs b/client/src/client_sync/v27/mod.rs index a4c9f449..c924ab49 100644 --- a/client/src/client_sync/v27/mod.rs +++ b/client/src/client_sync/v27/mod.rs @@ -23,7 +23,7 @@ pub use crate::client_sync::{ v23::AddressType, }; -crate::define_jsonrpc_minreq_client!("v27"); +crate::define_jsonrpc_bitreq_client!("v27"); crate::impl_client_check_expected_server_version!({ [270000, 270100, 270200] }); // == Blockchain == @@ -75,6 +75,9 @@ crate::impl_client_v17__invalidate_block!(); // == Hidden == crate::impl_client_v21__add_peer_address!(); +crate::impl_client_v17__wait_for_block!(); +crate::impl_client_v17__wait_for_block_height!(); +crate::impl_client_v17__wait_for_new_block!(); // == Mining == crate::impl_client_v17__get_block_template!(); diff --git a/client/src/client_sync/v28/mod.rs b/client/src/client_sync/v28/mod.rs index 5c2c24bf..881758d9 100644 --- a/client/src/client_sync/v28/mod.rs +++ b/client/src/client_sync/v28/mod.rs @@ -26,7 +26,7 @@ pub use crate::client_sync::{ v23::AddressType, }; -crate::define_jsonrpc_minreq_client!("v28"); +crate::define_jsonrpc_bitreq_client!("v28"); crate::impl_client_check_expected_server_version!({ [280000, 280100, 280200] }); // == Blockchain == @@ -78,6 +78,9 @@ crate::impl_client_v17__invalidate_block!(); // == Hidden == crate::impl_client_v21__add_peer_address!(); +crate::impl_client_v17__wait_for_block!(); +crate::impl_client_v17__wait_for_block_height!(); +crate::impl_client_v17__wait_for_new_block!(); // == Mining == crate::impl_client_v17__get_block_template!(); diff --git a/client/src/client_sync/v28/raw_transactions.rs b/client/src/client_sync/v28/raw_transactions.rs index 14b38696..de8f1db9 100644 --- a/client/src/client_sync/v28/raw_transactions.rs +++ b/client/src/client_sync/v28/raw_transactions.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `submitpackage`. #[macro_export] diff --git a/client/src/client_sync/v28/wallet.rs b/client/src/client_sync/v28/wallet.rs index 1ef32cae..8173f8ea 100644 --- a/client/src/client_sync/v28/wallet.rs +++ b/client/src/client_sync/v28/wallet.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `gethdkeys`. #[macro_export] diff --git a/client/src/client_sync/v29/blockchain.rs b/client/src/client_sync/v29/blockchain.rs index 06aac87a..519a368b 100644 --- a/client/src/client_sync/v29/blockchain.rs +++ b/client/src/client_sync/v29/blockchain.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `dumptxoutset`. #[macro_export] diff --git a/client/src/client_sync/v29/mod.rs b/client/src/client_sync/v29/mod.rs index d8754589..16160bbb 100644 --- a/client/src/client_sync/v29/mod.rs +++ b/client/src/client_sync/v29/mod.rs @@ -25,7 +25,7 @@ pub use crate::client_sync::{ v23::AddressType, }; -crate::define_jsonrpc_minreq_client!("v29"); +crate::define_jsonrpc_bitreq_client!("v29"); crate::impl_client_check_expected_server_version!({ [290000] }); // == Blockchain == @@ -78,6 +78,9 @@ crate::impl_client_v17__invalidate_block!(); // == Hidden == crate::impl_client_v21__add_peer_address!(); +crate::impl_client_v17__wait_for_block!(); +crate::impl_client_v17__wait_for_block_height!(); +crate::impl_client_v17__wait_for_new_block!(); // == Mining == crate::impl_client_v17__get_block_template!(); diff --git a/client/src/client_sync/v29/util.rs b/client/src/client_sync/v29/util.rs index 87ed5f25..968799ee 100644 --- a/client/src/client_sync/v29/util.rs +++ b/client/src/client_sync/v29/util.rs @@ -7,7 +7,7 @@ //! //! All macros require `Client` to be in scope. //! -//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`. +//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`. /// Implements Bitcoin Core JSON-RPC API method `deriveaddresses`. #[macro_export] diff --git a/client/src/client_sync/v30/mod.rs b/client/src/client_sync/v30/mod.rs index e62fa86c..3446ae0e 100644 --- a/client/src/client_sync/v30/mod.rs +++ b/client/src/client_sync/v30/mod.rs @@ -22,7 +22,7 @@ pub use crate::client_sync::{ v29::{TemplateRequest, TemplateRules} }; -crate::define_jsonrpc_minreq_client!("v30"); +crate::define_jsonrpc_bitreq_client!("v30"); crate::impl_client_check_expected_server_version!({ [300000] }); // == Blockchain == @@ -58,6 +58,9 @@ crate::impl_client_v23__save_mempool!(); crate::impl_client_v25__scan_blocks!(); crate::impl_client_v17__verify_chain!(); crate::impl_client_v17__verify_tx_out_proof!(); +crate::impl_client_v17__wait_for_block!(); +crate::impl_client_v17__wait_for_block_height!(); +crate::impl_client_v17__wait_for_new_block!(); // == Control == crate::impl_client_v17__get_memory_info!(); diff --git a/clippy.toml b/clippy.toml index ddca6b4c..4dc6505e 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,2 +1,2 @@ -msrv = "1.63.0" +msrv = "1.75.0" too-many-arguments-threshold = 13 diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 741bda61..ac142228 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "jsonrpc-fuzz" edition = "2021" -rust-version = "1.63.0" +rust-version = "1.75.0" version = "0.0.1" authors = ["Generated by fuzz/generate-files.sh"] publish = false @@ -11,7 +11,7 @@ cargo-fuzz = true [dependencies] honggfuzz = { version = "0.5.55", default-features = false } -jsonrpc = { path = "..", features = ["minreq_http"] } +jsonrpc = { path = "..", features = ["bitreq_http"] } serde = { version = "1.0.103", features = [ "derive" ] } serde_json = "1.0" @@ -20,8 +20,8 @@ serde_json = "1.0" unexpected_cfgs = { level = "deny", check-cfg = ['cfg(fuzzing)'] } [[bin]] -name = "minreq_http" -path = "fuzz_targets/minreq_http.rs" +name = "bitreq_http" +path = "fuzz_targets/bitreq_http.rs" [[bin]] name = "simple_http" diff --git a/fuzz/fuzz_targets/minreq_http.rs b/fuzz/fuzz_targets/bitreq_http.rs similarity index 92% rename from fuzz/fuzz_targets/minreq_http.rs rename to fuzz/fuzz_targets/bitreq_http.rs index ea358b30..90416ee0 100644 --- a/fuzz/fuzz_targets/minreq_http.rs +++ b/fuzz/fuzz_targets/bitreq_http.rs @@ -8,12 +8,12 @@ fn do_test(data: &[u8]) { { use std::io; - use jsonrpc::minreq_http::{MinreqHttpTransport, FUZZ_TCP_SOCK}; + use jsonrpc::bitreq_http::{BitreqHttpTransport, FUZZ_TCP_SOCK}; use jsonrpc::Client; *FUZZ_TCP_SOCK.lock().unwrap() = Some(io::Cursor::new(data.to_vec())); - let t = MinreqHttpTransport::builder() + let t = BitreqHttpTransport::builder() .url("localhost:123") .expect("parse url") .basic_auth("".to_string(), None) diff --git a/fuzz/generate-files.sh b/fuzz/generate-files.sh index dfca1678..9afe14bd 100755 --- a/fuzz/generate-files.sh +++ b/fuzz/generate-files.sh @@ -13,7 +13,7 @@ cat > "$REPO_DIR/fuzz/Cargo.toml" < = node.client.verify_chain(); +} + #[test] fn blockchain__verify_tx_out_proof__modelled() { let node = Node::with_wallet(Wallet::Default, &[]); node.fund_wallet(); - verify_tx_out_proof(&node).unwrap(); + + let (_address, tx) = node.create_mined_transaction(); + let txid = tx.compute_txid(); + + let proof = node.client.get_tx_out_proof(&[txid]).expect("gettxoutproof"); + + let json: VerifyTxOutProof = node.client.verify_tx_out_proof(&proof).expect("verifytxoutproof"); + let model: Result = json.into_model(); + let txids = model.unwrap(); + + // sanity check + assert_eq!(txids.0.len(), 1); } #[test] -fn blockchain__get_tx_out_proof__modelled() { +fn blockchain__wait_for_block__modelled() { let node = Node::with_wallet(Wallet::Default, &[]); node.fund_wallet(); - verify_tx_out_proof(&node).unwrap(); + let (_address, _tx) = node.create_mined_transaction(); + let block_hash = node.client.best_block_hash().expect("bestblockhash"); + + let json: WaitForBlock = node.client.wait_for_block(&block_hash).expect("waitforblock"); + let model: Result = json.into_model(); + let block = model.unwrap(); + assert_eq!(block.hash, block_hash); } #[test] -fn blockchain__verify_chain() { - let node = Node::with_wallet(Wallet::None, &[]); +fn blockchain__wait_for_block_height__modelled() { + let node = Node::with_wallet(Wallet::Default, &[]); + node.fund_wallet(); + let (_address, _tx) = node.create_mined_transaction(); + let height = node.client.get_block_count().expect("getblockcount").0; + let block_hash = node.client.best_block_hash().expect("bestblockhash"); + let target_height = height; - let _: Result = node.client.verify_chain(); + let json: WaitForBlockHeight = + node.client.wait_for_block_height(target_height).expect("waitforblockheight"); + let model: Result = json.into_model(); + let block = model.unwrap(); + assert_eq!(block.height, target_height as u32); + assert_eq!(block.hash, block_hash); } -fn verify_tx_out_proof(node: &Node) -> Result<(), client_sync::Error> { - let (_address, tx) = node.create_mined_transaction(); - let txid = tx.compute_txid(); +#[test] +fn blockchain__wait_for_new_block__modelled() { + let (node1, node2, _node3) = integration_test::three_node_network(); + node1.fund_wallet(); + node1.mine_a_block(); - let proof = node.client.get_tx_out_proof(&[txid])?; + let prev_hash = node1.client.best_block_hash().expect("bestblockhash"); + let prev_height = node1.client.get_block_count().expect("getblockcount").0; - let json: VerifyTxOutProof = node.client.verify_tx_out_proof(&proof)?; - let model: Result = json.into_model(); - let txids = model.unwrap(); + // Start waiting for a new block on node1 in a separate thread. + let handle = std::thread::spawn(move || { + let json: WaitForNewBlock = node1.client.wait_for_new_block().expect("waitfornewblock"); + let model: Result = json.into_model(); + model.unwrap() + }); + std::thread::sleep(std::time::Duration::from_millis(200)); - // sanity check - assert_eq!(txids.0.len(), 1); + // Trigger a new block on node2. + node2.mine_a_block(); - Ok(()) + let block = handle.join().expect("waitfornewblock thread panicked"); + assert_eq!(block.height, (prev_height + 1) as u32); + assert_ne!(block.hash, prev_hash); } /// Create and broadcast a child transaction spending vout 0 of the given parent mempool txid. diff --git a/jsonrpc/Cargo.toml b/jsonrpc/Cargo.toml index 98fc7055..b6a6bcdf 100644 --- a/jsonrpc/Cargo.toml +++ b/jsonrpc/Cargo.toml @@ -9,7 +9,7 @@ description = "Rust support for the JSON-RPC 2.0 protocol" keywords = [ "protocol", "json", "http", "jsonrpc" ] readme = "README.md" edition = "2021" -rust-version = "1.63.0" +rust-version = "1.75.0" exclude = ["tests", "contrib"] [package.metadata.docs.rs] @@ -20,8 +20,8 @@ rustdoc-args = ["--cfg", "docsrs"] default = [ "simple_http", "simple_tcp" ] # A bare-minimum HTTP transport. simple_http = [ "base64" ] -# A transport that uses `minreq` as the HTTP client. -minreq_http = [ "base64", "minreq" ] +# A transport that uses `bitreq` as the HTTP client. +bitreq_http = [ "base64", "bitreq" ] # Basic transport over a raw TcpListener simple_tcp = [] # Basic transport over a raw UnixStream @@ -34,7 +34,7 @@ serde = { version = "1", features = ["derive"] } serde_json = { version = "1", features = [ "raw_value" ] } base64 = { version = "0.22.1", optional = true } -minreq = { version = "2.7.0", features = ["json-using-serde"], optional = true } +bitreq = { version = "0.2.0", path = "../bitreq", features = ["json-using-serde"], optional = true } socks = { version = "0.3.4", optional = true} [lints.rust] diff --git a/jsonrpc/README.md b/jsonrpc/README.md index 40cbd5ba..707025c6 100644 --- a/jsonrpc/README.md +++ b/jsonrpc/README.md @@ -2,7 +2,7 @@ # Rust Version compatibility -This library is compatible with Rust **1.63.0** or higher. +This library is compatible with Rust **1.75.0** or higher. # Rust JSONRPC Client diff --git a/jsonrpc/contrib/test_vars.sh b/jsonrpc/contrib/test_vars.sh index 72d3c963..56bcb8eb 100644 --- a/jsonrpc/contrib/test_vars.sh +++ b/jsonrpc/contrib/test_vars.sh @@ -4,7 +4,7 @@ FEATURES_WITH_STD="" # So this is the var to use for all tests. -FEATURES_WITHOUT_STD="simple_http minreq_http simple_tcp simple_uds proxy" +FEATURES_WITHOUT_STD="simple_http bitreq_http simple_tcp simple_uds proxy" # Run these examples. EXAMPLES="" diff --git a/jsonrpc/src/http/minreq_http.rs b/jsonrpc/src/http/bitreq_http.rs similarity index 84% rename from jsonrpc/src/http/minreq_http.rs rename to jsonrpc/src/http/bitreq_http.rs index 05afba6d..20903bfc 100644 --- a/jsonrpc/src/http/minreq_http.rs +++ b/jsonrpc/src/http/bitreq_http.rs @@ -1,7 +1,7 @@ -//! This module implements the [`crate::client::Transport`] trait using [`minreq`] +//! This module implements the [`crate::client::Transport`] trait using [`bitreq`] //! as the underlying HTTP transport. //! -//! [minreq]: +//! [bitreq]: #[cfg(jsonrpc_fuzz)] use std::io::{self, Read, Write}; @@ -23,9 +23,9 @@ const DEFAULT_TIMEOUT_SECONDS: u64 = 15; #[cfg(jsonrpc_fuzz)] const DEFAULT_TIMEOUT_SECONDS: u64 = 1; -/// An HTTP transport that uses [`minreq`] and is useful for running a bitcoind RPC client. +/// An HTTP transport that uses [`bitreq`] and is useful for running a bitcoind RPC client. #[derive(Clone, Debug)] -pub struct MinreqHttpTransport { +pub struct BitreqHttpTransport { /// URL of the RPC server. url: String, /// Timeout only supports second granularity. @@ -34,9 +34,9 @@ pub struct MinreqHttpTransport { basic_auth: Option, } -impl Default for MinreqHttpTransport { +impl Default for BitreqHttpTransport { fn default() -> Self { - MinreqHttpTransport { + BitreqHttpTransport { url: format!("{}:{}", DEFAULT_URL, DEFAULT_PORT), timeout: Duration::from_secs(DEFAULT_TIMEOUT_SECONDS), basic_auth: None, @@ -44,11 +44,11 @@ impl Default for MinreqHttpTransport { } } -impl MinreqHttpTransport { - /// Constructs a new [`MinreqHttpTransport`] with default parameters. - pub fn new() -> Self { MinreqHttpTransport::default() } +impl BitreqHttpTransport { + /// Constructs a new [`BitreqHttpTransport`] with default parameters. + pub fn new() -> Self { BitreqHttpTransport::default() } - /// Returns a builder for [`MinreqHttpTransport`]. + /// Returns a builder for [`BitreqHttpTransport`]. pub fn builder() -> Builder { Builder::new() } fn request(&self, req: impl serde::Serialize) -> Result @@ -56,11 +56,11 @@ impl MinreqHttpTransport { R: for<'a> serde::de::Deserialize<'a>, { let req = match &self.basic_auth { - Some(auth) => minreq::Request::new(minreq::Method::Post, &self.url) + Some(auth) => bitreq::Request::new(bitreq::Method::Post, &self.url) .with_timeout(self.timeout.as_secs()) .with_header("Authorization", auth) .with_json(&req)?, - None => minreq::Request::new(minreq::Method::Post, &self.url) + None => bitreq::Request::new(bitreq::Method::Post, &self.url) .with_timeout(self.timeout.as_secs()) .with_json(&req)?, }; @@ -71,20 +71,20 @@ impl MinreqHttpTransport { let resp = req.send()?; match resp.json() { Ok(json) => Ok(json), - Err(minreq_err) => + Err(bitreq_err) => if resp.status_code != 200 { Err(Error::Http(HttpError { status_code: resp.status_code, body: resp.as_str().unwrap_or("").to_string(), })) } else { - Err(Error::Minreq(minreq_err)) + Err(Error::Bitreq(bitreq_err)) }, } } } -impl Transport for MinreqHttpTransport { +impl Transport for BitreqHttpTransport { fn send_request(&self, req: Request) -> Result { Ok(self.request(req)?) } @@ -96,15 +96,15 @@ impl Transport for MinreqHttpTransport { fn fmt_target(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.url) } } -/// Builder for simple bitcoind [`MinreqHttpTransport`]. +/// Builder for simple bitcoind [`BitreqHttpTransport`]. #[derive(Clone, Debug)] pub struct Builder { - tp: MinreqHttpTransport, + tp: BitreqHttpTransport, } impl Builder { /// Constructs a new [`Builder`] with default configuration and the URL to use. - pub fn new() -> Builder { Builder { tp: MinreqHttpTransport::new() } } + pub fn new() -> Builder { Builder { tp: BitreqHttpTransport::new() } } /// Sets the timeout after which requests will abort if they aren't finished. pub fn timeout(mut self, timeout: Duration) -> Self { @@ -137,22 +137,22 @@ impl Builder { /// # Examples /// /// ```no_run - /// # use jsonrpc::minreq_http::MinreqHttpTransport; + /// # use jsonrpc::bitreq_http::BitreqHttpTransport; /// # use std::fs::{self, File}; /// # use std::path::Path; /// # let cookie_file = Path::new("~/.bitcoind/.cookie"); /// let mut file = File::open(cookie_file).expect("couldn't open cookie file"); /// let mut cookie = String::new(); /// fs::read_to_string(&mut cookie).expect("couldn't read cookie file"); - /// let client = MinreqHttpTransport::builder().cookie_auth(cookie); + /// let client = BitreqHttpTransport::builder().cookie_auth(cookie); /// ``` pub fn cookie_auth>(mut self, cookie: S) -> Self { self.tp.basic_auth = Some(format!("Basic {}", &BASE64.encode(cookie.as_ref().as_bytes()))); self } - /// Builds the final [`MinreqHttpTransport`]. - pub fn build(self) -> MinreqHttpTransport { self.tp } + /// Builds the final [`BitreqHttpTransport`]. + pub fn build(self) -> BitreqHttpTransport { self.tp } } impl Default for Builder { @@ -185,8 +185,8 @@ impl error::Error for HttpError {} pub enum Error { /// JSON parsing error. Json(serde_json::Error), - /// Minreq error. - Minreq(minreq::Error), + /// Bitreq error. + Bitreq(bitreq::Error), /// HTTP error that does not contain valid JSON as body. Http(HttpError), } @@ -195,7 +195,7 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { match *self { Error::Json(ref e) => write!(f, "parsing JSON failed: {}", e), - Error::Minreq(ref e) => write!(f, "minreq: {}", e), + Error::Bitreq(ref e) => write!(f, "bitreq: {}", e), Error::Http(ref e) => write!(f, "http ({})", e), } } @@ -207,7 +207,7 @@ impl error::Error for Error { match *self { Json(ref e) => Some(e), - Minreq(ref e) => Some(e), + Bitreq(ref e) => Some(e), Http(ref e) => Some(e), } } @@ -217,8 +217,8 @@ impl From for Error { fn from(e: serde_json::Error) -> Self { Error::Json(e) } } -impl From for Error { - fn from(e: minreq::Error) -> Self { Error::Minreq(e) } +impl From for Error { + fn from(e: bitreq::Error) -> Self { Error::Bitreq(e) } } impl From for crate::Error { diff --git a/jsonrpc/src/http/mod.rs b/jsonrpc/src/http/mod.rs index 318d8c29..f6221f38 100644 --- a/jsonrpc/src/http/mod.rs +++ b/jsonrpc/src/http/mod.rs @@ -3,8 +3,8 @@ #[cfg(feature = "simple_http")] pub mod simple_http; -#[cfg(feature = "minreq_http")] -pub mod minreq_http; +#[cfg(feature = "bitreq_http")] +pub mod bitreq_http; /// The default TCP port to use for connections. /// Set to 8332, the default RPC port for bitcoind. diff --git a/jsonrpc/src/lib.rs b/jsonrpc/src/lib.rs index f6a3c690..473eba27 100644 --- a/jsonrpc/src/lib.rs +++ b/jsonrpc/src/lib.rs @@ -17,16 +17,16 @@ pub extern crate serde_json; #[cfg(feature = "base64")] pub extern crate base64; -/// Re-export `minreq` crate if the feature is set. -#[cfg(feature = "minreq")] -pub extern crate minreq; +/// Re-export `bitreq` crate if the feature is set. +#[cfg(feature = "bitreq")] +pub extern crate bitreq; pub mod client; pub mod error; pub mod http; -#[cfg(feature = "minreq_http")] -pub use http::minreq_http; +#[cfg(feature = "bitreq_http")] +pub use http::bitreq_http; #[cfg(feature = "simple_http")] pub use http::simple_http; diff --git a/node/CHANGELOG.md b/node/CHANGELOG.md index 962c40bb..9c0c233d 100644 --- a/node/CHANGELOG.md +++ b/node/CHANGELOG.md @@ -1,8 +1,8 @@ -# 0.10.0 2025-10-07 +# 0.10.0 - 2025-10-07 - Update to use latest `client v0.10.0`. -# 0.9.0 2025-09-11 +# 0.9.0 - 2025-09-11 The `types v0.9.0` release adds support for **all** remaining documented Core RPC methods. These are then pickup up in the update of `client`. @@ -12,7 +12,7 @@ Core RPC methods. These are then pickup up in the update of `client`. - Fix build on macOS. Only codesign bitcoind if necessary [#309](https://github.com/rust-bitcoin/corepc/pull/309) - Add support for Core `v28.2` [#279](https://github.com/rust-bitcoin/corepc/pull/279) -# 0.8.0 2025-05-21 +# 0.8.0 - 2025-05-21 - Add support for Bitcoin Core 29.0 [#131](https://github.com/rust-bitcoin/corepc/pull/131) - Add support for Core version 28.1 [#184](https://github.com/rust-bitcoin/corepc/pull/184) @@ -20,11 +20,11 @@ Core RPC methods. These are then pickup up in the update of `client`. - Upgrade `zip` in light of RUSTSEC-2020-0071 [#143](https://github.com/rust-bitcoin/corepc/pull/143) - Drop default features for `zip` [#130](https://github.com/rust-bitcoin/corepc/pull/130) -# 0.7.1 2025-05-05 +# 0.7.1 - 2025-05-05 - backport: bump zip in light of RUSTSEC-2020-0071 [#145](https://github.com/rust-bitcoin/corepc/pull/145) -# 0.7.0 2025-04-04 +# 0.7.0 - 2025-04-04 - Retry initial client connections [#111](https://github.com/rust-bitcoin/corepc/pull/111) diff --git a/node/Cargo.toml b/node/Cargo.toml index f98149a8..6f970dde 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -9,7 +9,7 @@ categories = ["cryptography::cryptocurrencies", "development-tools::testing"] keywords = ["bitcoin", "bitcoind", "json-rpc"] readme = "README.md" edition = "2021" -rust-version = "1.63.0" +rust-version = "1.75.0" exclude = ["tests", "contrib"] [dependencies] @@ -27,7 +27,7 @@ env_logger = { version = "0.9.3", default-features = false } anyhow = { version = "1.0.66", optional = true } bitcoin_hashes = { version = ">= 0.13, <= 0.14", optional = true } flate2 = { version = "1.0", optional = true } -minreq = { version = "2.9.1", default-features = false, features = ["https"], optional = true } +bitreq = { version = "0.2.0", path = "../bitreq", features = ["https"], optional = true } tar = { version = "0.4", optional = true } zip = { version = "0.6.6", default-features = false, features = ["bzip2", "deflate"], optional = true } @@ -42,7 +42,7 @@ zip = { version = "0.6.6", default-features = false, features = ["bzip2", "defla [features] default = ["0_17_2"] -download = ["anyhow", "bitcoin_hashes", "flate2", "tar", "minreq", "zip"] +download = ["anyhow", "bitcoin_hashes", "flate2", "tar", "bitreq", "zip"] # We support all minor releases of the latest four versions. 30_0 = ["29_0"] diff --git a/node/README.md b/node/README.md index cebc7a19..975386bb 100644 --- a/node/README.md +++ b/node/README.md @@ -57,7 +57,7 @@ RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --features download,doc --open ## Minimum Supported Rust Version (MSRV) -This library should always compile with any combination of features on **Rust 1.63.0**. +This library should always compile with any combination of features on **Rust 1.75.0**. ## Nix diff --git a/node/build.rs b/node/build.rs index dfec7348..0bdd55d8 100644 --- a/node/build.rs +++ b/node/build.rs @@ -90,7 +90,7 @@ mod download { "{}/bitcoin-core-{}/{}", download_endpoint, VERSION, download_filename ); - let resp = minreq::get(&url) + let resp = bitreq::get(&url) .send() .with_context(|| format!("cannot reach url {}", url))?; assert_eq!(resp.status_code, 200, "url {} didn't return 200", url); diff --git a/types/CHANGELOG.md b/types/CHANGELOG.md index a2df5745..62368222 100644 --- a/types/CHANGELOG.md +++ b/types/CHANGELOG.md @@ -1,14 +1,14 @@ -# 0.10.1 2025-10-10 +# 0.10.1 - 2025-10-10 - v24+ should use the correct `GetRawMempoolVerbose` [#381](https://github.com/rust-bitcoin/corepc/pull/381) -# 0.10.0 2025-10-07 +# 0.10.0 - 2025-10-07 - Add `ScriptPubKey` model [#370](https://github.com/rust-bitcoin/corepc/pull/370) - Add a feature for `serde` deny unknown fields [#367](https://github.com/rust-bitcoin/corepc/pull/367) - Fix a few of type fields in v24 and v28 fixes [#375](https://github.com/rust-bitcoin/corepc/pull/375) -# 0.9.0 2025-09-11 +# 0.9.0 - 2025-09-11 This release is massive, it delivers support for **all** documented Core RPC methods. It also adds integration testing for all the new ones and many that @@ -23,7 +23,7 @@ for also shortly, stay tuned. - Integration test all methods (excl. two that have open issues). - Add support for Core `v28.2` [#279](https://github.com/rust-bitcoin/corepc/pull/279) -# 0.8.0 2025-05-21 +# 0.8.0 - 2025-05-21 - doc: update docs for now explicit download feature flag [#177](https://github.com/rust-bitcoin/corepc/pull/177) - Implement all v17 util functions [#163](https://github.com/rust-bitcoin/corepc/pull/163) @@ -37,7 +37,7 @@ for also shortly, stay tuned. - Change `signmessage` returned signature type [#179](https://github.com/rust-bitcoin/corepc/pull/179) - Add model for `getnodeaddresses` [#191](https://github.com/rust-bitcoin/corepc/pull/191) -# 0.7.0 2025-04-04 +# 0.7.0 - 2025-04-04 - Fix `{create,load}wallet` on `v25` [#108](https://github.com/rust-bitcoin/corepc/pull/108) - Fix unloadwallet method [#110](https://github.com/rust-bitcoin/corepc/pull/110) diff --git a/types/Cargo.toml b/types/Cargo.toml index d3d4e28d..11e7dd07 100644 --- a/types/Cargo.toml +++ b/types/Cargo.toml @@ -9,7 +9,7 @@ categories = ["cryptography::cryptocurrencies"] keywords = ["bitcoin", "bitcoind", "json-rpc"] readme = "README.md" edition = "2021" -rust-version = "1.63.0" +rust-version = "1.75.0" exclude = ["tests", "contrib"] [features] diff --git a/types/README.md b/types/README.md index 30c1d8d6..5dc216e5 100644 --- a/types/README.md +++ b/types/README.md @@ -31,7 +31,7 @@ testing in the wild. ## Minimum Supported Rust Version (MSRV) -This library should always compile with any combination of features on **Rust 1.63.0**. +This library should always compile with any combination of features on **Rust 1.75.0**. ## Licensing diff --git a/types/src/model/blockchain.rs b/types/src/model/blockchain.rs index 1c43b219..87e18e59 100644 --- a/types/src/model/blockchain.rs +++ b/types/src/model/blockchain.rs @@ -739,3 +739,30 @@ pub struct ScanBlocksStart { /// Models the result of JSON-RPC method `verifytxoutproof`. #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct VerifyTxOutProof(pub Vec); + +/// Models the result of JSON-RPC method `waitforblock`. +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] +pub struct WaitForBlock { + /// The blockhash. + pub hash: BlockHash, + /// Block height. + pub height: u32, +} + +/// Models the result of JSON-RPC method `waitforblockheight`. +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] +pub struct WaitForBlockHeight { + /// The blockhash. + pub hash: BlockHash, + /// Block height. + pub height: u32, +} + +/// Models the result of JSON-RPC method `waitfornewblock`. +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] +pub struct WaitForNewBlock { + /// The blockhash. + pub hash: BlockHash, + /// Block height. + pub height: u32, +} diff --git a/types/src/model/mod.rs b/types/src/model/mod.rs index c414822b..189b4ca2 100644 --- a/types/src/model/mod.rs +++ b/types/src/model/mod.rs @@ -34,7 +34,8 @@ pub use self::{ GetMempoolDescendants, GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo, GetRawMempool, GetRawMempoolVerbose, GetTxOut, GetTxOutSetInfo, GetTxSpendingPrevout, GetTxSpendingPrevoutItem, LoadTxOutSet, MempoolEntry, MempoolEntryFees, ReceiveActivity, - ScanBlocksStart, Softfork, SoftforkType, SpendActivity, VerifyTxOutProof, + ScanBlocksStart, Softfork, SoftforkType, SpendActivity, VerifyTxOutProof, WaitForBlock, + WaitForBlockHeight, WaitForNewBlock, }, generating::{Generate, GenerateBlock, GenerateToAddress, GenerateToDescriptor}, mining::{ diff --git a/types/src/v17/hidden/error.rs b/types/src/v17/hidden/error.rs new file mode 100644 index 00000000..f326b6df --- /dev/null +++ b/types/src/v17/hidden/error.rs @@ -0,0 +1,104 @@ +// SPDX-License-Identifier: CC0-1.0 + +use core::fmt; + +use bitcoin::hex; + +use crate::error::write_err; +use crate::NumericError; + +/// Error when converting a `WaitForBlock` type into the model type. +#[derive(Debug)] +pub enum WaitForBlockError { + /// Conversion of numeric type to expected type failed. + Numeric(NumericError), + /// Conversion of the `hash` field failed. + Hash(hex::HexToArrayError), +} + +impl fmt::Display for WaitForBlockError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + Self::Numeric(ref e) => write_err!(f, "numeric"; e), + Self::Hash(ref e) => write_err!(f, "conversion of the `hash` field failed"; e), + } + } +} + +#[cfg(feature = "std")] +impl std::error::Error for WaitForBlockError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match *self { + Self::Numeric(ref e) => Some(e), + Self::Hash(ref e) => Some(e), + } + } +} + +impl From for WaitForBlockError { + fn from(e: NumericError) -> Self { Self::Numeric(e) } +} + +/// Error when converting a `WaitForBlockHeight` type into the model type. +#[derive(Debug)] +pub enum WaitForBlockHeightError { + /// Conversion of numeric type to expected type failed. + Numeric(NumericError), + /// Conversion of the `hash` field failed. + Hash(hex::HexToArrayError), +} + +impl fmt::Display for WaitForBlockHeightError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + Self::Numeric(ref e) => write_err!(f, "numeric"; e), + Self::Hash(ref e) => write_err!(f, "conversion of the `hash` field failed"; e), + } + } +} + +#[cfg(feature = "std")] +impl std::error::Error for WaitForBlockHeightError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match *self { + Self::Numeric(ref e) => Some(e), + Self::Hash(ref e) => Some(e), + } + } +} + +impl From for WaitForBlockHeightError { + fn from(e: NumericError) -> Self { Self::Numeric(e) } +} + +/// Error when converting a `WaitForNewBlock` type into the model type. +#[derive(Debug)] +pub enum WaitForNewBlockError { + /// Conversion of numeric type to expected type failed. + Numeric(NumericError), + /// Conversion of the `hash` field failed. + Hash(hex::HexToArrayError), +} + +impl fmt::Display for WaitForNewBlockError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + Self::Numeric(ref e) => write_err!(f, "numeric"; e), + Self::Hash(ref e) => write_err!(f, "conversion of the `hash` field failed"; e), + } + } +} + +#[cfg(feature = "std")] +impl std::error::Error for WaitForNewBlockError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match *self { + Self::Numeric(ref e) => Some(e), + Self::Hash(ref e) => Some(e), + } + } +} + +impl From for WaitForNewBlockError { + fn from(e: NumericError) -> Self { Self::Numeric(e) } +} diff --git a/types/src/v17/hidden/into.rs b/types/src/v17/hidden/into.rs new file mode 100644 index 00000000..9027bf4a --- /dev/null +++ b/types/src/v17/hidden/into.rs @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: CC0-1.0 + +use bitcoin::BlockHash; + +use super::{ + WaitForBlock, WaitForBlockError, WaitForBlockHeight, WaitForBlockHeightError, WaitForNewBlock, + WaitForNewBlockError, +}; +use crate::model; + +impl WaitForBlock { + /// Converts version specific type to a version nonspecific, more strongly typed type. + pub fn into_model(self) -> Result { + use WaitForBlockError as E; + + let hash = self.hash.parse::().map_err(E::Hash)?; + + Ok(model::WaitForBlock { hash, height: crate::to_u32(self.height, "height")? }) + } +} + +impl WaitForBlockHeight { + /// Converts version specific type to a version nonspecific, more strongly typed type. + pub fn into_model(self) -> Result { + use WaitForBlockHeightError as E; + + let hash = self.hash.parse::().map_err(E::Hash)?; + + Ok(model::WaitForBlockHeight { hash, height: crate::to_u32(self.height, "height")? }) + } +} + +impl WaitForNewBlock { + /// Converts version specific type to a version nonspecific, more strongly typed type. + pub fn into_model(self) -> Result { + use WaitForNewBlockError as E; + + let hash = self.hash.parse::().map_err(E::Hash)?; + + Ok(model::WaitForNewBlock { hash, height: crate::to_u32(self.height, "height")? }) + } +} diff --git a/types/src/v17/hidden/mod.rs b/types/src/v17/hidden/mod.rs new file mode 100644 index 00000000..2001c0d3 --- /dev/null +++ b/types/src/v17/hidden/mod.rs @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: CC0-1.0 + +//! The JSON-RPC API for Bitcoin Core `v0.17` - hidden. +//! +//! Types for methods that are excluded from the API docs by default. + +mod error; +mod into; + +use serde::{Deserialize, Serialize}; + +pub use self::error::{WaitForBlockError, WaitForBlockHeightError, WaitForNewBlockError}; + +/// Result of JSON-RPC method `waitforblock`. +/// +/// > waitforblock "blockhash" ( timeout ) +/// > +/// > Waits for a specific new block and returns useful info about it. +/// > +/// > Returns the current block on timeout or exit. +/// > +/// > Arguments: +/// > 1. "blockhash" (string, required) Block hash to wait for. +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))] +pub struct WaitForBlock { + /// The blockhash. + pub hash: String, + /// Block height. + pub height: i64, +} + +/// Result of JSON-RPC method `waitforblockheight`. +/// +/// > waitforblockheight "height" ( timeout ) +/// > +/// > Waits for (at least) block height and returns the height and hash +/// > of the current tip. +/// > +/// > Arguments: +/// > 1. "blockhash" (string, required) Block hash to wait for +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))] +pub struct WaitForBlockHeight { + /// The blockhash. + pub hash: String, + /// Block height. + pub height: i64, +} + +/// Result of JSON-RPC method `waitfornewblock`. +/// +/// > waitfornewblock ( timeout "current_tip" ) +/// > +/// > Waits for any new block and returns useful info about it. +/// > +/// > Returns the current block on timeout or exit. +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))] +pub struct WaitForNewBlock { + /// The blockhash. + pub hash: String, + /// Block height. + pub height: i64, +} diff --git a/types/src/v17/mod.rs b/types/src/v17/mod.rs index 44125f64..f6bfed6b 100644 --- a/types/src/v17/mod.rs +++ b/types/src/v17/mod.rs @@ -224,6 +224,7 @@ mod blockchain; mod control; mod generating; +mod hidden; mod mining; mod network; pub(crate) mod raw_transactions; @@ -248,6 +249,10 @@ pub use self::{ }, control::{GetMemoryInfoStats, Locked, Logging}, generating::{Generate, GenerateToAddress}, + hidden::{ + WaitForBlock, WaitForBlockError, WaitForBlockHeight, WaitForBlockHeightError, + WaitForNewBlock, WaitForNewBlockError, + }, mining::{ BlockTemplateTransaction, BlockTemplateTransactionError, GetBlockTemplate, GetBlockTemplateError, GetMiningInfo, diff --git a/types/src/v18/mod.rs b/types/src/v18/mod.rs index 9f719e05..9177f138 100644 --- a/types/src/v18/mod.rs +++ b/types/src/v18/mod.rs @@ -285,6 +285,7 @@ pub use crate::v17::{ SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, Softfork, SoftforkReject, TestMempoolAccept, TransactionCategory, TransactionItem, TransactionItemError, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage, - VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt, - WitnessUtxo, + VerifyTxOutProof, WaitForBlock, WaitForBlockError, WaitForBlockHeight, WaitForBlockHeightError, + WaitForNewBlock, WaitForNewBlockError, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, + WalletProcessPsbt, WitnessUtxo, }; diff --git a/types/src/v19/mod.rs b/types/src/v19/mod.rs index 81f8cd73..26378399 100644 --- a/types/src/v19/mod.rs +++ b/types/src/v19/mod.rs @@ -277,8 +277,10 @@ pub use crate::v17::{ SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject, TestMempoolAccept, TransactionCategory, TransactionItem, TransactionItemError, UploadTarget, ValidateAddress, - ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, - WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo, + ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, WaitForBlock, + WaitForBlockError, WaitForBlockHeight, WaitForBlockHeightError, WaitForNewBlock, + WaitForNewBlockError, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WalletProcessPsbt, + WitnessUtxo, }; #[doc(inline)] pub use crate::v18::{ diff --git a/types/src/v20/mod.rs b/types/src/v20/mod.rs index 0e20fd37..137ce467 100644 --- a/types/src/v20/mod.rs +++ b/types/src/v20/mod.rs @@ -272,8 +272,9 @@ pub use crate::{ SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, - VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, - WalletProcessPsbt, WitnessUtxo, + VerifyMessage, VerifyTxOutProof, WaitForBlock, WaitForBlockError, WaitForBlockHeight, + WaitForBlockHeightError, WaitForNewBlock, WaitForNewBlockError, WalletCreateFundedPsbt, + WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo, }, v18::{ ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing, diff --git a/types/src/v21/mod.rs b/types/src/v21/mod.rs index a42db85c..066ff55c 100644 --- a/types/src/v21/mod.rs +++ b/types/src/v21/mod.rs @@ -288,8 +288,9 @@ pub use crate::{ SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, - VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, - WalletProcessPsbt, WitnessUtxo, + VerifyMessage, VerifyTxOutProof, WaitForBlock, WaitForBlockError, WaitForBlockHeight, + WaitForBlockHeightError, WaitForNewBlock, WaitForNewBlockError, WalletCreateFundedPsbt, + WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo, }, v18::{ ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing, diff --git a/types/src/v22/mod.rs b/types/src/v22/mod.rs index a1b6193f..91bcaab5 100644 --- a/types/src/v22/mod.rs +++ b/types/src/v22/mod.rs @@ -290,8 +290,9 @@ pub use crate::{ SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, - VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, - WalletProcessPsbt, WitnessUtxo, + VerifyMessage, VerifyTxOutProof, WaitForBlock, WaitForBlockError, WaitForBlockHeight, + WaitForBlockHeightError, WaitForNewBlock, WaitForNewBlockError, WalletCreateFundedPsbt, + WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo, }, v18::{ ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing, diff --git a/types/src/v23/mod.rs b/types/src/v23/mod.rs index 292c8917..9779728a 100644 --- a/types/src/v23/mod.rs +++ b/types/src/v23/mod.rs @@ -291,8 +291,9 @@ pub use crate::{ SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, - VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, - WalletProcessPsbt, WitnessUtxo, + VerifyMessage, VerifyTxOutProof, WaitForBlock, WaitForBlockError, WaitForBlockHeight, + WaitForBlockHeightError, WaitForNewBlock, WaitForNewBlockError, WalletCreateFundedPsbt, + WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo, }, v18::{ ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing, diff --git a/types/src/v24/mod.rs b/types/src/v24/mod.rs index 8728519c..50be7bbe 100644 --- a/types/src/v24/mod.rs +++ b/types/src/v24/mod.rs @@ -290,8 +290,9 @@ pub use crate::{ SetTxFee, SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, - VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, - WalletProcessPsbt, WitnessUtxo, + VerifyMessage, VerifyTxOutProof, WaitForBlock, WaitForBlockError, WaitForBlockHeight, + WaitForBlockHeightError, WaitForNewBlock, WaitForNewBlockError, WalletCreateFundedPsbt, + WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo, }, v18::{ ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing, diff --git a/types/src/v25/mod.rs b/types/src/v25/mod.rs index d186e22d..24132b7d 100644 --- a/types/src/v25/mod.rs +++ b/types/src/v25/mod.rs @@ -285,8 +285,9 @@ pub use crate::{ SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, - VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, - WalletProcessPsbt, WitnessUtxo, + VerifyMessage, VerifyTxOutProof, WaitForBlock, WaitForBlockError, WaitForBlockHeight, + WaitForBlockHeightError, WaitForNewBlock, WaitForNewBlockError, WalletCreateFundedPsbt, + WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo, }, v18::{ ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing, diff --git a/types/src/v26/mod.rs b/types/src/v26/mod.rs index f2588ab3..be48a17f 100644 --- a/types/src/v26/mod.rs +++ b/types/src/v26/mod.rs @@ -303,8 +303,9 @@ pub use crate::{ SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, - VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, - WitnessUtxo, + VerifyMessage, VerifyTxOutProof, WaitForBlock, WaitForBlockError, WaitForBlockHeight, + WaitForBlockHeightError, WaitForNewBlock, WaitForNewBlockError, WalletCreateFundedPsbt, + WalletCreateFundedPsbtError, WitnessUtxo, }, v18::{ ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing, diff --git a/types/src/v27/mod.rs b/types/src/v27/mod.rs index 45e4b723..7a80045b 100644 --- a/types/src/v27/mod.rs +++ b/types/src/v27/mod.rs @@ -279,8 +279,9 @@ pub use crate::{ SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, - VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, - WitnessUtxo, + VerifyMessage, VerifyTxOutProof, WaitForBlock, WaitForBlockError, WaitForBlockHeight, + WaitForBlockHeightError, WaitForNewBlock, WaitForNewBlockError, WalletCreateFundedPsbt, + WalletCreateFundedPsbtError, WitnessUtxo, }, v18::{ ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing, diff --git a/types/src/v28/mod.rs b/types/src/v28/mod.rs index 50b96b80..302784e8 100644 --- a/types/src/v28/mod.rs +++ b/types/src/v28/mod.rs @@ -300,8 +300,9 @@ pub use crate::{ SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, SoftforkReject, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, - VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, - WitnessUtxo, + VerifyMessage, VerifyTxOutProof, WaitForBlock, WaitForBlockError, WaitForBlockHeight, + WaitForBlockHeightError, WaitForNewBlock, WaitForNewBlockError, WalletCreateFundedPsbt, + WalletCreateFundedPsbtError, WitnessUtxo, }, v18::{ ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing, diff --git a/types/src/v29/mod.rs b/types/src/v29/mod.rs index b5be8c28..a2e5a6ca 100644 --- a/types/src/v29/mod.rs +++ b/types/src/v29/mod.rs @@ -293,7 +293,9 @@ pub use crate::{ SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, - WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WitnessUtxo, + WaitForBlock, WaitForBlockError, WaitForBlockHeight, WaitForBlockHeightError, + WaitForNewBlock, WaitForNewBlockError, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, + WitnessUtxo, }, v18::{ ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing, diff --git a/types/src/v30/mod.rs b/types/src/v30/mod.rs index 1442de44..cd73423e 100644 --- a/types/src/v30/mod.rs +++ b/types/src/v30/mod.rs @@ -60,9 +60,9 @@ //! | scantxoutset | omitted | API marked as experimental | //! | verifychain | version | | //! | verifytxoutproof | version + model | | -//! | waitforblock | version + model | TODO | -//! | waitforblockheight | version + model | TODO | -//! | waitfornewblock | version + model | TODO | +//! | waitforblock | version + model | | +//! | waitforblockheight | version + model | | +//! | waitfornewblock | version + model | | //! //! //! @@ -265,7 +265,9 @@ pub use crate::{ SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, SignRawTransactionWithKey, SignRawTransactionWithWallet, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain, VerifyMessage, VerifyTxOutProof, - WalletCreateFundedPsbt, WalletCreateFundedPsbtError, WitnessUtxo, + WaitForBlock, WaitForBlockError, WaitForBlockHeight, WaitForBlockHeightError, + WaitForNewBlock, WaitForNewBlockError, WalletCreateFundedPsbt, WalletCreateFundedPsbtError, + WitnessUtxo, }, v18::{ ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,