1- extern crate indy_crypto;
2- extern crate serde_json;
3-
41use errors:: common:: CommonError ;
52use errors:: did:: DidError ;
63use errors:: wallet:: WalletError ;
@@ -10,11 +7,11 @@ use domain::crypto::did::{MyDidInfo, Did, TheirDidInfo, TheirDid, TemporaryDid,
107use domain:: ledger:: response:: Reply ;
118use domain:: ledger:: nym:: { GetNymReplyResult , GetNymResultDataV0 } ;
129use domain:: ledger:: attrib:: { GetAttrReplyResult , AttribData , Endpoint } ;
13- use services:: pool:: PoolService ;
1410use services:: wallet:: { WalletService , RecordOptions , SearchOptions } ;
1511use services:: crypto:: CryptoService ;
1612use services:: ledger:: LedgerService ;
1713
14+ use serde_json;
1815use std:: error:: Error ;
1916use std:: rc:: Rc ;
2017use std:: str;
@@ -24,10 +21,7 @@ use commands::ledger::LedgerCommand;
2421use commands:: { Command , CommandExecutor } ;
2522use std:: collections:: HashMap ;
2623use utils:: sequence:: SequenceUtils ;
27- use utils:: crypto:: base58:: Base58 ;
28- use self :: indy_crypto:: utils:: json:: { JsonEncodable , JsonDecodable } ;
29-
30- use super :: utils:: check_wallet_and_pool_handles_consistency;
24+ use utils:: crypto:: base58;
3125
3226pub enum DidCommand {
3327 CreateAndStoreMyDid (
@@ -105,10 +99,6 @@ macro_rules! ensure_their_did {
10599 ( $self_: ident, $wallet_handle: ident, $pool_handle: ident, $their_did: ident, $deferred_cmd: expr, $cb: ident) => ( match $self_. _wallet_get_their_did( $wallet_handle, & $their_did) {
106100 Ok ( val) => val,
107101 Err ( WalletError :: ItemNotFound ) => {
108-
109- check_wallet_and_pool_handles_consistency!( $self_. wallet_service, $self_. pool_service,
110- $wallet_handle, $pool_handle, $cb) ;
111-
112102 // No their their_did present in the wallet. Defer this command until it is fetched from ledger.
113103 return $self_. _fetch_their_did_from_ledger( $wallet_handle, $pool_handle, & $their_did, $deferred_cmd) ;
114104 }
@@ -117,20 +107,17 @@ macro_rules! ensure_their_did {
117107}
118108
119109pub struct DidCommandExecutor {
120- pool_service : Rc < PoolService > ,
121110 wallet_service : Rc < WalletService > ,
122111 crypto_service : Rc < CryptoService > ,
123112 ledger_service : Rc < LedgerService > ,
124113 deferred_commands : RefCell < HashMap < i32 , DidCommand > > ,
125114}
126115
127116impl DidCommandExecutor {
128- pub fn new ( pool_service : Rc < PoolService > ,
129- wallet_service : Rc < WalletService > ,
117+ pub fn new ( wallet_service : Rc < WalletService > ,
130118 crypto_service : Rc < CryptoService > ,
131119 ledger_service : Rc < LedgerService > ) -> DidCommandExecutor {
132120 DidCommandExecutor {
133- pool_service,
134121 wallet_service,
135122 crypto_service,
136123 ledger_service,
@@ -208,7 +195,7 @@ impl DidCommandExecutor {
208195 my_did_info_json : & str ) -> Result < ( String , String ) , IndyError > {
209196 debug ! ( "create_and_store_my_did >>> wallet_handle: {:?}, my_did_info_json: {:?}" , wallet_handle, my_did_info_json) ;
210197
211- let my_did_info = MyDidInfo :: from_json ( & my_did_info_json)
198+ let my_did_info: MyDidInfo = serde_json :: from_str ( & my_did_info_json)
212199 . map_err ( map_err_trace ! ( ) )
213200 . map_err ( |err|
214201 CommonError :: InvalidStructure (
@@ -238,7 +225,7 @@ impl DidCommandExecutor {
238225
239226 self . crypto_service . validate_did ( my_did) ?;
240227
241- let key_info: KeyInfo = KeyInfo :: from_json ( key_info_json)
228+ let key_info: KeyInfo = serde_json :: from_str ( key_info_json)
242229 . map_err ( map_err_trace ! ( ) )
243230 . map_err ( |err|
244231 CommonError :: InvalidStructure ( format ! ( "Invalid KeyInfo json: {}" , err. description( ) ) ) ) ?;
@@ -284,7 +271,7 @@ impl DidCommandExecutor {
284271 their_did_info_json : & str ) -> Result < ( ) , IndyError > {
285272 debug ! ( "store_their_did >>> wallet_handle: {:?}, their_did_info_json: {:?}" , wallet_handle, their_did_info_json) ;
286273
287- let their_did_info = TheirDidInfo :: from_json ( their_did_info_json)
274+ let their_did_info: TheirDidInfo = serde_json :: from_str ( their_did_info_json)
288275 . map_err ( map_err_trace ! ( ) )
289276 . map_err ( |err|
290277 CommonError :: InvalidStructure ( format ! ( "Invalid TheirDidInfo json: {}" , err. description( ) ) ) ) ?;
@@ -305,8 +292,8 @@ impl DidCommandExecutor {
305292
306293 let did_record = self . wallet_service . get_indy_record :: < Did > ( wallet_handle, & my_did, & RecordOptions :: full ( ) ) ?;
307294
308- let did = did_record. get_value ( )
309- . and_then ( |tags_json| Did :: from_json ( & tags_json) . ok ( ) )
295+ let did: Did = did_record. get_value ( )
296+ . and_then ( |tags_json| serde_json :: from_str ( & tags_json) . ok ( ) )
310297 . ok_or ( CommonError :: InvalidStructure ( format ! ( "Cannot deserialize Did: {:?}" , my_did) ) ) ?;
311298
312299 let meta: Option < String > = did_record. get_tags ( )
@@ -318,7 +305,7 @@ impl DidCommandExecutor {
318305 metadata : meta
319306 } ;
320307
321- let res = did_with_meta . to_json ( )
308+ let res = serde_json :: to_string ( & did_with_meta )
322309 . map_err ( |err|
323310 IndyError :: CommonError ( CommonError :: InvalidState ( format ! ( "Can't serialize DID {}" , err) ) ) ) ?;
324311
@@ -338,8 +325,8 @@ impl DidCommandExecutor {
338325 while let Some ( did_record) = did_search. fetch_next_record ( ) ? {
339326 let did_id = did_record. get_id ( ) ;
340327
341- let did = did_record. get_value ( )
342- . and_then ( |tags_json| Did :: from_json ( & tags_json) . ok ( ) )
328+ let did: Did = did_record. get_value ( )
329+ . and_then ( |tags_json| serde_json :: from_str ( & tags_json) . ok ( ) )
343330 . ok_or ( CommonError :: InvalidStructure ( format ! ( "Cannot deserialize Did: {:?}" , did_id) ) ) ?;
344331
345332 let meta: Option < String > = did_record. get_tags ( )
@@ -434,11 +421,10 @@ impl DidCommandExecutor {
434421
435422 let endpoint = Endpoint :: new ( address. to_string ( ) , Some ( transport_key. to_string ( ) ) ) ;
436423
437- let res = self . wallet_service . upsert_indy_object ( wallet_handle, & did, & endpoint) ?;
424+ self . wallet_service . upsert_indy_object ( wallet_handle, & did, & endpoint) ?;
438425
439- debug ! ( "set_endpoint_for_did <<< res: {:?}" , res) ;
440-
441- Ok ( res)
426+ debug ! ( "set_endpoint_for_did <<<" ) ;
427+ Ok ( ( ) )
442428 }
443429
444430 fn get_endpoint_for_did ( & self ,
@@ -456,9 +442,6 @@ impl DidCommandExecutor {
456442 match endpoint {
457443 Ok ( endpoint) => cb ( Ok ( ( endpoint. ha , endpoint. verkey ) ) ) ,
458444 Err ( WalletError :: ItemNotFound ) => {
459- check_wallet_and_pool_handles_consistency ! ( self . wallet_service, self . pool_service,
460- wallet_handle, pool_handle, cb) ;
461-
462445 return self . _fetch_attrib_from_ledger ( wallet_handle,
463446 pool_handle,
464447 & did,
@@ -517,13 +500,13 @@ impl DidCommandExecutor {
517500 self . crypto_service . validate_did ( & did) ?;
518501 self . crypto_service . validate_key ( & verkey) ?;
519502
520- let did = Base58 :: decode ( & did) ?;
521- let dverkey = Base58 :: decode ( & verkey) ?;
503+ let did = base58 :: decode ( & did) ?;
504+ let dverkey = base58 :: decode ( & verkey) ?;
522505
523506 let ( first_part, second_part) = dverkey. split_at ( 16 ) ;
524507
525508 let res = if first_part. eq ( did. as_slice ( ) ) {
526- format ! ( "~{}" , Base58 :: encode( second_part) )
509+ format ! ( "~{}" , base58 :: encode( second_part) )
527510 } else {
528511 verkey
529512 } ;
@@ -546,13 +529,13 @@ impl DidCommandExecutor {
546529
547530 let get_nym_reply = get_nym_reply_result?;
548531
549- let get_nym_response: Reply < GetNymReplyResult > = Reply :: from_json ( & get_nym_reply)
532+ let get_nym_response: Reply < GetNymReplyResult > = serde_json :: from_str ( & get_nym_reply)
550533 . map_err ( map_err_trace ! ( ) )
551534 . map_err ( |err| CommonError :: InvalidState ( format ! ( "Invalid GetNymReplyResult json: {:?}" , err) ) ) ?;
552535
553536 let their_did_info = match get_nym_response. result ( ) {
554537 GetNymReplyResult :: GetNymReplyResultV0 ( res) => {
555- let gen_nym_result_data = GetNymResultDataV0 :: from_json ( & res. data )
538+ let gen_nym_result_data: GetNymResultDataV0 = serde_json :: from_str ( & res. data )
556539 . map_err ( map_err_trace ! ( ) )
557540 . map_err ( |_| CommonError :: InvalidState ( "Invalid GetNymResultData json" . to_string ( ) ) ) ?;
558541
@@ -583,7 +566,7 @@ impl DidCommandExecutor {
583566
584567 let get_attrib_reply = get_attrib_reply_result?;
585568
586- let get_attrib_reply: Reply < GetAttrReplyResult > = Reply :: from_json ( & get_attrib_reply)
569+ let get_attrib_reply: Reply < GetAttrReplyResult > = serde_json :: from_str ( & get_attrib_reply)
587570 . map_err ( map_err_trace ! ( ) )
588571 . map_err ( |err| CommonError :: InvalidState ( format ! ( "Invalid GetAttrReplyResult json {:?}" , err) ) ) ?;
589572
@@ -592,7 +575,7 @@ impl DidCommandExecutor {
592575 GetAttrReplyResult :: GetAttrReplyResultV1 ( res) => ( res. txn . data . raw , res. txn . data . did )
593576 } ;
594577
595- let attrib_data = AttribData :: from_json ( & raw )
578+ let attrib_data: AttribData = serde_json :: from_str ( & raw )
596579 . map_err ( map_err_trace ! ( ) )
597580 . map_err ( |err| CommonError :: InvalidState ( format ! ( "Invalid GetAttReply json: {:?}" , err) ) ) ?;
598581
0 commit comments