From 1acaa37b5d8bee8e90ce6200f3b8b04914d2f563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=97=E5=AE=87?= Date: Thu, 13 Jun 2024 14:13:46 +0800 Subject: [PATCH] chore(chain): relax `miniscript` feature flag scope Still enable the `persist` submodule without `miniscript` feature flag. Only disable `CombinedChangeSet`. Also stop `cargo clippy` from complaining about unused imports when `miniscript` is disabled. --- crates/chain/src/lib.rs | 1 - crates/chain/src/persist.rs | 40 +++++++++++++++++++--------------- crates/chain/src/spk_client.rs | 11 +++++----- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/crates/chain/src/lib.rs b/crates/chain/src/lib.rs index 7c542aba8d..b62d665a15 100644 --- a/crates/chain/src/lib.rs +++ b/crates/chain/src/lib.rs @@ -49,7 +49,6 @@ pub use descriptor_ext::{DescriptorExt, DescriptorId}; mod spk_iter; #[cfg(feature = "miniscript")] pub use spk_iter::*; -#[cfg(feature = "miniscript")] pub mod persist; pub mod spk_client; diff --git a/crates/chain/src/persist.rs b/crates/chain/src/persist.rs index 49973c163d..2daf1585c8 100644 --- a/crates/chain/src/persist.rs +++ b/crates/chain/src/persist.rs @@ -4,18 +4,16 @@ //! The [`CombinedChangeSet`] type encapsulates a combination of [`crate`] structures that are //! typically persisted together. -use crate::{indexed_tx_graph, keychain, local_chain, Anchor, Append}; #[cfg(feature = "async")] use alloc::boxed::Box; #[cfg(feature = "async")] use async_trait::async_trait; -use bitcoin::Network; use core::convert::Infallible; -use core::default::Default; use core::fmt::{Debug, Display}; /// A changeset containing [`crate`] structures typically persisted together. #[derive(Debug, Clone, PartialEq)] +#[cfg(feature = "miniscript")] #[cfg_attr( feature = "serde", derive(crate::serde::Deserialize, crate::serde::Serialize), @@ -28,28 +26,30 @@ use core::fmt::{Debug, Display}; ) )] pub struct CombinedChangeSet { - /// Changes to the [`LocalChain`](local_chain::LocalChain). - pub chain: local_chain::ChangeSet, - /// Changes to [`IndexedTxGraph`](indexed_tx_graph::IndexedTxGraph). - pub indexed_tx_graph: indexed_tx_graph::ChangeSet>, + /// Changes to the [`LocalChain`](crate::local_chain::LocalChain). + pub chain: crate::local_chain::ChangeSet, + /// Changes to [`IndexedTxGraph`](crate::indexed_tx_graph::IndexedTxGraph). + pub indexed_tx_graph: crate::indexed_tx_graph::ChangeSet>, /// Stores the network type of the transaction data. - pub network: Option, + pub network: Option, } -impl Default for CombinedChangeSet { +#[cfg(feature = "miniscript")] +impl core::default::Default for CombinedChangeSet { fn default() -> Self { Self { - chain: Default::default(), - indexed_tx_graph: Default::default(), + chain: core::default::Default::default(), + indexed_tx_graph: core::default::Default::default(), network: None, } } } -impl Append for CombinedChangeSet { +#[cfg(feature = "miniscript")] +impl crate::Append for CombinedChangeSet { fn append(&mut self, other: Self) { - Append::append(&mut self.chain, other.chain); - Append::append(&mut self.indexed_tx_graph, other.indexed_tx_graph); + crate::Append::append(&mut self.chain, other.chain); + crate::Append::append(&mut self.indexed_tx_graph, other.indexed_tx_graph); if other.network.is_some() { debug_assert!( self.network.is_none() || self.network == other.network, @@ -64,8 +64,9 @@ impl Append for CombinedChangeSet { } } -impl From for CombinedChangeSet { - fn from(chain: local_chain::ChangeSet) -> Self { +#[cfg(feature = "miniscript")] +impl From for CombinedChangeSet { + fn from(chain: crate::local_chain::ChangeSet) -> Self { Self { chain, ..Default::default() @@ -73,10 +74,13 @@ impl From for CombinedChangeSet { } } -impl From>> +#[cfg(feature = "miniscript")] +impl From>> for CombinedChangeSet { - fn from(indexed_tx_graph: indexed_tx_graph::ChangeSet>) -> Self { + fn from( + indexed_tx_graph: crate::indexed_tx_graph::ChangeSet>, + ) -> Self { Self { indexed_tx_graph, ..Default::default() diff --git a/crates/chain/src/spk_client.rs b/crates/chain/src/spk_client.rs index fdc3be35b0..c29f397ef7 100644 --- a/crates/chain/src/spk_client.rs +++ b/crates/chain/src/spk_client.rs @@ -3,9 +3,9 @@ use crate::{ collections::BTreeMap, local_chain::CheckPoint, ConfirmationTimeHeightAnchor, TxGraph, }; -use alloc::{boxed::Box, vec::Vec}; +use alloc::boxed::Box; use bitcoin::{OutPoint, Script, ScriptBuf, Txid}; -use core::{fmt::Debug, marker::PhantomData, ops::RangeBounds}; +use core::marker::PhantomData; /// Data required to perform a spk-based blockchain client sync. /// @@ -157,12 +157,13 @@ impl SyncRequest { /// This consumes the [`SyncRequest`] and returns the updated one. #[cfg(feature = "miniscript")] #[must_use] - pub fn populate_with_revealed_spks( + pub fn populate_with_revealed_spks( self, index: &crate::keychain::KeychainTxOutIndex, - spk_range: impl RangeBounds, + spk_range: impl core::ops::RangeBounds, ) -> Self { use alloc::borrow::ToOwned; + use alloc::vec::Vec; self.chain_spks( index .revealed_spks(spk_range) @@ -222,7 +223,7 @@ impl FullScanRequest { index: &crate::keychain::KeychainTxOutIndex, ) -> Self where - K: Debug, + K: core::fmt::Debug, { let mut req = Self::from_chain_tip(chain_tip); for (keychain, spks) in index.all_unbounded_spk_iters() {