diff --git a/libvcx_core/src/api_vcx/api_global/pool.rs b/libvcx_core/src/api_vcx/api_global/pool.rs index c54f8dc188..1c5b540659 100644 --- a/libvcx_core/src/api_vcx/api_global/pool.rs +++ b/libvcx_core/src/api_vcx/api_global/pool.rs @@ -53,21 +53,23 @@ pub fn is_main_pool_open() -> bool { // global_profile.inject_anoncreds_ledger_read() } -pub fn reset_global_pool() { - setup_global_pool(None); +pub fn reset_global_pool() + -> LibvcxResult<()> { + setup_global_pool(None)?; legacy_setup_global_pool(None); + Ok(()) } -pub fn setup_global_pool(handle: Option) { +pub fn setup_global_pool(handle: Option) -> LibvcxResult<()> { match handle { None => { - let mut anoncreds_read = ledger_anoncreds_read.write().unwrap(); + let mut anoncreds_read = ledger_anoncreds_read.write()?; *anoncreds_read = None; - let mut anoncreds_write = ledger_anoncreds_write.write().unwrap(); + let mut anoncreds_write = ledger_anoncreds_write.write()?; *anoncreds_write = None; - let mut indy_read = ledger_indy_read.write().unwrap(); + let mut indy_read = ledger_indy_read.write()?; *indy_read = None; - let mut indy_write = ledger_indy_write.write().unwrap(); + let mut indy_write = ledger_indy_write.write()?; *indy_write = None; } Some(pool_handle) => { @@ -75,16 +77,17 @@ pub fn setup_global_pool(handle: Option) { let wallet_handle = get_main_wallet_handle(); let ledger_read = Arc::new(IndySdkLedgerRead::new(wallet_handle, pool_handle)); let ledger_write = Arc::new(IndySdkLedgerWrite::new(wallet_handle, pool_handle)); - let mut anoncreds_read = ledger_anoncreds_read.write().unwrap(); + let mut anoncreds_read = ledger_anoncreds_read.write()?; *anoncreds_read = Some(ledger_read.clone() as Arc); - let mut anoncreds_write = ledger_anoncreds_write.write().unwrap(); + let mut anoncreds_write = ledger_anoncreds_write.write()?; *anoncreds_write = Some(ledger_write.clone() as Arc); - let mut indy_read = ledger_indy_read.write().unwrap(); + let mut indy_read = ledger_indy_read.write()?; *indy_read = Some(ledger_read.clone() as Arc); - let mut indy_write = ledger_indy_write.write().unwrap(); + let mut indy_write = ledger_indy_write.write()?; *indy_write = Some(ledger_write.clone() as Arc); } } + Ok(()) } pub async fn open_main_pool(config: &PoolConfig) -> LibvcxResult<()> { @@ -114,7 +117,7 @@ pub async fn open_main_pool(config: &PoolConfig) -> LibvcxResult<()> { .map_err(|err| err.extend("Can not open Pool Ledger"))?; legacy_setup_global_pool(Some(pool_handle)); - setup_global_pool(Some(pool_handle)); + setup_global_pool(Some(pool_handle))?; info!("open_pool >> Pool Opened Successfully"); @@ -126,7 +129,7 @@ pub async fn close_main_pool() -> LibvcxResult<()> { indy_close_pool(get_main_pool_handle()?).await?; // todo: better way to go about this? legacy_setup_global_pool(None); - setup_global_pool(None); + setup_global_pool(None)?; Ok(()) } @@ -158,7 +161,7 @@ pub mod tests { }; open_main_pool(&config).await.unwrap(); // delete_test_pool(get_main_pool_handle().unwrap()).await; - reset_global_pool(); + reset_global_pool().unwrap(); } #[cfg(feature = "pool_tests")] @@ -187,7 +190,7 @@ pub mod tests { ); delete_named_test_pool(&pool_name).await; - reset_global_pool(); + reset_global_pool().unwrap(); } #[cfg(feature = "pool_tests")] diff --git a/libvcx_core/src/api_vcx/api_global/profile.rs b/libvcx_core/src/api_vcx/api_global/profile.rs index ec1d6c3230..7a600c9af6 100644 --- a/libvcx_core/src/api_vcx/api_global/profile.rs +++ b/libvcx_core/src/api_vcx/api_global/profile.rs @@ -48,7 +48,7 @@ impl Debug for VcxGlobalsProfile { impl ProfileV2 for VcxGlobalsProfile { fn inject_indy_ledger_read(&self) -> LibvcxResult> { - let ledger = ledger_indy_read.read().unwrap(); + let ledger = ledger_indy_read.read()?; match ledger.as_ref() { None => Err(LibvcxError::from_msg( LibvcxErrorKind::NotReady, @@ -59,7 +59,7 @@ impl ProfileV2 for VcxGlobalsProfile { } fn inject_indy_ledger_write(&self) -> LibvcxResult> { - let ledger = ledger_indy_write.read().unwrap(); + let ledger = ledger_indy_write.read()?; match ledger.as_ref() { None => Err(LibvcxError::from_msg( LibvcxErrorKind::NotReady, @@ -70,7 +70,7 @@ impl ProfileV2 for VcxGlobalsProfile { } fn inject_anoncreds(&self) -> LibvcxResult> { - let anoncreds = base_anoncreds.read().unwrap(); + let anoncreds = base_anoncreds.read()?; match anoncreds.as_ref() { None => Err(LibvcxError::from_msg( LibvcxErrorKind::NotReady, @@ -81,7 +81,7 @@ impl ProfileV2 for VcxGlobalsProfile { } fn inject_anoncreds_ledger_read(&self) -> LibvcxResult> { - let ledger = ledger_anoncreds_read.read().unwrap(); + let ledger = ledger_anoncreds_read.read()?; match ledger.as_ref() { None => Err(LibvcxError::from_msg( LibvcxErrorKind::NotReady, @@ -92,7 +92,7 @@ impl ProfileV2 for VcxGlobalsProfile { } fn inject_anoncreds_ledger_write(&self) -> LibvcxResult> { - let ledger = ledger_anoncreds_write.read().unwrap(); + let ledger = ledger_anoncreds_write.read()?; match ledger.as_ref() { None => Err(LibvcxError::from_msg( LibvcxErrorKind::NotReady, @@ -103,7 +103,7 @@ impl ProfileV2 for VcxGlobalsProfile { } fn inject_wallet(&self) -> LibvcxResult> { - let global_base_wallet = base_wallet.read().unwrap(); + let global_base_wallet = base_wallet.read()?; match global_base_wallet.as_ref() { None => Err(LibvcxError::from_msg( LibvcxErrorKind::NotReady, diff --git a/libvcx_core/src/api_vcx/api_global/state.rs b/libvcx_core/src/api_vcx/api_global/state.rs index a9b81e72bf..6aeb39b0a9 100644 --- a/libvcx_core/src/api_vcx/api_global/state.rs +++ b/libvcx_core/src/api_vcx/api_global/state.rs @@ -9,6 +9,7 @@ use aries_vcx::global::settings::{ reset_config_values, CONFIG_POOL_NAME, CONFIG_WALLET_KEY, CONFIG_WALLET_KEY_DERIVATION, CONFIG_WALLET_NAME, CONFIG_WALLET_TYPE, DEFAULT_POOL_NAME, DEFAULT_WALLET_NAME, UNINITIALIZED_WALLET_KEY, WALLET_KDF_DEFAULT, }; +use crate::errors::error::LibvcxResult; pub fn state_vcx_shutdown(delete: bool) { info!("vcx_shutdown >>>"); @@ -51,7 +52,12 @@ pub fn state_vcx_shutdown(delete: bool) { let _ = reset_config_values(); reset_main_agency_client(); - reset_global_pool(); + match reset_global_pool() { + Ok(_) => {} + Err(err) => { + error!("Failed to reset global pool: {}", err); + } + } } #[cfg(test)] diff --git a/libvcx_core/src/api_vcx/api_global/wallet.rs b/libvcx_core/src/api_vcx/api_global/wallet.rs index 2e6917bda3..9e2f58e3e9 100644 --- a/libvcx_core/src/api_vcx/api_global/wallet.rs +++ b/libvcx_core/src/api_vcx/api_global/wallet.rs @@ -50,31 +50,32 @@ pub async fn export_main_wallet(path: &str, backup_key: &str) -> LibvcxResult<() map_ariesvcx_core_result(indy::wallet::export_wallet(get_main_wallet_handle(), path, backup_key).await) } -fn setup_global_wallet(handle: WalletHandle) { +fn setup_global_wallet(handle: WalletHandle) -> LibvcxResult<()> { // new way let base_wallet_impl: Arc = Arc::new(IndySdkWallet::new(handle)); - let mut b_wallet = base_wallet.write().unwrap(); + let mut b_wallet = base_wallet.write()?; *b_wallet = Some(base_wallet_impl); // anoncreds let base_anoncreds_impl: Arc = Arc::new(IndySdkAnonCreds::new(handle)); - let mut b_anoncreds = base_anoncreds.write().unwrap(); + let mut b_anoncreds = base_anoncreds.write()?; *b_anoncreds = Some(base_anoncreds_impl); + Ok(()) } -pub fn setup_wallet(handle: WalletHandle) { +pub fn setup_wallet(handle: WalletHandle) -> LibvcxResult<()> { legacy_setup_global_wallet(handle); - setup_global_wallet(handle); + setup_global_wallet(handle) } pub async fn open_as_main_wallet(wallet_config: &WalletConfig) -> LibvcxResult { let handle = indy::wallet::open_wallet(wallet_config).await?; - setup_wallet(handle); + setup_wallet(handle)?; Ok(handle) } pub async fn create_and_open_as_main_wallet(wallet_config: &WalletConfig) -> LibvcxResult { let handle = indy::wallet::create_and_open_wallet(wallet_config).await?; - setup_wallet(handle); + setup_wallet(handle)?; Ok(handle) } @@ -83,7 +84,7 @@ pub async fn close_main_wallet() -> LibvcxResult<()> { //legacy reset_main_wallet_handle(); // new way - let mut b_wallet = base_wallet.write().unwrap(); + let mut b_wallet = base_wallet.write()?; *b_wallet = None; Ok(()) } diff --git a/libvcx_core/src/api_vcx/utils/devsetup.rs b/libvcx_core/src/api_vcx/utils/devsetup.rs index 115c0656ac..ac755f98ef 100644 --- a/libvcx_core/src/api_vcx/utils/devsetup.rs +++ b/libvcx_core/src/api_vcx/utils/devsetup.rs @@ -46,7 +46,7 @@ impl SetupGlobalsWalletPoolAgency { setup_wallet(init.wallet_handle); set_main_agency_client(init.agency_client.clone()); - setup_global_pool(Some(init.pool_handle)); + setup_global_pool(Some(init.pool_handle)).unwrap(); f(init).await;