use std::str::FromStr;

use bdk::miniscript::policy;

use crate::bitcoin;

/// A miniscript-based simple transfer, equivalent to the `simple_transfer`
/// but using a Bitcoin miniscript policy. TODO: finish implementation, it's not
/// working yet.
pub(crate) async fn run() -> anyhow::Result<()> {
    let (dave, _sammy) = bitcoin::driver::setup().await?;

    tracing::info!("starting transfer policy flow");

    let policy_str = format!("pk2wsh({:?})", dave.public_key);

    let policy = policy::Concrete::<bdk::bitcoin::PublicKey>::from_str(&policy_str)
        .expect("policy compilation failed")
        .to_owned();

    tracing::info!("policy: {}", policy);
    Ok(())
}
