Skip to content

Commit

Permalink
clippy
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 7, 2024
1 parent 78c0784 commit e56374a
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 91 deletions.
1 change: 0 additions & 1 deletion aries/agents/rust/mediator/client-tui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::VecDeque;

use aries_vcx_core::wallet::base_wallet::BaseWallet;
use mediator::{
aries_agent::{client::transports::AriesReqwest, ArcAgent},
persistence::MediatorPersistence,
Expand Down
1 change: 0 additions & 1 deletion aries/agents/rust/mediator/client-tui/src/tui.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::Arc;

use aries_vcx_core::wallet::base_wallet::BaseWallet;
use client_tui::handle_register;
use cursive::{
direction::Orientation,
Expand Down
1 change: 0 additions & 1 deletion aries/agents/rust/mediator/src/aries_agent/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use aries_vcx::{
},
utils::encryption_envelope::EncryptionEnvelope,
};
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use messages::{
msg_fields::protocols::{
connection::{response::Response, Connection},
Expand Down
6 changes: 1 addition & 5 deletions aries/agents/rust/mediator/src/aries_agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ use aries_vcx_core::{
errors::error::AriesVcxCoreError,
wallet::{
base_wallet::{BaseWallet, ManageWallet},
indy::{
wallet_config::{self, WalletConfig},
IndySdkWallet,
},
indy::wallet_config::WalletConfig,
structs_io::UnpackMessageOutput,
},
WalletHandle,
};
use diddoc_legacy::aries::{diddoc::AriesDidDoc, service::AriesService};
use messages::{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use messages::msg_fields::protocols::connection::Connection;

use super::{unhandled_aries_message, utils::prelude::*, ArcAgent};
Expand Down
1 change: 0 additions & 1 deletion aries/agents/rust/mediator/src/didcomm_handlers/forward.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use messages::msg_fields::protocols::{notification::ack::Ack, routing::Forward};

use super::{utils::prelude::*, ArcAgent};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use messages::msg_fields::protocols::coordinate_mediation::{
CoordinateMediation, MediateGrant, MediateGrantContent, MediateGrantDecorators,
};
Expand Down
1 change: 0 additions & 1 deletion aries/agents/rust/mediator/src/didcomm_handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::fmt::Debug;

use aries_vcx_core::wallet::base_wallet::BaseWallet;
use axum::{body::Bytes, extract::State, Json};
use messages::AriesMessage;
use serde::{Deserialize, Serialize};
Expand Down
1 change: 0 additions & 1 deletion aries/agents/rust/mediator/src/didcomm_handlers/pickup.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use messages::msg_fields::protocols::pickup::Pickup;

use super::utils::prelude::*;
Expand Down
3 changes: 0 additions & 3 deletions aries/agents/rust/mediator/src/didcomm_handlers/utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
pub mod prelude {
pub use std::sync::Arc;

pub use aries_vcx::utils::encryption_envelope::EncryptionEnvelope;
pub use aries_vcx_core::wallet::base_wallet::BaseWallet;

pub use crate::{aries_agent::ArcAgent, persistence::MediatorPersistence, utils::prelude::*};
}
1 change: 0 additions & 1 deletion aries/agents/rust/mediator/src/http_routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::Arc;

use aries_vcx_core::wallet::base_wallet::BaseWallet;
use axum::{
body::Bytes,
extract::State,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use aries_vcx::{
},
utils::encryption_envelope::EncryptionEnvelope,
};
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use diddoc_legacy::aries::diddoc::AriesDidDoc;
use mediator::{
aries_agent::{
Expand Down
3 changes: 1 addition & 2 deletions aries/aries_vcx_core/src/wallet/base_wallet/did_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use std::sync::Arc;
use async_trait::async_trait;
use public_key::Key;

use crate::{errors::error::VcxCoreResult, wallet::structs_io::UnpackMessageOutput};

use super::{did_data::DidData, BaseWallet};
use crate::{errors::error::VcxCoreResult, wallet::structs_io::UnpackMessageOutput};

#[async_trait]
pub trait DidWallet {
Expand Down
17 changes: 7 additions & 10 deletions aries/aries_vcx_core/src/wallet/base_wallet/migrate.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use super::{record::Record, BaseWallet};
use crate::{
errors::error::{AriesVcxCoreErrorKind, VcxCoreResult},
wallet::entry_tags::EntryTags,
};

use super::{record::Record, BaseWallet};

#[derive(Debug)]
pub struct MigrationStats {
migrated: u32,
Expand Down Expand Up @@ -36,8 +35,8 @@ where
num_record += 1;
if num_record % 1000 == 1 {
warn!(
"Migrating wallet record number {num_record} / {total:?}, intermediary \
migration result: ${migration_result:?}"
"Migrating wallet record number {num_record} / {total:?}, intermediary migration \
result: ${migration_result:?}"
);
}
trace!("Migrating record: {:?}", source_record);
Expand All @@ -55,8 +54,7 @@ where
let unwrapped_value = match &source_record.value() {
None => {
warn!(
"Skipping item missing 'value' field, record ({num_record}): \
{source_record:?}"
"Skipping item missing 'value' field, record ({num_record}): {source_record:?}"
);
migration_result.skipped += 1;
continue;
Expand Down Expand Up @@ -98,16 +96,15 @@ where
Err(err) => match err.kind() {
AriesVcxCoreErrorKind::DuplicationWalletRecord => {
trace!(
"Record type: {migrated_record:?} already exists in destination \
wallet, skipping"
"Record type: {migrated_record:?} already exists in destination wallet, \
skipping"
);
migration_result.duplicated += 1;
continue;
}
_ => {
error!(
"Error adding record {migrated_record:?} to destination wallet: \
{err:?}"
"Error adding record {migrated_record:?} to destination wallet: {err:?}"
);
migration_result.failed += 1;
return Err(err);
Expand Down
3 changes: 1 addition & 2 deletions aries/aries_vcx_core/src/wallet/base_wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use self::{
did_wallet::DidWallet, issuer_config::IssuerConfig, record::AllRecords,
record_wallet::RecordWallet,
};

use crate::errors::error::VcxCoreResult;

pub mod did_data;
Expand All @@ -24,7 +23,7 @@ pub trait ImportWallet {

#[async_trait]
pub trait ManageWallet {
async fn create_wallet(&self) -> VcxCoreResult<Arc<dyn BaseWallet>>;
async fn create_wallet(&self) -> VcxCoreResult<()>;

async fn open_wallet(&self) -> VcxCoreResult<Arc<dyn BaseWallet>>;

Expand Down
5 changes: 2 additions & 3 deletions aries/aries_vcx_core/src/wallet/base_wallet/record.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use async_trait::async_trait;
use typed_builder::TypedBuilder;

use crate::{errors::error::VcxCoreResult, wallet::entry_tags::EntryTags};

#[cfg(feature = "vdrtools_wallet")]
use vdrtools::WalletRecord;

use crate::{errors::error::VcxCoreResult, wallet::entry_tags::EntryTags};

#[derive(Debug, Default, Clone, TypedBuilder)]
pub struct Record {
category: String,
Expand Down
3 changes: 1 addition & 2 deletions aries/aries_vcx_core/src/wallet/base_wallet/record_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use std::sync::Arc;

use async_trait::async_trait;

use crate::{errors::error::VcxCoreResult, wallet::entry_tags::EntryTags};

use super::{record::Record, search_filter::SearchFilter, BaseWallet};
use crate::{errors::error::VcxCoreResult, wallet::entry_tags::EntryTags};

#[async_trait]
pub trait RecordWallet {
Expand Down
1 change: 0 additions & 1 deletion aries/aries_vcx_core/src/wallet/indy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use indy_api_types::domain::wallet::{default_key_derivation_method, IndyRecord};
use vdrtools::{indy_wallet::iterator::WalletIterator, Locator};

use self::indy_tags::IndyTags;

use super::base_wallet::{
did_wallet::DidWallet,
issuer_config::IssuerConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use async_trait::async_trait;
use vdrtools::types::domain::wallet::default_key_derivation_method;

use serde::{Deserialize, Serialize};
use vdrtools::Locator;

use crate::{errors::error::VcxCoreResult, wallet::base_wallet::ImportWallet};
use vdrtools::{types::domain::wallet::default_key_derivation_method, Locator};

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 {
Expand Down
63 changes: 36 additions & 27 deletions aries/aries_vcx_core/src/wallet/indy/wallet_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;
use vdrtools::Locator;

use super::{indy_utils::parse_key_derivation_method, BaseWallet};
use crate::{
errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult},
wallet::{base_wallet::ManageWallet, indy::IndySdkWallet},
};

use super::{indy_utils::parse_key_derivation_method, BaseWallet};

#[derive(Clone, Debug, TypedBuilder, Serialize, Deserialize)]
#[builder(field_defaults(default))]
pub struct WalletConfig {
Expand All @@ -38,10 +37,24 @@ pub struct WalletConfig {

#[async_trait]
impl ManageWallet for WalletConfig {
async fn create_wallet(&self) -> VcxCoreResult<Arc<dyn BaseWallet>> {
let handle = Locator::instance()
async fn create_wallet(&self) -> VcxCoreResult<()> {
let credentials = vdrtools::types::domain::wallet::Credentials {
key: self.wallet_key.clone(),
key_derivation_method: parse_key_derivation_method(&self.wallet_key_derivation)?,

rekey: None,
rekey_derivation_method: default_key_derivation_method(),

storage_credentials: self
.storage_credentials
.as_deref()
.map(serde_json::from_str)
.transpose()?,
};

let res = Locator::instance()
.wallet_controller
.open(
.create(
vdrtools::types::domain::wallet::Config {
id: self.wallet_name.clone(),
storage_type: self.wallet_type.clone(),
Expand All @@ -52,30 +65,26 @@ impl ManageWallet for WalletConfig {
.transpose()?,
cache: None,
},
vdrtools::types::domain::wallet::Credentials {
key: self.wallet_key.clone(),
key_derivation_method: parse_key_derivation_method(
&self.wallet_key_derivation,
)?,

rekey: self.rekey.clone(),
rekey_derivation_method: self
.rekey_derivation_method
.as_deref()
.map(parse_key_derivation_method)
.transpose()?
.unwrap_or_else(default_key_derivation_method),

storage_credentials: self
.storage_credentials
.as_deref()
.map(serde_json::from_str)
.transpose()?,
},
credentials,
)
.await?;
.await;

Ok(Arc::new(IndySdkWallet::new(handle)))
match res {
Ok(()) => Ok(()),

Err(err) if err.kind() == IndyErrorKind::WalletAlreadyExists => {
warn!(
"wallet \"{}\" already exists. skipping creation",
self.wallet_name
);
Ok(())
}

Err(err) => Err(AriesVcxCoreError::from_msg(
AriesVcxCoreErrorKind::WalletCreate,
format!("could not create wallet {}: {}", self.wallet_name, err,),
)),
}
}

async fn open_wallet(&self) -> VcxCoreResult<Arc<dyn BaseWallet>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use aries_vcx::{
global::settings::DEFAULT_LINK_SECRET_ALIAS,
protocols::mediated_connection::pairwise_info::PairwiseInfo,
};

use aries_vcx_core::{
errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind},
wallet::{
Expand Down Expand Up @@ -280,7 +279,7 @@ pub async fn wallet_search_records(xtype: &str, query_json: &str) -> LibvcxResul

let indy_records = records
.into_iter()
.map(|record| IndyWalletRecord::from_record(record))
.map(IndyWalletRecord::from_record)
.collect::<Result<Vec<_>, _>>()?;

let res = serde_json::to_string(&indy_records)
Expand All @@ -296,10 +295,10 @@ pub async fn wallet_import(config: &RestoreWalletConfigs) -> LibvcxResult<()> {
pub async fn wallet_migrate(wallet_config: &WalletConfig) -> LibvcxResult<()> {
let src_wallet = get_main_wallet()?;
info!("Assuring target wallet exists.");
let dest_wallet = wallet_config.create_wallet().await?;
wallet_config.create_wallet().await?;
let dest_wallet = wallet_config.open_wallet().await?;
info!("Opening target wallet.");

let dest_wallet: Arc<_> = dest_wallet.into();
let migration_res = wallet_migrator::migrate_wallet(
src_wallet,
dest_wallet,
Expand Down Expand Up @@ -436,7 +435,6 @@ mod tests {
}))
.unwrap();

#[cfg(feature("vdrtools_wallet"))]
super::wallet_migrate(&new_config).await.unwrap();
}

Expand Down
12 changes: 2 additions & 10 deletions aries/misc/legacy/libvdrtools/indy-wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
};

use indy_api_types::{
domain::wallet::{CacheConfig, Config, Credentials, ExportConfig, IndyRecord, Tags},
domain::wallet::{CacheConfig, Config, Credentials, ExportConfig, Tags},
errors::prelude::*,
WalletHandle,
};
Expand All @@ -17,7 +17,7 @@ use indy_utils::{
secret,
};
use iterator::WalletIterator;
use log::{error, info, trace, warn};
use log::trace;
use serde::{Deserialize, Serialize};
use serde_json::Value as SValue;

Expand All @@ -43,14 +43,6 @@ mod cache;
mod export_import;
mod wallet;

#[derive(Debug)]
pub struct MigrationResult {
migrated: u32,
skipped: u32,
duplicated: u32,
failed: u32,
}

#[allow(clippy::type_complexity)]
pub struct WalletService {
storage_types: Mutex<HashMap<String, Arc<dyn WalletStorageType>>>,
Expand Down
1 change: 1 addition & 0 deletions aries/misc/legacy/libvdrtools/indy-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct Keys {
pub tags_hmac_key: hmacsha256::Key,
}

#[allow(clippy::new_without_default)]
impl Keys {
pub fn new() -> Keys {
Keys {
Expand Down
Loading

0 comments on commit e56374a

Please sign in to comment.