Просмотр исходного кода

display node name instead of rpc_url

* read name param from config and display in UI
* rename node_id to rpc_url
lunar-mining 4 лет назад
Родитель
Сommit
acb77e5be9
3 измененных файлов с 11 добавлено и 12 удалено
  1. 3 3
      bin/dnetview/dnetview_config.toml
  2. 2 2
      bin/dnetview/src/config.rs
  3. 6 7
      bin/dnetview/src/main.rs

+ 3 - 3
bin/dnetview/dnetview_config.toml

@@ -5,13 +5,13 @@
 
 [[nodes]]
 name = "Node 1"
-node_id = "tcp://127.0.0.1:8000"
+rpc_url = "tcp://127.0.0.1:8000"
 
 [[nodes]]
 name = "Node 2"
-node_id = "tcp://127.0.0.1:7777"
+rpc_url = "tcp://127.0.0.1:7777"
 
 [[nodes]]
 name = "Node 3"
-node_id = "tcp://127.0.0.1:1234"
+rpc_url = "tcp://127.0.0.1:1234"
 

+ 2 - 2
bin/dnetview/src/config.rs

@@ -9,6 +9,6 @@ pub struct DnvConfig {
 
 #[derive(Clone, Serialize, Deserialize, Debug)]
 pub struct IrcNode {
-    pub node_id: String,
-    //pub rpc_url: String,
+    pub name: String,
+    pub rpc_url: String,
 }

+ 6 - 7
bin/dnetview/src/main.rs

@@ -36,11 +36,12 @@ use dnetview::{
 
 struct DNetView {
     url: Url,
+    name: String,
 }
 
 impl DNetView {
-    pub fn new(url: Url) -> Self {
-        Self { url }
+    pub fn new(url: Url, name: String) -> Self {
+        Self { url, name }
     }
 
     async fn request(&self, r: jsonrpc::JsonRequest) -> Result<Value> {
@@ -134,7 +135,7 @@ async fn main() -> Result<()> {
 
 async fn run_rpc(config: &DnvConfig, ex: Arc<Executor<'_>>, model: Arc<Model>) -> Result<()> {
     for node in config.nodes.clone() {
-        let client = DNetView::new(Url::parse(&node.node_id)?);
+        let client = DNetView::new(Url::parse(&node.rpc_url)?, node.name);
         ex.spawn(poll(client, model.clone())).detach();
     }
     Ok(())
@@ -230,10 +231,8 @@ async fn poll(client: DNetView, model: Arc<Model>) -> Result<()> {
             let infos = NodeInfo { outbound: oconnects, manual: mconnects, inbound: iconnects };
             let mut node_info = FxHashMap::default();
 
-            // TODO: here we are setting the RPC url as the node_id.
-            // next step is to read the string variable 'name' from dnetview.toml
-            let node_id = &client.url.as_str();
-            node_info.insert(&node_id, infos.clone());
+            let node_name = &client.name.as_str();
+            node_info.insert(&node_name, infos.clone());
 
             for (key, value) in node_info.clone() {
                 model.id_list.node_id.lock().await.insert(key.to_string().clone());