Skip to content

Commit ac603c4

Browse files
authored
Merge pull request #56 from chainwayxyz/documentation
Documentation improvements
2 parents 1503836 + cec8fcd commit ac603c4

File tree

3 files changed

+70
-5
lines changed

3 files changed

+70
-5
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn my_func() {
2929
let strct = MyStruct {
3030
data: 0x45,
3131
// This will connect to Bitcoin RPC.
32-
rpc: bitcoincore_rpc::Client::new(/** parameters here **/),
32+
rpc: bitcoincore_rpc::Client::new("127.0.0.1", bitcoincore_rpc::Auth::None).unwrap(),
3333
};
3434

3535
// Do stuff...
@@ -40,7 +40,7 @@ fn test() {
4040
let strct = MyStruct {
4141
data: 0x1F,
4242
// This will connect to mock RPC.
43-
rpc: bitcoin_mock_rpc::Client::new(/** parameters here **/),
43+
rpc: bitcoin_mock_rpc::Client::new("db_name", bitcoincore_rpc::Auth::None).unwrap(),
4444
};
4545

4646
// Do stuff...

src/lib.rs

+64-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,69 @@
11
//! # Bitcoin Mock Remote Procedure Call
22
//!
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)
410
//! library. This mock takes advantage of `RpcApi` trait.
511
//!
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+
//! ```
867
968
pub mod client;
1069
mod ledger;
@@ -15,3 +74,5 @@ pub use client::*;
1574

1675
#[cfg(feature = "rpc_server")]
1776
pub mod rpc;
77+
#[cfg(feature = "rpc_server")]
78+
pub use rpc::*;

src/rpc/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
//!
33
//! This crate provides an RPC server that will act like the real Bitcoin RPC
44
//! interface.
5+
//!
6+
//! WARNING: This crate is not actively maintained. And won't work correctly.
7+
//! There is so much work needs to be done in this crate. Use it in your own
8+
//! risk. `--features rpc_server` can be used to enable this crate.
59
610
use crate::{Client, RpcApiWrapper};
711
use jsonrpsee::server::middleware::rpc::RpcServiceT;

0 commit comments

Comments
 (0)