diff --git a/aries_vcx/src/utils/mockdata/profile/mock_wallet.rs b/aries_vcx/src/utils/mockdata/profile/mock_wallet.rs index af79ddd9b9..e8317e6379 100644 --- a/aries_vcx/src/utils/mockdata/profile/mock_wallet.rs +++ b/aries_vcx/src/utils/mockdata/profile/mock_wallet.rs @@ -4,6 +4,7 @@ use aries_vcx_core::wallet::base_wallet::BaseWallet; use async_trait::async_trait; use crate::utils::{self}; +use std::collections::HashMap; #[derive(Debug)] pub(crate) struct MockWallet; @@ -38,12 +39,12 @@ impl BaseWallet for MockWallet { xtype: &str, id: &str, value: &str, - tags_json: Option<&str>, + tags: Option>, ) -> VcxCoreResult<()> { Ok(()) } - async fn get_wallet_record(&self, xtype: &str, id: &str, options_json: &str) -> VcxCoreResult { + async fn get_wallet_record(&self, xtype: &str, id: &str, options: &str) -> VcxCoreResult { Ok(r#"{"id":"123","type":"record type","value":"record value","tags":null}"#.to_string()) } @@ -59,11 +60,16 @@ impl BaseWallet for MockWallet { Ok(()) } - async fn add_wallet_record_tags(&self, xtype: &str, id: &str, tags_json: &str) -> VcxCoreResult<()> { + async fn add_wallet_record_tags(&self, xtype: &str, id: &str, tags: HashMap) -> VcxCoreResult<()> { Ok(()) } - async fn update_wallet_record_tags(&self, xtype: &str, id: &str, tags_json: &str) -> VcxCoreResult<()> { + async fn update_wallet_record_tags( + &self, + xtype: &str, + id: &str, + tags: HashMap, + ) -> VcxCoreResult<()> { Ok(()) } diff --git a/aries_vcx_core/src/anoncreds/credx_anoncreds.rs b/aries_vcx_core/src/anoncreds/credx_anoncreds.rs index aae049a2b3..49c3dc0151 100644 --- a/aries_vcx_core/src/anoncreds/credx_anoncreds.rs +++ b/aries_vcx_core/src/anoncreds/credx_anoncreds.rs @@ -880,10 +880,10 @@ impl BaseAnonCreds for IndyCredxAnonCreds { let credential_id = cred_id.map_or(Uuid::new_v4().to_string(), String::from); let record_value = serde_json::to_string(&credential)?; - let tags_json = serde_json::to_string(&tags)?; + let tags_json: HashMap = serde_json::from_value(tags)?; self.wallet - .add_wallet_record(CATEGORY_CREDENTIAL, &credential_id, &record_value, Some(&tags_json)) + .add_wallet_record(CATEGORY_CREDENTIAL, &credential_id, &record_value, Some(tags_json)) .await?; Ok(credential_id) diff --git a/aries_vcx_core/src/wallet/agency_client_wallet.rs b/aries_vcx_core/src/wallet/agency_client_wallet.rs index ac1a3fa34d..f8f31c53c0 100644 --- a/aries_vcx_core/src/wallet/agency_client_wallet.rs +++ b/aries_vcx_core/src/wallet/agency_client_wallet.rs @@ -1,6 +1,6 @@ -use std::sync::Arc; - use crate::utils::async_fn_iterator::AsyncFnIterator; +use std::collections::HashMap; +use std::sync::Arc; use super::base_wallet::BaseWallet; use crate::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResult}; @@ -43,12 +43,12 @@ impl BaseWallet for AgencyClientWallet { xtype: &str, id: &str, value: &str, - tags_json: Option<&str>, + tags: Option>, ) -> VcxCoreResult<()> { Err(unimplemented_agency_client_wallet_method("add_wallet_record")) } - async fn get_wallet_record(&self, xtype: &str, id: &str, options_json: &str) -> VcxCoreResult { + async fn get_wallet_record(&self, xtype: &str, id: &str, options: &str) -> VcxCoreResult { Err(unimplemented_agency_client_wallet_method("get_wallet_record")) } @@ -64,7 +64,7 @@ impl BaseWallet for AgencyClientWallet { Err(unimplemented_agency_client_wallet_method("update_wallet_record_value")) } - async fn add_wallet_record_tags(&self, xtype: &str, id: &str, tags_json: &str) -> VcxCoreResult<()> { + async fn add_wallet_record_tags(&self, xtype: &str, id: &str, tags: HashMap) -> VcxCoreResult<()> { Err(unimplemented_agency_client_wallet_method("add_wallet_record_tags")) } @@ -72,7 +72,12 @@ impl BaseWallet for AgencyClientWallet { Err(unimplemented_agency_client_wallet_method("delete_wallet_record_tags")) } - async fn update_wallet_record_tags(&self, xtype: &str, id: &str, tags_json: &str) -> VcxCoreResult<()> { + async fn update_wallet_record_tags( + &self, + xtype: &str, + id: &str, + tags: HashMap, + ) -> VcxCoreResult<()> { Err(unimplemented_agency_client_wallet_method("update_wallet_record_tags")) } diff --git a/aries_vcx_core/src/wallet/base_wallet.rs b/aries_vcx_core/src/wallet/base_wallet.rs index ac3256728e..95e22a5c13 100644 --- a/aries_vcx_core/src/wallet/base_wallet.rs +++ b/aries_vcx_core/src/wallet/base_wallet.rs @@ -3,6 +3,8 @@ use async_trait::async_trait; use crate::errors::error::VcxCoreResult; use crate::utils::async_fn_iterator::AsyncFnIterator; +use std::collections::HashMap; + /// Trait defining standard 'wallet' related functionality. The APIs, including /// input and output types are loosely based off the indy Wallet API: /// see: @@ -26,10 +28,15 @@ pub trait BaseWallet: std::fmt::Debug + Send + Sync { // ---- records - async fn add_wallet_record(&self, xtype: &str, id: &str, value: &str, tags_json: Option<&str>) - -> VcxCoreResult<()>; + async fn add_wallet_record( + &self, + xtype: &str, + id: &str, + value: &str, + tags: Option>, + ) -> VcxCoreResult<()>; - async fn get_wallet_record(&self, xtype: &str, id: &str, options_json: &str) -> VcxCoreResult; + async fn get_wallet_record(&self, xtype: &str, id: &str, options: &str) -> VcxCoreResult; async fn get_wallet_record_value(&self, xtype: &str, id: &str) -> VcxCoreResult; @@ -37,9 +44,14 @@ pub trait BaseWallet: std::fmt::Debug + Send + Sync { async fn update_wallet_record_value(&self, xtype: &str, id: &str, value: &str) -> VcxCoreResult<()>; - async fn add_wallet_record_tags(&self, xtype: &str, id: &str, tags_json: &str) -> VcxCoreResult<()>; + async fn add_wallet_record_tags(&self, xtype: &str, id: &str, tags: HashMap) -> VcxCoreResult<()>; - async fn update_wallet_record_tags(&self, xtype: &str, id: &str, tags_json: &str) -> VcxCoreResult<()>; + async fn update_wallet_record_tags( + &self, + xtype: &str, + id: &str, + tags: HashMap, + ) -> VcxCoreResult<()>; async fn delete_wallet_record_tags(&self, xtype: &str, id: &str, tag_names: &str) -> VcxCoreResult<()>; diff --git a/aries_vcx_core/src/wallet/indy_wallet.rs b/aries_vcx_core/src/wallet/indy_wallet.rs index fb101c6477..cc01f78d24 100644 --- a/aries_vcx_core/src/wallet/indy_wallet.rs +++ b/aries_vcx_core/src/wallet/indy_wallet.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; use std::thread; use async_trait::async_trait; @@ -53,13 +54,15 @@ impl BaseWallet for IndySdkWallet { xtype: &str, id: &str, value: &str, - tags_json: Option<&str>, + tags: Option>, ) -> VcxCoreResult<()> { + let res = tags.map(|x| serde_json::to_string(&x)).transpose()?.to_owned(); + let tags_json = res.as_deref(); indy::wallet::add_wallet_record(self.wallet_handle, xtype, id, value, tags_json).await } - async fn get_wallet_record(&self, xtype: &str, id: &str, options_json: &str) -> VcxCoreResult { - indy::wallet::get_wallet_record(self.wallet_handle, xtype, id, options_json).await + async fn get_wallet_record(&self, xtype: &str, id: &str, options: &str) -> VcxCoreResult { + indy::wallet::get_wallet_record(self.wallet_handle, xtype, id, options).await } async fn get_wallet_record_value(&self, xtype: &str, id: &str) -> VcxCoreResult { @@ -87,12 +90,19 @@ impl BaseWallet for IndySdkWallet { indy::wallet::update_wallet_record_value(self.wallet_handle, xtype, id, value).await } - async fn update_wallet_record_tags(&self, xtype: &str, id: &str, tags_json: &str) -> VcxCoreResult<()> { - indy::wallet::update_wallet_record_tags(self.wallet_handle, xtype, id, tags_json).await + async fn update_wallet_record_tags( + &self, + xtype: &str, + id: &str, + tags: HashMap, + ) -> VcxCoreResult<()> { + let tags_json = serde_json::to_string(&tags)?; + indy::wallet::update_wallet_record_tags(self.wallet_handle, xtype, id, &tags_json).await } - async fn add_wallet_record_tags(&self, xtype: &str, id: &str, tags_json: &str) -> VcxCoreResult<()> { - indy::wallet::add_wallet_record_tags(self.wallet_handle, xtype, id, tags_json).await + async fn add_wallet_record_tags(&self, xtype: &str, id: &str, tags: HashMap) -> VcxCoreResult<()> { + let tags_json = serde_json::to_string(&tags)?; + indy::wallet::add_wallet_record_tags(self.wallet_handle, xtype, id, &tags_json).await } async fn delete_wallet_record_tags(&self, xtype: &str, id: &str, tag_names: &str) -> VcxCoreResult<()> { diff --git a/libvcx_core/src/api_vcx/api_global/wallet.rs b/libvcx_core/src/api_vcx/api_global/wallet.rs index 756ac54750..d92734de18 100644 --- a/libvcx_core/src/api_vcx/api_global/wallet.rs +++ b/libvcx_core/src/api_vcx/api_global/wallet.rs @@ -13,6 +13,8 @@ use crate::errors::error::LibvcxResult; use crate::errors::mapping_from_ariesvcx::map_ariesvcx_result; use crate::errors::mapping_from_ariesvcxcore::map_ariesvcx_core_result; +use std::collections::HashMap; + pub static mut WALLET_HANDLE: WalletHandle = INVALID_WALLET_HANDLE; pub fn set_main_wallet_handle(handle: WalletHandle) -> WalletHandle { @@ -113,7 +115,8 @@ pub async fn wallet_configure_issuer(enterprise_seed: &str) -> LibvcxResult) -> LibvcxResult<()> { let wallet = get_main_wallet(); - map_ariesvcx_core_result(wallet.add_wallet_record(type_, id, value, option).await) + let tags: Option> = option.map(|tags| serde_json::from_str(tags)).transpose()?; + map_ariesvcx_core_result(wallet.add_wallet_record(type_, id, value, tags).await) } pub async fn wallet_update_wallet_record_value(xtype: &str, id: &str, value: &str) -> LibvcxResult<()> { @@ -123,12 +126,14 @@ pub async fn wallet_update_wallet_record_value(xtype: &str, id: &str, value: &st pub async fn wallet_update_wallet_record_tags(xtype: &str, id: &str, tags_json: &str) -> LibvcxResult<()> { let wallet = get_main_wallet(); - map_ariesvcx_core_result(wallet.update_wallet_record_tags(xtype, id, tags_json).await) + let tags: HashMap = serde_json::from_str(tags_json)?; + map_ariesvcx_core_result(wallet.update_wallet_record_tags(xtype, id, tags).await) } pub async fn wallet_add_wallet_record_tags(xtype: &str, id: &str, tags_json: &str) -> LibvcxResult<()> { let wallet = get_main_wallet(); - map_ariesvcx_core_result(wallet.add_wallet_record_tags(xtype, id, tags_json).await) + let tags: HashMap = serde_json::from_str(tags_json)?; + map_ariesvcx_core_result(wallet.add_wallet_record_tags(xtype, id, tags).await) } pub async fn wallet_delete_wallet_record_tags(xtype: &str, id: &str, tags_json: &str) -> LibvcxResult<()> {