Skip to main content

bitcoin_rpc/
lib.rs

1//! A JSON-RPC client for Bitcoin Core.
2//!
3//! The typed methods and their result types are transcribed from Bitcoin
4//! Core v31.1. Replies from v29 onward deserialize: every field Core added
5//! after v29 is an `Option` that is `None` on an older node, and each such
6//! field's docs say which release introduced it.
7//!
8//! Enable the `sync` feature for a blocking client or the `aio` feature for an
9//! async one. Neither is enabled by default.
10#![warn(missing_docs)]
11// Lets docs.rs label which feature gates each item; nightly-only, so docs.rs only.
12#![cfg_attr(docsrs, feature(doc_cfg))]
13
14mod auth;
15mod error;
16
17#[cfg(any(feature = "sync", feature = "aio"))]
18mod config;
19#[cfg(any(feature = "sync", feature = "aio"))]
20mod jsonrpc;
21#[cfg(any(feature = "sync", feature = "aio"))]
22#[cfg_attr(docsrs, doc(cfg(any(feature = "sync", feature = "aio"))))]
23pub mod params;
24
25pub mod types;
26
27#[cfg(feature = "sync")]
28#[cfg_attr(docsrs, doc(cfg(feature = "sync")))]
29pub mod sync;
30
31#[cfg(feature = "aio")]
32#[cfg_attr(docsrs, doc(cfg(feature = "aio")))]
33pub mod aio;
34
35pub use auth::Auth;
36pub use error::{Error, Result, RpcError};
37
38/// Everything you normally want in scope.
39///
40/// The sync and async method traits share names, so importing both preludes'
41/// worth of traits at once is ambiguous by design — import
42/// `prelude::sync::*` or `prelude::aio::*` when both features are on.
43pub mod prelude {
44    /// Blocking traits.
45    #[cfg(feature = "sync")]
46    #[cfg_attr(docsrs, doc(cfg(feature = "sync")))]
47    pub mod sync {
48        pub use crate::params::positional;
49        pub use crate::sync::{
50            BlockchainRpc, Client, ClientBuilder, ControlRpc, FeeRpc, MempoolRpc, MiningRpc,
51            NetworkRpc, RawTransactionsRpc, RpcCall, RpcCallExt, UtilRpc,
52        };
53    }
54
55    /// Async traits.
56    #[cfg(feature = "aio")]
57    #[cfg_attr(docsrs, doc(cfg(feature = "aio")))]
58    pub mod aio {
59        pub use crate::aio::{
60            BlockchainRpc, Client, ClientBuilder, ControlRpc, FeeRpc, MempoolRpc, MiningRpc,
61            NetworkRpc, RawTransactionsRpc, RpcCallAsync, RpcCallAsyncExt, UtilRpc,
62        };
63        pub use crate::params::positional;
64    }
65
66    pub use crate::{Auth, Error, Result, RpcError};
67
68    #[cfg(all(feature = "sync", not(feature = "aio")))]
69    pub use sync::*;
70
71    #[cfg(all(feature = "aio", not(feature = "sync")))]
72    pub use aio::*;
73}
74
75// Wires README.md's code samples in as doctests, so `cargo test
76// --features sync,aio --doc` fails if they stop compiling. Only makes sense
77// with both `sync` and `aio` on, since the README shows both clients.
78#[cfg_attr(
79    all(feature = "sync", feature = "aio"),
80    doc = include_str!("../README.md")
81)]
82mod readme_doctest {}