ソースを参照

drk: change the way handling features response from darkfid

ghassmo 4 年 前
コミット
e6072dac8a
1 ファイル変更19 行追加5 行削除
  1. 19 5
      src/bin/drk.rs

+ 19 - 5
src/bin/drk.rs

@@ -9,7 +9,7 @@ use prettytable::{format, Table};
 use serde_json::{json, Value};
 use serde_json::{json, Value};
 
 
 use drk::cli::{Config, DrkConfig};
 use drk::cli::{Config, DrkConfig};
-use drk::util::{join_config_path, NetworkName, path::expand_path};
+use drk::util::{join_config_path, path::expand_path, NetworkName};
 use drk::{rpc::jsonrpc, rpc::jsonrpc::JsonResult, Error, Result};
 use drk::{rpc::jsonrpc, rpc::jsonrpc::JsonResult, Error, Result};
 
 
 struct Drk {
 struct Drk {
@@ -26,13 +26,27 @@ impl Drk {
     async fn check_network(&self, network: &NetworkName) -> Result<()> {
     async fn check_network(&self, network: &NetworkName) -> Result<()> {
         let features = self.features().await?;
         let features = self.features().await?;
 
 
-        if features.as_object().is_none() {
+        if features.as_object().is_none()
+            && features.as_object().unwrap()["networks"]
+                .as_array()
+                .is_none()
+            && features.as_object().unwrap()["networks"]
+                .as_array()
+                .unwrap()
+                .len()
+                == 0
+        {
             return Err(Error::NotSupportedNetwork);
             return Err(Error::NotSupportedNetwork);
         }
         }
 
 
-        for (net, _) in features.as_object().unwrap() {
-            if network == &NetworkName::from_str(&net.as_str().to_lowercase())? {
-                return Ok(());
+        for nets in features.as_object().unwrap()["networks"]
+            .as_array()
+            .unwrap()
+        {
+            for (net, _) in nets.as_object().unwrap() {
+                if network == &NetworkName::from_str(net.as_str())? {
+                    return Ok(());
+                }
             }
             }
         }
         }