Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion dongle-smartcontract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::review_registry::ReviewRegistry;
use crate::storage_manager::StorageManager;
use crate::types::{
FeeConfig, Project, ProjectRegistrationParams, ProjectStats, ProjectUpdateParams, Review,
VerificationRecord,
VerificationRecord, VerificationStatus,
};
use crate::verification_registry::VerificationRegistry;
use soroban_sdk::{contract, contractimpl, Address, Env, String, Vec};
Expand Down Expand Up @@ -95,6 +95,19 @@ impl DongleContract {
ProjectRegistry::get_owner_project_count(&env, &owner)
}

pub fn get_projects_by_ids(env: Env, ids: Vec<u64>) -> Vec<Project> {
ProjectRegistry::get_projects_by_ids(&env, ids)
}

pub fn list_projects_by_status(
env: Env,
status: VerificationStatus,
start_id: u64,
limit: u32,
) -> Vec<Project> {
ProjectRegistry::list_projects_by_status(&env, status, start_id, limit)
}

// --- Review Registry ---

pub fn add_review(
Expand Down Expand Up @@ -129,6 +142,10 @@ impl DongleContract {
ReviewRegistry::get_review(&env, project_id, reviewer)
}

pub fn get_reviews_by_ids(env: Env, ids: Vec<(u64, Address)>) -> Vec<Review> {
ReviewRegistry::get_reviews_by_ids(&env, ids)
}

pub fn list_reviews(env: Env, project_id: u64, start_id: u32, limit: u32) -> Vec<Review> {
ReviewRegistry::list_reviews(&env, project_id, start_id, limit)
}
Expand Down
56 changes: 56 additions & 0 deletions dongle-smartcontract/src/project_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,62 @@ impl ProjectRegistry {
Self::owner_project_count(env, owner)
}

pub fn get_projects_by_ids(env: &Env, ids: Vec<u64>) -> Vec<Project> {
let mut projects = Vec::new(env);
let len = ids.len();
for i in 0..len {
if let Some(id) = ids.get(i) {
if let Some(project) = Self::get_project(env, id) {
projects.push_back(project);
}
}
}
projects
}

pub fn list_projects_by_status(
env: &Env,
status: VerificationStatus,
start_id: u64,
limit: u32,
) -> Vec<Project> {
let effective_limit = if limit == 0 || limit > MAX_PAGE_LIMIT {
MAX_PAGE_LIMIT
} else {
limit
};

let count: u64 = env
.storage()
.persistent()
.get(&StorageKey::ProjectCount)
.unwrap_or(0);

let mut projects = Vec::new(env);
if count == 0 {
return projects;
}

let first = if start_id == 0 { 1u64 } else { start_id };
if first > count {
return projects;
}

let mut collected: u32 = 0;
for id in first..=count {
if collected >= effective_limit {
break;
}
if let Some(project) = Self::get_project(env, id) {
if project.verification_status == status {
projects.push_back(project);
collected += 1;
}
}
}
projects
}

pub fn list_projects(env: &Env, start_id: u64, limit: u32) -> Vec<Project> {
// Enforce pagination limits: limit must be 1..=MAX_PAGE_LIMIT
let effective_limit = if limit == 0 || limit > MAX_PAGE_LIMIT {
Expand Down
13 changes: 13 additions & 0 deletions dongle-smartcontract/src/review_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,19 @@ impl ReviewRegistry {
Ok(())
}

pub fn get_reviews_by_ids(env: &Env, ids: Vec<(u64, Address)>) -> Vec<Review> {
let mut reviews = Vec::new(env);
let len = ids.len();
for i in 0..len {
if let Some((project_id, reviewer)) = ids.get(i) {
if let Some(review) = Self::get_review(env, project_id, reviewer) {
reviews.push_back(review);
}
}
}
reviews
}

pub fn get_review(env: &Env, project_id: u64, reviewer: Address) -> Option<Review> {
env.storage()
.persistent()
Expand Down
Loading