essential_rest_client/
lib.rs1#![deny(missing_docs)]
4
5use anyhow::Context;
6use std::path::Path;
7
8use essential_types::{Contract, Program};
9
10pub mod builder_client;
12pub mod node_client;
14
15pub async fn contract_from_path(contract_path: &Path) -> anyhow::Result<(Contract, Vec<Program>)> {
19 let contract_string = tokio::fs::read_to_string(&contract_path)
20 .await
21 .with_context(|| format!("failed to read contract from file {contract_path:?}"))?;
22 let (contract, programs): (Contract, Vec<Program>) = serde_json::from_str(&contract_string)
23 .with_context(|| {
24 format!("failed to parse contract and/or its programs from JSON at {contract_path:?}")
25 })?;
26 Ok((contract, programs))
27}
28
29async fn handle_response(response: reqwest::Response) -> anyhow::Result<reqwest::Response> {
31 let status = response.status();
32 if status.is_success() {
33 Ok(response)
34 } else {
35 let text = response.text().await?;
36 Err(anyhow::anyhow!("{}: {}", status, text))
37 }
38}