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