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 <[email protected]>
  • Loading branch information
Harshil-Jani committed Aug 1, 2023
1 parent 4773718 commit 1794af9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,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 @@ -558,6 +558,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 @@ -634,6 +636,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 @@ -676,6 +679,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 1794af9

Please sign in to comment.