//! Chain API methods. use uuid::Uuid; use super::client::{ApiClient, ApiError}; use super::supervisor::JsonValue; use crate::db::models::CreateChainRequest; impl ApiClient { /// Create a new chain with contracts. pub async fn create_chain(&self, req: CreateChainRequest) -> Result { self.post("/api/v1/chains", &req).await } /// List all chains for the authenticated user. pub async fn list_chains( &self, status: Option<&str>, limit: i32, ) -> Result { let mut params = Vec::new(); if let Some(s) = status { params.push(format!("status={}", s)); } params.push(format!("limit={}", limit)); let query_string = format!("?{}", params.join("&")); self.get(&format!("/api/v1/chains{}", query_string)).await } /// Get a chain by ID. pub async fn get_chain(&self, chain_id: Uuid) -> Result { self.get(&format!("/api/v1/chains/{}", chain_id)).await } /// Get contracts in a chain. pub async fn get_chain_contracts(&self, chain_id: Uuid) -> Result { self.get(&format!("/api/v1/chains/{}/contracts", chain_id)) .await } /// Get chain DAG structure for visualization. pub async fn get_chain_graph(&self, chain_id: Uuid) -> Result { self.get(&format!("/api/v1/chains/{}/graph", chain_id)) .await } /// Archive a chain. pub async fn archive_chain(&self, chain_id: Uuid) -> Result { self.delete_with_response(&format!("/api/v1/chains/{}", chain_id)) .await } }