Skip to content

Commit

Permalink
[cli] fix: always close client in trusted_operation and return if the…
Browse files Browse the repository at this point in the history
… status is invalid.
  • Loading branch information
clangenb committed Oct 27, 2024
1 parent bc95fe9 commit 0d2cade
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions cli/src/trusted_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ pub(crate) fn send_direct_request(
match await_status(&receiver, connection_can_be_closed) {
Ok((_hash, status)) => {
debug!("Trusted operation reached status {status:?}");
direct_api.close().unwrap();
Ok(top_hash)
},
Err(e) => {
Expand Down Expand Up @@ -350,6 +351,11 @@ pub(crate) fn await_status(

println!("Trusted call {:?} is {:?}", hash, status);

if is_cancelled(status) {
debug!("trusted call has been cancelled");
return Ok((hash, status))
}

if wait_until(status) {
return Ok((hash, status))
}
Expand Down Expand Up @@ -428,12 +434,11 @@ pub(crate) fn get_json_request(
}

fn connection_can_be_closed(top_status: TrustedOperationStatus) -> bool {
!matches!(
top_status,
TrustedOperationStatus::Submitted
| TrustedOperationStatus::Future
| TrustedOperationStatus::Ready
| TrustedOperationStatus::Broadcast
| TrustedOperationStatus::Invalid
)
use TrustedOperationStatus::*;
!matches!(top_status, Submitted | Future | Ready | Broadcast)
}

fn is_cancelled(top_status: TrustedOperationStatus) -> bool {
use TrustedOperationStatus::*;
matches!(top_status, Invalid | Usurped | Dropped | Retracted)
}

0 comments on commit 0d2cade

Please sign in to comment.