small refactoring on var names and impls
This commit is contained in:
parent
df805ea291
commit
5c213f2eb4
@ -675,7 +675,7 @@ impl BrainData {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn find_contracts_by_admin_pubkey(&self, admin_pubkey: &str) -> Vec<VmContract> {
|
||||
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
|
||||
@ -689,7 +689,7 @@ impl BrainData {
|
||||
contracts
|
||||
}
|
||||
|
||||
pub fn find_contracts_by_node_pubkey(&self, node_pubkey: &str) -> Vec<VmContract> {
|
||||
pub fn find_vm_contracts_by_node(&self, node_pubkey: &str) -> Vec<VmContract> {
|
||||
let contracts = self.vm_contracts.read().unwrap();
|
||||
contracts
|
||||
.iter()
|
||||
|
86
src/grpc.rs
86
src/grpc.rs
@ -1,4 +1,3 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
pub mod snp_proto {
|
||||
tonic::include_proto!("vm_proto");
|
||||
@ -64,7 +63,7 @@ impl BrainVmDaemon for BrainDaemonMock {
|
||||
self.data.insert_node(node);
|
||||
|
||||
info!("Sending existing contracts to {}", req.node_pubkey);
|
||||
let contracts = self.data.find_contracts_by_node_pubkey(&req.node_pubkey);
|
||||
let contracts = self.data.find_vm_contracts_by_node(&req.node_pubkey);
|
||||
let (tx, rx) = mpsc::channel(6);
|
||||
tokio::spawn(async move {
|
||||
for contract in contracts {
|
||||
@ -218,7 +217,7 @@ impl BrainCli for BrainCliMock {
|
||||
Some(contract) => vec![contract],
|
||||
None => Vec::new(),
|
||||
},
|
||||
true => self.data.find_contracts_by_admin_pubkey(&req.admin_pubkey),
|
||||
true => self.data.find_vm_contracts_by_admin(&req.admin_pubkey),
|
||||
};
|
||||
let (tx, rx) = mpsc::channel(6);
|
||||
tokio::spawn(async move {
|
||||
@ -328,65 +327,34 @@ trait PubkeyGetter {
|
||||
fn get_pubkey(&self) -> Option<String>;
|
||||
}
|
||||
|
||||
impl PubkeyGetter for Pubkey {
|
||||
fn get_pubkey(&self) -> Option<String> {
|
||||
Some(self.pubkey.clone())
|
||||
}
|
||||
macro_rules! impl_pubkey_getter {
|
||||
($t:ty, $field:ident) => {
|
||||
impl PubkeyGetter for $t {
|
||||
fn get_pubkey(&self) -> Option<String> {
|
||||
Some(self.$field.clone())
|
||||
}
|
||||
}
|
||||
};
|
||||
($t:ty) => {
|
||||
impl PubkeyGetter for $t {
|
||||
fn get_pubkey(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl PubkeyGetter for NewVmReq {
|
||||
fn get_pubkey(&self) -> Option<String> {
|
||||
Some(self.admin_pubkey.clone())
|
||||
}
|
||||
}
|
||||
impl_pubkey_getter!(Pubkey, pubkey);
|
||||
impl_pubkey_getter!(NewVmReq, admin_pubkey);
|
||||
impl_pubkey_getter!(DeleteVmReq, admin_pubkey);
|
||||
impl_pubkey_getter!(UpdateVmReq, admin_pubkey);
|
||||
impl_pubkey_getter!(ExtendVmReq, admin_pubkey);
|
||||
impl_pubkey_getter!(ListVmContractsReq, admin_pubkey);
|
||||
impl_pubkey_getter!(RegisterVmNodeReq, node_pubkey);
|
||||
|
||||
impl PubkeyGetter for DeleteVmReq {
|
||||
fn get_pubkey(&self) -> Option<String> {
|
||||
Some(self.admin_pubkey.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl PubkeyGetter for UpdateVmReq {
|
||||
fn get_pubkey(&self) -> Option<String> {
|
||||
Some(self.admin_pubkey.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl PubkeyGetter for ExtendVmReq {
|
||||
fn get_pubkey(&self) -> Option<String> {
|
||||
Some(self.admin_pubkey.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl PubkeyGetter for ListVmContractsReq {
|
||||
fn get_pubkey(&self) -> Option<String> {
|
||||
Some(self.admin_pubkey.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl PubkeyGetter for VmNodeFilters {
|
||||
fn get_pubkey(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl PubkeyGetter for RegisterVmNodeReq {
|
||||
fn get_pubkey(&self) -> Option<String> {
|
||||
Some(self.node_pubkey.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl PubkeyGetter for Empty {
|
||||
fn get_pubkey(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl PubkeyGetter for AirdropReq {
|
||||
fn get_pubkey(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
}
|
||||
impl_pubkey_getter!(VmNodeFilters);
|
||||
impl_pubkey_getter!(Empty);
|
||||
impl_pubkey_getter!(AirdropReq);
|
||||
|
||||
fn check_sig_from_req<T: std::fmt::Debug + PubkeyGetter>(req: Request<T>) -> Result<T, Status> {
|
||||
let time = match req.metadata().get("timestamp") {
|
||||
|
Loading…
Reference in New Issue
Block a user