Skip to content

Commit

Permalink
Adjusted uniffi_aries_vcx
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Mircea <[email protected]>
  • Loading branch information
bobozaur committed Oct 16, 2023
1 parent d2a7392 commit bdb0088
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 39 deletions.
11 changes: 2 additions & 9 deletions libvcx_core/src/api_vcx/api_global/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use aries_vcx::{
InMemoryResponseCacherConfig, InMemoryResponseCacherConfigBuilder,
},
},
wallet::base_wallet::BaseWallet,
PoolConfig,
},
utils::ledger::{indyvdr_build_ledger_read, indyvdr_build_ledger_write},
Expand All @@ -22,10 +21,7 @@ use aries_vcx_core::ledger::{
response_cacher::in_memory::InMemoryResponseCacher,
};

use crate::{
api_vcx::api_global::profile::get_main_wallet,
errors::error::{LibvcxError, LibvcxResult},
};
use crate::errors::error::{LibvcxError, LibvcxResult};

pub static GLOBAL_LEDGER_INDY_READ: RwLock<
Option<Arc<IndyVdrLedgerRead<IndyVdrSubmitter, InMemoryResponseCacher>>>,
Expand Down Expand Up @@ -71,7 +67,6 @@ impl TryFrom<LibvcxInMemoryResponseCacherConfig> for InMemoryResponseCacherConfi
}

fn build_components_ledger(
base_wallet: Arc<dyn BaseWallet>,
libvcx_pool_config: &LibvcxLedgerConfig,
) -> LibvcxResult<(
IndyVdrLedgerRead<IndyVdrSubmitter, InMemoryResponseCacher>,
Expand Down Expand Up @@ -110,9 +105,7 @@ pub fn reset_ledger_components() -> LibvcxResult<()> {
}

pub async fn setup_ledger_components(config: &LibvcxLedgerConfig) -> LibvcxResult<()> {
let base_wallet = get_main_wallet()?;

let (ledger_read, ledger_write) = build_components_ledger(base_wallet, config)?;
let (ledger_read, ledger_write) = build_components_ledger(config)?;
let mut indy_read_guard = GLOBAL_LEDGER_INDY_READ.write()?;
*indy_read_guard = Some(Arc::new(ledger_read));
let mut indy_write_guard = GLOBAL_LEDGER_INDY_WRITE.write()?;
Expand Down
18 changes: 10 additions & 8 deletions libvcx_core/src/api_vcx/api_handle/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use serde_json;

use crate::{
api_vcx::{
api_global::profile::{get_main_anoncreds, get_main_ledger_read, get_main_ledger_write},
api_global::profile::{
get_main_anoncreds, get_main_ledger_read, get_main_ledger_write, get_main_wallet,
},
api_handle::object_cache::ObjectCache,
},
errors::error::{LibvcxError, LibvcxErrorKind, LibvcxResult},
Expand Down Expand Up @@ -50,7 +52,10 @@ pub async fn create_and_publish_schema(
&data,
)
.await?
.publish(get_main_ledger_write()?.as_ref())
.publish(
get_main_wallet()?.as_ref(),
get_main_ledger_write()?.as_ref(),
)
.await?;
std::thread::sleep(std::time::Duration::from_millis(100));
debug!(
Expand Down Expand Up @@ -164,16 +169,13 @@ pub mod test_utils {

#[cfg(test)]
pub mod tests {
use aries_vcx::{
global::settings::DEFAULT_DID,
utils::devsetup::{SetupDefaults, SetupEmpty},
};
use aries_vcx::{global::settings::DEFAULT_DID, utils::devsetup::SetupMocks};

use super::*;

#[tokio::test]
async fn test_create_schema_fails() {
let _setup = SetupDefaults::init();
let _setup = SetupMocks::init();

let err = create_and_publish_schema(
DEFAULT_DID,
Expand All @@ -189,7 +191,7 @@ pub mod tests {

#[test]
fn test_handle_errors() {
let _setup = SetupEmpty::init();
let _setup = SetupMocks::init();

assert_eq!(
to_string(13435178).unwrap_err().kind(),
Expand Down
26 changes: 9 additions & 17 deletions uniffi_aries_vcx/core/src/core/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,38 @@ use aries_vcx::{
ledger::base_ledger::TxnAuthrAgrmtOptions,
wallet::indy::{wallet::create_and_open_wallet, IndySdkWallet, WalletConfig},
},
core::profile::Profile,
errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult},
utils::mockdata::profile::mock_ledger::MockLedger,
};
use async_trait::async_trait;

use crate::{errors::error::VcxUniFFIResult, runtime::block_on};

#[derive(Debug)]
pub struct UniffiProfile {
wallet: Arc<IndySdkWallet>,
wallet: IndySdkWallet,
anoncreds: IndyCredxAnonCreds,
ledger_read: MockLedger,
ledger_write: MockLedger,
}

#[async_trait]
impl Profile for UniffiProfile {
type LedgerRead = MockLedger;
type LedgerWrite = MockLedger;
type Anoncreds = IndyCredxAnonCreds;
type Wallet = IndySdkWallet;

fn ledger_read(&self) -> &Self::LedgerRead {
impl UniffiProfile {
pub fn ledger_read(&self) -> &MockLedger {
&self.ledger_read
}

fn ledger_write(&self) -> &Self::LedgerWrite {
pub fn ledger_write(&self) -> &MockLedger {
&self.ledger_write
}

fn anoncreds(&self) -> &Self::Anoncreds {
pub fn anoncreds(&self) -> &IndyCredxAnonCreds {
&self.anoncreds
}

fn wallet(&self) -> &Self::Wallet {
pub fn wallet(&self) -> &IndySdkWallet {
&self.wallet
}

fn update_taa_configuration(&self, _taa_options: TxnAuthrAgrmtOptions) -> VcxResult<()> {
pub fn update_taa_configuration(&self, _taa_options: TxnAuthrAgrmtOptions) -> VcxResult<()> {
Err(AriesVcxError::from_msg(
AriesVcxErrorKind::ActionNotSupported,
"update_taa_configuration no implemented for VdrtoolsProfile",
Expand All @@ -61,9 +53,9 @@ pub fn new_indy_profile(wallet_config: WalletConfig) -> VcxUniFFIResult<Arc<Prof
block_on(async {
let wh = create_and_open_wallet(&wallet_config).await?;

let wallet = Arc::new(IndySdkWallet::new(wh));
let wallet = IndySdkWallet::new(wh);
let profile = UniffiProfile {
anoncreds: IndyCredxAnonCreds::new(wallet.clone()),
anoncreds: IndyCredxAnonCreds,
wallet,
ledger_read: MockLedger,
ledger_write: MockLedger,
Expand Down
5 changes: 1 addition & 4 deletions uniffi_aries_vcx/core/src/core/unpack_message.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use std::sync::Arc;

use aries_vcx::{
aries_vcx_core::wallet::{base_wallet::BaseWallet, structs_io::UnpackMessageOutput},
core::profile::Profile,
};
use aries_vcx::aries_vcx_core::wallet::{base_wallet::BaseWallet, structs_io::UnpackMessageOutput};

use super::profile::ProfileHolder;
use crate::{errors::error::VcxUniFFIResult, runtime::block_on};
Expand Down
1 change: 0 additions & 1 deletion uniffi_aries_vcx/core/src/handlers/connection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::{Arc, Mutex};

use aries_vcx::{
core::profile::Profile,
errors::error::{AriesVcxError, AriesVcxErrorKind},
protocols::connection::{
pairwise_info::PairwiseInfo, Connection as VcxConnection,
Expand Down

0 comments on commit bdb0088

Please sign in to comment.