Fix path calculation, fix test
This commit is contained in:
parent
2a7c7d5272
commit
914719ccf4
@ -646,7 +646,7 @@ mod test {
|
||||
assert_eq!(tree.get_last_index(ScriptType::Internal).unwrap(), None);
|
||||
|
||||
let res = tree.increment_last_index(ScriptType::External).unwrap();
|
||||
assert_eq!(res, 1337);
|
||||
assert_eq!(res, 1338);
|
||||
let res = tree.increment_last_index(ScriptType::Internal).unwrap();
|
||||
assert_eq!(res, 0);
|
||||
|
||||
@ -654,7 +654,7 @@ mod test {
|
||||
tree.get_last_index(ScriptType::External).unwrap(),
|
||||
Some(1338)
|
||||
);
|
||||
assert_eq!(tree.get_last_index(ScriptType::Internal).unwrap(), Some(1));
|
||||
assert_eq!(tree.get_last_index(ScriptType::Internal).unwrap(), Some(0));
|
||||
}
|
||||
|
||||
// TODO: more tests...
|
||||
|
@ -59,6 +59,14 @@ impl DescriptorExtendedKey {
|
||||
let path_as_vec: Vec<ChildNumber> = path.clone().into();
|
||||
final_path.extend_from_slice(&path_as_vec);
|
||||
}
|
||||
let our_path: Vec<ChildNumber> = self.path_with_index(index).into();
|
||||
final_path.extend_from_slice(&our_path);
|
||||
|
||||
final_path.into()
|
||||
}
|
||||
|
||||
pub fn path_with_index(&self, index: u32) -> DerivationPath {
|
||||
let mut final_path: Vec<ChildNumber> = Vec::new();
|
||||
let our_path: Vec<ChildNumber> = self.path.clone().into();
|
||||
final_path.extend_from_slice(&our_path);
|
||||
let other_path: Vec<ChildNumber> = self.final_index.as_path(index).into();
|
||||
@ -67,6 +75,7 @@ impl DescriptorExtendedKey {
|
||||
final_path.into()
|
||||
}
|
||||
|
||||
|
||||
pub fn derive<C: secp256k1::Verification + secp256k1::Signing>(
|
||||
&self,
|
||||
ctx: &secp256k1::Secp256k1<C>,
|
||||
@ -81,10 +90,10 @@ impl DescriptorExtendedKey {
|
||||
index: u32,
|
||||
) -> Result<ExtendedPubKey, super::Error> {
|
||||
if let Some(xprv) = self.secret {
|
||||
let derive_priv = xprv.derive_priv(ctx, &self.full_path(index))?;
|
||||
let derive_priv = xprv.derive_priv(ctx, &self.path_with_index(index))?;
|
||||
Ok(ExtendedPubKey::from_private(ctx, &derive_priv))
|
||||
} else {
|
||||
Ok(self.pubkey.derive_pub(ctx, &self.full_path(index))?)
|
||||
Ok(self.pubkey.derive_pub(ctx, &self.path_with_index(index))?)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -479,7 +479,7 @@ mod test {
|
||||
.to_string(),
|
||||
"mqwpxxvfv3QbM8PU8uBx2jaNt9btQqvQNx"
|
||||
);
|
||||
assert_eq!(desc.get_secret_keys().len(), 1);
|
||||
assert_eq!(desc.get_secret_keys().into_iter().collect::<Vec<_>>().len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -503,7 +503,7 @@ mod test {
|
||||
.to_string(),
|
||||
"mqwpxxvfv3QbM8PU8uBx2jaNt9btQqvQNx"
|
||||
);
|
||||
assert_eq!(desc.get_secret_keys().len(), 0);
|
||||
assert_eq!(desc.get_secret_keys().into_iter().collect::<Vec<_>>().len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -527,7 +527,7 @@ mod test {
|
||||
.to_string(),
|
||||
"mhtuS1QaEV4HPcK4bWk4Wvpd64SUjiC5Zt"
|
||||
);
|
||||
assert_eq!(desc.get_xprv().len(), 0);
|
||||
assert_eq!(desc.get_xprv().into_iter().collect::<Vec<_>>().len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user