pub(in crate) mod data;
use crate::client::schema::{Schema, SchemaClient};
use crate::client::reqwest::{fetch_entities_list, fetch_entity, post_batches};
use crate::client::Client;
use crate::error::ClientError;
use sawtooth_sdk::messages::batch::BatchList;
const SCHEMA_ROUTE: &str = "schema";
pub struct ReqwestSchemaClient {
url: String,
}
impl ReqwestSchemaClient {
pub fn new(url: String) -> Self {
Self { url }
}
}
impl Client for ReqwestSchemaClient {
fn post_batches(
&self,
wait: u64,
batch_list: &BatchList,
service_id: Option<&str>,
) -> Result<(), ClientError> {
post_batches(&self.url, wait, batch_list, service_id)
}
}
impl SchemaClient for ReqwestSchemaClient {
fn get_schema(&self, name: String, service_id: Option<&str>) -> Result<Schema, ClientError> {
let dto = fetch_entity::<data::Schema>(
&self.url,
format!("{}/{}", SCHEMA_ROUTE, name),
service_id,
)?;
Ok(Schema::from(&dto))
}
fn list_schemas(&self, service_id: Option<&str>) -> Result<Vec<Schema>, ClientError> {
let dto_vec = fetch_entities_list::<data::Schema>(
&self.url,
SCHEMA_ROUTE.to_string(),
service_id,
None,
)?;
Ok(dto_vec.iter().map(Schema::from).collect())
}
}