diff --git a/Cargo.lock b/Cargo.lock index 6aef7a2..2796f00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/src/data.rs b/src/data.rs index 0d22f82..822a37c 100644 --- a/src/data.rs +++ b/src/data.rs @@ -1279,6 +1279,11 @@ impl BrainData { contracts } + pub fn list_all_app_contracts(&self) -> Vec { + let contracts = self.app_contracts.read().unwrap(); + contracts.iter().cloned().collect() + } + pub fn find_app_contracts_by_node(&self, node_pubkey: &str) -> Vec { let app_contracts = self.app_contracts.read().unwrap(); app_contracts diff --git a/src/grpc.rs b/src/grpc.rs index c4113fb..c5a7102 100644 --- a/src/grpc.rs +++ b/src/grpc.rs @@ -458,6 +458,8 @@ trait PubkeyGetter { impl BrainAppCli for BrainAppCliMock { type ListAppContractsStream = Pin> + Send>>; type ListAppNodesStream = Pin> + Send>>; + type ListAllAppContractsStream = + Pin> + Send>>; async fn deploy_app( &self, @@ -548,6 +550,23 @@ impl BrainAppCli for BrainAppCliMock { )), } } + + async fn list_all_app_contracts( + &self, + req: tonic::Request, + ) -> Result, 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(req: Request) -> Result {