diff --git a/contract/contract/src/base/types.rs b/contract/contract/src/base/types.rs index 6add706..83baae7 100644 --- a/contract/contract/src/base/types.rs +++ b/contract/contract/src/base/types.rs @@ -127,6 +127,8 @@ pub struct CampaignMetrics { pub total_raised: i128, pub contributor_count: u32, pub last_donation_at: u64, + pub max_donation: i128, + pub top_contributor: Option
, } impl Default for CampaignMetrics { @@ -141,6 +143,8 @@ impl CampaignMetrics { total_raised: 0, contributor_count: 0, last_donation_at: 0, + max_donation: 0, + top_contributor: None, } } } diff --git a/contract/contract/src/crowdfunding.rs b/contract/contract/src/crowdfunding.rs index 24d8441..18b9a27 100644 --- a/contract/contract/src/crowdfunding.rs +++ b/contract/contract/src/crowdfunding.rs @@ -172,6 +172,25 @@ impl CrowdfundingTrait for CrowdfundingContract { .unwrap_or(0) } + fn get_top_contributor_for_campaign( + env: Env, + campaign_id: BytesN<32>, + ) -> Result { + // Validate campaign exists + Self::get_campaign(env.clone(), campaign_id.clone())?; + + let metrics_key = StorageKey::CampaignMetrics(campaign_id); + let metrics: CampaignMetrics = env + .storage() + .instance() + .get(&metrics_key) + .unwrap_or_default(); + + metrics + .top_contributor + .ok_or(CrowdfundingError::CampaignNotFound) + } + fn get_all_campaigns(env: Env) -> Vec