Skip to content

Commit

Permalink
Ledger response parser
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Kovar <miroslav.kovar@absa.africa>
  • Loading branch information
mirgee committed May 17, 2023
1 parent 0ef8430 commit 49281f7
Show file tree
Hide file tree
Showing 21 changed files with 760 additions and 180 deletions.
39 changes: 26 additions & 13 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ members = [
"did_resolver",
"did_resolver_registry",
"did_resolver_sov",
"did_resolver_web"
"did_resolver_web",
"indy_ledger_response_parser"
]

[workspace.package]
Expand Down
15 changes: 11 additions & 4 deletions aries_vcx/src/core/profile/modular_libs_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use std::sync::Arc;
use aries_vcx_core::anoncreds::base_anoncreds::BaseAnonCreds;
use aries_vcx_core::anoncreds::credx_anoncreds::IndyCredxAnonCreds;
use aries_vcx_core::ledger::base_ledger::BaseLedger;
use aries_vcx_core::ledger::indy_vdr_ledger::IndyVdrLedger;
use aries_vcx_core::ledger::indy_vdr_ledger::{IndyVdrLedger, IndyVdrLedgerConfig};
use aries_vcx_core::ledger::request_submitter::vdr_ledger::{IndyVdrLedgerPool, IndyVdrSubmitter, LedgerPoolConfig};
use aries_vcx_core::wallet::base_wallet::BaseWallet;
use aries_vcx_core::ResponseParser;

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

Expand All @@ -21,10 +22,16 @@ pub struct ModularLibsProfile {

impl ModularLibsProfile {
pub fn new(wallet: Arc<dyn BaseWallet>, ledger_pool_config: LedgerPoolConfig) -> VcxResult<Self> {
let ledger_pool = Arc::new(IndyVdrLedgerPool::new(ledger_pool_config)?);
let submitter = Arc::new(IndyVdrSubmitter::new(ledger_pool));
let ledger = Arc::new(IndyVdrLedger::new(Arc::clone(&wallet), submitter));
let anoncreds = Arc::new(IndyCredxAnonCreds::new(Arc::clone(&wallet)));
let ledger_pool = Arc::new(IndyVdrLedgerPool::new(ledger_pool_config)?);
let request_submitter = Arc::new(IndyVdrSubmitter::new(ledger_pool));
let response_parser = Arc::new(ResponseParser::new());
let config = IndyVdrLedgerConfig {
wallet: wallet.clone(),
request_submitter,
response_parser,
};
let ledger = Arc::new(IndyVdrLedger::new(config));
Ok(ModularLibsProfile {
wallet,
ledger,
Expand Down
16 changes: 12 additions & 4 deletions aries_vcx/src/core/profile/vdr_proxy_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use std::sync::Arc;
use aries_vcx_core::{
anoncreds::{base_anoncreds::BaseAnonCreds, indy_anoncreds::IndySdkAnonCreds},
ledger::{
base_ledger::BaseLedger, indy_vdr_ledger::IndyVdrLedger, request_submitter::vdr_proxy::VdrProxySubmitter,
base_ledger::BaseLedger,
indy_vdr_ledger::{IndyVdrLedger, IndyVdrLedgerConfig},
request_submitter::vdr_proxy::VdrProxySubmitter,
},
wallet::{base_wallet::BaseWallet, indy_wallet::IndySdkWallet},
VdrProxyClient, WalletHandle,
ResponseParser, VdrProxyClient, WalletHandle,
};

use super::profile::Profile;
Expand All @@ -21,9 +23,15 @@ pub struct VdrProxyProfile {
impl VdrProxyProfile {
pub fn new(wallet_handle: WalletHandle, client: VdrProxyClient) -> Self {
let wallet = Arc::new(IndySdkWallet::new(wallet_handle));
let submitter = Arc::new(VdrProxySubmitter::new(Arc::new(client)));
let ledger = Arc::new(IndyVdrLedger::new(wallet.clone(), submitter));
let anoncreds = Arc::new(IndySdkAnonCreds::new(wallet_handle));
let request_submitter = Arc::new(VdrProxySubmitter::new(Arc::new(client)));
let response_parser = Arc::new(ResponseParser::new());
let config = IndyVdrLedgerConfig {
wallet: wallet.clone(),
request_submitter,
response_parser,
};
let ledger = Arc::new(IndyVdrLedger::new(config));
VdrProxyProfile {
wallet,
ledger,
Expand Down
5 changes: 3 additions & 2 deletions aries_vcx_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ edition = "2021"
# Feature flag to include the libvdrtools dependency
vdrtools = ["dep:libvdrtools"]
# Feature flag to include the 'modular library' dependencies (vdrtools alternatives; indy-vdr, indy-credx)
modular_libs = ["dep:indy-vdr", "dep:indy-credx"]
vdr_proxy_ledger = ["dep:indy-vdr", "dep:indy-credx", "dep:indy-vdr-proxy-client"]
modular_libs = ["dep:indy-vdr", "dep:indy-credx", "dep:indy-ledger-response-parser"]
vdr_proxy_ledger = ["dep:indy-vdr", "dep:indy-credx", "dep:indy-vdr-proxy-client", "dep:indy-ledger-response-parser"]

[dependencies]
agency_client = { path = "../agency_client" }
Expand Down Expand Up @@ -42,6 +42,7 @@ uuid = { version = "1.3.0", default-features = false, features = ["v4"] }
tokio = { version = "1.20" }
# TODO: Point to the official repo if / when vdr-proxy-client PR is merged: https://github.com/hyperledger/indy-vdr/pull/184
indy-vdr-proxy-client = { git = "https://github.com/mirgee/indy-vdr.git", rev = "fab0535", optional = true }
indy-ledger-response-parser = { path = "../indy_ledger_response_parser", optional = true }

[dev-dependencies]
tokio = { version = "1.20", features = ["rt", "macros", "rt-multi-thread"] }
24 changes: 18 additions & 6 deletions aries_vcx_core/src/errors/mapping_vdrtools.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
use vdrtools::types;
use vdrtools::types::errors::IndyErrorKind;
#[cfg(feature = "vdrtools")]
use vdrtools::types::{
errors::{IndyError, IndyErrorKind},
ErrorCode,
};

#[cfg(all(
not(feature = "vdrtools"),
any(feature = "modular_libs", feature = "vdr_proxy_ledger")
))]
use indy_ledger_response_parser::{
errors::{IndyError, IndyErrorKind},
ErrorCode,
};

use crate::errors::error::{AriesVcxCoreError, AriesVcxCoreErrorKind};

impl From<IndyErrorKind> for AriesVcxCoreErrorKind {
fn from(indy: IndyErrorKind) -> Self {
use types::errors::IndyErrorKind::*;
use IndyErrorKind::*;

match indy {
InvalidParam(_) => AriesVcxCoreErrorKind::InvalidLibindyParam,
Expand Down Expand Up @@ -33,15 +45,15 @@ impl From<IndyErrorKind> for AriesVcxCoreErrorKind {
WalletAccessFailed => AriesVcxCoreErrorKind::WalletAccessFailed,
ProofRejected => AriesVcxCoreErrorKind::ProofRejected,
_ => {
let err_code = types::ErrorCode::from(indy) as u32;
let err_code = ErrorCode::from(indy) as u32;
AriesVcxCoreErrorKind::VdrToolsError(err_code)
}
}
}
}

impl From<types::errors::IndyError> for AriesVcxCoreError {
fn from(indy: types::errors::IndyError) -> Self {
impl From<IndyError> for AriesVcxCoreError {
fn from(indy: IndyError) -> Self {
let vcx_kind: AriesVcxCoreErrorKind = indy.kind().into();
AriesVcxCoreError::from_msg(vcx_kind, indy.to_string())
}
Expand Down
2 changes: 1 addition & 1 deletion aries_vcx_core/src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ mod mapping_indyvdr;
#[cfg(feature = "vdr_proxy_ledger")]
mod mapping_indyvdr_proxy;
mod mapping_others;
#[cfg(feature = "vdrtools")]
#[cfg(any(feature = "vdrtools", feature = "modular_libs", feature = "vdr_proxy_ledger"))]
mod mapping_vdrtools;
Loading

0 comments on commit 49281f7

Please sign in to comment.