descriptors: lifting *can* fail

Not sure what i was thinking when writing this.
This commit is contained in:
Antoine Poinsot 2024-03-12 18:04:44 +01:00
parent 8d33f49935
commit f7924fb9dc
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
2 changed files with 8 additions and 1 deletions

View File

@ -25,6 +25,7 @@ pub enum LianaPolicyError {
/// The spending policy is not a valid Miniscript policy: it may for instance be malleable, or
/// overflow some limit.
InvalidPolicy(compiler::CompilerError),
PolicyAnalysis(miniscript::Error),
}
impl std::fmt::Display for LianaPolicyError {
@ -54,6 +55,7 @@ impl std::fmt::Display for LianaPolicyError {
"Descriptor is not compatible with a Liana spending policy."
),
Self::InvalidPolicy(e) => write!(f, "Invalid Miniscript policy: {}", e),
Self::PolicyAnalysis(e) => write!(f, "Analyzing the policy of the miniscript: {}", e),
}
}
}
@ -452,7 +454,7 @@ impl LianaPolicy {
};
let policy = ms
.lift()
.expect("Lifting can't fail on a Miniscript")
.map_err(LianaPolicyError::PolicyAnalysis)?
.normalized();
// The policy must always be "1 of N spending paths" with at least an always-available

View File

@ -1405,5 +1405,10 @@ mod tests {
));
}
#[test]
fn unliftable_miniscript() {
LianaDescriptor::from_str("wsh(0)").unwrap_err();
}
// TODO: test error conditions of deserialization.
}