feat: add function to find app contracts by operator and and by uuid
This commit is contained in:
parent
78525cc638
commit
ef629dff88
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -414,7 +414,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "detee-shared"
|
||||
version = "0.1.0"
|
||||
source = "git+ssh://git@gitea.detee.cloud/testnet/proto?branch=main#70e83dd0e982eeb491212c4a9d265df0b148fe24"
|
||||
source = "git+ssh://git@gitea.detee.cloud/testnet/proto?branch=main#3024c00b8e1c93e70902793385b92bc0a8d1f26a"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"prost",
|
||||
|
17
src/data.rs
17
src/data.rs
@ -1319,6 +1319,23 @@ impl BrainData {
|
||||
nodes.iter().cloned().find(|n| n.node_pubkey == public_key)
|
||||
}
|
||||
|
||||
pub fn find_app_contracts_by_operator(&self, wallet: &str) -> Vec<AppContract> {
|
||||
debug!("Searching contracts for operator {wallet}");
|
||||
let nodes = match self.operators.get(wallet) {
|
||||
Some(op) => op.vm_nodes.clone(),
|
||||
None => return Vec::new(),
|
||||
};
|
||||
let contracts: Vec<AppContract> = self
|
||||
.app_contracts
|
||||
.read()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|c| nodes.contains(&c.node_pubkey))
|
||||
.cloned()
|
||||
.collect();
|
||||
contracts
|
||||
}
|
||||
|
||||
pub fn find_app_contracts_by_admin_pubkey(&self, admin_pubkey: &str) -> Vec<AppContract> {
|
||||
debug!("Searching contracts for admin pubkey {admin_pubkey}");
|
||||
let contracts: Vec<AppContract> = self
|
||||
|
28
src/grpc.rs
28
src/grpc.rs
@ -544,9 +544,33 @@ impl BrainAppCli for BrainAppCliMock {
|
||||
req: tonic::Request<ListAppContractsReq>,
|
||||
) -> Result<tonic::Response<Self::ListAppContractsStream>, Status> {
|
||||
let req_data = check_sig_from_req(req)?;
|
||||
let app_contracts = self
|
||||
info!(
|
||||
"CLI {} requested ListAppContractsStream. As operator: {}",
|
||||
req_data.admin_pubkey, req_data.as_operator
|
||||
);
|
||||
let mut app_contracts = vec![];
|
||||
|
||||
if !req_data.uuid.is_empty() {
|
||||
if let Ok(specific_contract) = self.data.find_app_contract_by_uuid(&req_data.uuid) {
|
||||
if specific_contract.admin_pubkey == req_data.admin_pubkey {
|
||||
app_contracts.push(specific_contract);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if req_data.as_operator {
|
||||
app_contracts.append(
|
||||
&mut self
|
||||
.data
|
||||
.find_app_contracts_by_admin_pubkey(&req_data.admin_pubkey);
|
||||
.find_app_contracts_by_operator(&req_data.admin_pubkey),
|
||||
);
|
||||
} else {
|
||||
app_contracts.append(
|
||||
&mut self
|
||||
.data
|
||||
.find_app_contracts_by_admin_pubkey(&req_data.admin_pubkey),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let (tx, rx) = mpsc::channel(6);
|
||||
tokio::spawn(async move {
|
||||
|
Loading…
Reference in New Issue
Block a user