Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'dev' into p-177-print-the-result-to-stdout-for-request-…
…vc-cli
  • Loading branch information
kziemianek committed Nov 18, 2023
commit d998825d23a4d3f7c0c3ebb2effc4a5df16f9f29
51 changes: 32 additions & 19 deletions tee-worker/cli/src/trusted_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
};
use base58::{FromBase58, ToBase58};
use codec::{Decode, Encode};
use ita_stf::{Getter, StfError, TrustedOperation};
use ita_stf::{Getter, StfError, TrustedCall, TrustedOperation};
use itc_rpc_client::direct_client::{DirectApi, DirectClient};
use itp_node_api::api_client::{ParentchainApi, TEEREX};
use itp_rpc::{RpcRequest, RpcResponse, RpcReturnValue};
Expand Down Expand Up @@ -71,6 +71,22 @@ pub(crate) fn perform_trusted_operation<T: Decode + Debug>(
}
}

pub(crate) fn perform_direct_operation<T: Decode + Debug>(
cli: &Cli,
trusted_args: &TrustedCli,
top: &TrustedOperation,
key: RequestAesKey,
) -> TrustedOpResult<T> {
match top {
TrustedOperation::direct_call(call) => match call.call {
TrustedCall::request_vc(..) => send_direct_vc_request(cli, trusted_args, top, key),
_ => Err(TrustedOperationError::Default { msg: "Only request vc allowed".to_string() }),
},
_ =>
Err(TrustedOperationError::Default { msg: "Only Direct Operation allowed".to_string() }),
}
}

pub(crate) fn execute_getter_from_cli_args<T: Decode + Debug>(
cli: &Cli,
trusted_args: &TrustedCli,
Expand Down Expand Up @@ -178,11 +194,11 @@ fn send_indirect_request<T: Decode + Debug>(
let event_records = subscription.next_events::<RuntimeEvent, Hash>().unwrap().unwrap();
for event_record in event_records {
if let RuntimeEvent::Teerex(TeerexEvent::ProcessedParentchainBlock(
_signer,
confirmed_block_hash,
_merkle_root,
confirmed_block_number,
)) = event_record.event
_signer,
confirmed_block_hash,
_merkle_root,
confirmed_block_number,
)) = event_record.event
{
info!("Confirmation of ProcessedParentchainBlock received");
debug!("Expected block Hash: {:?}", block_hash);
Expand Down Expand Up @@ -346,12 +362,12 @@ fn send_direct_request<T: Decode + Debug>(
}
}

fn send_direct_vc_request(
fn send_direct_vc_request<T: Decode + Debug>(
cli: &Cli,
trusted_args: &TrustedCli,
operation_call: &TrustedOperation,
key: RequestAesKey,
) -> TrustedOpResult {
) -> TrustedOpResult<T> {
let encryption_key = get_shielding_key(cli).unwrap();
let shard = read_shard(trusted_args, cli).unwrap();
let jsonrpc_call: String = get_vc_json_request(shard, operation_call, encryption_key, key);
Expand Down Expand Up @@ -384,22 +400,19 @@ fn send_direct_vc_request(
},
DirectRequestStatus::TrustedOperationStatus(status, top_hash) => {
debug!("request status is: {:?}, top_hash: {:?}", status, top_hash);
if connection_can_be_closed(status) {
direct_api.close().unwrap();
return Ok(None)
}
},
DirectRequestStatus::Ok => {
debug!("request status is ignored");
direct_api.close().unwrap();
return Ok(None)
let value =
T::decode(&mut return_value.value.as_slice()).map_err(|e| {
TrustedOperationError::Default {
msg: format!("Could not decode result value: {:?}", e),
}
})?;
return Ok(value)
},
}
if !return_value.do_watch {
debug!("do watch is false, closing connection");
direct_api.close().unwrap();
return Ok(None)
}
};
},
Err(e) => {
Expand Down Expand Up @@ -441,7 +454,7 @@ pub(crate) fn get_json_request(
"author_submitAndWatchRsaRequest".to_string(),
vec![request.to_hex()],
)
.unwrap()
.unwrap()
}

pub(crate) fn wait_until(
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.