Skip to content

Commit

Permalink
Fix descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptoquick committed Jan 14, 2024
1 parent 8317922 commit 8c7caf2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/bitcoin/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,21 @@ fn get_descriptor(
fn xprv_desc(xprv: &ExtendedPrivKey, path: &str, change: u32) -> Result<String, BitcoinKeysError> {
let xprv = get_descriptor(xprv, path, change)?;

#[cfg(not(feature = "segwit"))]
Ok(format!("tr({xprv})"))
#[cfg(feature = "segwit")]
Ok(format!("wpkh({xprv})"))
}

fn xpub_desc(xprv: &ExtendedPrivKey, path: &str, change: u32) -> Result<String, BitcoinKeysError> {
let secp = Secp256k1::new();
let xprv = get_descriptor(xprv, path, change)?;
let xpub = xprv.to_public(&secp)?;

Ok(format!("tr({xpub})"))
#[cfg(not(feature = "segwit"))]
Ok(format!("tr({xprv})"))
#[cfg(feature = "segwit")]
Ok(format!("wpkh({xprv})"))
}

fn watcher_xpub(
Expand Down Expand Up @@ -245,7 +251,11 @@ pub async fn get_marketplace_descriptor() -> Result<Option<SecretString>, Bitcoi
};

let desc_xpub = DescriptorPublicKey::XPub(desc).to_string();
let tap = format!("tr({desc_xpub}/*)");

Ok(Some(SecretString(tap)))
#[cfg(not(feature = "segwit"))]
let desc_str = format!("tr({desc_xpub}/*)");
#[cfg(feature = "segwit")]
let desc_str = format!("wpkh({desc_xpub}/*)");

Ok(Some(SecretString(desc_str)))
}

0 comments on commit 8c7caf2

Please sign in to comment.