Fix example/doctests format
This commit is contained in:
		
							parent
							
								
									4a23070cc8
								
							
						
					
					
						commit
						224be27aa8
					
				| @ -37,7 +37,7 @@ pub type DescriptorTemplateOut = (ExtendedDescriptor, KeyMap, ValidNetworks); | |||||||
| ///
 | ///
 | ||||||
| /// ```
 | /// ```
 | ||||||
| /// use bdk::descriptor::error::Error as DescriptorError;
 | /// use bdk::descriptor::error::Error as DescriptorError;
 | ||||||
| /// use bdk::keys::{KeyError, IntoDescriptorKey};
 | /// use bdk::keys::{IntoDescriptorKey, KeyError};
 | ||||||
| /// use bdk::miniscript::Legacy;
 | /// use bdk::miniscript::Legacy;
 | ||||||
| /// use bdk::template::{DescriptorTemplate, DescriptorTemplateOut};
 | /// use bdk::template::{DescriptorTemplate, DescriptorTemplateOut};
 | ||||||
| ///
 | ///
 | ||||||
|  | |||||||
| @ -192,7 +192,7 @@ impl<Ctx: ScriptContext + 'static> ExtScriptContext for Ctx { | |||||||
| /// ```
 | /// ```
 | ||||||
| /// use bdk::bitcoin::PublicKey;
 | /// use bdk::bitcoin::PublicKey;
 | ||||||
| ///
 | ///
 | ||||||
| /// use bdk::keys::{DescriptorKey, KeyError, ScriptContext, IntoDescriptorKey};
 | /// use bdk::keys::{DescriptorKey, IntoDescriptorKey, KeyError, ScriptContext};
 | ||||||
| ///
 | ///
 | ||||||
| /// pub struct MyKeyType {
 | /// pub struct MyKeyType {
 | ||||||
| ///     pubkey: PublicKey,
 | ///     pubkey: PublicKey,
 | ||||||
| @ -211,8 +211,8 @@ impl<Ctx: ScriptContext + 'static> ExtScriptContext for Ctx { | |||||||
| /// use bdk::bitcoin::PublicKey;
 | /// use bdk::bitcoin::PublicKey;
 | ||||||
| ///
 | ///
 | ||||||
| /// use bdk::keys::{
 | /// use bdk::keys::{
 | ||||||
| ///     mainnet_network, DescriptorKey, DescriptorPublicKey, DescriptorSinglePub, KeyError,
 | ///     mainnet_network, DescriptorKey, DescriptorPublicKey, DescriptorSinglePub,
 | ||||||
| ///     ScriptContext, IntoDescriptorKey,
 | ///     IntoDescriptorKey, KeyError, ScriptContext,
 | ||||||
| /// };
 | /// };
 | ||||||
| ///
 | ///
 | ||||||
| /// pub struct MyKeyType {
 | /// pub struct MyKeyType {
 | ||||||
| @ -237,7 +237,7 @@ impl<Ctx: ScriptContext + 'static> ExtScriptContext for Ctx { | |||||||
| /// ```
 | /// ```
 | ||||||
| /// use bdk::bitcoin::PublicKey;
 | /// use bdk::bitcoin::PublicKey;
 | ||||||
| ///
 | ///
 | ||||||
| /// use bdk::keys::{DescriptorKey, ExtScriptContext, KeyError, ScriptContext, IntoDescriptorKey};
 | /// use bdk::keys::{DescriptorKey, ExtScriptContext, IntoDescriptorKey, KeyError, ScriptContext};
 | ||||||
| ///
 | ///
 | ||||||
| /// pub struct MyKeyType {
 | /// pub struct MyKeyType {
 | ||||||
| ///     is_legacy: bool,
 | ///     is_legacy: bool,
 | ||||||
| @ -266,7 +266,7 @@ impl<Ctx: ScriptContext + 'static> ExtScriptContext for Ctx { | |||||||
| /// use bdk::bitcoin::PublicKey;
 | /// use bdk::bitcoin::PublicKey;
 | ||||||
| /// use std::str::FromStr;
 | /// use std::str::FromStr;
 | ||||||
| ///
 | ///
 | ||||||
| /// use bdk::keys::{DescriptorKey, KeyError, IntoDescriptorKey};
 | /// use bdk::keys::{DescriptorKey, IntoDescriptorKey, KeyError};
 | ||||||
| ///
 | ///
 | ||||||
| /// pub struct MySegwitOnlyKeyType {
 | /// pub struct MySegwitOnlyKeyType {
 | ||||||
| ///     pubkey: PublicKey,
 | ///     pubkey: PublicKey,
 | ||||||
|  | |||||||
| @ -46,17 +46,25 @@ | |||||||
| //!         let mut selected_amount = 0;
 | //!         let mut selected_amount = 0;
 | ||||||
| //!         let mut additional_weight = 0;
 | //!         let mut additional_weight = 0;
 | ||||||
| //!         let all_utxos_selected = required_utxos
 | //!         let all_utxos_selected = required_utxos
 | ||||||
| //!             .into_iter().chain(optional_utxos)
 | //!             .into_iter()
 | ||||||
| //!             .scan((&mut selected_amount, &mut additional_weight), |(selected_amount, additional_weight), weighted_utxo| {
 | //!             .chain(optional_utxos)
 | ||||||
| //!                 **selected_amount += weighted_utxo.utxo.txout().value;
 | //!             .scan(
 | ||||||
| //!                 **additional_weight += TXIN_BASE_WEIGHT + weighted_utxo.satisfaction_weight;
 | //!                 (&mut selected_amount, &mut additional_weight),
 | ||||||
| //!                 Some(weighted_utxo.utxo)
 | //!                 |(selected_amount, additional_weight), weighted_utxo| {
 | ||||||
| //!             })
 | //!                     **selected_amount += weighted_utxo.utxo.txout().value;
 | ||||||
|  | //!                     **additional_weight += TXIN_BASE_WEIGHT + weighted_utxo.satisfaction_weight;
 | ||||||
|  | //!                     Some(weighted_utxo.utxo)
 | ||||||
|  | //!                 },
 | ||||||
|  | //!             )
 | ||||||
| //!             .collect::<Vec<_>>();
 | //!             .collect::<Vec<_>>();
 | ||||||
| //!         let additional_fees = additional_weight as f32 * fee_rate.as_sat_vb() / 4.0;
 | //!         let additional_fees = additional_weight as f32 * fee_rate.as_sat_vb() / 4.0;
 | ||||||
| //!         let amount_needed_with_fees = (fee_amount + additional_fees).ceil() as u64 + amount_needed;
 | //!         let amount_needed_with_fees =
 | ||||||
| //!         if  amount_needed_with_fees > selected_amount {
 | //!             (fee_amount + additional_fees).ceil() as u64 + amount_needed;
 | ||||||
| //!             return Err(bdk::Error::InsufficientFunds{ needed: amount_needed_with_fees, available: selected_amount });
 | //!         if amount_needed_with_fees > selected_amount {
 | ||||||
|  | //!             return Err(bdk::Error::InsufficientFunds {
 | ||||||
|  | //!                 needed: amount_needed_with_fees,
 | ||||||
|  | //!                 available: selected_amount,
 | ||||||
|  | //!             });
 | ||||||
| //!         }
 | //!         }
 | ||||||
| //!
 | //!
 | ||||||
| //!         Ok(CoinSelectionResult {
 | //!         Ok(CoinSelectionResult {
 | ||||||
| @ -72,8 +80,7 @@ | |||||||
| //! let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap();
 | //! let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap();
 | ||||||
| //! let (psbt, details) = {
 | //! let (psbt, details) = {
 | ||||||
| //!     let mut builder = wallet.build_tx().coin_selection(AlwaysSpendEverything);
 | //!     let mut builder = wallet.build_tx().coin_selection(AlwaysSpendEverything);
 | ||||||
| //!     builder
 | //!     builder.add_recipient(to_address.script_pubkey(), 50_000);
 | ||||||
| //!         .add_recipient(to_address.script_pubkey(), 50_000);
 |  | ||||||
| //!     builder.finish()?
 | //!     builder.finish()?
 | ||||||
| //! };
 | //! };
 | ||||||
| //!
 | //!
 | ||||||
|  | |||||||
| @ -87,9 +87,9 @@ impl TxBuilderContext for BumpFee {} | |||||||
| /// let (psbt1, details) = {
 | /// let (psbt1, details) = {
 | ||||||
| ///     let mut builder = wallet.build_tx();
 | ///     let mut builder = wallet.build_tx();
 | ||||||
| ///     builder
 | ///     builder
 | ||||||
| ///        .ordering(TxOrdering::Untouched)
 | ///         .ordering(TxOrdering::Untouched)
 | ||||||
| ///        .add_recipient(addr1.script_pubkey(), 50_000)
 | ///         .add_recipient(addr1.script_pubkey(), 50_000)
 | ||||||
| ///        .add_recipient(addr2.script_pubkey(), 50_000);
 | ///         .add_recipient(addr2.script_pubkey(), 50_000);
 | ||||||
| ///     builder.finish()?
 | ///     builder.finish()?
 | ||||||
| /// };
 | /// };
 | ||||||
| ///
 | ///
 | ||||||
| @ -103,7 +103,10 @@ impl TxBuilderContext for BumpFee {} | |||||||
| ///     builder.finish()?
 | ///     builder.finish()?
 | ||||||
| /// };
 | /// };
 | ||||||
| ///
 | ///
 | ||||||
| /// assert_eq!(psbt1.global.unsigned_tx.output[..2], psbt2.global.unsigned_tx.output[..2]);
 | /// assert_eq!(
 | ||||||
|  | ///     psbt1.global.unsigned_tx.output[..2],
 | ||||||
|  | ///     psbt2.global.unsigned_tx.output[..2]
 | ||||||
|  | /// );
 | ||||||
| /// # Ok::<(), bdk::Error>(())
 | /// # Ok::<(), bdk::Error>(())
 | ||||||
| /// ```
 | /// ```
 | ||||||
| ///
 | ///
 | ||||||
| @ -246,7 +249,8 @@ impl<'a, B, D: BatchDatabase, Cs: CoinSelectionAlgorithm<D>, Ctx: TxBuilderConte | |||||||
|     /// let mut path = BTreeMap::new();
 |     /// let mut path = BTreeMap::new();
 | ||||||
|     /// path.insert("aabbccdd".to_string(), vec![0, 1]);
 |     /// path.insert("aabbccdd".to_string(), vec![0, 1]);
 | ||||||
|     ///
 |     ///
 | ||||||
|     /// let builder = wallet.build_tx()
 |     /// let builder = wallet
 | ||||||
|  |     ///     .build_tx()
 | ||||||
|     ///     .add_recipient(to_address.script_pubkey(), 50_000)
 |     ///     .add_recipient(to_address.script_pubkey(), 50_000)
 | ||||||
|     ///     .policy_path(path, KeychainKind::External);
 |     ///     .policy_path(path, KeychainKind::External);
 | ||||||
|     ///
 |     ///
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user