diff --git a/src/main.rs b/src/main.rs index 27810c3..2644a68 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use node::HttpGrinNode; use store::SwapStore; use wallet::HttpWallet; +use crate::node::GrinNode; use crate::store::StoreError; use clap::App; use grin_core::global; @@ -133,19 +134,32 @@ fn real_main() -> Result<(), Box> { server_config.wallet_owner_secret_path = Some(wallet_owner_secret_path.to_owned()); } + // Create GrinNode + let node = HttpGrinNode::new( + &server_config.grin_node_url, + &server_config.node_api_secret(), + ); + + // Node API health check + if let Err(e) = node.get_chain_height() { + eprintln!("Node communication failure. Is node listening?"); + return Err(e.into()); + }; + // Open wallet let wallet_pass = prompt_wallet_password(&args.value_of("wallet_pass")); let wallet = HttpWallet::open_wallet( &server_config.wallet_owner_url, &server_config.wallet_owner_api_secret(), &wallet_pass, - )?; - - // Create GrinNode - let node = HttpGrinNode::new( - &server_config.grin_node_url, - &server_config.node_api_secret(), ); + let wallet = match wallet { + Ok(w) => w, + Err(e) => { + eprintln!("Wallet communication failure. Is wallet listening?"); + return Err(e.into()); + } + }; // Open SwapStore let store = SwapStore::new( diff --git a/src/node.rs b/src/node.rs index c4941cc..d37cde0 100644 --- a/src/node.rs +++ b/src/node.rs @@ -150,9 +150,8 @@ impl GrinNode for HttpGrinNode { fn get_chain_height(&self) -> Result { let params = json!([]); let tip_json = self.send_json_request::("get_tip", ¶ms)?; - - let tip = serde_json::from_value::(tip_json["Ok"].clone()) - .map_err(NodeError::DecodeResponseError)?; + let tip = + serde_json::from_value::(tip_json).map_err(NodeError::DecodeResponseError)?; Ok(tip.height) }