@@ -17,7 +17,20 @@ pub enum DecodeScriptError {
1717 Addresses ( address:: ParseError ) ,
1818 /// Conversion of the transaction `p2sh` field failed.
1919 P2sh ( address:: ParseError ) ,
20+ /// Conversion of the transaction `segwit` field failed.
21+ Segwit ( DecodeScriptSegwitError ) ,
2022}
23+ #[ derive( Debug ) ]
24+ pub enum DecodeScriptSegwitError {
25+ /// Conversion of the `hex` field failed.
26+ InvalidField ( & ' static str ) ,
27+ /// Conversion of the transaction `address` field failed.
28+ Address ( address:: ParseError ) ,
29+
30+ /// Conversion of the transaction `addresses` field failed.
31+ Addresses ( address:: ParseError ) ,
32+ }
33+
2134
2235impl fmt:: Display for DecodeScriptError {
2336 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
@@ -28,6 +41,7 @@ impl fmt::Display for DecodeScriptError {
2841 E :: Address ( ref e) => write_err ! ( f, "conversion of the `address` field failed" ; e) ,
2942 E :: Addresses ( ref e) => write_err ! ( f, "conversion of the `addresses` field failed" ; e) ,
3043 E :: P2sh ( ref e) => write_err ! ( f, "conversion of the `p2sh` field failed" ; e) ,
44+ E :: Segwit ( ref e) => write_err ! ( f, "conversion of the `segwit` field failed" ; e) ,
3145 }
3246 }
3347}
@@ -42,6 +56,26 @@ impl std::error::Error for DecodeScriptError {
4256 E :: Address ( ref e) => Some ( e) ,
4357 E :: Addresses ( ref e) => Some ( e) ,
4458 E :: P2sh ( ref e) => Some ( e) ,
59+ E :: Segwit ( ref e) => Some ( e) ,
4560 }
4661 }
4762}
63+
64+ impl fmt:: Display for DecodeScriptSegwitError {
65+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
66+ match self {
67+ DecodeScriptSegwitError :: InvalidField ( name) => {
68+ write ! ( f, "invalid or missing field `{}` in segwit" , name)
69+ }
70+ DecodeScriptSegwitError :: Address ( err) => {
71+ write ! ( f, "conversion of the `address` field in segwit failed: {}" , err)
72+ }
73+ DecodeScriptSegwitError :: Addresses ( err) => {
74+ write ! ( f, "conversion of the `addresses` field in segwit failed: {}" , err)
75+ }
76+ }
77+ }
78+ }
79+
80+ #[ cfg( feature = "std" ) ]
81+ impl std:: error:: Error for DecodeScriptSegwitError { }
0 commit comments