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,
|
||||
secp: &Secp256k1<C>
|
||||
) -> Result<Option<PrivateKey>, 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);
|
||||
|
|
Loading…
Reference in New Issue