adding node api health check

This commit is contained in:
scilio 2022-09-14 16:14:31 -04:00
parent 2cd450cfa9
commit f70e1dfbf2
2 changed files with 22 additions and 9 deletions

View file

@ -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<dyn std::error::Error>> {
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(

View file

@ -150,9 +150,8 @@ impl GrinNode for HttpGrinNode {
fn get_chain_height(&self) -> Result<u64, NodeError> {
let params = json!([]);
let tip_json = self.send_json_request::<serde_json::Value>("get_tip", &params)?;
let tip = serde_json::from_value::<Tip>(tip_json["Ok"].clone())
.map_err(NodeError::DecodeResponseError)?;
let tip =
serde_json::from_value::<Tip>(tip_json).map_err(NodeError::DecodeResponseError)?;
Ok(tip.height)
}