implement node health check
@@ -53,15 +53,7 @@ pub async fn run(command: RunCommand) -> Result<(), CliError> {
_ => DEFAULT_NODE_URL,
};
- let client = FuelClient::new(node_url)?;
-
- match client.transact(&tx).await {
- Ok(logs) => {
- println!("{:?}", logs);
- Ok(())
- }
- Err(e) => Err(e.to_string().into()),
- }
+ send_tx(node_url, &tx).await
}
} else {
let parse_type = {
@@ -88,6 +80,22 @@ pub async fn run(command: RunCommand) -> Result<(), CliError> {
}
}
+async fn send_tx(node_url: &str, tx: &Transaction) -> Result<(), CliError> {
+ let client = FuelClient::new(node_url)?;
+
+ if let Err(_) = client.health().await {
+ return Err(format!("Node at given url `{}` is unreachable, please start the node by running `fuel-core` and try again", node_url).into());
+ }
+
+ match client.transact(&tx).await {
+ Ok(logs) => {
+ println!("{:?}", logs);
+ Ok(())
+ }
+ Err(e) => Err(e.to_string().into()),
+ }
+}
+
fn create_tx_with_script_and_data(script: Vec<u8>, script_data: Vec<u8>) -> Transaction {
let gas_price = 0;
let gas_limit = 10000000;
