]> Untitled Git - bdk/commitdiff
Use no_run instead of ignore
authorTobin Harding <me@tobin.cc>
Tue, 11 May 2021 01:10:54 +0000 (11:10 +1000)
committerAlekos Filini <alekos.filini@gmail.com>
Wed, 9 Jun 2021 09:29:57 +0000 (11:29 +0200)
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 <alekos.filini@gmail.com>
src/lib.rs

index 756e442953c0f058ebacc03d3f9d46a07ab2dd47..284e49b9ddf5fdef9706889f9ee7afe968356350 100644 (file)
 //! ```toml
 //! bdk = "0.7.0"
 //! ```
-//!
-//! ## Sync the balance of a descriptor
-//!
-//! ### Example
-//! ```ignore
-//! use bdk::Wallet;
-//! use bdk::database::MemoryDatabase;
-//! use bdk::blockchain::{noop_progress, ElectrumBlockchain};
-//!
-//! use bdk::electrum_client::Client;
-//!
-//! fn main() -> Result<(), bdk::Error> {
-//!     let client = Client::new("ssl://electrum.blockstream.info:60002")?;
-//!     let wallet = Wallet::new(
-//!         "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
-//!         Some("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"),
-//!         bitcoin::Network::Testnet,
-//!         MemoryDatabase::default(),
-//!         ElectrumBlockchain::from(client)
-//!     )?;
-//!
-//!     wallet.sync(noop_progress(), None)?;
-//!
-//!     println!("Descriptor balance: {} SAT", wallet.get_balance()?);
-//!
-//!     Ok(())
-//! }
-//! ```
+#![cfg_attr(
+    feature = "electrum",
+    doc = r##"
+## Sync the balance of a descriptor
+
+### Example
+```no_run
+use bdk::Wallet;
+use bdk::database::MemoryDatabase;
+use bdk::blockchain::{noop_progress, ElectrumBlockchain};
+use bdk::electrum_client::Client;
+
+fn main() -> Result<(), bdk::Error> {
+    let client = Client::new("ssl://electrum.blockstream.info:60002")?;
+    let wallet = Wallet::new(
+        "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
+        Some("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"),
+        bitcoin::Network::Testnet,
+        MemoryDatabase::default(),
+        ElectrumBlockchain::from(client)
+    )?;
+
+    wallet.sync(noop_progress(), None)?;
+
+    println!("Descriptor balance: {} SAT", wallet.get_balance()?);
+
+    Ok(())
+}
+```
+"##
+)]
 //!
 //! ## Generate a few addresses
 //!
 //!     Ok(())
 //! }
 //! ```
-//!
-//! ## Create a transaction
-//!
-//! ### Example
-//! ```ignore
-//! use base64::decode;
-//! use bdk::{FeeRate, Wallet};
-//! use bdk::database::MemoryDatabase;
-//! use bdk::blockchain::{noop_progress, ElectrumBlockchain};
-//!
-//! use bdk::electrum_client::Client;
-//!
-//! use bitcoin::consensus::serialize;
-//! use bdk::wallet::AddressIndex::New;
-//!
-//! fn main() -> Result<(), bdk::Error> {
-//!     let client = Client::new("ssl://electrum.blockstream.info:60002")?;
-//!     let wallet = Wallet::new(
-//!         "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
-//!         Some("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"),
-//!         bitcoin::Network::Testnet,
-//!         MemoryDatabase::default(),
-//!         ElectrumBlockchain::from(client)
-//!     )?;
-//!
-//!     wallet.sync(noop_progress(), None)?;
-//!
-//!     let send_to = wallet.get_address(New)?;
-//!     let (psbt, details) = {
-//!         let mut builder =  wallet.build_tx();
-//!         builder
-//!             .add_recipient(send_to.script_pubkey(), 50_000)
-//!             .enable_rbf()
-//!             .do_not_spend_change()
-//!             .fee_rate(FeeRate::from_sat_per_vb(5.0))
-//!         builder.finish()?
-//!     };
-//!
-//!     println!("Transaction details: {:#?}", details);
-//!     println!("Unsigned PSBT: {}", base64::encode(&serialize(&psbt)));
-//!
-//!     Ok(())
-//! }
-//! ```
+#![cfg_attr(
+    feature = "electrum",
+    doc = r##"
+## Create a transaction
+
+### Example
+```no_run
+use base64::decode;
+
+use bdk::{FeeRate, Wallet};
+use bdk::database::MemoryDatabase;
+use bdk::blockchain::{noop_progress, ElectrumBlockchain};
+use bdk::electrum_client::Client;
+
+use bitcoin::consensus::serialize;
+use bdk::wallet::AddressIndex::New;
+
+fn main() -> Result<(), bdk::Error> {
+    let client = Client::new("ssl://electrum.blockstream.info:60002")?;
+    let wallet = Wallet::new(
+        "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)",
+        Some("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"),
+        bitcoin::Network::Testnet,
+        MemoryDatabase::default(),
+        ElectrumBlockchain::from(client)
+    )?;
+
+    wallet.sync(noop_progress(), None)?;
+
+    let send_to = wallet.get_address(New)?;
+    let (psbt, details) = {
+        let mut builder =  wallet.build_tx();
+        builder
+            .add_recipient(send_to.script_pubkey(), 50_000)
+            .enable_rbf()
+            .do_not_spend_change()
+            .fee_rate(FeeRate::from_sat_per_vb(5.0));
+        builder.finish()?
+    };
+
+    println!("Transaction details: {:#?}", details);
+    println!("Unsigned PSBT: {}", base64::encode(&serialize(&psbt)));
+
+    Ok(())
+}
+```
+"##
+)]
 //!
 //! ## Sign a transaction
 //!
 //! ### Example
-//! ```ignore
+//! ```no_run
 //! use base64::decode;
-//! use bdk::{Wallet};
-//! use bdk::database::MemoryDatabase;
-//!
 //! use bitcoin::consensus::deserialize;
 //!
+//! use bdk::{Wallet, SignOptions};
+//! use bdk::database::MemoryDatabase;
+//!
 //! fn main() -> Result<(), bdk::Error> {
 //!     let wallet = Wallet::new_offline(
 //!         "wpkh([c258d2e4/84h/1h/0h]tprv8griRPhA7342zfRyB6CqeKF8CJDXYu5pgnj1cjL1u2ngKcJha5jjTRimG82ABzJQ4MQe71CV54xfn25BbhCNfEGGJZnxvCDQCd6JkbvxW6h/0/*)",
 //!     let psbt = "...";
 //!     let mut psbt = deserialize(&base64::decode(psbt).unwrap())?;
 //!
-//!     let finalized = wallet.sign(&mut psbt, None)?;
+//!     let finalized = wallet.sign(&mut psbt, SignOptions::default())?;
 //!
 //!     Ok(())
 //! }