94 lines
3.2 KiB
Rust
94 lines
3.2 KiB
Rust
use crate::snp::grpc;
|
|
use crate::snp::grpc::brain;
|
|
use crate::utils::block_on;
|
|
use tabled::Tabled;
|
|
|
|
#[derive(Tabled)]
|
|
struct TabledOperator {
|
|
wallet: String,
|
|
email: String,
|
|
escrow: u64,
|
|
app_nodes: u64,
|
|
vm_nodes: u64,
|
|
reports: u64,
|
|
}
|
|
|
|
impl From<grpc::brain::ListOperatorsResp> for TabledOperator {
|
|
fn from(brain_operator: grpc::brain::ListOperatorsResp) -> Self {
|
|
TabledOperator {
|
|
wallet: brain_operator.pubkey,
|
|
escrow: brain_operator.escrow,
|
|
email: brain_operator.email,
|
|
app_nodes: brain_operator.app_nodes,
|
|
vm_nodes: brain_operator.vm_nodes,
|
|
reports: brain_operator.reports,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn register(escrow: u64, email: String) -> Result<crate::SimpleOutput, grpc::Error> {
|
|
block_on(grpc::register_operator(escrow, email))?;
|
|
Ok(crate::SimpleOutput::from("Successfully registered you as operator."))
|
|
}
|
|
|
|
impl crate::HumanOutput for brain::InspectOperatorResp {
|
|
fn human_cli_print(&self) {
|
|
match &self.operator {
|
|
Some(op) => {
|
|
println!("The operator {} supplies {} nanoLP as escrow,", op.pubkey, op.escrow,);
|
|
println!(
|
|
"has {} app servers, {} VM servers, and {} total reports for all servers.",
|
|
op.app_nodes, op.vm_nodes, op.reports
|
|
);
|
|
println!("He can be contacted at {}", op.email);
|
|
}
|
|
None => (),
|
|
}
|
|
if self.vm_nodes.len() == 0 {
|
|
return;
|
|
}
|
|
println!("\n-- VM NODES --");
|
|
let mut count = 1;
|
|
for vm_node in self.vm_nodes.iter() {
|
|
println!("\nNODE #{count}:");
|
|
vm_node.human_cli_print();
|
|
count += 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
// TODO: move non-SNP gRPC requrests out of the SNP module (currently in crate::snp::grpc)
|
|
// This is an example of why we need refactoring... requesting information about operators is not
|
|
// bound in any way to the SNP module, however our gRPC module is stuck in the SNP module.
|
|
// We should figure how to architect the CLI so that this is a bit cleaner.
|
|
pub fn inspect_operator(wallet: String) -> Result<brain::InspectOperatorResp, grpc::Error> {
|
|
block_on(grpc::inspect_operator(wallet))
|
|
}
|
|
|
|
impl crate::HumanOutput for Vec<brain::ListOperatorsResp> {
|
|
fn human_cli_print(&self) {
|
|
let operators: Vec<TabledOperator> = self.iter().map(|op| op.clone().into()).collect();
|
|
|
|
let mut table = tabled::Table::new(operators);
|
|
table.with(tabled::settings::Style::rounded());
|
|
println!("{table}");
|
|
println!("To join our program a node operator, visit https://detee.ltd");
|
|
}
|
|
}
|
|
|
|
pub fn print_operators() -> Result<Vec<brain::ListOperatorsResp>, grpc::Error> {
|
|
Ok(block_on(grpc::list_operators())?)
|
|
}
|
|
|
|
pub fn kick(contract_uuid: String, reason: String) -> Result<crate::SimpleOutput, grpc::Error> {
|
|
let nano_lp = block_on(grpc::kick_contract(contract_uuid, reason))?;
|
|
Ok(crate::SimpleOutput::from(
|
|
format!("Successfully terminated contract. Refunded {} nanoLP.", nano_lp).as_str(),
|
|
))
|
|
}
|
|
|
|
pub fn ban(wallet: String) -> Result<crate::SimpleOutput, grpc::Error> {
|
|
block_on(grpc::ban_user(wallet))?;
|
|
Ok(crate::SimpleOutput::from("Successfully banned user"))
|
|
}
|