Implement App functionality #11

Open
noormohammedb wants to merge 30 commits from noormohammedb/brain-mock:app_brain into main
3 changed files with 26 additions and 1 deletions
Showing only changes of commit 0aa484f79e - Show all commits

2
Cargo.lock generated

@ -420,7 +420,7 @@ dependencies = [
[[package]]
name = "detee-shared"
version = "0.1.0"
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared?branch=stable_01#a9dcfbe9fec5a86cd69aa2853db124aae9b85598"
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared?branch=stable_01#d6ffc0d4cb5ed5533379f82d04d15ae286fb49b9"
dependencies = [
"base64",
"prost",

@ -1279,6 +1279,11 @@ impl BrainData {
contracts
}
pub fn list_all_app_contracts(&self) -> Vec<AppContract> {
let contracts = self.app_contracts.read().unwrap();
contracts.iter().cloned().collect()
}
pub fn find_app_contracts_by_node(&self, node_pubkey: &str) -> Vec<AppContract> {
let app_contracts = self.app_contracts.read().unwrap();
app_contracts

@ -458,6 +458,8 @@ trait PubkeyGetter {
impl BrainAppCli for BrainAppCliMock {
type ListAppContractsStream = Pin<Box<dyn Stream<Item = Result<AppContract, Status>> + Send>>;
type ListAppNodesStream = Pin<Box<dyn Stream<Item = Result<AppNodeListResp, Status>> + Send>>;
type ListAllAppContractsStream =
Pin<Box<dyn Stream<Item = Result<AppContract, Status>> + Send>>;
async fn deploy_app(
&self,
@ -548,6 +550,23 @@ impl BrainAppCli for BrainAppCliMock {
)),
}
}
async fn list_all_app_contracts(
&self,
req: tonic::Request<detee_shared::sgx::pb::brain::Empty>,
) -> Result<tonic::Response<Self::ListAllAppContractsStream>, Status> {
check_admin_key(&req)?;
let _ = check_sig_from_req(req)?;
let contracts = self.data.list_all_app_contracts();
let (tx, rx) = mpsc::channel(6);
tokio::spawn(async move {
for contract in contracts {
let _ = tx.send(Ok(contract.into())).await;
}
});
let output_stream = ReceiverStream::new(rx);
Ok(Response::new(Box::pin(output_stream)))
}
}
#[tonic::async_trait]
@ -713,6 +732,7 @@ impl_pubkey_getter!(DelAppReq, admin_pubkey);
impl_pubkey_getter!(ListAppContractsReq, admin_pubkey);
impl_pubkey_getter!(RegisterAppNodeReq);
impl_pubkey_getter!(detee_shared::sgx::pb::brain::Empty);
impl_pubkey_getter!(AppNodeFilters);
fn check_sig_from_req<T: std::fmt::Debug + PubkeyGetter>(req: Request<T>) -> Result<T, Status> {