Skip to content

Add anchor_settlement_count(anchor) to avoid a full list_settlements_by_anchor scan just to countΒ #114

Description

@Jagadeeshftw

πŸ“Œ Description

settlement_count_by_status(status) gives a full-history count filtered by lifecycle state without pagination, but there is no equivalent for filtering by anchor β€” a caller who only wants "how many settlements has this anchor ever opened" must page through list_settlements_by_anchor accumulating a Vec just to measure its length, which is both more expensive and more awkward than a direct count.

🧩 Requirements and context

  • Add anchor_settlement_count(env, anchor) -> u64 scanning the full settlement history (same loop shape as settlement_count_by_status) and counting matches on anchor instead of status.
  • Document the O(n) scan cost consistent with the other full-history aggregate functions.
  • Add regression tests with settlements from multiple anchors interleaved.

πŸ› οΈ Suggested execution

  • Add the entrypoint to src/lib.rs beside settlement_count_by_status.
  • Add src/test.rs coverage for an anchor with zero, one, and many settlements, interleaved with other anchors' settlements.
  • Add the new view to the README settlement table.

βœ… Acceptance criteria

  • anchor_settlement_count(anchor) equals the number of settlements ever opened by that anchor, regardless of status.
  • It returns 0 for an anchor that has never opened a settlement.
  • Existing list_settlements_by_anchor behavior is unchanged.

πŸ”’ Security notes

A dedicated count avoids callers building an unbounded Vec client-side just to measure activity volume, keeping per-call instruction cost predictable for dashboards that poll many anchors.

πŸ“‹ Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issueperformancePerformance / gas / resource usesmart-contractSoroban/Rust smart contract work

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions