[bdk_chain_redesign] Rm anchor type param for structs that don't use it

This commit is contained in:
志宇
2023-03-28 14:58:59 +08:00
parent 3440a05711
commit 34d0277e44
16 changed files with 174 additions and 201 deletions

View File

@@ -48,7 +48,7 @@ pub struct ScanOptions {
}
fn main() -> anyhow::Result<()> {
let (args, keymap, tracker, db) = cli::init::<ElectrumCommands, _, _>()?;
let (args, keymap, tracker, db) = cli::init::<ElectrumCommands, _>()?;
let electrum_url = match args.network {
Network::Bitcoin => "ssl://electrum.blockstream.info:50002",

View File

@@ -49,7 +49,7 @@ pub struct ScanOptions {
}
fn main() -> anyhow::Result<()> {
let (args, keymap, keychain_tracker, db) = cli::init::<EsploraCommands, _, _>()?;
let (args, keymap, keychain_tracker, db) = cli::init::<EsploraCommands, _>()?;
let esplora_url = match args.network {
Network::Bitcoin => "https://mempool.space/api",
Network::Testnet => "https://mempool.space/testnet/api",

View File

@@ -13,7 +13,7 @@ use bdk_chain::{
Descriptor, DescriptorPublicKey,
},
sparse_chain::{self, ChainPosition},
BlockAnchor, DescriptorExt, FullTxOut,
DescriptorExt, FullTxOut,
};
use bdk_coin_select::{coin_select_bnb, CoinSelector, CoinSelectorOpt, WeightedValue};
use bdk_file_store::KeychainStore;
@@ -179,16 +179,15 @@ pub struct AddrsOutput {
used: bool,
}
pub fn run_address_cmd<A, P>(
tracker: &Mutex<KeychainTracker<Keychain, A, P>>,
db: &Mutex<KeychainStore<Keychain, A, P>>,
pub fn run_address_cmd<P>(
tracker: &Mutex<KeychainTracker<Keychain, P>>,
db: &Mutex<KeychainStore<Keychain, P>>,
addr_cmd: AddressCmd,
network: Network,
) -> Result<()>
where
A: bdk_chain::BlockAnchor,
P: bdk_chain::sparse_chain::ChainPosition,
KeychainChangeSet<Keychain, A, P>: serde::Serialize + serde::de::DeserializeOwned,
KeychainChangeSet<Keychain, P>: serde::Serialize + serde::de::DeserializeOwned,
{
let mut tracker = tracker.lock().unwrap();
let txout_index = &mut tracker.txout_index;
@@ -242,9 +241,7 @@ where
}
}
pub fn run_balance_cmd<A: BlockAnchor, P: ChainPosition>(
tracker: &Mutex<KeychainTracker<Keychain, A, P>>,
) {
pub fn run_balance_cmd<P: ChainPosition>(tracker: &Mutex<KeychainTracker<Keychain, P>>) {
let tracker = tracker.lock().unwrap();
let (confirmed, unconfirmed) =
tracker
@@ -261,9 +258,9 @@ pub fn run_balance_cmd<A: BlockAnchor, P: ChainPosition>(
println!("unconfirmed: {}", unconfirmed);
}
pub fn run_txo_cmd<K: Debug + Clone + Ord, A: BlockAnchor, P: ChainPosition>(
pub fn run_txo_cmd<K: Debug + Clone + Ord, P: ChainPosition>(
txout_cmd: TxOutCmd,
tracker: &Mutex<KeychainTracker<K, A, P>>,
tracker: &Mutex<KeychainTracker<K, P>>,
network: Network,
) {
match txout_cmd {
@@ -316,11 +313,11 @@ pub fn run_txo_cmd<K: Debug + Clone + Ord, A: BlockAnchor, P: ChainPosition>(
}
#[allow(clippy::type_complexity)] // FIXME
pub fn create_tx<A: BlockAnchor, P: ChainPosition>(
pub fn create_tx<P: ChainPosition>(
value: u64,
address: Address,
coin_select: CoinSelectionAlgo,
keychain_tracker: &mut KeychainTracker<Keychain, A, P>,
keychain_tracker: &mut KeychainTracker<Keychain, P>,
keymap: &HashMap<DescriptorPublicKey, DescriptorSecretKey>,
) -> Result<(
Transaction,
@@ -529,20 +526,19 @@ pub fn create_tx<A: BlockAnchor, P: ChainPosition>(
Ok((transaction, change_info))
}
pub fn handle_commands<C: clap::Subcommand, A, P>(
pub fn handle_commands<C: clap::Subcommand, P>(
command: Commands<C>,
broadcast: impl FnOnce(&Transaction) -> Result<()>,
// we Mutex around these not because we need them for a simple CLI app but to demonstrate how
// all the stuff we're doing can be made thread-safe and not keep locks up over an IO bound.
tracker: &Mutex<KeychainTracker<Keychain, A, P>>,
store: &Mutex<KeychainStore<Keychain, A, P>>,
tracker: &Mutex<KeychainTracker<Keychain, P>>,
store: &Mutex<KeychainStore<Keychain, P>>,
network: Network,
keymap: &HashMap<DescriptorPublicKey, DescriptorSecretKey>,
) -> Result<()>
where
A: BlockAnchor,
P: ChainPosition,
KeychainChangeSet<Keychain, A, P>: serde::Serialize + serde::de::DeserializeOwned,
KeychainChangeSet<Keychain, P>: serde::Serialize + serde::de::DeserializeOwned,
{
match command {
// TODO: Make these functions return stuffs
@@ -623,18 +619,17 @@ where
}
#[allow(clippy::type_complexity)] // FIXME
pub fn init<C: clap::Subcommand, A, P>() -> anyhow::Result<(
pub fn init<C: clap::Subcommand, P>() -> anyhow::Result<(
Args<C>,
KeyMap,
// These don't need to have mutexes around them, but we want the cli example code to make it obvious how they
// are thread-safe, forcing the example developers to show where they would lock and unlock things.
Mutex<KeychainTracker<Keychain, A, P>>,
Mutex<KeychainStore<Keychain, A, P>>,
Mutex<KeychainTracker<Keychain, P>>,
Mutex<KeychainStore<Keychain, P>>,
)>
where
A: BlockAnchor,
P: sparse_chain::ChainPosition,
KeychainChangeSet<Keychain, A, P>: serde::Serialize + serde::de::DeserializeOwned,
KeychainChangeSet<Keychain, P>: serde::Serialize + serde::de::DeserializeOwned,
{
let args = Args::<C>::parse();
let secp = Secp256k1::default();
@@ -660,7 +655,7 @@ where
.add_keychain(Keychain::Internal, internal_descriptor);
};
let mut db = KeychainStore::<Keychain, A, P>::new_from_path(args.db_path.as_path())?;
let mut db = KeychainStore::<Keychain, P>::new_from_path(args.db_path.as_path())?;
if let Err(e) = db.load_into_keychain_tracker(&mut tracker) {
match tracker.chain().latest_checkpoint() {
@@ -674,8 +669,8 @@ where
Ok((args, keymap, Mutex::new(tracker), Mutex::new(db)))
}
pub fn planned_utxos<'a, AK: bdk_tmp_plan::CanDerive + Clone, A: BlockAnchor, P: ChainPosition>(
tracker: &'a KeychainTracker<Keychain, A, P>,
pub fn planned_utxos<'a, AK: bdk_tmp_plan::CanDerive + Clone, P: ChainPosition>(
tracker: &'a KeychainTracker<Keychain, P>,
assets: &'a bdk_tmp_plan::Assets<AK>,
) -> impl Iterator<Item = (bdk_tmp_plan::Plan<AK>, FullTxOut<P>)> + 'a {
tracker