Skip to content

Commit

Permalink
Tweak inviter to extract msg sending out
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
  • Loading branch information
Patrik-Stas committed Aug 19, 2023
1 parent dae1105 commit 4a73b39
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
6 changes: 4 additions & 2 deletions agents/rust/aries-vcx-agent/src/services/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ impl ServiceConnections {

pub async fn send_response(&self, thread_id: &str) -> AgentResult<()> {
let inviter: Connection<_, _> = self.connections.get(thread_id)?.try_into()?;
let inviter = inviter
.send_response(&self.profile.inject_wallet(), &HttpClient)
let response = inviter.get_connection_response_msg();
inviter
.send_message(&self.profile.inject_wallet(), &response.into(), &HttpClient)
.await?;
let inviter = inviter.mark_response_sent()?;

self.connections.insert(thread_id, inviter.into())?;

Expand Down
5 changes: 1 addition & 4 deletions aries_vcx/src/protocols/connection/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,9 @@ mod connection_serde_tests {
}

async fn make_inviter_responded() -> InviterConnection<InviterResponded> {
let wallet: Arc<dyn BaseWallet> = Arc::new(MockWallet {});

make_inviter_requested()
.await
.send_response(&wallet, &MockTransport)
.await
.mark_response_sent()
.unwrap()
}

Expand Down
29 changes: 11 additions & 18 deletions aries_vcx/src/protocols/connection/inviter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,31 +233,24 @@ impl InviterConnection<Invited> {
}

impl InviterConnection<Requested> {
/// Sends a [`Response`] to the invitee and transitions to [`InviterConnection<Responded>`].
/// Returns pre-built [`Response`] message which shall be delivered to counterparty
///
/// # Errors
///
/// Will return an error if sending the response fails.
pub async fn send_response<T>(
self,
wallet: &Arc<dyn BaseWallet>,
transport: &T,
) -> VcxResult<InviterConnection<Responded>>
where
T: Transport,
{
trace!(
"Connection::send_response >>> signed_response: {:?}",
&self.state.signed_response
);
pub fn get_connection_response_msg(&self) -> Response {
self.state.signed_response.clone()
}

/// Transitions to [`InviterConnection<Responded>`] under assumption the caller has assured delivery of [`Response`] message
///
/// # Errors
///
/// Will return an error if sending the response fails.
pub fn mark_response_sent(self) -> VcxResult<InviterConnection<Responded>>
{
let thread_id = self.state.signed_response.decorators.thread.thid.clone();

self.send_message(wallet, &self.state.signed_response.clone().into(), transport)
.await?;

let state = Responded::new(self.state.did_doc, thread_id);

Ok(Connection {
state,
source_id: self.source_id,
Expand Down
6 changes: 4 additions & 2 deletions libvcx_core/src/api_vcx/api_handle/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,10 @@ pub async fn send_response(handle: u32) -> LibvcxResult<()> {
trace!("send_response >>>");

let con = get_cloned_connection(&handle)?;
let con = con.send_response(&get_main_wallet()?, &HttpClient).await?;

let response = con.get_connection_response_msg();
con.send_message(&get_main_wallet()?, &response.into(), &HttpClient)
.await?;
let con = con.mark_response_sent()?;
insert_connection(handle, con)
}

Expand Down
6 changes: 4 additions & 2 deletions uniffi_aries_vcx/core/src/handlers/connection/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ impl Connection {
let connection = VcxConnection::try_from(handler.clone())?;

block_on(async {
let new_conn = connection
.send_response(&profile.inner.inject_wallet(), &HttpClient)
let response = connection.get_connection_response_msg();
connection
.send_message(&profile.inner.inject_wallet(), &response.into(), &HttpClient)
.await?;
let new_conn = connection.mark_response_sent()?;

*handler = VcxGenericConnection::from(new_conn);

Expand Down

0 comments on commit 4a73b39

Please sign in to comment.