@@ -176,7 +176,7 @@ impl<K: Clone + Ord + Debug> Indexer for KeychainTxOutIndex<K> {
176
176
}
177
177
}
178
178
179
- fn apply_changeset ( & mut self , changeset : Self :: ChangeSet ) {
179
+ fn apply_changeset ( & mut self , changeset : Self :: ChangeSet ) -> Result < ( ) , InsertDescriptorError > {
180
180
self . apply_changeset ( changeset)
181
181
}
182
182
@@ -790,18 +790,22 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
790
790
}
791
791
792
792
/// Applies the `ChangeSet<K>` to the [`KeychainTxOutIndex<K>`]
793
- pub fn apply_changeset ( & mut self , changeset : ChangeSet ) {
793
+ pub fn apply_changeset ( & mut self , changeset : ChangeSet ) -> Result < ( ) , InsertDescriptorError > {
794
794
for ( & desc_id, & index) in & changeset. last_revealed {
795
795
let v = self . last_revealed . entry ( desc_id) . or_default ( ) ;
796
+ if index > BIP32_MAX_INDEX {
797
+ return Err ( InsertDescriptorError :: OutOfBounds ) ;
798
+ }
796
799
* v = index. max ( * v) ;
797
800
self . replenish_inner_index_did ( desc_id, self . lookahead ) ;
798
801
}
802
+ Ok ( ( ) )
799
803
}
800
804
}
801
805
802
806
#[ derive( Debug , PartialEq ) ]
803
807
/// Error returned from [`KeychainTxOutIndex::insert_descriptor`]
804
- pub enum InsertDescriptorError < K > {
808
+ pub enum InsertDescriptorError < K = ( ) > {
805
809
/// The descriptor has already been assigned to a keychain so you can't assign it to another
806
810
DescriptorAlreadyAssigned {
807
811
/// The descriptor you have attempted to reassign
@@ -820,6 +824,8 @@ pub enum InsertDescriptorError<K> {
820
824
Miniscript ( miniscript:: Error ) ,
821
825
/// The descriptor contains hardened derivation steps on public extended keys
822
826
HardenedDerivationXpub ,
827
+ /// The last revealed index of derivation is out of bounds
828
+ OutOfBounds ,
823
829
}
824
830
825
831
impl < K > From < miniscript:: Error > for InsertDescriptorError < K > {
@@ -854,6 +860,9 @@ impl<K: core::fmt::Debug> core::fmt::Display for InsertDescriptorError<K> {
854
860
f,
855
861
"The descriptor contains hardened derivation steps on public extended keys"
856
862
) ,
863
+ InsertDescriptorError :: OutOfBounds => {
864
+ write ! ( f, "The last revealed index of derivation is out of bounds" )
865
+ }
857
866
}
858
867
}
859
868
}
0 commit comments