Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Prazak <[email protected]>
  • Loading branch information
Ondrej Prazak committed Feb 14, 2024
1 parent 0c10398 commit 4fc6053
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 102 deletions.
9 changes: 8 additions & 1 deletion aries/aries_vcx_core/src/anoncreds/credx_anoncreds/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ use crate::{
},
wallet::{
base_wallet::{
record::Record, record_wallet::RecordWallet, search_filter::SearchFilter, BaseWallet,
record::{AllRecords, Record},
record_wallet::RecordWallet,
search_filter::SearchFilter,
BaseWallet,
},
record_tags::{RecordTag, RecordTags},
},
Expand Down Expand Up @@ -89,6 +92,10 @@ struct WalletAdapter(Arc<dyn BaseWallet>);

#[async_trait]
impl RecordWallet for WalletAdapter {
async fn all_records(&self) -> VcxCoreResult<Box<dyn AllRecords + Send>> {
self.0.all_records().await
}

async fn add_record(&self, record: Record) -> VcxCoreResult<()> {
self.0.add_record(record).await
}
Expand Down
8 changes: 4 additions & 4 deletions aries/aries_vcx_core/src/wallet/agency_client_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ impl BaseWallet for AgencyClientWallet {
"configure_issuer",
))
}

async fn all(&self) -> VcxCoreResult<Box<dyn AllRecords + Send>> {
Err(unimplemented_agency_client_wallet_method("get_all"))
}
}

#[allow(unused_variables)]
#[async_trait]
impl RecordWallet for AgencyClientWallet {
async fn all_records(&self) -> VcxCoreResult<Box<dyn AllRecords + Send>> {
Err(unimplemented_agency_client_wallet_method("get_all"))
}

async fn add_record(&self, record: Record) -> VcxCoreResult<()> {
Err(unimplemented_agency_client_wallet_method("add_record"))
}
Expand Down
2 changes: 1 addition & 1 deletion aries/aries_vcx_core/src/wallet/base_wallet/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub async fn migrate_records<E>(
where
E: std::fmt::Display,
{
let mut records = src_wallet.all().await?;
let mut records = src_wallet.all_records().await?;
let total = records.total_count();
info!("Migrating {total:?} records");
let mut num_record = 0;
Expand Down
11 changes: 1 addition & 10 deletions aries/aries_vcx_core/src/wallet/base_wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use std::sync::Arc;

use async_trait::async_trait;

use self::{
did_wallet::DidWallet, issuer_config::IssuerConfig, record::AllRecords,
record_wallet::RecordWallet,
};
use self::{did_wallet::DidWallet, issuer_config::IssuerConfig, record_wallet::RecordWallet};
use crate::errors::error::VcxCoreResult;

pub mod did_data;
Expand Down Expand Up @@ -37,8 +34,6 @@ pub trait BaseWallet: RecordWallet + DidWallet + Send + Sync + std::fmt::Debug {
async fn close_wallet(&self) -> VcxCoreResult<()>;

async fn configure_issuer(&self, key_seed: &str) -> VcxCoreResult<IssuerConfig>;

async fn all(&self) -> VcxCoreResult<Box<dyn AllRecords + Send>>;
}

#[async_trait]
Expand All @@ -54,10 +49,6 @@ impl BaseWallet for Arc<dyn BaseWallet> {
async fn configure_issuer(&self, key_seed: &str) -> VcxCoreResult<IssuerConfig> {
self.as_ref().configure_issuer(key_seed).await
}

async fn all(&self) -> VcxCoreResult<Box<dyn AllRecords + Send>> {
self.as_ref().all().await
}
}

#[cfg(test)]
Expand Down
20 changes: 0 additions & 20 deletions aries/aries_vcx_core/src/wallet/base_wallet/record.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use async_trait::async_trait;
use typed_builder::TypedBuilder;
#[cfg(feature = "vdrtools_wallet")]
use vdrtools::WalletRecord;

use crate::{errors::error::VcxCoreResult, wallet::record_tags::RecordTags};

Expand Down Expand Up @@ -57,24 +55,6 @@ impl PartialRecord {
pub fn tags(&self) -> &Option<RecordTags> {
&self.tags
}

#[cfg(feature = "vdrtools_wallet")]
pub fn from_wallet_record(wallet_record: WalletRecord) -> Self {
use crate::wallet::indy::indy_tags::IndyTags;

let name = wallet_record.get_id().into();
let category = wallet_record.get_type();
let value = wallet_record.get_value();

let found_tags = wallet_record.get_tags();

Self::builder()
.name(name)
.category(category.map(Into::into))
.value(value.map(Into::into))
.tags(found_tags.map(|tags| IndyTags::new(tags.clone()).into_entry_tags()))
.build()
}
}

#[async_trait]
Expand Down
12 changes: 11 additions & 1 deletion aries/aries_vcx_core/src/wallet/base_wallet/record_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ use std::sync::Arc;

use async_trait::async_trait;

use super::{record::Record, search_filter::SearchFilter, BaseWallet};
use super::{
record::{AllRecords, Record},
search_filter::SearchFilter,
BaseWallet,
};
use crate::{errors::error::VcxCoreResult, wallet::record_tags::RecordTags};

#[async_trait]
pub trait RecordWallet {
async fn all_records(&self) -> VcxCoreResult<Box<dyn AllRecords + Send>>;

async fn add_record(&self, record: Record) -> VcxCoreResult<()>;

async fn get_record(&self, category: &str, name: &str) -> VcxCoreResult<Record>;
Expand Down Expand Up @@ -36,6 +42,10 @@ pub trait RecordWallet {

#[async_trait]
impl RecordWallet for Arc<dyn BaseWallet> {
async fn all_records(&self) -> VcxCoreResult<Box<dyn AllRecords + Send>> {
self.as_ref().all_records().await
}

async fn add_record(&self, record: Record) -> VcxCoreResult<()> {
self.as_ref().add_record(record).await
}
Expand Down
40 changes: 38 additions & 2 deletions aries/aries_vcx_core/src/wallet/indy/indy_record_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,56 @@ use async_trait::async_trait;
use indy_api_types::domain::wallet::IndyRecord;
use serde::Deserialize;
use serde_json::Value;
use vdrtools::Locator;
use vdrtools::{indy_wallet::iterator::WalletIterator, Locator};

use super::{indy_tags::IndyTags, SEARCH_OPTIONS, WALLET_OPTIONS};
use crate::{
errors::error::{AriesVcxCoreError, VcxCoreResult},
wallet::{
base_wallet::{record::Record, record_wallet::RecordWallet, search_filter::SearchFilter},
base_wallet::{
record::{AllRecords, PartialRecord, Record},
record_wallet::RecordWallet,
search_filter::SearchFilter,
},
indy::IndySdkWallet,
record_tags::RecordTags,
},
};

pub struct AllIndyRecords {
iterator: WalletIterator,
}

impl AllIndyRecords {
pub fn new(iterator: WalletIterator) -> Self {
Self { iterator }
}
}

#[async_trait]
impl AllRecords for AllIndyRecords {
fn total_count(&self) -> VcxCoreResult<Option<usize>> {
Ok(self.iterator.get_total_count()?)
}

async fn next(&mut self) -> VcxCoreResult<Option<PartialRecord>> {
let item = self.iterator.next().await?;

Ok(item.map(PartialRecord::from_wallet_record))
}
}

#[async_trait]
impl RecordWallet for IndySdkWallet {
async fn all_records(&self) -> VcxCoreResult<Box<dyn AllRecords + Send>> {
let all = Locator::instance()
.wallet_controller
.get_all(self.get_wallet_handle())
.await?;

Ok(Box::new(AllIndyRecords::new(all)))
}

async fn add_record(&self, record: Record) -> VcxCoreResult<()> {
let tags_map = if record.tags().is_empty() {
None
Expand Down
56 changes: 20 additions & 36 deletions aries/aries_vcx_core/src/wallet/indy/mod.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
use async_trait::async_trait;
use indy_api_types::domain::wallet::{default_key_derivation_method, IndyRecord};
use vdrtools::{indy_wallet::iterator::WalletIterator, Locator};
use vdrtools::{Locator, WalletRecord};

use self::indy_tags::IndyTags;
use super::base_wallet::{
did_wallet::DidWallet,
issuer_config::IssuerConfig,
record::{AllRecords, PartialRecord, Record},
record::{PartialRecord, Record},
BaseWallet,
};
use crate::{errors::error::VcxCoreResult, WalletHandle};

mod indy_did_wallet;
mod indy_record_wallet;
pub(crate) mod indy_tags;
mod indy_tags;
mod indy_utils;
pub mod indy_wallet_record;
pub mod restore_wallet_configs;
pub mod wallet_config;
pub mod wallet_credentials;

impl PartialRecord {
pub fn from_wallet_record(wallet_record: WalletRecord) -> Self {
let name = wallet_record.get_id().into();
let category = wallet_record.get_type();
let value = wallet_record.get_value();

let found_tags = wallet_record.get_tags();

Self::builder()
.name(name)
.category(category.map(Into::into))
.value(value.map(Into::into))
.tags(found_tags.map(|tags| IndyTags::new(tags.clone()).into_entry_tags()))
.build()
}
}

impl From<IndyRecord> for Record {
fn from(ir: IndyRecord) -> Self {
Expand Down Expand Up @@ -97,38 +113,6 @@ impl BaseWallet for IndySdkWallet {
institution_did: did_data.did().to_string(),
})
}

async fn all(&self) -> VcxCoreResult<Box<dyn AllRecords + Send>> {
let all = Locator::instance()
.wallet_controller
.get_all(self.get_wallet_handle())
.await?;

Ok(Box::new(AllIndyRecords::new(all)))
}
}

pub struct AllIndyRecords {
iterator: WalletIterator,
}

impl AllIndyRecords {
pub fn new(iterator: WalletIterator) -> Self {
Self { iterator }
}
}

#[async_trait]
impl AllRecords for AllIndyRecords {
fn total_count(&self) -> VcxCoreResult<Option<usize>> {
Ok(self.iterator.get_total_count()?)
}

async fn next(&mut self) -> VcxCoreResult<Option<PartialRecord>> {
let item = self.iterator.next().await?;

Ok(item.map(PartialRecord::from_wallet_record))
}
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::indy_utils::parse_key_derivation_method;
use crate::{errors::error::VcxCoreResult, wallet::base_wallet::ImportWallet};

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RestoreWalletConfigs {
pub struct ImportWalletConfigs {
pub wallet_name: String,
pub wallet_key: String,
pub exported_wallet_path: String,
Expand All @@ -16,7 +16,7 @@ pub struct RestoreWalletConfigs {
}

#[async_trait]
impl ImportWallet for RestoreWalletConfigs {
impl ImportWallet for ImportWalletConfigs {
async fn import_wallet(&self) -> VcxCoreResult<()> {
Locator::instance()
.wallet_controller
Expand Down
13 changes: 0 additions & 13 deletions aries/aries_vcx_core/src/wallet/indy/wallet_credentials.rs

This file was deleted.

8 changes: 4 additions & 4 deletions aries/aries_vcx_core/src/wallet/mock_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ impl BaseWallet for MockWallet {
async fn configure_issuer(&self, key_seed: &str) -> VcxCoreResult<IssuerConfig> {
Ok(IssuerConfig::builder().build())
}

async fn all(&self) -> VcxCoreResult<Box<dyn AllRecords + Send>> {
Ok(Box::new(MockAllRecords {}))
}
}

#[async_trait]
#[allow(unused_variables)]
impl RecordWallet for MockWallet {
async fn all_records(&self) -> VcxCoreResult<Box<dyn AllRecords + Send>> {
Ok(Box::new(MockAllRecords {}))
}

async fn add_record(&self, record: Record) -> VcxCoreResult<()> {
Ok(())
}
Expand Down
12 changes: 6 additions & 6 deletions aries/misc/legacy/libvcx_core/src/api_vcx/api_global/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use aries_vcx_core::{
ManageWallet,
},
indy::{
indy_wallet_record::IndyWalletRecord, restore_wallet_configs::RestoreWalletConfigs,
indy_wallet_record::IndyWalletRecord, restore_wallet_configs::ImportWalletConfigs,
wallet_config::WalletConfig,
},
record_tags::RecordTags,
Expand Down Expand Up @@ -288,7 +288,7 @@ pub async fn wallet_search_records(xtype: &str, query_json: &str) -> LibvcxResul
map_ariesvcx_core_result(res)
}

pub async fn wallet_import(config: &RestoreWalletConfigs) -> LibvcxResult<()> {
pub async fn wallet_import(config: &ImportWalletConfigs) -> LibvcxResult<()> {
map_ariesvcx_core_result(config.import_wallet().await)
}

Expand Down Expand Up @@ -395,7 +395,7 @@ pub mod test_utils {
#[cfg(test)]
mod tests {
use aries_vcx::{
aries_vcx_core::wallet::indy::restore_wallet_configs::RestoreWalletConfigs,
aries_vcx_core::wallet::indy::restore_wallet_configs::ImportWalletConfigs,
global::settings::{DEFAULT_WALLET_BACKUP_KEY, DEFAULT_WALLET_KEY, WALLET_KDF_RAW},
};
use aries_vcx_core::wallet::{
Expand Down Expand Up @@ -584,7 +584,7 @@ mod tests {
.unwrap();
close_main_wallet().await.unwrap();
wallet_config.delete_wallet().await.unwrap();
let import_config: RestoreWalletConfigs = serde_json::from_value(json!({
let import_config: ImportWalletConfigs = serde_json::from_value(json!({
"wallet_name": wallet_config.wallet_name.clone(),
"wallet_key": wallet_config.wallet_key.clone(),
"exported_wallet_path": export_file.path,
Expand Down Expand Up @@ -649,7 +649,7 @@ mod tests {

wallet_config.delete_wallet().await.unwrap();

let import_config = RestoreWalletConfigs {
let import_config = ImportWalletConfigs {
wallet_name: wallet_name.clone(),
wallet_key: DEFAULT_WALLET_KEY.into(),
exported_wallet_path: export_wallet_path.path.clone(),
Expand Down Expand Up @@ -677,7 +677,7 @@ mod tests {

open_as_main_wallet(&wallet_config).await.unwrap();

let import_config = RestoreWalletConfigs {
let import_config = ImportWalletConfigs {
wallet_name,
wallet_key: DEFAULT_WALLET_KEY.into(),
exported_wallet_path: export_wallet_path.path.clone(),
Expand Down
Loading

0 comments on commit 4fc6053

Please sign in to comment.