Skip to content

Commit

Permalink
Remove vdrtools based ledger client
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas committed Jul 26, 2023
1 parent 29cde27 commit 32919e1
Show file tree
Hide file tree
Showing 54 changed files with 172 additions and 19,224 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,6 @@ jobs:
strategy:
matrix:
features: [
"ledger_vdrtools,anoncreds_vdrtools",
"ledger_vdrtools,anoncreds_credx",
"ledger_indyvdr,anoncreds_vdrtools",
"ledger_indyvdr,anoncreds_credx"
]
Expand All @@ -523,8 +521,6 @@ jobs:
strategy:
matrix:
features: [
"ledger_vdrtools,anoncreds_vdrtools",
"ledger_vdrtools,anoncreds_credx",
"ledger_indyvdr,anoncreds_vdrtools",
"ledger_indyvdr,anoncreds_credx"
]
Expand Down
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 21 additions & 16 deletions agents/rust/aries-vcx-agent/src/agent/init.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use std::sync::Arc;

use aries_vcx::core::profile::ledger::build_ledger_components;
use aries_vcx::global::settings::DEFAULT_LINK_SECRET_ALIAS;
use aries_vcx::{
agency_client::{agency_client::AgencyClient, configuration::AgentProvisionConfig},
core::profile::{profile::Profile, vdrtools_profile::VdrtoolsProfile},
global::settings::init_issuer_config,
utils::provision::provision_cloud_agent,
};
use aries_vcx_core::ledger::indy::pool::{create_pool_ledger_config, indy_open_pool, PoolConfigBuilder};
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::WalletConfig;
use aries_vcx_core::wallet::indy::{IndySdkWallet, WalletConfig};
use url::Url;

use crate::{
Expand Down Expand Up @@ -67,26 +69,29 @@ impl Agent {
};

let wallet_handle = create_and_open_wallet(&config_wallet).await.unwrap();

let config_issuer = wallet_configure_issuer(wallet_handle, &init_config.enterprise_seed)
.await
.unwrap();
init_issuer_config(&config_issuer.institution_did).unwrap();
let wallet = Arc::new(IndySdkWallet::new(wallet_handle));

let pool_config = PoolConfigBuilder::default()
.genesis_path(&init_config.pool_config.genesis_path)
.build()
.expect("Failed to build pool config");
create_pool_ledger_config(
&init_config.pool_config.pool_name,
&init_config.pool_config.genesis_path,
)
.unwrap();
let pool_handle = indy_open_pool(&init_config.pool_config.pool_name, pool_config.pool_config)
.await
.unwrap();
let indy_vdr_pool_config = LedgerPoolConfig {
genesis_file_path: init_config.pool_config.genesis_path.clone(),
};

let (ledger_read, ledger_write) = build_ledger_components(wallet.clone(), indy_vdr_pool_config).unwrap();
let anoncreds_ledger_read: Arc<dyn AnoncredsLedgerRead> = ledger_read.clone();
let anoncreds_ledger_write: Arc<dyn AnoncredsLedgerWrite> = ledger_write.clone();
let indy_ledger_read: Arc<dyn IndyLedgerRead> = ledger_read.clone();
let indy_ledger_write: Arc<dyn IndyLedgerWrite> = ledger_write.clone();

let indy_profile = VdrtoolsProfile::init(wallet_handle, pool_handle);
let indy_profile = VdrtoolsProfile::init(
wallet,
anoncreds_ledger_read,
anoncreds_ledger_write,
indy_ledger_read,
indy_ledger_write,
);
let profile: Arc<dyn Profile> = Arc::new(indy_profile);
let wallet = profile.inject_wallet();
let anoncreds = profile.inject_anoncreds();
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx/src/common/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds;
use aries_vcx_core::ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite};
use aries_vcx_core::ledger::indy::pool::test_utils::{get_temp_dir_path, get_temp_file_path};
use aries_vcx_core::ledger::indy::pool::test_utils::get_temp_dir_path;
use std::sync::Arc;
use std::thread;
use std::time::Duration;
Expand Down
65 changes: 65 additions & 0 deletions aries_vcx/src/core/profile/ledger.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use crate::errors::error::VcxResult;
use aries_vcx_core::ledger::base_ledger::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 std::sync::Arc;
use std::time::Duration;

pub fn build_ledger_components(
wallet: Arc<dyn BaseWallet>,
ledger_pool_config: LedgerPoolConfig,
) -> VcxResult<(
Arc<IndyVdrLedgerRead<IndyVdrSubmitter, InMemoryResponseCacher>>,
Arc<IndyVdrLedgerWrite<IndyVdrSubmitter, BaseWalletRequestSigner>>,
)> {
let ledger_pool = Arc::new(IndyVdrLedgerPool::new(ledger_pool_config)?);
let request_submitter = Arc::new(IndyVdrSubmitter::new(ledger_pool));

let ledger_read = indyvdr_build_ledger_read(request_submitter.clone())?;
let ledger_write = indyvdr_build_ledger_write(wallet, request_submitter, None);

let ledger_read = Arc::new(ledger_read);
let ledger_write = Arc::new(ledger_write);

return Ok((ledger_read, ledger_write));
}

pub fn indyvdr_build_ledger_read(
request_submitter: Arc<IndyVdrSubmitter>,
) -> VcxResult<IndyVdrLedgerRead<IndyVdrSubmitter, InMemoryResponseCacher>> {
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_read = IndyVdrLedgerReadConfig {
request_submitter: request_submitter.clone(),
response_parser,
response_cacher,
protocol_version: ProtocolVersion::node_1_4(),
};
Ok(IndyVdrLedgerRead::new(config_read))
}

pub fn indyvdr_build_ledger_write(
wallet: Arc<dyn BaseWallet>,
request_submitter: Arc<IndyVdrSubmitter>,
taa_options: Option<TxnAuthrAgrmtOptions>,
) -> IndyVdrLedgerWrite<IndyVdrSubmitter, BaseWalletRequestSigner> {
let request_signer = Arc::new(BaseWalletRequestSigner::new(wallet.clone()));
let config_write = IndyVdrLedgerWriteConfig {
request_signer,
request_submitter,
taa_options,
protocol_version: ProtocolVersion::node_1_4(),
};
IndyVdrLedgerWrite::new(config_write)
}
6 changes: 1 addition & 5 deletions aries_vcx/src/core/profile/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod ledger;
#[cfg(feature = "modular_libs")]
pub mod modular_libs_profile;
pub mod profile;
Expand All @@ -6,20 +7,15 @@ pub mod vdr_proxy_profile;
#[cfg(feature = "vdrtools")]
pub mod vdrtools_profile;

#[cfg(any(feature = "modular_libs", feature = "vdr_proxy_ledger"))]
const DEFAULT_AML_LABEL: &str = "eula";

#[cfg(any(feature = "modular_libs", feature = "vdr_proxy_ledger"))]
use std::sync::Arc;

#[cfg(any(feature = "modular_libs", feature = "vdr_proxy_ledger"))]
use aries_vcx_core::ledger::base_ledger::TxnAuthrAgrmtOptions;
#[cfg(any(feature = "modular_libs", feature = "vdr_proxy_ledger"))]
use aries_vcx_core::ledger::{base_ledger::IndyLedgerRead, indy_vdr_ledger::GetTxnAuthorAgreementData};

use crate::errors::error::VcxResult;

#[cfg(any(feature = "modular_libs", feature = "vdr_proxy_ledger"))]
pub async fn prepare_taa_options(ledger_read: Arc<dyn IndyLedgerRead>) -> VcxResult<Option<TxnAuthrAgrmtOptions>> {
if let Some(taa_result) = ledger_read.get_txn_author_agreement().await? {
let taa_result: GetTxnAuthorAgreementData = serde_json::from_str(&taa_result)?;
Expand Down
47 changes: 4 additions & 43 deletions aries_vcx/src/core/profile/modular_libs_profile.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
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::{
Expand All @@ -14,7 +17,6 @@ use aries_vcx_core::ledger::request_submitter::vdr_ledger::{IndyVdrLedgerPool, I
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 async_trait::async_trait;

use crate::errors::error::VcxResult;

Expand All @@ -36,52 +38,11 @@ pub struct ModularLibsProfile {
taa_configurator: Arc<dyn TaaConfigurator>,
}

pub fn indyvdr_build_ledger_read(
request_submitter: Arc<IndyVdrSubmitter>,
) -> VcxResult<IndyVdrLedgerRead<IndyVdrSubmitter, InMemoryResponseCacher>> {
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_read = IndyVdrLedgerReadConfig {
request_submitter: request_submitter.clone(),
response_parser,
response_cacher,
protocol_version: ProtocolVersion::node_1_4(),
};
Ok(IndyVdrLedgerRead::new(config_read))
}

pub fn indyvdr_build_ledger_write(
wallet: Arc<dyn BaseWallet>,
request_submitter: Arc<IndyVdrSubmitter>,
taa_options: Option<TxnAuthrAgrmtOptions>,
) -> IndyVdrLedgerWrite<IndyVdrSubmitter, BaseWalletRequestSigner> {
let request_signer = Arc::new(BaseWalletRequestSigner::new(wallet.clone()));
let config_write = IndyVdrLedgerWriteConfig {
request_signer,
request_submitter,
taa_options,
protocol_version: ProtocolVersion::node_1_4(),
};
IndyVdrLedgerWrite::new(config_write)
}

impl ModularLibsProfile {
pub fn init(wallet: Arc<dyn BaseWallet>, ledger_pool_config: LedgerPoolConfig) -> VcxResult<Self> {
let anoncreds = Arc::new(IndyCredxAnonCreds::new(Arc::clone(&wallet)));
let (ledger_read, ledger_write) = build_ledger_components(wallet.clone(), ledger_pool_config)?;

let ledger_pool = Arc::new(IndyVdrLedgerPool::new(ledger_pool_config)?);
let request_submitter = Arc::new(IndyVdrSubmitter::new(ledger_pool));

let ledger_read = indyvdr_build_ledger_read(request_submitter.clone())?;
let ledger_write = indyvdr_build_ledger_write(wallet.clone(), request_submitter, None);

let ledger_read = Arc::new(ledger_read);
let ledger_write = Arc::new(ledger_write);
Ok(ModularLibsProfile {
wallet,
anoncreds,
Expand Down
37 changes: 20 additions & 17 deletions aries_vcx/src/core/profile/vdrtools_profile.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use std::sync::Arc;

use super::profile::Profile;
use crate::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult};
use async_trait::async_trait;

use aries_vcx_core::ledger::base_ledger::TxnAuthrAgrmtOptions;
use aries_vcx_core::wallet::indy::IndySdkWallet;
use aries_vcx_core::{
anoncreds::{base_anoncreds::BaseAnonCreds, indy_anoncreds::IndySdkAnonCreds},
ledger::{
base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite},
indy_ledger::{IndySdkLedgerRead, IndySdkLedgerWrite},
},
ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite},
wallet::base_wallet::BaseWallet,
PoolHandle, WalletHandle,
WalletHandle,
};
use async_trait::async_trait;

use crate::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult};

use super::profile::Profile;

#[derive(Debug)]
pub struct VdrtoolsProfile {
Expand All @@ -26,18 +26,21 @@ pub struct VdrtoolsProfile {
}

impl VdrtoolsProfile {
pub fn init(wallet_handle: WalletHandle, pool_handle: PoolHandle) -> Self {
let wallet = Arc::new(IndySdkWallet::new(wallet_handle));
let anoncreds = Arc::new(IndySdkAnonCreds::new(wallet_handle));
let ledger_read = Arc::new(IndySdkLedgerRead::new(wallet_handle, pool_handle));
let ledger_write = Arc::new(IndySdkLedgerWrite::new(wallet_handle, pool_handle));
pub fn init(
wallet: Arc<IndySdkWallet>,
anoncreds_ledger_read: Arc<dyn AnoncredsLedgerRead>,
anoncreds_ledger_write: Arc<dyn AnoncredsLedgerWrite>,
indy_ledger_read: Arc<dyn IndyLedgerRead>,
indy_ledger_write: Arc<dyn IndyLedgerWrite>,
) -> Self {
let anoncreds = Arc::new(IndySdkAnonCreds::new(wallet.wallet_handle));
VdrtoolsProfile {
wallet,
anoncreds,
anoncreds_ledger_read: ledger_read.clone(),
anoncreds_ledger_write: ledger_write.clone(),
indy_ledger_read: ledger_read,
indy_ledger_write: ledger_write,
anoncreds_ledger_read,
anoncreds_ledger_write,
indy_ledger_read,
indy_ledger_write,
}
}
}
Expand Down
Loading

0 comments on commit 32919e1

Please sign in to comment.