mirror of
https://github.com/mimblewimble/mwixnet.git
synced 2025-01-20 19:11:09 +03:00
adding node api health check
This commit is contained in:
parent
2cd450cfa9
commit
f70e1dfbf2
2 changed files with 22 additions and 9 deletions
26
src/main.rs
26
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<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(
|
||||
|
|
|
@ -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", ¶ms)?;
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue