Compare commits

..

1 Commits

Author SHA1 Message Date
b1795eec65
add support for operators 2025-02-14 18:23:17 +02:00
3 changed files with 16 additions and 42 deletions

@ -903,33 +903,17 @@ impl BrainData {
})
}
pub fn find_vm_contracts_by_operator(&self, wallet: &str) -> Vec<VmContract> {
debug!("Searching contracts for operator {wallet}");
let nodes = match self.operators.get(wallet) {
Some(op) => op.vm_nodes.clone(),
None => return Vec::new(),
};
pub fn find_vm_contracts_by_admin(&self, admin_pubkey: &str) -> Vec<VmContract> {
debug!("Searching contracts for admin pubkey {admin_pubkey}");
let contracts: Vec<VmContract> = self
.vm_contracts
.read()
.unwrap()
.iter()
.filter(|c| nodes.contains(&c.node_pubkey))
.cloned()
.collect();
contracts
}
pub fn find_vm_contracts_by_admin(&self, admin_wallet: &str) -> Vec<VmContract> {
debug!("Searching contracts for admin pubkey {admin_wallet}");
let contracts: Vec<VmContract> = self
.vm_contracts
.read()
.unwrap()
.iter()
.filter(|c| c.admin_pubkey == admin_wallet)
.filter(|c| c.admin_pubkey == admin_pubkey)
.cloned()
.collect();
debug!("Found {} contracts or {admin_pubkey}.", contracts.len());
contracts
}

@ -234,25 +234,14 @@ impl BrainCli for BrainCliMock {
req: Request<ListVmContractsReq>,
) -> Result<Response<Self::ListVmContractsStream>, Status> {
let req = check_sig_from_req(req)?;
info!(
"CLI {} requested ListVMVmContractsStream. As operator: {}",
req.wallet, req.as_operator
);
let mut contracts = Vec::new();
if req.uuid.is_empty() {
if let Ok(specific_contract) = self.data.find_contract_by_uuid(&req.uuid) {
if specific_contract.admin_pubkey == req.wallet {
contracts.push(specific_contract);
}
// TODO: allow operator to inspect contracts
}
} else {
if req.as_operator {
contracts.append(&mut self.data.find_vm_contracts_by_operator(&req.wallet));
} else {
contracts.append(&mut self.data.find_vm_contracts_by_admin(&req.wallet));
}
}
info!("CLI {} requested ListVMVmContractsStream", req.admin_pubkey);
let contracts = match req.uuid.is_empty() {
false => match self.data.find_contract_by_uuid(&req.uuid) {
Ok(contract) => vec![contract],
_ => Vec::new(),
},
true => self.data.find_vm_contracts_by_admin(&req.admin_pubkey),
};
let (tx, rx) = mpsc::channel(6);
tokio::spawn(async move {
for contract in contracts {
@ -443,7 +432,7 @@ impl_pubkey_getter!(DeleteVmReq, admin_pubkey);
impl_pubkey_getter!(UpdateVmReq, admin_pubkey);
impl_pubkey_getter!(ExtendVmReq, admin_pubkey);
impl_pubkey_getter!(ReportNodeReq, admin_pubkey);
impl_pubkey_getter!(ListVmContractsReq, wallet);
impl_pubkey_getter!(ListVmContractsReq, admin_pubkey);
impl_pubkey_getter!(RegisterVmNodeReq, node_pubkey);
impl_pubkey_getter!(RegOperatorReq, pubkey);
impl_pubkey_getter!(KickReq, operator_wallet);

@ -154,8 +154,8 @@ service BrainVmDaemon {
}
message ListVmContractsReq {
string wallet = 1;
bool as_operator = 2;
string admin_pubkey = 1;
string node_pubkey = 2;
string uuid = 3;
}
@ -248,6 +248,7 @@ message KickResp {
uint64 nano_lp = 1;
}
service BrainCli {
rpc GetBalance (Pubkey) returns (AccountBalance);
rpc NewVm (NewVmReq) returns (NewVmResp);