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

refactor: move ledger to a separate crate #1172

Merged
merged 2 commits into from
Apr 5, 2024
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
27 changes: 26 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"aries/wrappers/uniffi-aries-vcx/core",
"aries/aries_vcx_core",
"aries/aries_vcx_wallet",
"aries/aries_vcx_ledger",
"aries/misc/indy_ledger_response_parser",
"aries/misc/wallet_migrator",
"aries/misc/test_utils",
Expand Down
1 change: 1 addition & 0 deletions aries/agents/aries-vcx-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ aries_vcx_core = { path = "../../aries_vcx_core", features = [
aries_vcx_wallet = { path = "../../aries_vcx_wallet", features = [
"vdrtools_wallet",
] }
aries_vcx_ledger = { path = "../../aries_vcx_ledger"}
anoncreds_types = { path = "../../misc/anoncreds_types" }
shared = { path = "../../misc/shared" }
did_resolver_registry = { path = "../../../did_core/did_resolver_registry" }
Expand Down
6 changes: 2 additions & 4 deletions aries/agents/aries-vcx-agent/src/agent/agent_struct.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::sync::Arc;

use aries_vcx_core::{
anoncreds::credx_anoncreds::IndyCredxAnonCreds,
ledger::indy_vdr_ledger::{DefaultIndyLedgerRead, DefaultIndyLedgerWrite},
};
use aries_vcx_core::anoncreds::credx_anoncreds::IndyCredxAnonCreds;
use aries_vcx_ledger::ledger::indy_vdr_ledger::{DefaultIndyLedgerRead, DefaultIndyLedgerWrite};
use aries_vcx_wallet::wallet::base_wallet::BaseWallet;

use crate::handlers::{
Expand Down
4 changes: 3 additions & 1 deletion aries/agents/aries-vcx-agent/src/agent/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use aries_vcx::{
use aries_vcx_core::{
self,
anoncreds::{base_anoncreds::BaseAnonCreds, credx_anoncreds::IndyCredxAnonCreds},
ledger::indy_vdr_ledger::{build_ledger_components, DefaultIndyLedgerRead, VcxPoolConfig},
};
use aries_vcx_ledger::ledger::indy_vdr_ledger::{
build_ledger_components, DefaultIndyLedgerRead, VcxPoolConfig,
};
use aries_vcx_wallet::wallet::{
base_wallet::{issuer_config::IssuerConfig, BaseWallet, ManageWallet},
Expand Down
9 changes: 9 additions & 0 deletions aries/agents/aries-vcx-agent/src/error/convertors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use aries_vcx::{
protocols::did_exchange::state_machine::generic::GenericDidExchange,
};
use aries_vcx_core::errors::error::AriesVcxCoreError;
use aries_vcx_ledger::errors::error::VcxLedgerError;
use did_resolver_sov::did_resolver::did_doc::schema::utils::error::DidDocumentLookupError;

use crate::error::*;
Expand Down Expand Up @@ -38,6 +39,14 @@ impl From<AriesVcxCoreError> for AgentError {
}
}

impl From<VcxLedgerError> for AgentError {
fn from(err: VcxLedgerError) -> Self {
let kind = AgentErrorKind::GenericAriesVcxError;
let message = format!("VcxLedgerCore Error; err: {:?}", err.to_string());
AgentError { message, kind }
}
}

impl From<DidDocumentBuilderError> for AgentError {
fn from(err: DidDocumentBuilderError) -> Self {
let kind = AgentErrorKind::GenericAriesVcxError;
Expand Down
2 changes: 1 addition & 1 deletion aries/agents/aries-vcx-agent/src/handlers/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use aries_vcx::{
pairwise_info::PairwiseInfo, Connection, GenericConnection, State, ThinState,
},
};
use aries_vcx_core::ledger::indy_vdr_ledger::DefaultIndyLedgerRead;
use aries_vcx_ledger::ledger::indy_vdr_ledger::DefaultIndyLedgerRead;
use aries_vcx_wallet::wallet::base_wallet::BaseWallet;
use url::Url;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ use std::sync::{Arc, Mutex};

use anoncreds_types::data_types::identifiers::schema_id::SchemaId;
use aries_vcx::{common::primitives::credential_definition::CredentialDef, did_parser_nom::Did};
use aries_vcx_core::{
anoncreds::credx_anoncreds::IndyCredxAnonCreds,
ledger::indy_vdr_ledger::{DefaultIndyLedgerRead, DefaultIndyLedgerWrite},
};
use aries_vcx_core::anoncreds::credx_anoncreds::IndyCredxAnonCreds;
use aries_vcx_ledger::ledger::indy_vdr_ledger::{DefaultIndyLedgerRead, DefaultIndyLedgerWrite};
use aries_vcx_wallet::wallet::base_wallet::BaseWallet;

use crate::{
Expand Down
5 changes: 2 additions & 3 deletions aries/agents/aries-vcx-agent/src/handlers/holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ use aries_vcx::{
},
protocols::{issuance::holder::state_machine::HolderState, SendClosure},
};
use aries_vcx_core::{
anoncreds::credx_anoncreds::IndyCredxAnonCreds, ledger::indy_vdr_ledger::DefaultIndyLedgerRead,
};
use aries_vcx_core::anoncreds::credx_anoncreds::IndyCredxAnonCreds;
use aries_vcx_ledger::ledger::indy_vdr_ledger::DefaultIndyLedgerRead;
use aries_vcx_wallet::wallet::base_wallet::BaseWallet;

use crate::{
Expand Down
5 changes: 2 additions & 3 deletions aries/agents/aries-vcx-agent/src/handlers/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use aries_vcx::{
},
protocols::{proof_presentation::prover::state_machine::ProverState, SendClosure},
};
use aries_vcx_core::{
anoncreds::credx_anoncreds::IndyCredxAnonCreds, ledger::indy_vdr_ledger::DefaultIndyLedgerRead,
};
use aries_vcx_core::anoncreds::credx_anoncreds::IndyCredxAnonCreds;
use aries_vcx_ledger::ledger::indy_vdr_ledger::DefaultIndyLedgerRead;
use aries_vcx_wallet::wallet::base_wallet::BaseWallet;
use serde_json::Value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ use std::{

use anoncreds_types::data_types::identifiers::cred_def_id::CredentialDefinitionId;
use aries_vcx::{common::primitives::revocation_registry::RevocationRegistry, did_parser_nom::Did};
use aries_vcx_core::{
anoncreds::credx_anoncreds::IndyCredxAnonCreds,
ledger::indy_vdr_ledger::{DefaultIndyLedgerRead, DefaultIndyLedgerWrite},
};
use aries_vcx_core::anoncreds::credx_anoncreds::IndyCredxAnonCreds;
use aries_vcx_ledger::ledger::indy_vdr_ledger::{DefaultIndyLedgerRead, DefaultIndyLedgerWrite};
use aries_vcx_wallet::wallet::base_wallet::BaseWallet;

use crate::{
Expand Down
10 changes: 4 additions & 6 deletions aries/agents/aries-vcx-agent/src/handlers/schema.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::sync::{Arc, Mutex};

use aries_vcx::{common::primitives::credential_schema::Schema, did_parser_nom::Did};
use aries_vcx_core::{
anoncreds::credx_anoncreds::IndyCredxAnonCreds,
ledger::{
base_ledger::AnoncredsLedgerRead,
indy_vdr_ledger::{DefaultIndyLedgerRead, DefaultIndyLedgerWrite},
},
use aries_vcx_core::anoncreds::credx_anoncreds::IndyCredxAnonCreds;
use aries_vcx_ledger::ledger::{
base_ledger::AnoncredsLedgerRead,
indy_vdr_ledger::{DefaultIndyLedgerRead, DefaultIndyLedgerWrite},
};
use aries_vcx_wallet::wallet::base_wallet::BaseWallet;

Expand Down
5 changes: 2 additions & 3 deletions aries/agents/aries-vcx-agent/src/handlers/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ use aries_vcx::{
SendClosure,
},
};
use aries_vcx_core::{
anoncreds::credx_anoncreds::IndyCredxAnonCreds, ledger::indy_vdr_ledger::DefaultIndyLedgerRead,
};
use aries_vcx_core::anoncreds::credx_anoncreds::IndyCredxAnonCreds;
use aries_vcx_ledger::ledger::indy_vdr_ledger::DefaultIndyLedgerRead;
use aries_vcx_wallet::wallet::base_wallet::BaseWallet;

use super::connection::ServiceConnections;
Expand Down
1 change: 1 addition & 0 deletions aries/aries_vcx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ messages = { path = "../messages" }
diddoc_legacy = { path = "../misc/legacy/diddoc_legacy" }
aries_vcx_core = { path = "../aries_vcx_core" }
aries_vcx_wallet = { path = "../aries_vcx_wallet" }
aries_vcx_ledger = { path = "../aries_vcx_ledger" }
shared = { path = "../misc/shared" }
anoncreds_types = { path = "../misc/anoncreds_types" }
did_parser_nom = { path = "../../did_core/did_parser_nom" }
Expand Down
6 changes: 2 additions & 4 deletions aries/aries_vcx/src/common/credentials/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use aries_vcx_core::{
anoncreds::base_anoncreds::{BaseAnonCreds, CredentialId},
ledger::base_ledger::AnoncredsLedgerRead,
};
use aries_vcx_core::anoncreds::base_anoncreds::{BaseAnonCreds, CredentialId};
use aries_vcx_ledger::ledger::base_ledger::AnoncredsLedgerRead;
use aries_vcx_wallet::wallet::base_wallet::BaseWallet;
use time::OffsetDateTime;

Expand Down
2 changes: 1 addition & 1 deletion aries/aries_vcx/src/common/keys.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use aries_vcx_core::ledger::base_ledger::{IndyLedgerRead, IndyLedgerWrite};
use aries_vcx_ledger::ledger::base_ledger::{IndyLedgerRead, IndyLedgerWrite};
use aries_vcx_wallet::wallet::base_wallet::BaseWallet;
use did_parser_nom::Did;
use public_key::{Key, KeyType};
Expand Down
2 changes: 1 addition & 1 deletion aries/aries_vcx/src/common/ledger/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use aries_vcx_core::ledger::{
use aries_vcx_ledger::ledger::{
base_ledger::{IndyLedgerRead, IndyLedgerWrite},
indy_vdr_ledger::{LedgerRole, UpdateRole},
};
Expand Down
26 changes: 15 additions & 11 deletions aries/aries_vcx/src/common/primitives/credential_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use anoncreds_types::data_types::{
messages::cred_definition_config::CredentialDefinitionConfig,
};
use aries_vcx_core::{
anoncreds::base_anoncreds::BaseAnonCreds,
errors::error::AriesVcxCoreErrorKind,
global::settings::DEFAULT_SERIALIZE_VERSION,
anoncreds::base_anoncreds::BaseAnonCreds, global::settings::DEFAULT_SERIALIZE_VERSION,
};
use aries_vcx_ledger::{
errors::error::VcxLedgerError,
ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite},
};
use aries_vcx_wallet::wallet::base_wallet::BaseWallet;
Expand Down Expand Up @@ -77,14 +78,17 @@ async fn _try_get_cred_def_from_ledger(
) -> VcxResult<Option<String>> {
match ledger.get_cred_def(cred_def_id, Some(issuer_did)).await {
Ok(cred_def) => Ok(Some(serde_json::to_string(&cred_def)?)),
Err(err) if err.kind() == AriesVcxCoreErrorKind::LedgerItemNotFound => Ok(None),
Err(err) => Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidLedgerResponse,
format!(
"Failed to check presence of credential definition id {} on the ledger\nError: {}",
cred_def_id, err
),
)),
Err(err) => match err {
VcxLedgerError::LedgerItemNotFound => Ok(None),
_ => Err(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidLedgerResponse,
format!(
"Failed to check presence of credential definition id {} on the \
ledger\nError: {}",
cred_def_id, err
),
)),
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion aries/aries_vcx/src/common/primitives/credential_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use anoncreds_types::data_types::{
};
use aries_vcx_core::{
anoncreds::base_anoncreds::BaseAnonCreds, global::settings::DEFAULT_SERIALIZE_VERSION,
ledger::base_ledger::AnoncredsLedgerWrite,
};
use aries_vcx_ledger::ledger::base_ledger::AnoncredsLedgerWrite;
use aries_vcx_wallet::wallet::base_wallet::BaseWallet;
use did_parser_nom::Did;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use anoncreds_types::data_types::{
use aries_vcx_core::{
anoncreds::base_anoncreds::BaseAnonCreds,
errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind},
ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite},
};
use aries_vcx_ledger::ledger::base_ledger::{AnoncredsLedgerRead, AnoncredsLedgerWrite};
use aries_vcx_wallet::wallet::base_wallet::BaseWallet;
use did_parser_nom::Did;

Expand Down
5 changes: 2 additions & 3 deletions aries/aries_vcx/src/common/proofs/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use anoncreds_types::data_types::messages::{
cred_selection::SelectedCredentials, pres_request::PresentationRequest,
presentation::Presentation,
};
use aries_vcx_core::{
anoncreds::base_anoncreds::BaseAnonCreds, ledger::base_ledger::AnoncredsLedgerRead,
};
use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds;
use aries_vcx_ledger::ledger::base_ledger::AnoncredsLedgerRead;
use aries_vcx_wallet::wallet::base_wallet::BaseWallet;

use crate::{
Expand Down
19 changes: 8 additions & 11 deletions aries/aries_vcx/src/common/proofs/prover/prover_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ use anoncreds_types::data_types::{
presentation::{RequestedAttribute, RequestedCredentials, RequestedPredicate},
},
};
use aries_vcx_core::{
anoncreds::base_anoncreds::{
BaseAnonCreds, CredentialDefinitionsMap, RevocationStatesMap, SchemasMap,
},
errors::error::AriesVcxCoreErrorKind,
ledger::base_ledger::AnoncredsLedgerRead,
use aries_vcx_core::anoncreds::base_anoncreds::{
BaseAnonCreds, CredentialDefinitionsMap, RevocationStatesMap, SchemasMap,
};
use aries_vcx_ledger::ledger::base_ledger::AnoncredsLedgerRead;

use crate::errors::error::prelude::*;

Expand Down Expand Up @@ -76,9 +73,9 @@ pub async fn build_cred_defs_json_prover(
let credential_def = ledger
.get_cred_def(&cred_info.cred_def_id, None)
.await
.map_err(|err| {
err.map(
AriesVcxCoreErrorKind::InvalidProofCredentialData,
.map_err(|_err| {
AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidProofCredentialData,
"Cannot get credential definition",
)
})?;
Expand Down Expand Up @@ -270,7 +267,7 @@ pub fn build_requested_credentials_json(
pub mod pool_tests {
use std::error::Error;

use aries_vcx_core::ledger::indy::pool::test_utils::get_temp_dir_path;
use aries_vcx_ledger::ledger::indy::pool::test_utils::get_temp_dir_path;
use test_utils::{
constants::{cred_def_id, schema_id, CRED_REV_ID, LICENCE_CRED_ID},
devsetup::build_setup_profile,
Expand Down Expand Up @@ -318,7 +315,7 @@ pub mod pool_tests {

#[cfg(test)]
pub mod unit_tests {
use aries_vcx_core::ledger::indy::pool::test_utils::get_temp_dir_path;
use aries_vcx_ledger::ledger::indy::pool::test_utils::get_temp_dir_path;
use serde_json::Value;
use test_utils::{
constants::{
Expand Down
5 changes: 2 additions & 3 deletions aries/aries_vcx/src/common/proofs/verifier/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
mod verifier_internal;

use aries_vcx_core::{
anoncreds::base_anoncreds::BaseAnonCreds, ledger::base_ledger::AnoncredsLedgerRead,
};
use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds;
use aries_vcx_ledger::ledger::base_ledger::AnoncredsLedgerRead;

use crate::{
common::proofs::verifier::verifier_internal::{
Expand Down
Loading
Loading