Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split IndyVdrLedger and IndySdkLedger #862

Merged
merged 3 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ jobs:
run: |
cd libvcx && cargo clippy

check-did-resolver-feature-variants:
runs-on: ubuntu-20.04
steps:
- name: "Git checkout"
uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.65.0
- name: "Install dependencies"
shell: bash
run: |
sudo apt-get update -y
sudo apt-get install -y libsodium-dev libssl-dev libzmq3-dev
- name: "Verify aries_vcx compiles with different dependency feature variants"
run: |
cd did_resolver_sov
cargo check
cargo check --features vdrtools --no-default-features
cargo check --features modular_libs --no-default-features

check-aries-vcx-feature-variants:
runs-on: ubuntu-20.04
steps:
Expand Down
24 changes: 15 additions & 9 deletions aries_vcx/src/core/profile/modular_libs_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use std::time::Duration;
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};
use aries_vcx_core::ledger::indy_vdr_ledger::{IndyVdrLedger, IndyVdrLedgerConfig};
use aries_vcx_core::ledger::indy_vdr_ledger::{
IndyVdrLedgerRead, IndyVdrLedgerReadConfig, IndyVdrLedgerWrite, IndyVdrLedgerWriteConfig,
};
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};
Expand Down Expand Up @@ -38,20 +40,24 @@ impl ModularLibsProfile {
.capacity(1000)?
.build();
let response_cacher = Arc::new(InMemoryResponseCacher::new(cacher_config));
let config = IndyVdrLedgerConfig {
request_signer,
request_submitter,
let config_read = IndyVdrLedgerReadConfig {
request_submitter: request_submitter.clone(),
response_parser,
response_cacher,
};
let ledger = Arc::new(IndyVdrLedger::new(config));
let config_write = IndyVdrLedgerWriteConfig {
request_signer,
request_submitter,
};
let ledger_read = Arc::new(IndyVdrLedgerRead::new(config_read));
let ledger_write = Arc::new(IndyVdrLedgerWrite::new(config_write));
Ok(ModularLibsProfile {
wallet,
anoncreds,
anoncreds_ledger_read: ledger.clone(),
anoncreds_ledger_write: ledger.clone(),
indy_ledger_read: ledger.clone(),
indy_ledger_write: ledger,
anoncreds_ledger_read: ledger_read.clone(),
anoncreds_ledger_write: ledger_write.clone(),
indy_ledger_read: ledger_read.clone(),
indy_ledger_write: ledger_write,
})
}
}
Expand Down
22 changes: 13 additions & 9 deletions aries_vcx/src/core/profile/vdr_proxy_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use aries_vcx_core::{
anoncreds::{base_anoncreds::BaseAnonCreds, indy_anoncreds::IndySdkAnonCreds},
ledger::{
base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite},
indy_vdr_ledger::{IndyVdrLedger, IndyVdrLedgerConfig},
indy_vdr_ledger::{IndyVdrLedgerRead, IndyVdrLedgerReadConfig, IndyVdrLedgerWrite, IndyVdrLedgerWriteConfig},
request_signer::base_wallet::BaseWalletRequestSigner,
request_submitter::vdr_proxy::VdrProxySubmitter,
response_cacher::in_memory::{InMemoryResponseCacher, InMemoryResponseCacherConfig},
Expand Down Expand Up @@ -39,20 +39,24 @@ impl VdrProxyProfile {
.capacity(1000)?
.build();
let response_cacher = Arc::new(InMemoryResponseCacher::new(cacher_config));
let config = IndyVdrLedgerConfig {
request_signer,
request_submitter,
let config_read = IndyVdrLedgerReadConfig {
request_submitter: request_submitter.clone(),
response_parser,
response_cacher,
};
let ledger = Arc::new(IndyVdrLedger::new(config));
let config_write = IndyVdrLedgerWriteConfig {
request_submitter,
request_signer,
};
let ledger_read = Arc::new(IndyVdrLedgerRead::new(config_read));
let ledger_write = Arc::new(IndyVdrLedgerWrite::new(config_write));
Ok(VdrProxyProfile {
wallet,
anoncreds,
anoncreds_ledger_read: ledger.clone(),
anoncreds_ledger_write: ledger.clone(),
indy_ledger_read: ledger.clone(),
indy_ledger_write: ledger,
anoncreds_ledger_read: ledger_read.clone(),
anoncreds_ledger_write: ledger_write.clone(),
indy_ledger_read: ledger_read,
indy_ledger_write: ledger_write,
})
}
}
Expand Down
13 changes: 7 additions & 6 deletions aries_vcx/src/core/profile/vdrtools_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use aries_vcx_core::{
anoncreds::{base_anoncreds::BaseAnonCreds, indy_anoncreds::IndySdkAnonCreds},
ledger::{
base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite},
indy_ledger::IndySdkLedger,
indy_ledger::{IndySdkLedgerRead, IndySdkLedgerWrite},
},
wallet::{base_wallet::BaseWallet, indy_wallet::IndySdkWallet},
PoolHandle, WalletHandle,
Expand All @@ -26,14 +26,15 @@ impl VdrtoolsProfile {
pub fn new(indy_wallet_handle: WalletHandle, indy_pool_handle: PoolHandle) -> Self {
let wallet = Arc::new(IndySdkWallet::new(indy_wallet_handle));
let anoncreds = Arc::new(IndySdkAnonCreds::new(indy_wallet_handle));
let ledger = Arc::new(IndySdkLedger::new(indy_wallet_handle, indy_pool_handle));
let ledger_read = Arc::new(IndySdkLedgerRead::new(indy_wallet_handle, indy_pool_handle));
let ledger_write = Arc::new(IndySdkLedgerWrite::new(indy_wallet_handle, indy_pool_handle));
VdrtoolsProfile {
wallet,
anoncreds,
anoncreds_ledger_read: ledger.clone(),
anoncreds_ledger_write: ledger.clone(),
indy_ledger_read: ledger.clone(),
indy_ledger_write: ledger,
anoncreds_ledger_read: ledger_read.clone(),
anoncreds_ledger_write: ledger_write.clone(),
indy_ledger_read: ledger_read,
indy_ledger_write: ledger_write,
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions aries_vcx/src/utils/mockdata/profile/mock_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ pub(crate) struct MockLedger;
#[allow(unused)]
#[async_trait]
impl IndyLedgerRead for MockLedger {
async fn set_endorser(&self, submitter_did: &str, request: &str, endorser: &str) -> VcxCoreResult<String> {
Ok(utils::constants::REQUEST_WITH_ENDORSER.to_string())
}

async fn get_txn_author_agreement(&self) -> VcxCoreResult<String> {
Ok(utils::constants::DEFAULT_AUTHOR_AGREEMENT.to_string())
}
Expand All @@ -39,6 +35,10 @@ impl IndyLedgerRead for MockLedger {
#[allow(unused)]
#[async_trait]
impl IndyLedgerWrite for MockLedger {
async fn set_endorser(&self, submitter_did: &str, request: &str, endorser: &str) -> VcxCoreResult<String> {
Ok(utils::constants::REQUEST_WITH_ENDORSER.to_string())
}

async fn endorse_transaction(&self, endorser_did: &str, request_json: &str) -> VcxCoreResult<()> {
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx_core/src/ledger/base_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub trait IndyLedgerRead: Debug + Send + Sync {
async fn get_attr(&self, target_did: &str, attr_name: &str) -> VcxCoreResult<String>;
async fn get_nym(&self, did: &str) -> VcxCoreResult<String>;
async fn get_txn_author_agreement(&self) -> VcxCoreResult<String>;
async fn set_endorser(&self, submitter_did: &str, request: &str, endorser: &str) -> VcxCoreResult<String>;
async fn get_ledger_txn(&self, seq_no: i32, submitter_did: Option<&str>) -> VcxCoreResult<String>;
}

Expand All @@ -23,6 +22,7 @@ pub trait IndyLedgerWrite: Debug + Send + Sync {
data: Option<&str>,
role: Option<&str>,
) -> VcxCoreResult<String>;
async fn set_endorser(&self, submitter_did: &str, request: &str, endorser: &str) -> VcxCoreResult<String>;
async fn endorse_transaction(&self, endorser_did: &str, request_json: &str) -> VcxCoreResult<()>;
async fn add_attr(&self, target_did: &str, attrib_json: &str) -> VcxCoreResult<String>;
}
Expand Down
37 changes: 26 additions & 11 deletions aries_vcx_core/src/ledger/indy_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,37 @@ use crate::{indy, PoolHandle, WalletHandle};
use super::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite};

#[derive(Debug)]
pub struct IndySdkLedger {
pub struct IndySdkLedgerRead {
indy_wallet_handle: WalletHandle,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps can be removed now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately get_ledger_txn still needs WalletHandle to sign the request if submitter_did is passed in - but perhaps we can omit this argument and not sign the request as with the other getters. However, I don't think there is much worth in optimizing IndySdkLedger as it is soon-to-be-deleted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not worth it doing it here, but how about taking a generic implementing BaseWallet along with the submitter_did? Something like Option(&str, &T) where T: BaseWallet. Shouldn't that remove the need to store the wallet handle while also making it easier to work with that scenario since the arguments are either provided together or not at all?

indy_pool_handle: PoolHandle,
}

impl IndySdkLedger {
impl IndySdkLedgerRead {
pub fn new(indy_wallet_handle: WalletHandle, indy_pool_handle: PoolHandle) -> Self {
IndySdkLedger {
IndySdkLedgerRead {
indy_wallet_handle,
indy_pool_handle,
}
}
}

#[derive(Debug)]
pub struct IndySdkLedgerWrite {
indy_wallet_handle: WalletHandle,
indy_pool_handle: PoolHandle,
}

impl IndySdkLedgerWrite {
pub fn new(indy_wallet_handle: WalletHandle, indy_pool_handle: PoolHandle) -> Self {
IndySdkLedgerWrite {
indy_wallet_handle,
indy_pool_handle,
}
}
}

#[async_trait]
impl IndyLedgerRead for IndySdkLedger {
impl IndyLedgerRead for IndySdkLedgerRead {
async fn get_attr(&self, target_did: &str, attr_name: &str) -> VcxCoreResult<String> {
indy::ledger::transactions::get_attr(self.indy_pool_handle, target_did, attr_name).await
}
Expand All @@ -34,10 +49,6 @@ impl IndyLedgerRead for IndySdkLedger {
indy::ledger::transactions::libindy_get_txn_author_agreement(self.indy_pool_handle).await
}

async fn set_endorser(&self, submitter_did: &str, request: &str, endorser: &str) -> VcxCoreResult<String> {
indy::ledger::transactions::set_endorser(self.indy_wallet_handle, submitter_did, request, endorser).await
}

async fn get_ledger_txn(&self, seq_no: i32, submitter_did: Option<&str>) -> VcxCoreResult<String> {
indy::ledger::transactions::get_ledger_txn(
self.indy_wallet_handle,
Expand All @@ -50,7 +61,7 @@ impl IndyLedgerRead for IndySdkLedger {
}

#[async_trait]
impl IndyLedgerWrite for IndySdkLedger {
impl IndyLedgerWrite for IndySdkLedgerWrite {
async fn publish_nym(
&self,
submitter_did: &str,
Expand All @@ -73,6 +84,10 @@ impl IndyLedgerWrite for IndySdkLedger {
.await
}

async fn set_endorser(&self, submitter_did: &str, request: &str, endorser: &str) -> VcxCoreResult<String> {
indy::ledger::transactions::set_endorser(self.indy_wallet_handle, submitter_did, request, endorser).await
}

async fn endorse_transaction(&self, endorser_did: &str, request_json: &str) -> VcxCoreResult<()> {
indy::ledger::transactions::endorse_transaction(
self.indy_wallet_handle,
Expand All @@ -90,7 +105,7 @@ impl IndyLedgerWrite for IndySdkLedger {
}

#[async_trait]
impl AnoncredsLedgerRead for IndySdkLedger {
impl AnoncredsLedgerRead for IndySdkLedgerRead {
async fn get_schema(&self, schema_id: &str, submitter_did: Option<&str>) -> VcxCoreResult<String> {
if let Some(submitter_did) = submitter_did {
// with cache if possible
Expand Down Expand Up @@ -136,7 +151,7 @@ impl AnoncredsLedgerRead for IndySdkLedger {
}

#[async_trait]
impl AnoncredsLedgerWrite for IndySdkLedger {
impl AnoncredsLedgerWrite for IndySdkLedgerWrite {
async fn publish_schema(
&self,
schema_json: &str,
Expand Down
Loading