display node name instead of rpc_url

* read name param from config and display in UI
* rename node_id to rpc_url
This commit is contained in:
lunar-mining
2022-03-19 07:22:08 +01:00
parent f19aeeecc8
commit acb77e5be9
3 changed files with 11 additions and 12 deletions

View File

@@ -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"

View File

@@ -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,
}

View File

@@ -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());