fn send_direct_request(
    matches: &ArgMatches<'_>,
    operation_call: TrustedOperation,
) -> Option<Vec<u8>> {
    let (_operation_call_encoded, operation_call_encrypted) =
        match encode_encrypt(matches, operation_call) {
            Ok((encoded, encrypted)) => (encoded, encrypted),
            Err(msg) => {
                println!("[Error] {}", msg);
                return None;
            }
        };
    let shard = read_shard(matches).unwrap();

    // compose jsonrpc call
    let data = Request {
        shard,
        cyphertext: operation_call_encrypted,
    };
    let direct_invocation_call = RpcRequest {
        jsonrpc: "2.0".to_owned(),
        method: "author_submitAndWatchExtrinsic".to_owned(),
        params: data.encode(),
        id: 1,
    };
    let jsonrpc_call: String = serde_json::to_string(&direct_invocation_call).unwrap();

    let direct_api = get_worker_api_direct(matches);
    let (sender, receiver) = channel();
    match direct_api.watch(jsonrpc_call, sender) {
        Ok(_) => {}
        Err(_) => panic!("Error when sending direct invocation call"),
    }

    loop {
        match receiver.recv() {
            Ok(response) => {
                let response: RpcResponse = serde_json::from_str(&response).unwrap();
                if let Ok(return_value) = RpcReturnValue::decode(&mut response.result.as_slice()) {
                    match return_value.status {
                        DirectRequestStatus::Error => {
                            if let Ok(value) = String::decode(&mut return_value.value.as_slice()) {
                                println!("[Error] {}", value);
                            }
                            return None;
                        }
                        DirectRequestStatus::TrustedOperationStatus(status) => {
                            if let Ok(value) = Hash::decode(&mut return_value.value.as_slice()) {
                                println!("Trusted call {:?} is {:?}", value, status);
                            }
                        }
                        _ => return None,
                    }
                    if !return_value.do_watch {
                        return None;
                    }
                };
            }
            Err(_) => return None,
        };
    }
}
/// sends a rpc watch request to the worker api server
sends a rpc watch request to the worker api server
sends a rpc watch request to the worker api server
fn send_direct_request(
    matches: &ArgMatches<'_>,
    operation_call: TrustedOperation,
) -> Option<Vec<u8>> {
    let (_operation_call_encoded, operation_call_encrypted) =
        match encode_encrypt(matches, operation_call) {
            Ok((encoded, encrypted)) => (encoded, encrypted),
            Err(msg) => {
                println!("[Error] {}", msg);
                return None;
            }
        };
    let shard = read_shard(matches).unwrap();
    // compose jsonrpc call
    let data = Request {
        shard,
        cyphertext: operation_call_encrypted,
    };
    let direct_invocation_call = RpcRequest {
        jsonrpc: "2.0".to_owned(),
        method: "author_submitAndWatchExtrinsic".to_owned(),
        params: data.encode(),
        id: 1,
    };
    let jsonrpc_call: String = serde_json::to_string(&direct_invocation_call).unwrap();
    let direct_api = get_worker_api_direct(matches);
    let (sender, receiver) = channel();
    match direct_api.watch(jsonrpc_call, sender) {
        Ok(_) => {}
        Err(_) => panic!("Error when sending direct invocation call"),
    }
    loop {
        match receiver.recv() {
            Ok(response) => {
                let response: RpcResponse = serde_json::from_str(&response).unwrap();
                if let Ok(return_value) = RpcReturnValue::decode(&mut response.result.as_slice()) {
                    match return_value.status {
                        DirectRequestStatus::Error => {
                            if let Ok(value) = String::decode(&mut return_value.value.as_slice()) {
                                println!("[Error] {}", value);
                            }
                            return None;
                        }
                        DirectRequestStatus::TrustedOperationStatus(status) => {
                            if let Ok(value) = Hash::decode(&mut return_value.value.as_slice()) {
                                println!("Trusted call {:?} is {:?}", value, status);
                            }
                        }
                        _ => return None,
                    }
                    if !return_value.do_watch {
                        return None;
                    }
                };
            }
            Err(_) => return None,
        };
    }
}
fn send_direct_request ( matches : & ArgMatches < ' _ > , operation_call : TrustedOperation , ) -> Option < Vec < u8 > > { let ( _operation_call_encoded , operation_call_encrypted ) = match encode_encrypt ( matches , operation_call ) { Ok ( ( encoded , encrypted ) ) => ( encoded , encrypted ) , Err ( msg ) => { println ! ( " " msg ) ; return None ; } } ; let shard = read_shard ( matches ) . unwrap ( ) ; // compose jsonrpc call let data = Request { shard , cyphertext : operation_call_encrypted , } ; let direct_invocation_call = RpcRequest { jsonrpc : " " . to_owned ( ) , method : " " . to_owned ( ) , params : data . encode ( ) , id : 1 , } ; let jsonrpc_call : String = serde_json :: to_string ( & direct_invocation_call ) . unwrap ( ) ; let direct_api = get_worker_api_direct ( matches ) ; let ( sender , receiver ) = channel ( ) ; match direct_api . watch ( jsonrpc_call , sender ) { Ok ( _ ) => { } Err ( _ ) => panic ! ( " " ) , } loop { match receiver . recv ( ) { Ok ( response ) => { let response : RpcResponse = serde_json :: from_str ( & response ) . unwrap ( ) ; if let Ok ( return_value ) = RpcReturnValue :: decode ( & mut response . result . as_slice ( ) ) { match return_value . status { DirectRequestStatus :: Error => { if let Ok ( value ) = String :: decode ( & mut return_value . value . as_slice ( ) ) { println ! ( " " value ) ; } return None ; } DirectRequestStatus :: TrustedOperationStatus ( status ) => { if let Ok ( value ) = Hash :: decode ( & mut return_value . value . as_slice ( ) ) { println ! ( " " value status ) ; } } _ => return None , } if ! return_value . do_watch { return None ; } } ; } Err ( _ ) => return None , } ; } }
sends a rpc watch request to the worker api server
sends a rpc watch request to the worker api server
matches
&ArgMatches<'_>
operation_call
TrustedOperation
matches
&ArgMatches<'_>
operation_call
TrustedOperation