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 <alekos.filini@gmail.com>
This commit is contained in:
Tobin Harding 2021-05-11 11:10:54 +10:00 committed by Alekos Filini
parent 378167efca
commit 3b446c9e14
No known key found for this signature in database
GPG Key ID: 431401E4A4530061

View File

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