Skip to content

Commit 7272cfb

Browse files
authored
Use generics over trait objects (#1003)
* Updated aries_vcx to rely more on generics than Arcs * Updated rust agent to rely more on generics than Arcs * Updated did_resolver_sov to rely more on generics than Arcs * Updated libvcx and uniffi to rely more on generics than Arcs Signed-off-by: Bogdan Mircea <mirceapetrebogdan@gmail.com>
1 parent 78bdd33 commit 7272cfb

File tree

95 files changed

+1790
-1342
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1790
-1342
lines changed

agents/rust/aries-vcx-agent/src/agent/agent_struct.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use aries_vcx::core::profile::profile::Profile;
3+
use aries_vcx::core::profile::vdrtools_profile::VdrtoolsProfile;
44

55
use crate::{
66
agent::agent_config::AgentConfig,
@@ -14,7 +14,7 @@ use crate::{
1414

1515
#[derive(Clone)]
1616
pub struct Agent {
17-
pub(super) profile: Arc<dyn Profile>,
17+
pub(super) profile: Arc<VdrtoolsProfile>,
1818
pub(super) config: AgentConfig,
1919
pub(super) connections: Arc<ServiceConnections>,
2020
pub(super) schemas: Arc<ServiceSchemas>,
@@ -27,8 +27,8 @@ pub struct Agent {
2727
}
2828

2929
impl Agent {
30-
pub fn profile(&self) -> Arc<dyn Profile> {
31-
Arc::clone(&self.profile)
30+
pub fn profile(&self) -> &VdrtoolsProfile {
31+
&self.profile
3232
}
3333

3434
pub fn agent_config(&self) -> AgentConfig {

agents/rust/aries-vcx-agent/src/agent/init.rs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
use std::sync::Arc;
22

33
use aries_vcx::{
4-
core::profile::{
5-
ledger::{build_ledger_components, VcxPoolConfig},
6-
profile::Profile,
7-
vdrtools_profile::VdrtoolsProfile,
8-
},
4+
core::profile::{ledger::VcxPoolConfig, profile::Profile, vdrtools_profile::VdrtoolsProfile},
95
global::settings::{init_issuer_config, DEFAULT_LINK_SECRET_ALIAS},
106
};
117
use aries_vcx_core::{
12-
ledger::base_ledger::{
13-
AnoncredsLedgerRead, AnoncredsLedgerWrite, IndyLedgerRead, IndyLedgerWrite,
14-
},
8+
self,
9+
anoncreds::base_anoncreds::BaseAnonCreds,
1510
wallet::indy::{
1611
wallet::{create_and_open_wallet, wallet_configure_issuer},
1712
IndySdkWallet, WalletConfig,
@@ -76,22 +71,10 @@ impl Agent {
7671
indy_vdr_config: None,
7772
response_cache_config: None,
7873
};
79-
let (ledger_read, ledger_write) =
80-
build_ledger_components(wallet.clone(), pool_config).unwrap();
81-
let anoncreds_ledger_read: Arc<dyn AnoncredsLedgerRead> = ledger_read.clone();
82-
let anoncreds_ledger_write: Arc<dyn AnoncredsLedgerWrite> = ledger_write.clone();
83-
let indy_ledger_read: Arc<dyn IndyLedgerRead> = ledger_read.clone();
84-
let indy_ledger_write: Arc<dyn IndyLedgerWrite> = ledger_write.clone();
8574

86-
let indy_profile = VdrtoolsProfile::init(
87-
wallet,
88-
anoncreds_ledger_read,
89-
anoncreds_ledger_write,
90-
indy_ledger_read,
91-
indy_ledger_write,
92-
);
93-
let profile: Arc<dyn Profile> = Arc::new(indy_profile);
94-
let anoncreds = profile.inject_anoncreds();
75+
let indy_profile = VdrtoolsProfile::init(wallet, pool_config).unwrap();
76+
let profile = Arc::new(indy_profile);
77+
let anoncreds = profile.anoncreds();
9578
anoncreds
9679
.prover_create_link_secret(DEFAULT_LINK_SECRET_ALIAS)
9780
.await

agents/rust/aries-vcx-agent/src/services/connection.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::sync::{Arc, Mutex};
22

33
use aries_vcx::{
4-
core::profile::profile::Profile,
4+
core::profile::{profile::Profile, vdrtools_profile::VdrtoolsProfile},
55
handlers::util::AnyInvitation,
66
messages::msg_fields::protocols::{
77
connection::{request::Request, response::Response},
@@ -22,13 +22,13 @@ use crate::{
2222
pub type ServiceEndpoint = Url;
2323

2424
pub struct ServiceConnections {
25-
profile: Arc<dyn Profile>,
25+
profile: Arc<VdrtoolsProfile>,
2626
service_endpoint: ServiceEndpoint,
2727
connections: Arc<ObjectCache<GenericConnection>>,
2828
}
2929

3030
impl ServiceConnections {
31-
pub fn new(profile: Arc<dyn Profile>, service_endpoint: ServiceEndpoint) -> Self {
31+
pub fn new(profile: Arc<VdrtoolsProfile>, service_endpoint: ServiceEndpoint) -> Self {
3232
Self {
3333
profile,
3434
service_endpoint,
@@ -40,7 +40,7 @@ impl ServiceConnections {
4040
&self,
4141
pw_info: Option<PairwiseInfo>,
4242
) -> AgentResult<AnyInvitation> {
43-
let pw_info = pw_info.unwrap_or(PairwiseInfo::create(&self.profile.inject_wallet()).await?);
43+
let pw_info = pw_info.unwrap_or(PairwiseInfo::create(self.profile.wallet()).await?);
4444
let inviter = Connection::new_inviter("".to_owned(), pw_info)
4545
.create_invitation(vec![], self.service_endpoint.clone());
4646
let invite = inviter.get_invitation().clone();
@@ -52,9 +52,9 @@ impl ServiceConnections {
5252
}
5353

5454
pub async fn receive_invitation(&self, invite: AnyInvitation) -> AgentResult<String> {
55-
let pairwise_info = PairwiseInfo::create(&self.profile.inject_wallet()).await?;
55+
let pairwise_info = PairwiseInfo::create(self.profile.wallet()).await?;
5656
let invitee = Connection::new_invitee("".to_owned(), pairwise_info)
57-
.accept_invitation(&self.profile.inject_indy_ledger_read(), invite)
57+
.accept_invitation(self.profile.ledger_read(), invite)
5858
.await?;
5959

6060
let thread_id = invitee.thread_id().to_owned();
@@ -69,7 +69,7 @@ impl ServiceConnections {
6969
.await?;
7070
let request = invitee.get_request().clone();
7171
invitee
72-
.send_message(&self.profile.inject_wallet(), &request.into(), &HttpClient)
72+
.send_message(self.profile.wallet(), &request.into(), &HttpClient)
7373
.await?;
7474
self.connections.insert(thread_id, invitee.into())?;
7575
Ok(())
@@ -94,7 +94,7 @@ impl ServiceConnections {
9494

9595
let inviter = inviter
9696
.handle_request(
97-
&self.profile.inject_wallet(),
97+
self.profile.wallet(),
9898
request,
9999
self.service_endpoint.clone(),
100100
vec![],
@@ -110,7 +110,7 @@ impl ServiceConnections {
110110
let inviter: Connection<_, _> = self.connections.get(thread_id)?.try_into()?;
111111
let response = inviter.get_connection_response_msg();
112112
inviter
113-
.send_message(&self.profile.inject_wallet(), &response.into(), &HttpClient)
113+
.send_message(self.profile.wallet(), &response.into(), &HttpClient)
114114
.await?;
115115

116116
self.connections.insert(thread_id, inviter.into())?;
@@ -121,7 +121,7 @@ impl ServiceConnections {
121121
pub async fn accept_response(&self, thread_id: &str, response: Response) -> AgentResult<()> {
122122
let invitee: Connection<_, _> = self.connections.get(thread_id)?.try_into()?;
123123
let invitee = invitee
124-
.handle_response(&self.profile.inject_wallet(), response)
124+
.handle_response(self.profile.wallet(), response)
125125
.await?;
126126

127127
self.connections.insert(thread_id, invitee.into())?;
@@ -133,7 +133,7 @@ impl ServiceConnections {
133133
let invitee: Connection<_, _> = self.connections.get(thread_id)?.try_into()?;
134134
invitee
135135
.send_message(
136-
&self.profile.inject_wallet(),
136+
self.profile.wallet(),
137137
&invitee.get_ack().into(),
138138
&HttpClient,
139139
)

agents/rust/aries-vcx-agent/src/services/credential_definition.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::{Arc, Mutex};
22

33
use aries_vcx::{
44
common::primitives::credential_definition::{CredentialDef, CredentialDefConfig},
5-
core::profile::profile::Profile,
5+
core::profile::{profile::Profile, vdrtools_profile::VdrtoolsProfile},
66
};
77

88
use crate::{
@@ -11,12 +11,12 @@ use crate::{
1111
};
1212

1313
pub struct ServiceCredentialDefinitions {
14-
profile: Arc<dyn Profile>,
14+
profile: Arc<VdrtoolsProfile>,
1515
cred_defs: ObjectCache<CredentialDef>,
1616
}
1717

1818
impl ServiceCredentialDefinitions {
19-
pub fn new(profile: Arc<dyn Profile>) -> Self {
19+
pub fn new(profile: Arc<VdrtoolsProfile>) -> Self {
2020
Self {
2121
profile,
2222
cred_defs: ObjectCache::new("cred-defs"),
@@ -25,8 +25,8 @@ impl ServiceCredentialDefinitions {
2525

2626
pub async fn create_cred_def(&self, config: CredentialDefConfig) -> AgentResult<String> {
2727
let cd = CredentialDef::create(
28-
&self.profile.inject_anoncreds_ledger_read(),
29-
&self.profile.inject_anoncreds(),
28+
self.profile.ledger_read(),
29+
self.profile.anoncreds(),
3030
"".to_string(),
3131
config,
3232
true,
@@ -38,10 +38,7 @@ impl ServiceCredentialDefinitions {
3838
pub async fn publish_cred_def(&self, thread_id: &str) -> AgentResult<()> {
3939
let cred_def = self.cred_defs.get(thread_id)?;
4040
let cred_def = cred_def
41-
.publish_cred_def(
42-
&self.profile.inject_anoncreds_ledger_read(),
43-
&self.profile.inject_anoncreds_ledger_write(),
44-
)
41+
.publish_cred_def(self.profile.ledger_read(), self.profile.ledger_write())
4542
.await?;
4643
self.cred_defs.insert(thread_id, cred_def)?;
4744
Ok(())

agents/rust/aries-vcx-agent/src/services/holder.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::sync::Arc;
22

33
use aries_vcx::{
4-
core::profile::profile::Profile,
4+
core::profile::{profile::Profile, vdrtools_profile::VdrtoolsProfile},
55
handlers::issuance::holder::Holder,
66
messages::{
77
msg_fields::protocols::cred_issuance::v1::{
@@ -36,13 +36,16 @@ impl HolderWrapper {
3636
}
3737

3838
pub struct ServiceCredentialsHolder {
39-
profile: Arc<dyn Profile>,
39+
profile: Arc<VdrtoolsProfile>,
4040
creds_holder: ObjectCache<HolderWrapper>,
4141
service_connections: Arc<ServiceConnections>,
4242
}
4343

4444
impl ServiceCredentialsHolder {
45-
pub fn new(profile: Arc<dyn Profile>, service_connections: Arc<ServiceConnections>) -> Self {
45+
pub fn new(
46+
profile: Arc<VdrtoolsProfile>,
47+
service_connections: Arc<ServiceConnections>,
48+
) -> Self {
4649
Self {
4750
profile,
4851
service_connections,
@@ -66,12 +69,12 @@ impl ServiceCredentialsHolder {
6669
propose_credential: ProposeCredentialV1,
6770
) -> AgentResult<String> {
6871
let connection = self.service_connections.get_by_id(connection_id)?;
69-
let wallet = self.profile.inject_wallet();
72+
let wallet = self.profile.wallet();
7073

7174
let mut holder = Holder::create("")?;
7275
holder.set_proposal(propose_credential.clone())?;
7376
connection
74-
.send_message(&wallet, &propose_credential.into(), &HttpClient)
77+
.send_message(wallet, &propose_credential.into(), &HttpClient)
7578
.await?;
7679

7780
self.creds_holder.insert(
@@ -105,16 +108,16 @@ impl ServiceCredentialsHolder {
105108
(None, None) => return Err(AgentError::from_kind(AgentErrorKind::InvalidArguments)),
106109
};
107110
let connection = self.service_connections.get_by_id(&connection_id)?;
108-
let wallet = self.profile.inject_wallet();
111+
let wallet = self.profile.wallet();
109112
let pw_did = connection.pairwise_info().pw_did.to_string();
110113

111114
let send_closure: SendClosure = Box::new(|msg: AriesMessage| {
112-
Box::pin(async move { connection.send_message(&wallet, &msg, &HttpClient).await })
115+
Box::pin(async move { connection.send_message(wallet, &msg, &HttpClient).await })
113116
});
114117
let msg_response = holder
115118
.prepare_credential_request(
116-
&self.profile.inject_anoncreds_ledger_read(),
117-
&self.profile.inject_anoncreds(),
119+
self.profile.ledger_read(),
120+
self.profile.anoncreds(),
118121
pw_did,
119122
)
120123
.await?;
@@ -133,12 +136,12 @@ impl ServiceCredentialsHolder {
133136
let mut holder = self.get_holder(thread_id)?;
134137
let connection_id = self.get_connection_id(thread_id)?;
135138
let connection = self.service_connections.get_by_id(&connection_id)?;
136-
let wallet = self.profile.inject_wallet();
139+
let wallet = self.profile.wallet();
137140

138141
holder
139142
.process_credential(
140-
&self.profile.inject_anoncreds_ledger_read(),
141-
&self.profile.inject_anoncreds(),
143+
self.profile.ledger_read(),
144+
self.profile.anoncreds(),
142145
msg_issue_credential.clone(),
143146
)
144147
.await?;
@@ -147,7 +150,7 @@ impl ServiceCredentialsHolder {
147150
Some(msg_response) => {
148151
let send_closure: SendClosure = Box::new(|msg: AriesMessage| {
149152
Box::pin(
150-
async move { connection.send_message(&wallet, &msg, &HttpClient).await },
153+
async move { connection.send_message(wallet, &msg, &HttpClient).await },
151154
)
152155
});
153156
send_closure(msg_response).await?;
@@ -165,7 +168,7 @@ impl ServiceCredentialsHolder {
165168

166169
pub async fn is_revokable(&self, thread_id: &str) -> AgentResult<bool> {
167170
self.get_holder(thread_id)?
168-
.is_revokable(&self.profile.inject_anoncreds_ledger_read())
171+
.is_revokable(self.profile.ledger_read())
169172
.await
170173
.map_err(|err| err.into())
171174
}

agents/rust/aries-vcx-agent/src/services/issuer.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::sync::Arc;
22

33
use aries_vcx::{
4-
core::profile::profile::Profile,
4+
core::profile::{profile::Profile, vdrtools_profile::VdrtoolsProfile},
55
handlers::{issuance::issuer::Issuer, util::OfferInfo},
66
messages::{
77
msg_fields::protocols::cred_issuance::v1::{
@@ -36,13 +36,16 @@ impl IssuerWrapper {
3636
}
3737

3838
pub struct ServiceCredentialsIssuer {
39-
profile: Arc<dyn Profile>,
39+
profile: Arc<VdrtoolsProfile>,
4040
creds_issuer: ObjectCache<IssuerWrapper>,
4141
service_connections: Arc<ServiceConnections>,
4242
}
4343

4444
impl ServiceCredentialsIssuer {
45-
pub fn new(profile: Arc<dyn Profile>, service_connections: Arc<ServiceConnections>) -> Self {
45+
pub fn new(
46+
profile: Arc<VdrtoolsProfile>,
47+
service_connections: Arc<ServiceConnections>,
48+
) -> Self {
4649
Self {
4750
profile,
4851
service_connections,
@@ -86,13 +89,13 @@ impl ServiceCredentialsIssuer {
8689
};
8790
let connection = self.service_connections.get_by_id(&connection_id)?;
8891
issuer
89-
.build_credential_offer_msg(&self.profile.inject_anoncreds(), offer_info, None)
92+
.build_credential_offer_msg(self.profile.anoncreds(), offer_info, None)
9093
.await?;
9194

92-
let wallet = self.profile.inject_wallet();
95+
let wallet = self.profile.wallet();
9396

9497
let send_closure: SendClosure = Box::new(|msg: AriesMessage| {
95-
Box::pin(async move { connection.send_message(&wallet, &msg, &HttpClient).await })
98+
Box::pin(async move { connection.send_message(wallet, &msg, &HttpClient).await })
9699
});
97100

98101
let credential_offer = issuer.get_credential_offer_msg()?;
@@ -140,15 +143,13 @@ impl ServiceCredentialsIssuer {
140143
} = self.creds_issuer.get(thread_id)?;
141144
let connection = self.service_connections.get_by_id(&connection_id)?;
142145

143-
let wallet = self.profile.inject_wallet();
146+
let wallet = self.profile.wallet();
144147

145148
let send_closure: SendClosure = Box::new(|msg: AriesMessage| {
146-
Box::pin(async move { connection.send_message(&wallet, &msg, &HttpClient).await })
149+
Box::pin(async move { connection.send_message(wallet, &msg, &HttpClient).await })
147150
});
148151

149-
issuer
150-
.build_credential(&self.profile.inject_anoncreds())
151-
.await?;
152+
issuer.build_credential(self.profile.anoncreds()).await?;
152153
match issuer.get_state() {
153154
IssuerState::Failed => {
154155
let problem_report = issuer.get_problem_report()?;

0 commit comments

Comments
 (0)