Skip to content

Commit c9781a1

Browse files
implement node health check (#269)
1 parent 034e56e commit c9781a1

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

forc/src/ops/forc_run.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,7 @@ pub async fn run(command: RunCommand) -> Result<(), CliError> {
5353
_ => DEFAULT_NODE_URL,
5454
};
5555

56-
let client = FuelClient::new(node_url)?;
57-
58-
match client.transact(&tx).await {
59-
Ok(logs) => {
60-
println!("{:?}", logs);
61-
Ok(())
62-
}
63-
Err(e) => Err(e.to_string().into()),
64-
}
56+
send_tx(node_url, &tx).await
6557
}
6658
} else {
6759
let parse_type = {
@@ -88,6 +80,22 @@ pub async fn run(command: RunCommand) -> Result<(), CliError> {
8880
}
8981
}
9082

83+
async fn send_tx(node_url: &str, tx: &Transaction) -> Result<(), CliError> {
84+
let client = FuelClient::new(node_url)?;
85+
86+
if let Err(_) = client.health().await {
87+
return Err(format!("Node at given url `{}` is unreachable, please start the node by running `fuel-core` and try again", node_url).into());
88+
}
89+
90+
match client.transact(&tx).await {
91+
Ok(logs) => {
92+
println!("{:?}", logs);
93+
Ok(())
94+
}
95+
Err(e) => Err(e.to_string().into()),
96+
}
97+
}
98+
9199
fn create_tx_with_script_and_data(script: Vec<u8>, script_data: Vec<u8>) -> Transaction {
92100
let gas_price = 0;
93101
let gas_limit = 10000000;

0 commit comments

Comments
 (0)