Skip to content

Commit 601adfc

Browse files
committed
retain claim ids
1 parent 61a52e4 commit 601adfc

File tree

1 file changed

+52
-36
lines changed

1 file changed

+52
-36
lines changed

src/lib.rs

+52-36
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,10 @@ impl Contract {
275275
claims_ids.len()
276276
));
277277

278-
let mut expired_claim_ids = Vec::new();
279-
280278
for claim_id in claims_ids.iter().take(MAX_CLAIMS_PER_BATCH).cloned() {
281279
if let Some(claim) = self.claims_by_id.get(&claim_id) {
282280
if claim.is_expired() {
283281
// Track expired claims for removal
284-
expired_claim_ids.push(claim_id);
285282
// claims_vector.remove(claim);
286283
continue;
287284
}
@@ -353,11 +350,6 @@ impl Contract {
353350
};
354351
}
355352
}
356-
if !expired_claim_ids.is_empty() {
357-
for claim_id in expired_claim_ids {
358-
claims_ids.remove(&claim_id);
359-
}
360-
}
361353
} else {
362354
env::log_str("No pending claims found for this handle");
363355
}
@@ -386,34 +378,24 @@ impl Contract {
386378
social_handle.handle
387379
));
388380
} else if let Some(claim) = self.claims_by_id.get_mut(&claim_id) {
389-
if let Some(claim_ids) = self.handle_claims.get_mut(&social_handle.to_string()) {
390-
claim_ids.remove(&claim_id);
391-
if claim_ids.is_empty() {
392-
self.handle_claims.remove(&social_handle.to_string());
393-
env::log_str(&format!(
394-
"All claims processed for {:?}:{:?}",
395-
social_handle.platform, social_handle.handle
396-
));
397-
}
398-
// TODO: maybe merge this two events into one? since they emit same params?
399-
if reclaim_trf.is_some() {
400-
log_tip_reclaimed_event(
401-
&social_handle.platform,
402-
&social_handle.handle,
403-
claim.amount().into(),
404-
claim.token_type(),
405-
claim.tipper(),
406-
);
407-
} else {
408-
claim.claimed = true;
409-
log_claim_processed_event(
410-
&social_handle.platform,
411-
&social_handle.handle,
412-
claim.amount().into(),
413-
&token_type,
414-
&recipient,
415-
);
416-
}
381+
// TODO: maybe merge this two events into one? since they emit same params?
382+
if reclaim_trf.is_some() {
383+
log_tip_reclaimed_event(
384+
&social_handle.platform,
385+
&social_handle.handle,
386+
claim.amount().into(),
387+
claim.token_type(),
388+
claim.tipper(),
389+
);
390+
} else {
391+
claim.claimed = true;
392+
log_claim_processed_event(
393+
&social_handle.platform,
394+
&social_handle.handle,
395+
claim.amount().into(),
396+
&token_type,
397+
&recipient,
398+
);
417399
}
418400
}
419401
}
@@ -880,4 +862,38 @@ impl Contract {
880862
vec![]
881863
}
882864
}
865+
866+
pub fn get_all_claims_for_handle(
867+
&self,
868+
platform: String,
869+
handle: String,
870+
from_index: u64,
871+
limit: u64,
872+
) -> Vec<ClaimExternal> {
873+
let social_handle = SocialHandle::new(platform, handle);
874+
875+
if let Some(claim_ids) = self.handle_claims.get(&social_handle.to_string()) {
876+
// First collect all claim IDs into a Vec
877+
let claim_id_vec: Vec<ClaimId> = claim_ids.iter().cloned().collect();
878+
879+
// Apply pagination
880+
let start = from_index as usize;
881+
let end = std::cmp::min(start + limit as usize, claim_id_vec.len());
882+
883+
if start < end {
884+
// Map each claim ID to its corresponding claim
885+
claim_id_vec[start..end]
886+
.iter()
887+
.map(|claim_id| {
888+
let claim = self.claims_by_id.get(claim_id).unwrap(); // Unwrap is safe here because we know the claim_id exists
889+
format_claim(claim_id, claim)
890+
})
891+
.collect()
892+
} else {
893+
vec![]
894+
}
895+
} else {
896+
vec![]
897+
}
898+
}
883899
}

0 commit comments

Comments
 (0)