Skip to content

Commit

Permalink
descriptors: lifting *can* fail
Browse files Browse the repository at this point in the history
Not sure what i was thinking when writing this.
  • Loading branch information
darosior committed Mar 13, 2024
1 parent 8d33f49 commit f7924fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/descriptors/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
}
}
}
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/descriptors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,5 +1405,10 @@ mod tests {
));
}

#[test]
fn unliftable_miniscript() {
LianaDescriptor::from_str("wsh(0)").unwrap_err();
}

// TODO: test error conditions of deserialization.
}

0 comments on commit f7924fb

Please sign in to comment.