1
1
//! # Bitcoin Mock Remote Procedure Call
2
2
//!
3
- //! This library mocks [bitcoincore-rpc](https://github.com/rust-bitcoin/rust-bitcoincore-rpc)
3
+ //! bitcoin-mock-rpc is an RPC library, that builds on a mock Bitcoin ledger and
4
+ //! without a wallet or consenses implementation. It aims to provide an easier
5
+ //! way to check your Bitcoin operations without you needing to setup a Bitcoin
6
+ //! environment.
7
+ //!
8
+ //! This library mocks
9
+ //! [bitcoincore-rpc](https://github.com/rust-bitcoin/rust-bitcoincore-rpc)
4
10
//! library. This mock takes advantage of `RpcApi` trait.
5
11
//!
6
- //! Applications can implement another trait that will switch between this mock
7
- //! and the real RPC interface, for tests and production respectively.
12
+ //! ## Interface
13
+ //!
14
+ //! ```text
15
+ //! ┌────────────────────┐
16
+ //! │ │
17
+ //! │ User Application │
18
+ //! │ │
19
+ //! └────────▲───────────┘
20
+ //! │
21
+ //! ┌───────┴────────┐
22
+ //! │ │
23
+ //! │ RpcApi Trait │
24
+ //! │ Interface │
25
+ //! │ │
26
+ //! └───────▲────────┘
27
+ //! │
28
+ //! ┌───────┴─────┐
29
+ //! │ │
30
+ //! │ Mock Ledger │
31
+ //! │ │
32
+ //! └─────────────┴
33
+ //! ```
34
+ //!
35
+ //! `RpcApiWrapper` trait can be used to select between real and mock RPC. It is
36
+ //! a simple wrapper that allows you to also use methods like `Client::new()`.
37
+ //! Needs changes in your code:
38
+ //!
39
+ //! ```rust
40
+ //! use bitcoin_mock_rpc::RpcApiWrapper;
41
+ //!
42
+ //! struct MyStruct<R: RpcApiWrapper> {
43
+ //! data: u32,
44
+ //! rpc: R,
45
+ //! }
46
+ //!
47
+ //! fn my_func() {
48
+ //! let strct = MyStruct {
49
+ //! data: 0x45,
50
+ //! // This will connect to Bitcoin RPC.
51
+ //! rpc: bitcoincore_rpc::Client::new("127.0.0.1", bitcoincore_rpc::Auth::None).unwrap(),
52
+ //! };
53
+ //!
54
+ //! // Do stuff...
55
+ //! }
56
+ //!
57
+ //! fn test() {
58
+ //! let strct = MyStruct {
59
+ //! data: 0x1F,
60
+ //! // This will connect to mock RPC.
61
+ //! rpc: bitcoin_mock_rpc::Client::new("db_name", bitcoincore_rpc::Auth::None).unwrap(),
62
+ //! };
63
+ //!
64
+ //! // Do stuff...
65
+ //! }
66
+ //! ```
8
67
9
68
pub mod client;
10
69
mod ledger;
@@ -15,3 +74,5 @@ pub use client::*;
15
74
16
75
#[ cfg( feature = "rpc_server" ) ]
17
76
pub mod rpc;
77
+ #[ cfg( feature = "rpc_server" ) ]
78
+ pub use rpc:: * ;
0 commit comments