diff --git a/bitcoin/src/psbt/mod.rs b/bitcoin/src/psbt/mod.rs index 09799f95e..af39d22fb 100644 --- a/bitcoin/src/psbt/mod.rs +++ b/bitcoin/src/psbt/mod.rs @@ -803,18 +803,11 @@ impl GetKey for $set { key_request: KeyRequest, secp: &Secp256k1 ) -> Result, Self::Error> { - match key_request { - KeyRequest::Pubkey(_) => Err(GetKeyError::NotSupported), - KeyRequest::Bip32((fingerprint, path)) => { - for xpriv in self.iter() { - if xpriv.fingerprint(secp) == fingerprint { - let k = xpriv.derive_priv(secp, &path); - return Ok(Some(k.to_priv())); - } - } - Ok(None) - } - } + // OK to stop at the first error because Xpriv::get_key() can only fail + // if this isn't a KeyRequest::Bip32, which would fail for all Xprivs. + self.iter() + .find_map(|xpriv| xpriv.get_key(key_request.clone(), secp).transpose()) + .transpose() } }}} impl_get_key_for_set!(BTreeSet);