@@ -66,11 +66,8 @@ impl Chain {
66
66
}
67
67
}
68
68
69
- pub ( crate ) fn address_from_script (
70
- self ,
71
- script : & Script ,
72
- ) -> Result < Address , bitcoin:: address:: Error > {
73
- Address :: from_script ( script, self . network ( ) )
69
+ pub ( crate ) fn address_from_script ( self , script : & Script ) -> Result < Address , SnafuError > {
70
+ Address :: from_script ( script, self . network ( ) ) . snafu_context ( error:: AddressConversion )
74
71
}
75
72
76
73
pub ( crate ) fn join_with_data_dir ( self , data_dir : impl AsRef < Path > ) -> PathBuf {
@@ -110,15 +107,17 @@ impl Display for Chain {
110
107
}
111
108
112
109
impl FromStr for Chain {
113
- type Err = Error ;
110
+ type Err = SnafuError ;
114
111
115
112
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
116
113
match s {
117
114
"mainnet" => Ok ( Self :: Mainnet ) ,
118
115
"regtest" => Ok ( Self :: Regtest ) ,
119
116
"signet" => Ok ( Self :: Signet ) ,
120
117
"testnet" => Ok ( Self :: Testnet ) ,
121
- _ => bail ! ( "invalid chain `{s}`" ) ,
118
+ _ => Err ( SnafuError :: InvalidChain {
119
+ chain : s. to_string ( ) ,
120
+ } ) ,
122
121
}
123
122
}
124
123
}
@@ -135,7 +134,7 @@ mod tests {
135
134
assert_eq ! ( "testnet" . parse:: <Chain >( ) . unwrap( ) , Chain :: Testnet ) ;
136
135
assert_eq ! (
137
136
"foo" . parse:: <Chain >( ) . unwrap_err( ) . to_string( ) ,
138
- "invalid chain `foo`"
137
+ "Invalid chain `foo`"
139
138
) ;
140
139
}
141
140
}
0 commit comments