From da5495b428ff1e1b76c67df65cb4bc43bf217801 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 28 Mar 2024 02:40:50 +0000 Subject: [PATCH] added available_allaccounts_batch --- crates/sugarfunge-api-types/src/fula.rs | 16 +++++++++++ src/fula.rs | 35 +++++++++++++++++++++++++ src/main.rs | 4 +++ 3 files changed, 55 insertions(+) diff --git a/crates/sugarfunge-api-types/src/fula.rs b/crates/sugarfunge-api-types/src/fula.rs index 439d6cb..d8f6168 100644 --- a/crates/sugarfunge-api-types/src/fula.rs +++ b/crates/sugarfunge-api-types/src/fula.rs @@ -246,13 +246,29 @@ pub struct GetAvailableManifestsBatchInput { pub cids: Vec, } +#[derive(Serialize, Deserialize, Debug)] +pub struct GetAvailableManifestsAllaccountsBatchInput { + pub pool_id: PoolId, + pub cids: Vec, +} + #[derive(Serialize, Deserialize, Debug)] pub struct GetAvailableManifestsBatchOutput { pub manifests: Vec, } +#[derive(Serialize, Deserialize, Debug)] +pub struct GetAvailableManifestsAllaccountsBatchOutput { + pub manifests: Vec, +} + #[derive(Serialize, Deserialize, Debug)] pub struct ManifestAvailableBatch { pub cid: Cid, pub replication_available: ReplicationFactor, } + +#[derive(Serialize, Deserialize, Debug)] +pub struct ManifestAvailableAllaccountsBatch { + pub cid: Cid, +} \ No newline at end of file diff --git a/src/fula.rs b/src/fula.rs index 2db2bc9..e429fee 100644 --- a/src/fula.rs +++ b/src/fula.rs @@ -753,6 +753,41 @@ pub async fn get_available_manifests_batch( } +pub async fn get_available_manifests_allaccounts_batch( + data: web::Data, + req: web::Json, +) -> error::Result { + let mut result_array = Vec::new(); + let api = &data.api; + + for cid_value in req.cids.to_vec() { + let cid: Vec = String::from(&cid_value.clone()).into_bytes(); + let cid = BoundedVec(cid); + + let call = sugarfunge::storage() + .fula() + .manifests(u32::from(req.pool_id), cid); + + let storage = api.storage().at_latest().await.map_err(map_subxt_err)?; + + let data = storage.fetch(&call).await.map_err(map_subxt_err)?; + + match data { + Some(_data) => { // Renaming `data` to `_data` to indicate it's intentionally unused + result_array.push(ManifestAvailableAllaccountsBatch { + cid: cid_value + }) + } + None => continue, + } + } + + Ok(HttpResponse::Ok().json(GetAvailableManifestsAllaccountsBatchOutput { + manifests: result_array, + })) +} + + async fn get_available_manifests_batch_direct( data: web::Data, req: web::Json, diff --git a/src/main.rs b/src/main.rs index 7b4e62c..fc9abe0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -173,6 +173,10 @@ async fn main() -> std::io::Result<()> { "fula/manifest/available_batch", web::post().to(fula::get_available_manifests_batch), ) + .route( + "fula/manifest/available_allaccounts_batch", + web::post().to(fula::get_available_manifests_allaccounts_batch), + ) .route( "fula/manifest/available/alter", web::post().to(fula::get_all_available_manifests_alter),