88 lines
2.9 KiB
Rust
88 lines
2.9 KiB
Rust
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use crate::general::grpc;
|
|
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::proto::ListOperatorsResp> for TabledOperator {
|
|
fn from(brain_operator: grpc::proto::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 grpc::proto::InspectOperatorResp {
|
|
fn human_cli_print(&self) {
|
|
if let Some(op) = &self.operator {
|
|
println!("The operator {} supplies {} nanocredits 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);
|
|
}
|
|
if self.vm_nodes.is_empty() {
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn inspect_operator(wallet: String) -> Result<grpc::proto::InspectOperatorResp, grpc::Error> {
|
|
block_on(grpc::inspect_operator(wallet))
|
|
}
|
|
|
|
impl crate::HumanOutput for Vec<grpc::proto::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<grpc::proto::ListOperatorsResp>, grpc::Error> {
|
|
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 {} nanocredits.", 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"))
|
|
}
|