diff --git a/agents/rust/aries-vcx-agent/src/agent/init.rs b/agents/rust/aries-vcx-agent/src/agent/init.rs index 95ce7ebbed..e5de359eec 100644 --- a/agents/rust/aries-vcx-agent/src/agent/init.rs +++ b/agents/rust/aries-vcx-agent/src/agent/init.rs @@ -1,6 +1,7 @@ use std::sync::Arc; +use std::time::Duration; -use aries_vcx::core::profile::ledger::build_ledger_components; +use aries_vcx::core::profile::ledger::{build_ledger_components, VcxPoolConfig}; use aries_vcx::global::settings::DEFAULT_LINK_SECRET_ALIAS; use aries_vcx::{ agency_client::{agency_client::AgencyClient, configuration::AgentProvisionConfig}, @@ -9,8 +10,7 @@ use aries_vcx::{ utils::provision::provision_cloud_agent, }; use aries_vcx_core::ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite}; -use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig; -use aries_vcx_core::wallet::indy::wallet::{create_and_open_wallet, open_wallet, wallet_configure_issuer}; +use aries_vcx_core::wallet::indy::wallet::{create_and_open_wallet, wallet_configure_issuer}; use aries_vcx_core::wallet::indy::{IndySdkWallet, WalletConfig}; use url::Url; @@ -75,11 +75,12 @@ impl Agent { init_issuer_config(&config_issuer.institution_did).unwrap(); let wallet = Arc::new(IndySdkWallet::new(wallet_handle)); - let indy_vdr_pool_config = LedgerPoolConfig { - genesis_file_path: init_config.pool_config.genesis_path.clone(), + let pool_config = VcxPoolConfig { + genesis_file_path: init_config.pool_config.genesis_path, + indy_vdr_config: None, + response_cache_config: None, }; - - let (ledger_read, ledger_write) = build_ledger_components(wallet.clone(), indy_vdr_pool_config).unwrap(); + let (ledger_read, ledger_write) = build_ledger_components(wallet.clone(), pool_config).unwrap(); let anoncreds_ledger_read: Arc = ledger_read.clone(); let anoncreds_ledger_write: Arc = ledger_write.clone(); let indy_ledger_read: Arc = ledger_read.clone(); diff --git a/aries_vcx/src/core/profile/ledger.rs b/aries_vcx/src/core/profile/ledger.rs index 0d197bde4d..bb30ce76d5 100644 --- a/aries_vcx/src/core/profile/ledger.rs +++ b/aries_vcx/src/core/profile/ledger.rs @@ -4,24 +4,42 @@ use aries_vcx_core::ledger::indy_vdr_ledger::{ IndyVdrLedgerRead, IndyVdrLedgerReadConfig, IndyVdrLedgerWrite, IndyVdrLedgerWriteConfig, ProtocolVersion, }; use aries_vcx_core::ledger::request_signer::base_wallet::BaseWalletRequestSigner; -use aries_vcx_core::ledger::request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter, LedgerPoolConfig}; +use aries_vcx_core::ledger::request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter}; use aries_vcx_core::ledger::response_cacher::in_memory::{InMemoryResponseCacher, InMemoryResponseCacherConfig}; use aries_vcx_core::wallet::base_wallet::BaseWallet; -use aries_vcx_core::ResponseParser; +use aries_vcx_core::{PoolConfig, ResponseParser}; use std::sync::Arc; use std::time::Duration; +pub struct VcxPoolConfig { + pub genesis_file_path: String, + pub indy_vdr_config: Option, + pub response_cache_config: Option, +} + pub fn build_ledger_components( wallet: Arc, - ledger_pool_config: LedgerPoolConfig, + pool_config: VcxPoolConfig, ) -> VcxResult<( Arc>, Arc>, )> { - let ledger_pool = Arc::new(IndyVdrLedgerPool::new(ledger_pool_config)?); + let indy_vdr_config = match pool_config.indy_vdr_config { + None => PoolConfig::default(), + Some(cfg) => cfg, + }; + let cache_config = match pool_config.response_cache_config { + None => InMemoryResponseCacherConfig::builder() + .ttl(Duration::from_secs(60)) + .capacity(1000)? + .build(), + Some(cfg) => cfg, + }; + + let ledger_pool = Arc::new(IndyVdrLedgerPool::new(pool_config.genesis_file_path, indy_vdr_config)?); let request_submitter = Arc::new(IndyVdrSubmitter::new(ledger_pool)); - let ledger_read = indyvdr_build_ledger_read(request_submitter.clone())?; + let ledger_read = indyvdr_build_ledger_read(request_submitter.clone(), cache_config)?; let ledger_write = indyvdr_build_ledger_write(wallet, request_submitter, None); let ledger_read = Arc::new(ledger_read); @@ -32,13 +50,10 @@ pub fn build_ledger_components( pub fn indyvdr_build_ledger_read( request_submitter: Arc, + cache_config: InMemoryResponseCacherConfig, ) -> VcxResult> { let response_parser = Arc::new(ResponseParser::new()); - let cacher_config = InMemoryResponseCacherConfig::builder() - .ttl(Duration::from_secs(60)) - .capacity(1000)? - .build(); - let response_cacher = Arc::new(InMemoryResponseCacher::new(cacher_config)); + let response_cacher = Arc::new(InMemoryResponseCacher::new(cache_config)); let config_read = IndyVdrLedgerReadConfig { request_submitter: request_submitter.clone(), diff --git a/aries_vcx/src/core/profile/modular_libs_profile.rs b/aries_vcx/src/core/profile/modular_libs_profile.rs index 6b37c4f2a7..b95c866e25 100644 --- a/aries_vcx/src/core/profile/modular_libs_profile.rs +++ b/aries_vcx/src/core/profile/modular_libs_profile.rs @@ -1,23 +1,15 @@ use std::sync::Arc; -use std::time::Duration; use async_trait::async_trait; -use crate::core::profile::ledger::build_ledger_components; use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds; use aries_vcx_core::anoncreds::credx_anoncreds::IndyCredxAnonCreds; use aries_vcx_core::ledger::base_ledger::{ AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite, TaaConfigurator, TxnAuthrAgrmtOptions, }; -use aries_vcx_core::ledger::indy_vdr_ledger::{ - IndyVdrLedgerRead, IndyVdrLedgerReadConfig, IndyVdrLedgerWrite, IndyVdrLedgerWriteConfig, ProtocolVersion, -}; -use aries_vcx_core::ledger::request_signer::base_wallet::BaseWalletRequestSigner; -use aries_vcx_core::ledger::request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter, LedgerPoolConfig}; -use aries_vcx_core::ledger::response_cacher::in_memory::{InMemoryResponseCacher, InMemoryResponseCacherConfig}; use aries_vcx_core::wallet::base_wallet::BaseWallet; -use aries_vcx_core::ResponseParser; +use crate::core::profile::ledger::{build_ledger_components, VcxPoolConfig}; use crate::errors::error::VcxResult; use super::profile::Profile; @@ -39,9 +31,9 @@ pub struct ModularLibsProfile { } impl ModularLibsProfile { - pub fn init(wallet: Arc, ledger_pool_config: LedgerPoolConfig) -> VcxResult { + pub fn init(wallet: Arc, vcx_pool_config: VcxPoolConfig) -> VcxResult { let anoncreds = Arc::new(IndyCredxAnonCreds::new(Arc::clone(&wallet))); - let (ledger_read, ledger_write) = build_ledger_components(wallet.clone(), ledger_pool_config)?; + let (ledger_read, ledger_write) = build_ledger_components(wallet.clone(), vcx_pool_config)?; Ok(ModularLibsProfile { wallet, diff --git a/aries_vcx/src/utils/devsetup.rs b/aries_vcx/src/utils/devsetup.rs index 497c960836..8bd58a58de 100644 --- a/aries_vcx/src/utils/devsetup.rs +++ b/aries_vcx/src/utils/devsetup.rs @@ -12,22 +12,19 @@ use aries_vcx_core::wallet::base_wallet::BaseWallet; use aries_vcx_core::WalletHandle; use chrono::{DateTime, Duration, Utc}; use futures::future::BoxFuture; -use uuid::Uuid; -use crate::core::profile::ledger::build_ledger_components; +use crate::core::profile::ledger::{build_ledger_components, VcxPoolConfig}; use agency_client::agency_client::AgencyClient; use agency_client::configuration::AgentProvisionConfig; use agency_client::testing::mocking::{enable_agency_mocks, AgencyMockDecrypted}; use aries_vcx_core::ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite}; use aries_vcx_core::ledger::indy::pool::test_utils::{create_testpool_genesis_txn_file, get_temp_file_path}; -use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig; use aries_vcx_core::wallet::indy::did_mocks::DidMocks; -use aries_vcx_core::wallet::indy::wallet::{create_and_open_wallet, open_wallet, wallet_configure_issuer}; +use aries_vcx_core::wallet::indy::wallet::{create_and_open_wallet, wallet_configure_issuer}; use aries_vcx_core::wallet::indy::{IndySdkWallet, WalletConfig}; #[cfg(feature = "modular_libs")] use crate::core::profile::modular_libs_profile::ModularLibsProfile; -use crate::core::profile::prepare_taa_options; use crate::core::profile::profile::Profile; #[cfg(feature = "vdrtools")] use crate::core::profile::vdrtools_profile::VdrtoolsProfile; @@ -116,7 +113,12 @@ impl Drop for SetupMocks { #[cfg(feature = "migration")] pub fn make_modular_profile(wallet_handle: WalletHandle, genesis_file_path: String) -> Arc { let wallet = IndySdkWallet::new(wallet_handle); - Arc::new(ModularLibsProfile::init(Arc::new(wallet), LedgerPoolConfig { genesis_file_path }).unwrap()) + let vcx_pool_config = VcxPoolConfig { + genesis_file_path: genesis_file_path.clone(), + indy_vdr_config: None, + response_cache_config: None, + }; + Arc::new(ModularLibsProfile::init(Arc::new(wallet), vcx_pool_config).unwrap()) } impl SetupProfile { @@ -155,11 +157,13 @@ impl SetupProfile { async fn build_profile_vdrtools(genesis_file_path: String) -> SetupProfile { let (institution_did, wallet_handle) = setup_issuer_wallet().await; let wallet = Arc::new(IndySdkWallet::new(wallet_handle)); - let indy_vdr_pool_config = LedgerPoolConfig { + let vcx_pool_config = VcxPoolConfig { genesis_file_path: genesis_file_path.clone(), + indy_vdr_config: None, + response_cache_config: None, }; - let (ledger_read, ledger_write) = build_ledger_components(wallet.clone(), indy_vdr_pool_config).unwrap(); + let (ledger_read, ledger_write) = build_ledger_components(wallet.clone(), vcx_pool_config).unwrap(); let anoncreds_ledger_read: Arc = ledger_read.clone(); let anoncreds_ledger_write: Arc = ledger_write.clone(); let indy_ledger_read: Arc = ledger_read.clone(); @@ -189,11 +193,13 @@ impl SetupProfile { let (institution_did, wallet_handle) = setup_issuer_wallet().await; let wallet = IndySdkWallet::new(wallet_handle); - let indy_vdr_pool_config = LedgerPoolConfig { + let vcx_pool_config = VcxPoolConfig { genesis_file_path: genesis_file_path.clone(), + indy_vdr_config: None, + response_cache_config: None, }; - let profile = Arc::new(ModularLibsProfile::init(Arc::new(wallet), indy_vdr_pool_config).unwrap()); + let profile = Arc::new(ModularLibsProfile::init(Arc::new(wallet), vcx_pool_config).unwrap()); async fn modular_teardown() { warn!("build_profile_modular::modular_teardown") diff --git a/aries_vcx/tests/utils/devsetup_alice.rs b/aries_vcx/tests/utils/devsetup_alice.rs index fc953ce80e..888e92dad6 100644 --- a/aries_vcx/tests/utils/devsetup_alice.rs +++ b/aries_vcx/tests/utils/devsetup_alice.rs @@ -7,12 +7,8 @@ use agency_client::agency_client::AgencyClient; use agency_client::configuration::{AgencyClientConfig, AgentProvisionConfig}; use agency_client::MessageStatusCode; use aries_vcx::common::ledger::transactions::into_did_doc; -#[cfg(feature = "modular_libs")] -use aries_vcx::core::profile::modular_libs_profile::ModularLibsProfile; use aries_vcx::core::profile::profile::Profile; -use aries_vcx::core::profile::vdrtools_profile::VdrtoolsProfile; use aries_vcx::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult}; -use aries_vcx::global::settings; use aries_vcx::handlers::connection::mediated_connection::{ConnectionState, MediatedConnection}; use aries_vcx::handlers::issuance::holder::test_utils::get_credential_offer_messages; use aries_vcx::handlers::issuance::holder::Holder; @@ -24,14 +20,8 @@ use aries_vcx::handlers::util::{AnyInvitation, Status}; use aries_vcx::protocols::issuance::holder::state_machine::HolderState; use aries_vcx::protocols::mediated_connection::invitee::state_machine::InviteeState; use aries_vcx::protocols::proof_presentation::prover::state_machine::ProverState; -use aries_vcx::utils::devsetup::{SetupPoolDirectory, SetupProfile, AGENCY_DID, AGENCY_ENDPOINT, AGENCY_VERKEY}; +use aries_vcx::utils::devsetup::{SetupProfile, AGENCY_DID, AGENCY_ENDPOINT, AGENCY_VERKEY}; use aries_vcx::utils::provision::provision_cloud_agent; -#[cfg(feature = "modular_libs")] -use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig; -use aries_vcx_core::wallet::base_wallet::BaseWallet; -use aries_vcx_core::wallet::indy::wallet::open_wallet; -use aries_vcx_core::wallet::indy::{IndySdkWallet, WalletConfig}; -use aries_vcx_core::WalletHandle; use messages::msg_fields::protocols::cred_issuance::offer_credential::OfferCredential; use messages::msg_fields::protocols::cred_issuance::CredentialIssuance; use messages::msg_fields::protocols::present_proof::request::RequestPresentation; diff --git a/aries_vcx/tests/utils/devsetup_faber.rs b/aries_vcx/tests/utils/devsetup_faber.rs index 4a82fe77fd..b59530ac91 100644 --- a/aries_vcx/tests/utils/devsetup_faber.rs +++ b/aries_vcx/tests/utils/devsetup_faber.rs @@ -25,13 +25,8 @@ use aries_vcx::protocols::mediated_connection::inviter::state_machine::InviterSt use aries_vcx::protocols::proof_presentation::verifier::state_machine::VerifierState; use aries_vcx::protocols::proof_presentation::verifier::verification_status::PresentationVerificationStatus; use aries_vcx::protocols::revocation_notification::sender::state_machine::SenderConfigBuilder; -use aries_vcx::utils::devsetup::{SetupPoolDirectory, SetupProfile, AGENCY_DID, AGENCY_ENDPOINT, AGENCY_VERKEY}; +use aries_vcx::utils::devsetup::{SetupProfile, AGENCY_DID, AGENCY_ENDPOINT, AGENCY_VERKEY}; use aries_vcx::utils::provision::provision_cloud_agent; -#[cfg(feature = "modular_libs")] -use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig; -use aries_vcx_core::wallet::indy::wallet::{open_wallet, wallet_configure_issuer}; -use aries_vcx_core::wallet::indy::{IssuerConfig, WalletConfig}; -use aries_vcx_core::WalletHandle; use diddoc_legacy::aries::service::AriesService; use messages::decorators::please_ack::AckOn; use messages::msg_fields::protocols::connection::invitation::public::{PublicInvitation, PublicInvitationContent}; diff --git a/aries_vcx/tests/utils/devsetup_util.rs b/aries_vcx/tests/utils/devsetup_util.rs index 485453092f..4f097ce198 100644 --- a/aries_vcx/tests/utils/devsetup_util.rs +++ b/aries_vcx/tests/utils/devsetup_util.rs @@ -1,35 +1,14 @@ -use std::sync::Arc; - -use futures::future::BoxFuture; - #[cfg(feature = "modular_libs")] use aries_vcx::core::profile::modular_libs_profile::ModularLibsProfile; use aries_vcx::core::profile::profile::Profile; -use aries_vcx::core::profile::vdrtools_profile::VdrtoolsProfile; -use aries_vcx::global::settings; -#[cfg(feature = "modular_libs")] -use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig; use aries_vcx_core::wallet::base_wallet::BaseWallet; -use aries_vcx_core::wallet::indy::wallet::open_wallet; -use aries_vcx_core::wallet::indy::{IndySdkWallet, WalletConfig}; -use aries_vcx_core::WalletHandle; - -use crate::utils::devsetup_alice::Alice; #[cfg(test)] pub mod test_utils { - use std::collections::HashMap; - use std::sync::Arc; - use agency_client::api::downloaded_message::DownloadedMessage; #[cfg(feature = "modular_libs")] use aries_vcx::core::profile::modular_libs_profile::ModularLibsProfile; use aries_vcx::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult}; - #[cfg(feature = "modular_libs")] - use aries_vcx_core::ledger::request_submitter::vdr_ledger::LedgerPoolConfig; - use aries_vcx_core::wallet::indy::wallet::{close_wallet, delete_wallet}; - use aries_vcx_core::wallet::indy::WalletConfig; - use aries_vcx_core::WalletHandle; use messages::msg_fields::protocols::connection::Connection; use messages::msg_fields::protocols::cred_issuance::CredentialIssuance; use messages::msg_fields::protocols::present_proof::PresentProof; diff --git a/aries_vcx/tests/utils/migration.rs b/aries_vcx/tests/utils/migration.rs index 5d5424974e..b10d8616c4 100644 --- a/aries_vcx/tests/utils/migration.rs +++ b/aries_vcx/tests/utils/migration.rs @@ -4,17 +4,12 @@ use async_trait::async_trait; use uuid::Uuid; use aries_vcx::utils::devsetup::make_modular_profile; -use aries_vcx::{ - core::profile::modular_libs_profile::ModularLibsProfile, global::settings::WALLET_KDF_RAW, - utils::devsetup::SetupProfile, -}; +use aries_vcx::{global::settings::WALLET_KDF_RAW, utils::devsetup::SetupProfile}; use aries_vcx_core::wallet::agency_client_wallet::ToBaseAgencyClientWallet; use aries_vcx_core::wallet::indy::wallet::create_and_open_wallet; use aries_vcx_core::wallet::indy::IndySdkWallet; use aries_vcx_core::wallet::indy::WalletConfig; -use aries_vcx_core::{ - ledger::request_submitter::vdr_ledger::LedgerPoolConfig, wallet::base_wallet::BaseWallet, WalletHandle, -}; +use aries_vcx_core::{wallet::base_wallet::BaseWallet, WalletHandle}; use crate::utils::devsetup_alice::Alice; use crate::utils::devsetup_faber::Faber; diff --git a/aries_vcx_core/src/ledger/indy/pool.rs b/aries_vcx_core/src/ledger/indy/pool.rs index 3aece71c7c..e48ddb03f8 100644 --- a/aries_vcx_core/src/ledger/indy/pool.rs +++ b/aries_vcx_core/src/ledger/indy/pool.rs @@ -1,3 +1,4 @@ +use indy_vdr::config::PoolConfig; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -227,11 +228,3 @@ pub mod test_utils { f.sync_all().unwrap(); } } - -#[derive(Clone, Debug, Default, Builder, Serialize, Deserialize)] -#[builder(setter(into, strip_option), default)] -pub struct PoolConfig { - pub genesis_path: String, - pub pool_name: Option, - pub pool_config: Option, -} diff --git a/aries_vcx_core/src/ledger/request_submitter/vdr_ledger.rs b/aries_vcx_core/src/ledger/request_submitter/vdr_ledger.rs index 1a105ab9e6..8738e2b957 100644 --- a/aries_vcx_core/src/ledger/request_submitter/vdr_ledger.rs +++ b/aries_vcx_core/src/ledger/request_submitter/vdr_ledger.rs @@ -19,10 +19,6 @@ use crate::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind, VcxCoreResu use super::RequestSubmitter; -pub struct LedgerPoolConfig { - pub genesis_file_path: String, -} - pub struct IndyVdrLedgerPool { pub(self) runner: Option, } @@ -32,11 +28,10 @@ impl IndyVdrLedgerPool { IndyVdrLedgerPool { runner: Some(runner) } } - pub fn new(config: LedgerPoolConfig) -> VcxCoreResult { - let vdr_config = PoolConfig::default(); - let txns = PoolTransactions::from_json_file(config.genesis_file_path)?; + pub fn new(genesis_file_path: String, indy_vdr_config: PoolConfig) -> VcxCoreResult { + let txns = PoolTransactions::from_json_file(genesis_file_path)?; - let runner = PoolBuilder::from(vdr_config).transactions(txns)?.into_runner()?; + let runner = PoolBuilder::from(indy_vdr_config).transactions(txns)?.into_runner()?; Ok(IndyVdrLedgerPool { runner: Some(runner) }) } diff --git a/aries_vcx_core/src/ledger/response_cacher/in_memory/config.rs b/aries_vcx_core/src/ledger/response_cacher/in_memory/config.rs index 5e4f1fc832..394f30ebb3 100644 --- a/aries_vcx_core/src/ledger/response_cacher/in_memory/config.rs +++ b/aries_vcx_core/src/ledger/response_cacher/in_memory/config.rs @@ -1,7 +1,9 @@ use std::{num::NonZeroUsize, time::Duration}; +use serde::Deserialize; use crate::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind}; +#[derive(Clone, Debug, Deserialize)] pub struct InMemoryResponseCacherConfig { ttl: Duration, capacity: NonZeroUsize, diff --git a/aries_vcx_core/src/lib.rs b/aries_vcx_core/src/lib.rs index 0d84734992..d9e4c0cc40 100644 --- a/aries_vcx_core/src/lib.rs +++ b/aries_vcx_core/src/lib.rs @@ -42,3 +42,5 @@ pub use vdrtools::{SearchHandle, WalletHandle, INVALID_SEARCH_HANDLE, INVALID_WA pub use indy_vdr_proxy_client::VdrProxyClient; pub use indy_ledger_response_parser::ResponseParser; + +pub use indy_vdr::config::PoolConfig; diff --git a/did_resolver_sov/src/reader/vdr_reader.rs b/did_resolver_sov/src/reader/vdr_reader.rs index 27c272ab1c..f30fed9f30 100644 --- a/did_resolver_sov/src/reader/vdr_reader.rs +++ b/did_resolver_sov/src/reader/vdr_reader.rs @@ -4,7 +4,7 @@ use crate::error::DidSovError; use aries_vcx_core::{ ledger::{ indy_vdr_ledger::{IndyVdrLedgerRead, IndyVdrLedgerReadConfig, ProtocolVersion}, - request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter, LedgerPoolConfig}, + request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter}, response_cacher::in_memory::{InMemoryResponseCacher, InMemoryResponseCacherConfig}, }, ResponseParser, @@ -12,25 +12,26 @@ use aries_vcx_core::{ use super::ConcreteAttrReader; -impl TryFrom for ConcreteAttrReader { - type Error = DidSovError; - - fn try_from(pool_config: LedgerPoolConfig) -> Result { - let ledger_pool = Arc::new(IndyVdrLedgerPool::new(pool_config)?); - let request_submitter = Arc::new(IndyVdrSubmitter::new(ledger_pool)); - let response_parser = Arc::new(ResponseParser::new()); - let cacher_config = InMemoryResponseCacherConfig::builder() - .ttl(Duration::from_secs(60)) - .capacity(1000)? - .build(); - let response_cacher = Arc::new(InMemoryResponseCacher::new(cacher_config)); - let config = IndyVdrLedgerReadConfig { - request_submitter, - response_parser, - response_cacher, - protocol_version: ProtocolVersion::node_1_4(), - }; - let ledger = Arc::new(IndyVdrLedgerRead::new(config)); - Ok(Self { ledger }) - } -} +// todo: make things work one way or the other +// impl TryFrom for ConcreteAttrReader { +// type Error = DidSovError; +// +// fn try_from(pool_config: LedgerPoolConfig) -> Result { +// let ledger_pool = Arc::new(IndyVdrLedgerPool::new(pool_config)?); +// let request_submitter = Arc::new(IndyVdrSubmitter::new(ledger_pool)); +// let response_parser = Arc::new(ResponseParser::new()); +// let cacher_config = InMemoryResponseCacherConfig::builder() +// .ttl(Duration::from_secs(60)) +// .capacity(1000)? +// .build(); +// let response_cacher = Arc::new(InMemoryResponseCacher::new(cacher_config)); +// let config = IndyVdrLedgerReadConfig { +// request_submitter, +// response_parser, +// response_cacher, +// protocol_version: ProtocolVersion::node_1_4(), +// }; +// let ledger = Arc::new(IndyVdrLedgerRead::new(config)); +// Ok(Self { ledger }) +// } +// } diff --git a/libvcx/src/api_c/vcx.rs b/libvcx/src/api_c/vcx.rs index c58af45d48..35fc8a2d5d 100644 --- a/libvcx/src/api_c/vcx.rs +++ b/libvcx/src/api_c/vcx.rs @@ -4,12 +4,11 @@ use futures::future::{BoxFuture, FutureExt}; use libc::c_char; use aries_vcx::agency_client::configuration::AgencyClientConfig; -use aries_vcx::aries_vcx_core::ledger::indy::pool::PoolConfig; use aries_vcx::aries_vcx_core::wallet::indy::IssuerConfig; use libvcx_core::api_vcx::api_global::agency_client::create_agency_client_for_main_wallet; use libvcx_core::api_vcx::api_global::agency_client::update_webhook_url; use libvcx_core::api_vcx::api_global::ledger::ledger_get_txn_author_agreement; -use libvcx_core::api_vcx::api_global::pool::open_main_pool; +use libvcx_core::api_vcx::api_global::pool::{LibvcxLedgerConfig, open_main_pool}; use libvcx_core::api_vcx::api_global::settings::{enable_mocks, settings_init_issuer_config}; use libvcx_core::api_vcx::api_global::state::state_vcx_shutdown; use libvcx_core::api_vcx::api_global::VERSION_STRING; @@ -238,7 +237,7 @@ pub extern "C" fn vcx_open_main_pool( info!("vcx_open_main_pool >>>"); check_useful_c_str!(pool_config, LibvcxErrorKind::InvalidOption); - let pool_config = match serde_json::from_str::(&pool_config) { + let pool_config = match serde_json::from_str::(&pool_config) { Ok(pool_config) => pool_config, Err(err) => { set_current_error(&err); diff --git a/libvcx_core/src/api_vcx/api_global/ledger.rs b/libvcx_core/src/api_vcx/api_global/ledger.rs index 82d22e2bfe..922600d180 100644 --- a/libvcx_core/src/api_vcx/api_global/ledger.rs +++ b/libvcx_core/src/api_vcx/api_global/ledger.rs @@ -124,7 +124,7 @@ pub mod tests { use aries_vcx::aries_vcx_core::ledger::indy::pool::test_utils::{ create_genesis_txn_file, create_testpool_genesis_txn_file, get_temp_file_path, get_txns_sovrin_testnet, }; - use aries_vcx::aries_vcx_core::ledger::indy::pool::PoolConfig; + use aries_vcx::aries_vcx_core::ledger::indy::pool::LedgerConfig; use aries_vcx::global::settings::{CONFIG_TXN_AUTHOR_AGREEMENT, DEFAULT_GENESIS_PATH}; use aries_vcx::utils::devsetup::{SetupEmpty, SetupMocks}; @@ -134,7 +134,7 @@ pub mod tests { _create_and_open_wallet().await.unwrap(); let genesis_path = get_temp_file_path(DEFAULT_GENESIS_PATH).to_str().unwrap().to_string(); create_genesis_txn_file(&genesis_path, Box::new(get_txns_sovrin_testnet)); - let config = PoolConfig { + let config = LedgerConfig { genesis_path, pool_name: None, pool_config: None, @@ -154,7 +154,7 @@ pub mod tests { _create_and_open_wallet().await.unwrap(); let genesis_path = get_temp_file_path(DEFAULT_GENESIS_PATH).to_str().unwrap().to_string(); create_testpool_genesis_txn_file(&genesis_path); - let config = PoolConfig { + let config = LedgerConfig { genesis_path, pool_name: None, pool_config: None, diff --git a/libvcx_core/src/api_vcx/api_global/pool.rs b/libvcx_core/src/api_vcx/api_global/pool.rs index 7536f12246..9876375815 100644 --- a/libvcx_core/src/api_vcx/api_global/pool.rs +++ b/libvcx_core/src/api_vcx/api_global/pool.rs @@ -1,23 +1,22 @@ use aries_vcx::aries_vcx_core::ledger::base_ledger::{ AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite, TaaConfigurator, }; -use aries_vcx::global::settings::{indy_mocks_enabled, DEFAULT_POOL_NAME}; use crate::api_vcx::api_global::profile::get_main_wallet; -use crate::api_vcx::api_global::wallet::get_main_wallet_handle; use crate::errors::error::{LibvcxError, LibvcxErrorKind, LibvcxResult}; -use aries_vcx::aries_vcx_core::errors::error::AriesVcxCoreError; -use aries_vcx::aries_vcx_core::ledger::indy::pool::PoolConfig; use aries_vcx::aries_vcx_core::ledger::request_submitter::vdr_ledger::{ - IndyVdrLedgerPool, IndyVdrSubmitter, LedgerPoolConfig, + IndyVdrLedgerPool, IndyVdrSubmitter, }; use aries_vcx::aries_vcx_core::wallet::base_wallet::BaseWallet; use aries_vcx::core::profile::ledger::indyvdr_build_ledger_read; use aries_vcx::core::profile::ledger::indyvdr_build_ledger_write; use aries_vcx::core::profile::profile::Profile; -use aries_vcx::errors::error::{AriesVcxError, VcxResult}; +use aries_vcx::errors::error::VcxResult; use std::sync::Arc; use std::sync::RwLock; +use std::time::Duration; +use aries_vcx::aries_vcx_core::ledger::response_cacher::in_memory::InMemoryResponseCacherConfig; +use aries_vcx::aries_vcx_core::PoolConfig; lazy_static! { pub static ref global_ledger_anoncreds_read: RwLock>> = RwLock::new(None); @@ -33,10 +32,16 @@ pub fn is_main_pool_open() -> bool { // global_profile.inject_anoncreds_ledger_read() } +#[derive(Clone, Debug, Deserialize)] +pub struct LibvcxLedgerConfig { + pub genesis_path: String, + pub pool_config: Option, + pub cache_config: Option, +} + async fn build_components_ledger( base_wallet: Arc, - pool_name: String, - config: &PoolConfig, + libvcx_pool_config: &LibvcxLedgerConfig, ) -> VcxResult<( Arc, Arc, @@ -44,13 +49,21 @@ async fn build_components_ledger( Arc, Arc, )> { - let ledger_pool_config = LedgerPoolConfig { - genesis_file_path: config.genesis_path.clone(), + let cache_config = match &libvcx_pool_config.cache_config { + None => InMemoryResponseCacherConfig::builder() + .ttl(Duration::from_secs(60)) + .capacity(1000)? + .build(), + Some(cfg) => cfg.clone() + }; + let indy_vdr_config = match &libvcx_pool_config.pool_config { + None => PoolConfig::default(), + Some(cfg) => cfg.clone() }; - let ledger_pool = Arc::new(IndyVdrLedgerPool::new(ledger_pool_config)?); + let ledger_pool = Arc::new(IndyVdrLedgerPool::new(libvcx_pool_config.genesis_path.clone(), indy_vdr_config)?); let request_submitter = Arc::new(IndyVdrSubmitter::new(ledger_pool)); - let ledger_read = Arc::new(indyvdr_build_ledger_read(request_submitter.clone())?); + let ledger_read = Arc::new(indyvdr_build_ledger_read(request_submitter.clone(), cache_config)?); let ledger_write = Arc::new(indyvdr_build_ledger_write(base_wallet, request_submitter, None)); let taa_configurator: Arc = ledger_write.clone(); let anoncreds_write: Arc = ledger_write.clone(); @@ -74,24 +87,24 @@ pub fn reset_ledger_components() -> LibvcxResult<()> { Ok(()) } -pub async fn setup_ledger_components(pool_name: String, config: &PoolConfig) -> LibvcxResult<()> { +pub async fn setup_ledger_components(config: &LibvcxLedgerConfig) -> LibvcxResult<()> { let base_wallet = get_main_wallet()?; let (anoncreds_read, anoncreds_write, indy_read, indy_write, taa_configurator) = - build_components_ledger(base_wallet, pool_name, config).await?; + build_components_ledger(base_wallet, config).await?; let mut anoncreds_read_guard = global_ledger_anoncreds_read.write()?; - *anoncreds_read_guard = Some(anoncreds_read.clone() as Arc); + *anoncreds_read_guard = Some(anoncreds_read.clone()); let mut anoncreds_write_guard = global_ledger_anoncreds_write.write()?; - *anoncreds_write_guard = Some(anoncreds_write.clone() as Arc); + *anoncreds_write_guard = Some(anoncreds_write.clone()); let mut indy_read_guard = global_ledger_indy_read.write()?; - *indy_read_guard = Some(indy_read.clone() as Arc); + *indy_read_guard = Some(indy_read.clone()); let mut indy_write_guard = global_ledger_indy_write.write()?; - *indy_write_guard = Some(indy_write.clone() as Arc); + *indy_write_guard = Some(indy_write.clone()); let mut indy_taa_configurator = global_taa_configurator.write()?; - *indy_taa_configurator = Some(taa_configurator.clone() as Arc); + *indy_taa_configurator = Some(taa_configurator.clone()); Ok(()) } -pub async fn open_main_pool(config: &PoolConfig) -> LibvcxResult<()> { +pub async fn open_main_pool(config: &LibvcxLedgerConfig) -> LibvcxResult<()> { if is_main_pool_open() { error!("open_main_pool >> Pool connection is already open."); return Err(LibvcxError::from_msg( @@ -100,15 +113,13 @@ pub async fn open_main_pool(config: &PoolConfig) -> LibvcxResult<()> { )); } - let pool_name = config.pool_name.clone().unwrap_or(DEFAULT_POOL_NAME.to_string()); trace!( - "open_pool >> pool_name: {}, path: {}, pool_config: {:?}", - pool_name, + "open_pool >> path: {}, pool_config: {:?}", config.genesis_path, config.pool_config ); - setup_ledger_components(pool_name, config).await?; + setup_ledger_components(config).await?; info!("open_pool >> Pool Opened Successfully"); @@ -132,7 +143,7 @@ pub mod tests { use aries_vcx::aries_vcx_core::ledger::indy::pool::test_utils::{ create_testpool_genesis_txn_file, get_temp_file_path, }; - use aries_vcx::aries_vcx_core::ledger::indy::pool::PoolConfig; + use aries_vcx::aries_vcx_core::ledger::indy::pool::LedgerConfig; use aries_vcx::core::profile::profile::Profile; use aries_vcx::global::settings::{set_config_value, CONFIG_GENESIS_PATH, DEFAULT_GENESIS_PATH}; use aries_vcx::utils::constants::POOL1_TXN; @@ -145,7 +156,7 @@ pub mod tests { _create_and_open_wallet().await.unwrap(); let genesis_path = get_temp_file_path(DEFAULT_GENESIS_PATH).to_str().unwrap().to_string(); create_testpool_genesis_txn_file(&genesis_path); - let config = PoolConfig { + let config = LedgerConfig { genesis_path, pool_name: None, pool_config: None, @@ -168,7 +179,7 @@ pub mod tests { set_config_value(CONFIG_GENESIS_PATH, &_genesis_transactions.path).unwrap(); - let pool_config = PoolConfig { + let pool_config = LedgerConfig { genesis_path: _genesis_transactions.path.clone(), pool_name: Some(pool_name.clone()), pool_config: None, @@ -190,7 +201,7 @@ pub mod tests { _create_and_open_wallet().await.unwrap(); let pool_name = format!("invalidpool_{}", uuid::Uuid::new_v4().to_string()); - let pool_config = PoolConfig { + let pool_config = LedgerConfig { genesis_path: "invalid/txn/path".to_string(), pool_name: Some(pool_name.clone()), pool_config: None, diff --git a/libvcx_core/src/api_vcx/utils/devsetup.rs b/libvcx_core/src/api_vcx/utils/devsetup.rs index 1c1976c3c9..54787ae915 100644 --- a/libvcx_core/src/api_vcx/utils/devsetup.rs +++ b/libvcx_core/src/api_vcx/utils/devsetup.rs @@ -1,7 +1,7 @@ use agency_client::agency_client::AgencyClient; use aries_vcx::aries_vcx_core::global::settings; use aries_vcx::aries_vcx_core::ledger::indy::pool::test_utils::{create_testpool_genesis_txn_file, get_temp_file_path}; -use aries_vcx::aries_vcx_core::ledger::indy::pool::PoolConfig; +use aries_vcx::aries_vcx_core::ledger::indy::pool::LedgerConfig; use aries_vcx::aries_vcx_core::WalletHandle; use aries_vcx::global::settings::{ set_config_value, CONFIG_GENESIS_PATH, CONFIG_INSTITUTION_DID, DEFAULT_DID, DEFAULT_GENESIS_PATH, @@ -41,18 +41,17 @@ impl SetupGlobalsWalletPoolAgency { { let init = Self::init().await; - let pool_name = Uuid::new_v4().to_string(); let genesis_path = get_temp_file_path(DEFAULT_GENESIS_PATH).to_str().unwrap().to_string(); create_testpool_genesis_txn_file(&genesis_path); setup_wallet(init.wallet_handle).unwrap(); set_main_agency_client(init.agency_client.clone()); - let pool_config = PoolConfig { + let pool_config = LedgerConfig { genesis_path, pool_name: None, pool_config: None, }; - setup_ledger_components(pool_name, &pool_config).await.unwrap(); + setup_ledger_components(&pool_config).await.unwrap(); f(init).await; diff --git a/libvdrtools/src/domain/mod.rs b/libvdrtools/src/domain/mod.rs index 09a0e36333..9eed3ac863 100644 --- a/libvdrtools/src/domain/mod.rs +++ b/libvdrtools/src/domain/mod.rs @@ -3,7 +3,6 @@ pub mod cache; pub mod crypto; pub mod ledger; pub mod pairwise; -pub mod pool; use indy_api_types::validation::Validatable; diff --git a/libvdrtools/src/domain/pool.rs b/libvdrtools/src/domain/pool.rs deleted file mode 100644 index 6aa1cfce24..0000000000 --- a/libvdrtools/src/domain/pool.rs +++ /dev/null @@ -1,118 +0,0 @@ -use indy_api_types::validation::Validatable; - -pub const POOL_CON_ACTIVE_TO: i64 = 5; -pub const POOL_ACK_TIMEOUT: i64 = 20; -pub const POOL_REPLY_TIMEOUT: i64 = 60; -pub const MAX_REQ_PER_POOL_CON: usize = 5; -pub const NUMBER_READ_NODES: u8 = 2; -pub const POOL_MODE: PoolMode = PoolMode::Persistent; - -#[derive(Debug, Serialize, Deserialize)] -pub struct PoolConfig { - pub genesis_txn: String, -} - -impl PoolConfig { - pub fn default_for_name(name: &str) -> PoolConfig { - let mut txn = name.to_string(); - txn += ".txn"; - PoolConfig { genesis_txn: txn } - } -} - -#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)] -pub enum PoolMode { - InMemory, - Persistent, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct VdrtoolsPoolOpenConfig { - #[serde(default = "VdrtoolsPoolOpenConfig::default_timeout")] - pub timeout: i64, - #[serde(default = "VdrtoolsPoolOpenConfig::default_extended_timeout")] - pub extended_timeout: i64, - #[serde(default = "VdrtoolsPoolOpenConfig::default_conn_limit")] - pub conn_limit: usize, - #[serde(default = "VdrtoolsPoolOpenConfig::default_conn_active_timeout")] - pub conn_active_timeout: i64, - #[serde(default = "VdrtoolsPoolOpenConfig::default_preordered_nodes")] - pub preordered_nodes: Vec, - #[serde(default = "VdrtoolsPoolOpenConfig::default_number_read_nodes")] - pub number_read_nodes: u8, - #[serde(default = "VdrtoolsPoolOpenConfig::default_pool_mode")] - pub pool_mode: PoolMode, - #[serde(default)] - pub transactions: Option, -} - -impl Validatable for VdrtoolsPoolOpenConfig { - fn validate(&self) -> Result<(), String> { - if self.timeout <= 0 { - return Err(String::from("`timeout` must be greater than 0")); - } - if self.extended_timeout <= 0 { - return Err(String::from("`extended_timeout` must be greater than 0")); - } - if self.conn_limit == 0 { - return Err(String::from("`conn_limit` must be greater than 0")); - } - if self.conn_active_timeout <= 0 { - return Err(String::from("`conn_active_timeout` must be greater than 0")); - } - if self.number_read_nodes == 0 { - return Err(String::from("`number_read_nodes` must be greater than 0")); - } - if self.pool_mode == PoolMode::InMemory && self.transactions.is_none() { - return Err(String::from( - "`transactions` should exist if pool_mode is set to 'InMemory'", - )); - } - Ok(()) - } -} - -impl Default for VdrtoolsPoolOpenConfig { - fn default() -> Self { - VdrtoolsPoolOpenConfig { - timeout: VdrtoolsPoolOpenConfig::default_timeout(), - extended_timeout: VdrtoolsPoolOpenConfig::default_extended_timeout(), - conn_limit: VdrtoolsPoolOpenConfig::default_conn_limit(), - conn_active_timeout: VdrtoolsPoolOpenConfig::default_conn_active_timeout(), - preordered_nodes: VdrtoolsPoolOpenConfig::default_preordered_nodes(), - number_read_nodes: VdrtoolsPoolOpenConfig::default_number_read_nodes(), - pool_mode: VdrtoolsPoolOpenConfig::default_pool_mode(), - transactions: None, - } - } -} - -impl VdrtoolsPoolOpenConfig { - fn default_timeout() -> i64 { - POOL_ACK_TIMEOUT - } - - fn default_extended_timeout() -> i64 { - POOL_REPLY_TIMEOUT - } - - fn default_conn_limit() -> usize { - MAX_REQ_PER_POOL_CON - } - - fn default_conn_active_timeout() -> i64 { - POOL_CON_ACTIVE_TO - } - - fn default_preordered_nodes() -> Vec { - Vec::new() - } - - fn default_number_read_nodes() -> u8 { - NUMBER_READ_NODES - } - - fn default_pool_mode() -> PoolMode { - POOL_MODE - } -} diff --git a/wrappers/vcx-napi-rs/src/api/pool.rs b/wrappers/vcx-napi-rs/src/api/pool.rs index 7a4da599f5..2638664a76 100644 --- a/wrappers/vcx-napi-rs/src/api/pool.rs +++ b/wrappers/vcx-napi-rs/src/api/pool.rs @@ -1,8 +1,9 @@ +use napi_derive::napi; + use libvcx_core::api_vcx::api_global::pool; -use libvcx_core::aries_vcx::aries_vcx_core::ledger::indy::pool::PoolConfig; +use libvcx_core::api_vcx::api_global::pool::LibvcxLedgerConfig; use libvcx_core::errors::error::{LibvcxError, LibvcxErrorKind}; use libvcx_core::serde_json; -use napi_derive::napi; use crate::error::to_napi_err; @@ -10,7 +11,7 @@ use crate::error::to_napi_err; // is async if the respective layer is async #[napi] async fn open_main_pool(pool_config: String) -> napi::Result<()> { - let pool_config = serde_json::from_str::(&pool_config) + let pool_config = serde_json::from_str::(&pool_config) .map_err(|err| LibvcxError::from_msg(LibvcxErrorKind::InvalidJson, format!("Serialization error: {:?}", err))) .map_err(to_napi_err)?; pool::open_main_pool(&pool_config).await.map_err(to_napi_err)?;