Skip to content

Commit

Permalink
Adding threshold error on exceeding 1000 ways
Browse files Browse the repository at this point in the history
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
  • Loading branch information
Harshil-Jani committed Aug 7, 2023
1 parent 9a2d4f5 commit eca5f8a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,11 @@ impl Descriptor<DescriptorPublicKey> {

/// Get all possible assets for a given descriptor
pub fn get_all_assets(&self) -> Result<Vec<Assets>, Error> {
let threshold = self.count_assets();
if threshold >= 1000 {
return Err(Error::MaxAssetThresholdExceeded);
}

match self {
Descriptor::Bare(k) => Ok(k.as_inner().get_all_assets()),
Descriptor::Pkh(k) => {
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ pub enum Error {
/// At least two BIP389 key expressions in the descriptor contain tuples of
/// derivation indexes of different lengths.
MultipathDescLenMismatch,
/// Cannot get assets for this large descriptor. Exceeds 1000 assets.
MaxAssetThresholdExceeded,
}

// https://github.com/sipa/miniscript/pull/5 for discussion on this number
Expand Down Expand Up @@ -636,6 +638,7 @@ impl fmt::Display for Error {
Error::TrNoScriptCode => write!(f, "No script code for Tr descriptors"),
Error::TrNoExplicitScript => write!(f, "No script code for Tr descriptors"),
Error::MultipathDescLenMismatch => write!(f, "At least two BIP389 key expressions in the descriptor contain tuples of derivation indexes of different lengths"),
Error::MaxAssetThresholdExceeded => write!(f,"Cannot plan descriptors having more than 1000 possible spend paths."),
}
}
}
Expand Down Expand Up @@ -678,6 +681,7 @@ impl error::Error for Error {
| TrNoScriptCode
| TrNoExplicitScript
| MultipathDescLenMismatch => None,
MaxAssetThresholdExceeded => None,
Script(e) => Some(e),
AddrError(e) => Some(e),
BadPubkey(e) => Some(e),
Expand Down

0 comments on commit eca5f8a

Please sign in to comment.