1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use prost::Message;
use super::rpc::Rpc;
mod proto { include!("../../../libqaul/src/rpc/protobuf_generated/rust/qaul.rpc.node.rs"); }
pub struct Node {}
impl Node {
pub fn cli(command: &str) {
match command {
cmd if cmd.starts_with("info") => {
Self::info();
},
_ => log::error!("unknown node command"),
}
}
fn info() {
let proto_message = proto::Node {
message: Some(proto::node::Message::GetNodeInfo(true)),
};
let mut buf = Vec::with_capacity(proto_message.encoded_len());
proto_message.encode(&mut buf).expect("Vec<u8> provides capacity as needed");
Rpc::send_message(buf, super::rpc::proto::Modules::Node.into(), "".to_string());
}
pub fn rpc(data: Vec<u8>) {
match proto::Node::decode(&data[..]) {
Ok(node) => {
match node.message {
Some(proto::node::Message::Info(proto_nodeinformation)) => {
println!("Node ID is: {}", proto_nodeinformation.id_base58 );
println!("Node Addresses are:");
for address in proto_nodeinformation.addresses {
println!(" {}", address);
}
}
_ => {},
}
},
Err(error) => {
log::error!("{:?}", error);
},
}
}
}