forked from hyperledger/aries-vcx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize files, remove access to global data from aries-vcx src (hy…
…perledger#517) * Refactor tests Signed-off-by: Patrik Stas <patrik.stas@absa.africa> * Reorganize files to separate global data based APIs Signed-off-by: Patrik Stas <patrik.stas@absa.africa> * Pull get_main_wallet_handle() calls up in call stack Signed-off-by: Patrik Stas <patrik.stas@absa.africa> * Pull more get_main_wallet_handle() calls up in call stack Signed-off-by: Patrik Stas <patrik.stas@absa.africa> * Pull get_main_agency_client() up the call stack Signed-off-by: Patrik Stas <patrik.stas@absa.africa> * AgencyClient: Use WalletHandle type, remove Default trait Signed-off-by: Patrik Stas <patrik.stas@absa.africa> * Remove access to global wallet or agency_client from aries-vcx src/ Signed-off-by: Patrik Stas <patrik.stas@absa.africa> * Optimize imports, reformat Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
- Loading branch information
1 parent
24701ca
commit 2948c2a
Showing
98 changed files
with
2,164 additions
and
2,091 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use strum::IntoEnumIterator; | ||
|
||
use crate::error::{VcxError, VcxErrorKind}; | ||
use crate::global::settings; | ||
use crate::global::settings::CONFIG_ACTORS; | ||
|
||
pub fn get_actors() -> Vec<Actors> { | ||
settings::get_config_value(CONFIG_ACTORS) | ||
.and_then(|actors| | ||
serde_json::from_str(&actors) | ||
.map_err(|_| VcxError::from(VcxErrorKind::InvalidOption)) | ||
).unwrap_or_else(|_| Actors::iter().collect()) | ||
} | ||
|
||
#[derive(Clone, Serialize, Deserialize, Debug, Eq, PartialEq, EnumIter)] | ||
#[serde(rename_all = "lowercase")] | ||
pub enum Actors { | ||
Inviter, | ||
Invitee, | ||
Issuer, | ||
Holder, | ||
Prover, | ||
Verifier, | ||
Sender, | ||
Receiver, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::ops::Deref; | ||
use std::sync::{RwLock, RwLockWriteGuard}; | ||
|
||
use agency_client::agency_client::AgencyClient; | ||
use agency_client::configuration::AgencyClientConfig; | ||
|
||
use crate::error::VcxResult; | ||
|
||
lazy_static! { | ||
pub static ref AGENCY_CLIENT: RwLock<AgencyClient> = RwLock::new(AgencyClient::new()); | ||
} | ||
|
||
pub fn get_main_agency_client_mut() -> VcxResult<RwLockWriteGuard<'static, AgencyClient>> { | ||
let agency_client = AGENCY_CLIENT.write()?; | ||
Ok(agency_client) | ||
} | ||
|
||
pub fn get_main_agency_client() -> VcxResult<AgencyClient> { | ||
let agency_client = AGENCY_CLIENT.read()?.deref().clone(); | ||
Ok(agency_client) | ||
} | ||
|
||
pub fn create_agency_client_for_main_wallet(config: &AgencyClientConfig) -> VcxResult<()> { | ||
get_main_agency_client_mut()? | ||
.configure(config)?; | ||
Ok(()) | ||
} | ||
|
||
pub fn enable_main_agency_client_mocks() -> VcxResult<()> { | ||
info!("enable_agency_mocks >>>"); | ||
get_main_agency_client_mut()?.enable_test_mode(); | ||
Ok(()) | ||
} | ||
|
||
pub fn reset_main_agency_client() { | ||
trace!("reset_agency_client >>>"); | ||
let mut agency_client = AGENCY_CLIENT.write().unwrap(); | ||
*agency_client = AgencyClient::new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub mod agency_client; | ||
pub mod settings; | ||
pub mod wallet; | ||
pub mod pool; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::sync::RwLock; | ||
|
||
use indy::{ErrorCode, pool}; | ||
|
||
use crate::error::{VcxError, VcxErrorKind, VcxResult}; | ||
use crate::error::prelude::*; | ||
use crate::global; | ||
use crate::global::settings; | ||
use crate::libindy::utils::pool::PoolConfig; | ||
use crate::libindy::utils::pool::{create_pool_ledger_config, open_pool_ledger}; | ||
|
||
lazy_static! { | ||
static ref POOL_HANDLE: RwLock<Option<i32>> = RwLock::new(None); | ||
} | ||
|
||
pub fn set_main_pool_handle(handle: Option<i32>) { | ||
let mut h = POOL_HANDLE.write().unwrap(); | ||
*h = handle; | ||
} | ||
|
||
pub fn get_main_pool_handle() -> VcxResult<i32> { | ||
POOL_HANDLE.read() | ||
.or(Err(VcxError::from_msg(VcxErrorKind::NoPoolOpen, "There is no pool opened")))? | ||
.ok_or(VcxError::from_msg(VcxErrorKind::NoPoolOpen, "There is no pool opened")) | ||
} | ||
|
||
pub fn is_main_pool_open() -> bool { | ||
get_main_pool_handle().is_ok() | ||
} | ||
|
||
pub fn reset_main_pool_handle() { set_main_pool_handle(None); } | ||
|
||
pub async fn open_main_pool(config: &PoolConfig) -> VcxResult<()> { | ||
let pool_name = config.pool_name.clone().unwrap_or(settings::DEFAULT_POOL_NAME.to_string()); | ||
trace!("open_pool >>> pool_name: {}, path: {}, pool_config: {:?}", pool_name, config.genesis_path, config.pool_config); | ||
|
||
create_pool_ledger_config(&pool_name, &config.genesis_path) | ||
.await | ||
.map_err(|err| err.extend("Can not create Pool Ledger Config"))?; | ||
|
||
debug!("open_pool ::: Pool Config Created Successfully"); | ||
|
||
let handle = open_pool_ledger(&pool_name, config.pool_config.as_deref()) | ||
.await | ||
.map_err(|err| err.extend("Can not open Pool Ledger"))?; | ||
|
||
set_main_pool_handle(Some(handle)); | ||
|
||
info!("open_pool ::: Pool Opened Successfully"); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.