@@ -2,6 +2,7 @@ use std::collections::HashSet;
22use std:: error:: Error ;
33
44use cacher:: { CacheKey , CacherClient } ;
5+ use futures:: future:: join_all;
56use primitives:: { AddressStatus , Chain , ChainAddress , WalletConfiguration , WalletConfigurationResult , WalletId } ;
67use settings_chain:: ChainProviders ;
78use storage:: { Database , WalletsRepository } ;
@@ -23,19 +24,25 @@ impl WalletConfigurationClient {
2324 Ok ( WalletConfigurationResult {
2425 wallet_id : wallet_identifier,
2526 configuration : WalletConfiguration {
26- has_multi_signature_accounts : self . has_multi_signature_accounts ( device_id, wallet_id) . await ?. then_some ( true ) ,
27+ multi_signature_accounts : self . multi_signature_accounts ( device_id, wallet_id) . await ?,
2728 } ,
2829 } )
2930 }
3031
31- async fn has_multi_signature_accounts ( & self , device_id : i32 , wallet_id : i32 ) -> Result < bool , Box < dyn Error + Send + Sync > > {
32- for address in self . subscribed_addresses ( device_id, wallet_id) ? {
33- if self . get_statuses ( address) . await . is_some_and ( |statuses| statuses. contains ( & AddressStatus :: MultiSignature ) ) {
34- return Ok ( true ) ;
35- }
36- }
32+ async fn multi_signature_accounts ( & self , device_id : i32 , wallet_id : i32 ) -> Result < Vec < ChainAddress > , Box < dyn Error + Send + Sync > > {
33+ Ok ( join_all (
34+ self . subscribed_addresses ( device_id, wallet_id) ?
35+ . into_iter ( )
36+ . map ( |address| async move { self . has_multi_signature_status ( & address) . await . then_some ( address) } ) ,
37+ )
38+ . await
39+ . into_iter ( )
40+ . flatten ( )
41+ . collect ( ) )
42+ }
3743
38- Ok ( false )
44+ async fn has_multi_signature_status ( & self , address : & ChainAddress ) -> bool {
45+ self . get_statuses ( address) . await . is_some_and ( |statuses| statuses. contains ( & AddressStatus :: MultiSignature ) )
3946 }
4047
4148 fn subscribed_addresses ( & self , device_id : i32 , wallet_id : i32 ) -> Result < HashSet < ChainAddress > , Box < dyn Error + Send + Sync > > {
@@ -52,10 +59,10 @@ impl WalletConfigurationClient {
5259 . collect ( ) )
5360 }
5461
55- async fn get_statuses ( & self , address : ChainAddress ) -> Option < Vec < AddressStatus > > {
62+ async fn get_statuses ( & self , address : & ChainAddress ) -> Option < Vec < AddressStatus > > {
5663 if let Some ( statuses) = self
5764 . cacher
58- . get_cached_optional :: < Vec < AddressStatus > > ( cache_key ( & address) )
65+ . get_cached_optional :: < Vec < AddressStatus > > ( cache_key ( address) )
5966 . await
6067 . ok ( )
6168 . flatten ( )
@@ -69,7 +76,7 @@ impl WalletConfigurationClient {
6976 return None ;
7077 }
7178
72- let _ = self . cacher . set_cached ( cache_key ( & address) , & statuses) . await ;
79+ let _ = self . cacher . set_cached ( cache_key ( address) , & statuses) . await ;
7380
7481 Some ( statuses)
7582 }
0 commit comments