@@ -333,12 +333,14 @@ impl DescriptorMultiXKey<bip32::Xpriv> {
333333#[ allow( missing_docs) ]
334334pub enum NonDefiniteKeyError {
335335 Wildcard ,
336+ Multipath ,
336337}
337338
338339impl fmt:: Display for NonDefiniteKeyError {
339340 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
340341 match * self {
341342 Self :: Wildcard => f. write_str ( "key with a wildcard cannot be a DerivedDescriptorKey" ) ,
343+ Self :: Multipath => f. write_str ( "multipath key cannot be a DerivedDescriptorKey" ) ,
342344 }
343345 }
344346}
@@ -1271,11 +1273,13 @@ impl DefiniteDescriptorKey {
12711273 /// Construct an instance from a descriptor key and a derivation index
12721274 ///
12731275 /// Returns `None` if the key contains a wildcard
1274- pub fn new ( key : DescriptorPublicKey ) -> Option < Self > {
1276+ pub fn new ( key : DescriptorPublicKey ) -> Result < Self , NonDefiniteKeyError > {
12751277 if key. has_wildcard ( ) {
1276- None
1278+ Err ( NonDefiniteKeyError :: Wildcard )
1279+ } else if key. is_multipath ( ) {
1280+ Err ( NonDefiniteKeyError :: Multipath )
12771281 } else {
1278- Some ( Self ( key) )
1282+ Ok ( Self ( key) )
12791283 }
12801284 }
12811285
@@ -1304,9 +1308,8 @@ impl FromStr for DefiniteDescriptorKey {
13041308 type Err = DescriptorKeyParseError ;
13051309
13061310 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
1307- let inner = DescriptorPublicKey :: from_str ( s) ?;
1308- DefiniteDescriptorKey :: new ( inner)
1309- . ok_or ( DescriptorKeyParseError :: NonDefiniteKey ( NonDefiniteKeyError :: Wildcard ) )
1311+ let d = DescriptorPublicKey :: from_str ( s) ?;
1312+ DefiniteDescriptorKey :: new ( d) . map_err ( DescriptorKeyParseError :: NonDefiniteKey )
13101313 }
13111314}
13121315
0 commit comments