Compare commits
1 Commits
b1795eec65
...
64b9168d0f
Author | SHA1 | Date | |
---|---|---|---|
64b9168d0f |
24
src/data.rs
24
src/data.rs
@ -903,17 +903,33 @@ impl BrainData {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn find_vm_contracts_by_admin(&self, admin_pubkey: &str) -> Vec<VmContract> {
|
||||
debug!("Searching contracts for admin pubkey {admin_pubkey}");
|
||||
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(),
|
||||
};
|
||||
let contracts: Vec<VmContract> = self
|
||||
.vm_contracts
|
||||
.read()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|c| c.admin_pubkey == admin_pubkey)
|
||||
.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)
|
||||
.cloned()
|
||||
.collect();
|
||||
debug!("Found {} contracts or {admin_pubkey}.", contracts.len());
|
||||
contracts
|
||||
}
|
||||
|
||||
|
29
src/grpc.rs
29
src/grpc.rs
@ -234,14 +234,25 @@ impl BrainCli for BrainCliMock {
|
||||
req: Request<ListVmContractsReq>,
|
||||
) -> Result<Response<Self::ListVmContractsStream>, Status> {
|
||||
let req = check_sig_from_req(req)?;
|
||||
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),
|
||||
};
|
||||
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));
|
||||
}
|
||||
}
|
||||
let (tx, rx) = mpsc::channel(6);
|
||||
tokio::spawn(async move {
|
||||
for contract in contracts {
|
||||
@ -432,7 +443,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, admin_pubkey);
|
||||
impl_pubkey_getter!(ListVmContractsReq, wallet);
|
||||
impl_pubkey_getter!(RegisterVmNodeReq, node_pubkey);
|
||||
impl_pubkey_getter!(RegOperatorReq, pubkey);
|
||||
impl_pubkey_getter!(KickReq, operator_wallet);
|
||||
|
5
vm.proto
5
vm.proto
@ -154,8 +154,8 @@ service BrainVmDaemon {
|
||||
}
|
||||
|
||||
message ListVmContractsReq {
|
||||
string admin_pubkey = 1;
|
||||
string node_pubkey = 2;
|
||||
string wallet = 1;
|
||||
bool as_operator = 2;
|
||||
string uuid = 3;
|
||||
}
|
||||
|
||||
@ -248,7 +248,6 @@ message KickResp {
|
||||
uint64 nano_lp = 1;
|
||||
}
|
||||
|
||||
|
||||
service BrainCli {
|
||||
rpc GetBalance (Pubkey) returns (AccountBalance);
|
||||
rpc NewVm (NewVmReq) returns (NewVmResp);
|
||||
|
Loading…
Reference in New Issue
Block a user