Skip to content

Commit

Permalink
added available_allaccounts_batch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Mar 28, 2024
1 parent 1171468 commit da5495b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/sugarfunge-api-types/src/fula.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,29 @@ pub struct GetAvailableManifestsBatchInput {
pub cids: Vec<Cid>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct GetAvailableManifestsAllaccountsBatchInput {
pub pool_id: PoolId,
pub cids: Vec<Cid>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct GetAvailableManifestsBatchOutput {
pub manifests: Vec<ManifestAvailableBatch>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct GetAvailableManifestsAllaccountsBatchOutput {
pub manifests: Vec<ManifestAvailableAllaccountsBatch>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ManifestAvailableBatch {
pub cid: Cid,
pub replication_available: ReplicationFactor,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ManifestAvailableAllaccountsBatch {
pub cid: Cid,
}
35 changes: 35 additions & 0 deletions src/fula.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,41 @@ pub async fn get_available_manifests_batch(
}


pub async fn get_available_manifests_allaccounts_batch(
data: web::Data<AppState>,
req: web::Json<GetAvailableManifestsAllaccountsBatchInput>,
) -> error::Result<HttpResponse> {
let mut result_array = Vec::new();
let api = &data.api;

for cid_value in req.cids.to_vec() {
let cid: Vec<u8> = 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<AppState>,
req: web::Json<GetAvailableManifestsBatchInput>,
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit da5495b

Please sign in to comment.