@@ -15,8 +15,11 @@ pub enum DecodeScriptError {
1515 Address ( address:: ParseError ) ,
1616 /// Conversion of the transaction `addresses` field failed.
1717 Addresses ( address:: ParseError ) ,
18+ /// Conversion of the transaction `segwit` field failed.
19+ Segwit ( DecodeScriptSegwitError ) ,
1820 /// Conversion of the transaction `p2sh` field failed.
1921 P2sh ( address:: ParseError ) ,
22+
2023}
2124
2225impl fmt:: Display for DecodeScriptError {
@@ -27,6 +30,7 @@ impl fmt::Display for DecodeScriptError {
2730 E :: Hex ( ref e) => write_err ! ( f, "conversion of the `hex` field failed" ; e) ,
2831 E :: Address ( ref e) => write_err ! ( f, "conversion of the `address` field failed" ; e) ,
2932 E :: Addresses ( ref e) => write_err ! ( f, "conversion of the `addresses` field failed" ; e) ,
33+ E :: Segwit ( ref e) => write_err ! ( f, "conversion of the `segwit` field failed" ; e) ,
3034 E :: P2sh ( ref e) => write_err ! ( f, "conversion of the `p2sh` field failed" ; e) ,
3135 }
3236 }
@@ -41,7 +45,49 @@ impl std::error::Error for DecodeScriptError {
4145 E :: Hex ( ref e) => Some ( e) ,
4246 E :: Address ( ref e) => Some ( e) ,
4347 E :: Addresses ( ref e) => Some ( e) ,
48+ E :: Segwit ( ref e) => Some ( e) ,
4449 E :: P2sh ( ref e) => Some ( e) ,
4550 }
4651 }
4752}
53+
54+ /// Error when converting a `DecodeScriptSegwit` type into the model type.
55+ #[ derive( Debug ) ]
56+ pub enum DecodeScriptSegwitError {
57+ /// An invalid or missing field in the `DecodeScriptSegwit` data.
58+ InvalidField ( & ' static str ) ,
59+ /// Conversion of the transaction `address` field failed.
60+ Address ( address:: ParseError ) ,
61+ /// Conversion of the transaction `addresses` field failed.
62+ Addresses ( address:: ParseError ) ,
63+ }
64+
65+ impl fmt:: Display for DecodeScriptSegwitError {
66+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
67+ use DecodeScriptSegwitError as E ;
68+
69+ match * self {
70+ E :: InvalidField ( name) =>
71+ write ! ( f, "conversion of the `segwit` field failed: invalid or missing field `{}`" , name) ,
72+ E :: Address ( ref e) =>
73+ write_err ! ( f, "conversion of the `address` field in `segwit` failed" ; e) ,
74+ E :: Addresses ( ref e) =>
75+ write_err ! ( f, "conversion of the `addresses` field in `segwit` failed" ; e) ,
76+ }
77+ }
78+ }
79+
80+ #[ cfg( feature = "std" ) ]
81+ impl std:: error:: Error for DecodeScriptSegwitError {
82+ fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
83+ use DecodeScriptSegwitError as E ;
84+
85+ match * self {
86+ E :: InvalidField ( _) => None ,
87+ E :: Address ( ref e) => Some ( e) ,
88+ E :: Addresses ( ref e) => Some ( e) ,
89+ }
90+ }
91+ }
92+
93+
0 commit comments