feat: add method to list all app contracts for super admin and update gRPC interface
This commit is contained in:
parent
952c62c218
commit
0aa484f79e
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -420,7 +420,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "detee-shared"
|
name = "detee-shared"
|
||||||
version = "0.1.0"
|
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 = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"prost",
|
"prost",
|
||||||
|
@ -1279,6 +1279,11 @@ impl BrainData {
|
|||||||
contracts
|
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> {
|
pub fn find_app_contracts_by_node(&self, node_pubkey: &str) -> Vec<AppContract> {
|
||||||
let app_contracts = self.app_contracts.read().unwrap();
|
let app_contracts = self.app_contracts.read().unwrap();
|
||||||
app_contracts
|
app_contracts
|
||||||
|
20
src/grpc.rs
20
src/grpc.rs
@ -458,6 +458,8 @@ trait PubkeyGetter {
|
|||||||
impl BrainAppCli for BrainAppCliMock {
|
impl BrainAppCli for BrainAppCliMock {
|
||||||
type ListAppContractsStream = Pin<Box<dyn Stream<Item = Result<AppContract, Status>> + Send>>;
|
type ListAppContractsStream = Pin<Box<dyn Stream<Item = Result<AppContract, Status>> + Send>>;
|
||||||
type ListAppNodesStream = Pin<Box<dyn Stream<Item = Result<AppNodeListResp, 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(
|
async fn deploy_app(
|
||||||
&self,
|
&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]
|
#[tonic::async_trait]
|
||||||
@ -713,6 +732,7 @@ impl_pubkey_getter!(DelAppReq, admin_pubkey);
|
|||||||
impl_pubkey_getter!(ListAppContractsReq, admin_pubkey);
|
impl_pubkey_getter!(ListAppContractsReq, admin_pubkey);
|
||||||
|
|
||||||
impl_pubkey_getter!(RegisterAppNodeReq);
|
impl_pubkey_getter!(RegisterAppNodeReq);
|
||||||
|
impl_pubkey_getter!(detee_shared::sgx::pb::brain::Empty);
|
||||||
impl_pubkey_getter!(AppNodeFilters);
|
impl_pubkey_getter!(AppNodeFilters);
|
||||||
|
|
||||||
fn check_sig_from_req<T: std::fmt::Debug + PubkeyGetter>(req: Request<T>) -> Result<T, Status> {
|
fn check_sig_from_req<T: std::fmt::Debug + PubkeyGetter>(req: Request<T>) -> Result<T, Status> {
|
||||||
|
Loading…
Reference in New Issue
Block a user