Skip to content

Commit

Permalink
Refactored inner methods and simplified them
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Mircea <mirceapetrebogdan@gmail.com>
  • Loading branch information
bobozaur committed Jan 25, 2023
1 parent ee571df commit 8fff813
Show file tree
Hide file tree
Showing 23 changed files with 327 additions and 734 deletions.
27 changes: 0 additions & 27 deletions aries_vcx/src/protocols/connection/invitee/states/requested.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::errors::error::{AriesVcxError, AriesVcxErrorKind, VcxResult};
use crate::protocols::connection::invitee::states::initial::InitialState;
use crate::protocols::connection::invitee::states::responded::RespondedState;
use messages::diddoc::aries::diddoc::AriesDidDoc;
Expand All @@ -12,32 +11,6 @@ pub struct RequestedState {
pub did_doc: AriesDidDoc,
}

impl RequestedState {
/// Attempts to convert [`Self`] based on a [`Response`] into a [`RespondedState`].
///
/// # Errors
/// An error is returned if the response has an unexpected thread ID.
pub fn try_into_responded(self, response: Response) -> VcxResult<RespondedState> {
if !response.from_thread(&self.request.get_thread_id()) {
let err_msg = format!(
"Cannot handle response: thread id does not match: {:?}",
response.thread
);

let err = AriesVcxError::from_msg(AriesVcxErrorKind::InvalidJson, err_msg);

Err(err)
} else {
let state = RespondedState {
response,
request: self.request,
did_doc: self.did_doc,
};
Ok(state)
}
}
}

impl From<(RequestedState, ProblemReport)> for InitialState {
fn from((_state, problem_report): (RequestedState, ProblemReport)) -> InitialState {
trace!(
Expand Down
1 change: 0 additions & 1 deletion aries_vcx/src/protocols/connection/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod initiation_type;
pub mod invitee;
pub mod inviter;
pub mod pairwise_info;
2 changes: 1 addition & 1 deletion aries_vcx/src/protocols/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub mod oob;
pub mod proof_presentation;
pub mod revocation_notification;
pub mod trustping;
mod typestate_con;
pub mod typestate_con;

pub type SendClosure = Box<dyn FnOnce(A2AMessage) -> BoxFuture<'static, VcxResult<()>> + Send + Sync>;
pub type SendClosureConnection =
Expand Down
1 change: 1 addition & 0 deletions aries_vcx/src/protocols/typestate_con/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod states;
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ use std::clone::Clone;
use messages::diddoc::aries::diddoc::AriesDidDoc;
use messages::protocols::discovery::disclose::{Disclose, ProtocolDescriptor};

use crate::protocols::typestate_con::trait_bounds::TheirDidDoc;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct CompleteState {
pub did_doc: AriesDidDoc,
pub thread_id: String,
pub protocols: Option<Vec<ProtocolDescriptor>>,
pub thread_id: Option<String>,
}

impl CompleteState {
pub fn new(did_doc: AriesDidDoc, thread_id: String, protocols: Option<Vec<ProtocolDescriptor>>) -> Self {
Self {
did_doc,
thread_id,
protocols,
}
}

pub fn remote_protocols(&self) -> Option<&[ProtocolDescriptor]> {
self.protocols.as_deref()
}
Expand All @@ -20,13 +30,8 @@ impl CompleteState {
}
}

impl From<(CompleteState, Vec<ProtocolDescriptor>)> for CompleteState {
fn from((state, protocols): (CompleteState, Vec<ProtocolDescriptor>)) -> CompleteState {
trace!("ConnectionInviter: transit state from CompleteState to CompleteState");
CompleteState {
did_doc: state.did_doc,
thread_id: state.thread_id,
protocols: Some(protocols),
}
impl TheirDidDoc for CompleteState {
fn their_did_doc(&self) -> &AriesDidDoc {
&self.did_doc
}
}
}
2 changes: 2 additions & 0 deletions aries_vcx/src/protocols/typestate_con/common/states/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod complete;
pub mod responded;
21 changes: 21 additions & 0 deletions aries_vcx/src/protocols/typestate_con/common/states/responded.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use messages::diddoc::aries::diddoc::AriesDidDoc;

use crate::protocols::typestate_con::trait_bounds::TheirDidDoc;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct RespondedState {
pub did_doc: AriesDidDoc,
pub thread_id: String
}

impl RespondedState {
pub fn new(did_doc: AriesDidDoc, thread_id: String) -> Self {
Self { did_doc, thread_id }
}
}

impl TheirDidDoc for RespondedState {
fn their_did_doc(&self) -> &AriesDidDoc {
&self.did_doc
}
}
Loading

0 comments on commit 8fff813

Please sign in to comment.