Skip to content

Commit eca5f8a

Browse files
committed
Adding threshold error on exceeding 1000 ways
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
1 parent 9a2d4f5 commit eca5f8a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/descriptor/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,11 @@ impl Descriptor<DescriptorPublicKey> {
616616

617617
/// Get all possible assets for a given descriptor
618618
pub fn get_all_assets(&self) -> Result<Vec<Assets>, Error> {
619+
let threshold = self.count_assets();
620+
if threshold >= 1000 {
621+
return Err(Error::MaxAssetThresholdExceeded);
622+
}
623+
619624
match self {
620625
Descriptor::Bare(k) => Ok(k.as_inner().get_all_assets()),
621626
Descriptor::Pkh(k) => {

src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ pub enum Error {
560560
/// At least two BIP389 key expressions in the descriptor contain tuples of
561561
/// derivation indexes of different lengths.
562562
MultipathDescLenMismatch,
563+
/// Cannot get assets for this large descriptor. Exceeds 1000 assets.
564+
MaxAssetThresholdExceeded,
563565
}
564566

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

0 commit comments

Comments
 (0)