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