diff --git a/bridges/centralized-ethereum/src/actors/watch_dog.rs b/bridges/centralized-ethereum/src/actors/watch_dog.rs
index 1c6633148..f9cdfe0e8 100644
--- a/bridges/centralized-ethereum/src/actors/watch_dog.rs
+++ b/bridges/centralized-ethereum/src/actors/watch_dog.rs
@@ -14,7 +14,7 @@ use std::{
use web3::{
contract::Contract,
transports::Http,
- types::{H160, U256},
+ types::H160,
};
use witnet_net::client::tcp::{jsonrpc, JsonRpcClient};
use witnet_node::utils::stop_system_if_panicking;
@@ -68,6 +68,32 @@ impl Actor for WatchDog {
}
}
+#[derive(Debug)]
+enum WatchDogStatus {
+ // Add all of them here
+ UpAndRunning,
+ EvmDisconnect,
+ EvmSyncing,
+ EvmErrors,
+ WitDisconnect,
+ WitSyncing,
+ WitErrors,
+}
+
+impl WatchDogStatus {
+ fn to_string(&self) -> String {
+ match self {
+ WatchDogStatus::UpAndRunning => "up-and-running".to_string(),
+ WatchDogStatus::EvmDisconnect => "evm-disconnect".to_string(),
+ WatchDogStatus::EvmSyncing => "evm-syncing".to_string(),
+ WatchDogStatus::EvmErrors => format!("evm-errors"),
+ WatchDogStatus::WitDisconnect => "wit-disconnect".to_string(),
+ WatchDogStatus::WitSyncing => "wit-syncing".to_string(),
+ WatchDogStatus::WitErrors => format!("wit-errors"),
+ }
+ }
+}
+
/// Required trait for being able to retrieve WatchDog address from system registry
impl actix::Supervised for WatchDog {}
impl SystemService for WatchDog {}
@@ -114,66 +140,34 @@ impl WatchDog {
let running_secs = self.start_ts.unwrap().elapsed().as_secs();
let fut = async move {
- let mut status = "up-and-running".to_string();
+ let mut status = WatchDogStatus::UpAndRunning;
if let Err(err) = check_wit_connection_status(&wit_jsonrpc_socket).await {
status = err;
}
- let wit_client = JsonRpcClient::start(&wit_jsonrpc_socket)
- .expect("cannot start JSON/WIT connection");
- let wit_account = match fetch_wit_account(&wit_client).await {
- Ok(pkh) => pkh,
+ let wit_client = match JsonRpcClient::start(&wit_jsonrpc_socket) {
+ Ok(client) => client,
+ Err(_) => return (None, None),
+ };
+ let (wit_account, wit_balance, wit_utxos_above_threshold) = match fetch_wit_info(
+ &wit_client,
+ wit_utxo_min_value_threshold
+ ).await {
+ Ok((wit_account, wit_balance, wit_utxos_above_threshold)) => {
+ (wit_account, wit_balance, wit_utxos_above_threshold)
+ }
Err(err) => {
- if status.eq("up-and-running") {
+ if status == WatchDogStatus::UpAndRunning {
status = err;
}
- None
- }
- };
-
- let wit_balance = match wit_account.clone() {
- Some(pkh) => match fetch_wit_account_balance(&wit_client, pkh.as_str()).await {
- Ok(wit_balance) => wit_balance,
- Err(err) => {
- if status.eq("up-and-running") {
- status = err;
- }
- None
- }
- },
- None => None,
- };
-
- let wit_utxos_above_threshold = match wit_account.clone() {
- Some(pkh) => {
- match fetch_wit_account_count_utxos_above(
- &wit_client,
- pkh.as_str(),
- wit_utxo_min_value_threshold,
- )
- .await
- {
- Ok(wit_utxos_above_threshold) => wit_utxos_above_threshold,
- Err(err) => {
- if status.eq("up-and-running") {
- status = err;
- }
- None
- }
- }
+ (None, None, None)
}
- None => None,
};
let eth_balance = match check_eth_account_balance(ð_jsonrpc_url, eth_account).await {
- Ok(Some(eth_balance)) => {
- let eth_balance: f64 = eth_balance.to_string().parse().unwrap_or_default();
- //Some(Unit::Wei(ð_balance.to_string()).to_eth_str().unwrap_or_default()),
- Some(eth_balance / 1000000000000000000.0)
- }
- Ok(None) => None,
+ Ok(eth_balance) => eth_balance,
Err(err) => {
- if status.eq("up-and-running") {
+ if status == WatchDogStatus::UpAndRunning {
status = err;
}
None
@@ -224,7 +218,7 @@ impl WatchDog {
));
}
metrics.push_str(&format!("\"runningSecs\": {running_secs}, "));
- metrics.push_str(&format!("\"status\": \"{status}\""));
+ metrics.push_str(&format!("\"status\": \"{}\"", status.to_string()));
metrics.push_str("}}");
log::info!("{metrics}");
@@ -248,9 +242,9 @@ impl WatchDog {
async fn check_eth_account_balance(
eth_jsonrpc_url: &str,
eth_account: H160,
-) -> Result