@@ -66,14 +66,15 @@ impl Adapter for EthereumAdapter {
66
66
67
67
fn unlock ( & self ) -> AdapterResult < bool > {
68
68
let json_file = File :: open ( & Path :: new ( & self . keystore_json ) . to_path_buf ( ) )
69
- . map_err ( |_| map_io_error ( "Invalid keystore location provided" ) ) ?;
69
+ . map_err ( |_| map_error ( "Invalid keystore location provided" ) ) ?;
70
70
71
71
let account = SafeAccount :: from_file (
72
- serde_json:: from_reader ( json_file) . unwrap ( ) ,
72
+ serde_json:: from_reader ( json_file)
73
+ . map_err ( |_| map_error ( "Invalid keystore location provided" ) ) ?,
73
74
None ,
74
75
& Some ( self . keystore_pwd . clone ( ) ) ,
75
76
)
76
- . map_err ( |_| map_io_error ( "Failed to create account" ) ) ?;
77
+ . map_err ( |_| map_error ( "Failed to create account" ) ) ?;
77
78
78
79
self . wallet . replace ( Some ( account) ) ;
79
80
@@ -86,7 +87,7 @@ impl Adapter for EthereumAdapter {
86
87
Some ( wallet) => {
87
88
let public = & wallet
88
89
. public ( & self . keystore_pwd )
89
- . map_err ( |_| map_io_error ( "Failed to get public key" ) ) ?;
90
+ . map_err ( |_| map_error ( "Failed to get public key" ) ) ?;
90
91
let address = format ! ( "{:?}" , public_to_address( public) ) ;
91
92
let checksum_address = eth_checksum:: checksum ( & address) ;
92
93
Ok ( checksum_address)
@@ -103,7 +104,7 @@ impl Adapter for EthereumAdapter {
103
104
Some ( wallet) => {
104
105
let wallet_sign = wallet
105
106
. sign ( & self . keystore_pwd , & message)
106
- . map_err ( |_| map_io_error ( "failed to sign messages" ) ) ?;
107
+ . map_err ( |_| map_error ( "failed to sign messages" ) ) ?;
107
108
let signature: Signature = wallet_sign. into_electrum ( ) . into ( ) ;
108
109
Ok ( format ! ( "0x{}" , signature) )
109
110
}
@@ -135,18 +136,18 @@ impl Adapter for EthereumAdapter {
135
136
136
137
fn validate_channel ( & self , channel : & Channel ) -> AdapterResult < bool > {
137
138
let ( _eloop, transport) = web3:: transports:: Http :: new ( & self . config . ethereum_network )
138
- . map_err ( |_| map_io_error ( "Failed to initialise web3 transport" ) ) ?;
139
+ . map_err ( |_| map_error ( "Failed to initialise web3 transport" ) ) ?;
139
140
let web3 = web3:: Web3 :: new ( transport) ;
140
141
let contract_address = Address :: from_slice ( self . config . ethereum_core_address . as_bytes ( ) ) ;
141
142
142
143
let contract = Contract :: from_json ( web3. eth ( ) , contract_address, & ADEXCORE_ABI )
143
- . map_err ( |_| map_io_error ( "Failed to initialise web3 transport" ) ) ?;
144
+ . map_err ( |_| map_error ( "Failed to initialise web3 transport" ) ) ?;
144
145
145
146
let eth_channel: EthereumChannel = channel. into ( ) ;
146
147
147
148
let channel_id = eth_channel
148
149
. hash_hex ( & self . config . ethereum_core_address )
149
- . map_err ( |_| map_io_error ( "Failed to hash the channel id" ) ) ?;
150
+ . map_err ( |_| map_error ( "Failed to hash the channel id" ) ) ?;
150
151
151
152
if channel_id != channel. id {
152
153
return Err ( AdapterError :: Configuration (
@@ -178,7 +179,7 @@ impl Adapter for EthereumAdapter {
178
179
let contract_query = contract. query ( "states" , channel_id, None , Options :: default ( ) , None ) ;
179
180
let channel_status: U256 = contract_query
180
181
. wait ( )
181
- . map_err ( |_| map_io_error ( "contract channel status query failed" ) ) ?;
182
+ . map_err ( |_| map_error ( "contract channel status query failed" ) ) ?;
182
183
183
184
if channel_status != 1 . into ( ) {
184
185
return Err ( AdapterError :: Configuration (
@@ -212,20 +213,20 @@ impl Adapter for EthereumAdapter {
212
213
Some ( identity) => {
213
214
let ( _eloop, transport) =
214
215
web3:: transports:: Http :: new ( & self . config . ethereum_network )
215
- . map_err ( |_| map_io_error ( "Failed to initialise web3 transport" ) ) ?;
216
+ . map_err ( |_| map_error ( "Failed to initialise web3 transport" ) ) ?;
216
217
let web3 = web3:: Web3 :: new ( transport) ;
217
218
218
219
let contract_address =
219
220
Address :: from_slice ( self . config . ethereum_core_address . as_bytes ( ) ) ;
220
221
221
222
let contract = Contract :: from_json ( web3. eth ( ) , contract_address, & IDENTITY_ABI )
222
- . map_err ( |_| map_io_error ( "failed to init identity contract" ) ) ?;
223
+ . map_err ( |_| map_error ( "failed to init identity contract" ) ) ?;
223
224
224
225
let contract_query =
225
226
contract. query ( "privileges" , verified. from , None , Options :: default ( ) , None ) ;
226
227
let priviledge_level: U256 = contract_query
227
228
. wait ( )
228
- . map_err ( |_| map_io_error ( "failed query priviledge level on contract" ) ) ?;
229
+ . map_err ( |_| map_error ( "failed query priviledge level on contract" ) ) ?;
229
230
230
231
if priviledge_level == 0 . into ( ) {
231
232
return Err ( AdapterError :: Authorization (
@@ -264,7 +265,7 @@ impl Adapter for EthereumAdapter {
264
265
address : None ,
265
266
} ;
266
267
let token = ewt_sign ( & wallet, & self . keystore_pwd , & payload)
267
- . map_err ( |_| map_io_error ( "Failed to sign token" ) ) ?;
268
+ . map_err ( |_| map_error ( "Failed to sign token" ) ) ?;
268
269
269
270
self . tokens_for_auth
270
271
. borrow_mut ( )
@@ -355,7 +356,7 @@ pub fn ewt_sign(
355
356
) ) ) ;
356
357
let signature: Signature = signer
357
358
. sign ( password, & message)
358
- . map_err ( |_| map_io_error ( "sign message" ) ) ?
359
+ . map_err ( |_| map_error ( "sign message" ) ) ?
359
360
. into_electrum ( )
360
361
. into ( ) ;
361
362
@@ -389,8 +390,8 @@ pub fn ewt_verify(token: &str) -> Result<VerifyPayload, Box<dyn Error>> {
389
390
Ok ( verified_payload)
390
391
}
391
392
392
- fn map_io_error ( err : & str ) -> AdapterError {
393
- AdapterError :: IO ( err. to_string ( ) )
393
+ fn map_error ( err : & str ) -> AdapterError {
394
+ AdapterError :: Failed ( err. to_string ( ) )
394
395
}
395
396
396
397
#[ cfg( test) ]
0 commit comments