Refactor GetKey for sets to internally use Xpriv::get_key()
This commit is contained in:
parent
d25c62bf45
commit
d15c57bd1f
|
@ -803,18 +803,11 @@ impl GetKey for $set<Xpriv> {
|
||||||
key_request: KeyRequest,
|
key_request: KeyRequest,
|
||||||
secp: &Secp256k1<C>
|
secp: &Secp256k1<C>
|
||||||
) -> Result<Option<PrivateKey>, Self::Error> {
|
) -> Result<Option<PrivateKey>, Self::Error> {
|
||||||
match key_request {
|
// OK to stop at the first error because Xpriv::get_key() can only fail
|
||||||
KeyRequest::Pubkey(_) => Err(GetKeyError::NotSupported),
|
// if this isn't a KeyRequest::Bip32, which would fail for all Xprivs.
|
||||||
KeyRequest::Bip32((fingerprint, path)) => {
|
self.iter()
|
||||||
for xpriv in self.iter() {
|
.find_map(|xpriv| xpriv.get_key(key_request.clone(), secp).transpose())
|
||||||
if xpriv.fingerprint(secp) == fingerprint {
|
.transpose()
|
||||||
let k = xpriv.derive_priv(secp, &path);
|
|
||||||
return Ok(Some(k.to_priv()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}}}
|
}}}
|
||||||
impl_get_key_for_set!(BTreeSet);
|
impl_get_key_for_set!(BTreeSet);
|
||||||
|
|
Loading…
Reference in New Issue