Merge pull request #17 from scilio/healthcheck

Health-check for APIs on startup
This commit is contained in:
phyro 2022-09-18 11:10:35 +02:00 committed by GitHub
commit f968efcea2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 9 deletions

View file

@ -3,6 +3,7 @@ use node::HttpGrinNode;
use store::SwapStore; use store::SwapStore;
use wallet::HttpWallet; use wallet::HttpWallet;
use crate::node::GrinNode;
use crate::store::StoreError; use crate::store::StoreError;
use clap::App; use clap::App;
use grin_core::global; 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()); 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 // Open wallet
let wallet_pass = prompt_wallet_password(&args.value_of("wallet_pass")); let wallet_pass = prompt_wallet_password(&args.value_of("wallet_pass"));
let wallet = HttpWallet::open_wallet( let wallet = HttpWallet::open_wallet(
&server_config.wallet_owner_url, &server_config.wallet_owner_url,
&server_config.wallet_owner_api_secret(), &server_config.wallet_owner_api_secret(),
&wallet_pass, &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 // Open SwapStore
let store = SwapStore::new( let store = SwapStore::new(

View file

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