Skip to content

Commit 3b446c9

Browse files
tchardingafilini
andcommitted
Use no_run instead of ignore
We have an attribute `no_run` that builds but does not run example code in Rustdocs, this keeps the examples building as the codebase evolves. use `no_run` and fix example code so it builds cleanly during test run. Some examples that require the `electrum` feature to be available have been feature-gated to make sure they aren't accidentally compiled when that feature is not enabled. Co-authored-by: Alekos Filini <[email protected]>
1 parent 378167e commit 3b446c9

File tree

1 file changed

+84
-77
lines changed

1 file changed

+84
-77
lines changed

src/lib.rs

+84-77
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,37 @@
4242
//! ```toml
4343
//! bdk = "0.7.0"
4444
//! ```
45-
//!
46-
//! ## Sync the balance of a descriptor
47-
//!
48-
//! ### Example
49-
//! ```ignore
50-
//! use bdk::Wallet;
51-
//! use bdk::database::MemoryDatabase;
52-
//! use bdk::blockchain::{noop_progress, ElectrumBlockchain};
53-
//!
54-
//! use bdk::electrum_client::Client;
55-
//!
56-
//! fn main() -> Result<(), bdk::Error> {
57-
//! let client = Client::new("ssl://electrum.blockstream.info:60002")?;
58-
//! let wallet = Wallet::new(
59-
//! "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
60-
//! Some("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"),
61-
//! bitcoin::Network::Testnet,
62-
//! MemoryDatabase::default(),
63-
//! ElectrumBlockchain::from(client)
64-
//! )?;
65-
//!
66-
//! wallet.sync(noop_progress(), None)?;
67-
//!
68-
//! println!("Descriptor balance: {} SAT", wallet.get_balance()?);
69-
//!
70-
//! Ok(())
71-
//! }
72-
//! ```
45+
#![cfg_attr(
46+
feature = "electrum",
47+
doc = r##"
48+
## Sync the balance of a descriptor
49+
50+
### Example
51+
```no_run
52+
use bdk::Wallet;
53+
use bdk::database::MemoryDatabase;
54+
use bdk::blockchain::{noop_progress, ElectrumBlockchain};
55+
use bdk::electrum_client::Client;
56+
57+
fn main() -> Result<(), bdk::Error> {
58+
let client = Client::new("ssl://electrum.blockstream.info:60002")?;
59+
let wallet = Wallet::new(
60+
"wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
61+
Some("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"),
62+
bitcoin::Network::Testnet,
63+
MemoryDatabase::default(),
64+
ElectrumBlockchain::from(client)
65+
)?;
66+
67+
wallet.sync(noop_progress(), None)?;
68+
69+
println!("Descriptor balance: {} SAT", wallet.get_balance()?);
70+
71+
Ok(())
72+
}
73+
```
74+
"##
75+
)]
7376
//!
7477
//! ## Generate a few addresses
7578
//!
@@ -94,61 +97,65 @@
9497
//! Ok(())
9598
//! }
9699
//! ```
97-
//!
98-
//! ## Create a transaction
99-
//!
100-
//! ### Example
101-
//! ```ignore
102-
//! use base64::decode;
103-
//! use bdk::{FeeRate, Wallet};
104-
//! use bdk::database::MemoryDatabase;
105-
//! use bdk::blockchain::{noop_progress, ElectrumBlockchain};
106-
//!
107-
//! use bdk::electrum_client::Client;
108-
//!
109-
//! use bitcoin::consensus::serialize;
110-
//! use bdk::wallet::AddressIndex::New;
111-
//!
112-
//! fn main() -> Result<(), bdk::Error> {
113-
//! let client = Client::new("ssl://electrum.blockstream.info:60002")?;
114-
//! let wallet = Wallet::new(
115-
//! "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
116-
//! Some("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"),
117-
//! bitcoin::Network::Testnet,
118-
//! MemoryDatabase::default(),
119-
//! ElectrumBlockchain::from(client)
120-
//! )?;
121-
//!
122-
//! wallet.sync(noop_progress(), None)?;
123-
//!
124-
//! let send_to = wallet.get_address(New)?;
125-
//! let (psbt, details) = {
126-
//! let mut builder = wallet.build_tx();
127-
//! builder
128-
//! .add_recipient(send_to.script_pubkey(), 50_000)
129-
//! .enable_rbf()
130-
//! .do_not_spend_change()
131-
//! .fee_rate(FeeRate::from_sat_per_vb(5.0))
132-
//! builder.finish()?
133-
//! };
134-
//!
135-
//! println!("Transaction details: {:#?}", details);
136-
//! println!("Unsigned PSBT: {}", base64::encode(&serialize(&psbt)));
137-
//!
138-
//! Ok(())
139-
//! }
140-
//! ```
100+
#![cfg_attr(
101+
feature = "electrum",
102+
doc = r##"
103+
## Create a transaction
104+
105+
### Example
106+
```no_run
107+
use base64::decode;
108+
109+
use bdk::{FeeRate, Wallet};
110+
use bdk::database::MemoryDatabase;
111+
use bdk::blockchain::{noop_progress, ElectrumBlockchain};
112+
use bdk::electrum_client::Client;
113+
114+
use bitcoin::consensus::serialize;
115+
use bdk::wallet::AddressIndex::New;
116+
117+
fn main() -> Result<(), bdk::Error> {
118+
let client = Client::new("ssl://electrum.blockstream.info:60002")?;
119+
let wallet = Wallet::new(
120+
"wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
121+
Some("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"),
122+
bitcoin::Network::Testnet,
123+
MemoryDatabase::default(),
124+
ElectrumBlockchain::from(client)
125+
)?;
126+
127+
wallet.sync(noop_progress(), None)?;
128+
129+
let send_to = wallet.get_address(New)?;
130+
let (psbt, details) = {
131+
let mut builder = wallet.build_tx();
132+
builder
133+
.add_recipient(send_to.script_pubkey(), 50_000)
134+
.enable_rbf()
135+
.do_not_spend_change()
136+
.fee_rate(FeeRate::from_sat_per_vb(5.0));
137+
builder.finish()?
138+
};
139+
140+
println!("Transaction details: {:#?}", details);
141+
println!("Unsigned PSBT: {}", base64::encode(&serialize(&psbt)));
142+
143+
Ok(())
144+
}
145+
```
146+
"##
147+
)]
141148
//!
142149
//! ## Sign a transaction
143150
//!
144151
//! ### Example
145-
//! ```ignore
152+
//! ```no_run
146153
//! use base64::decode;
147-
//! use bdk::{Wallet};
148-
//! use bdk::database::MemoryDatabase;
149-
//!
150154
//! use bitcoin::consensus::deserialize;
151155
//!
156+
//! use bdk::{Wallet, SignOptions};
157+
//! use bdk::database::MemoryDatabase;
158+
//!
152159
//! fn main() -> Result<(), bdk::Error> {
153160
//! let wallet = Wallet::new_offline(
154161
//! "wpkh([c258d2e4/84h/1h/0h]tprv8griRPhA7342zfRyB6CqeKF8CJDXYu5pgnj1cjL1u2ngKcJha5jjTRimG82ABzJQ4MQe71CV54xfn25BbhCNfEGGJZnxvCDQCd6JkbvxW6h/0/*)",
@@ -160,7 +167,7 @@
160167
//! let psbt = "...";
161168
//! let mut psbt = deserialize(&base64::decode(psbt).unwrap())?;
162169
//!
163-
//! let finalized = wallet.sign(&mut psbt, None)?;
170+
//! let finalized = wallet.sign(&mut psbt, SignOptions::default())?;
164171
//!
165172
//! Ok(())
166173
//! }

0 commit comments

Comments
 (0)