Skip to content

Add anchor_settlement FIX#239

Open
Mitch5000 wants to merge 1 commit into
AnchorNet-Org:mainfrom
Mitch5000:Add-anchor_settlement-FIXED
Open

Add anchor_settlement FIX#239
Mitch5000 wants to merge 1 commit into
AnchorNet-Org:mainfrom
Mitch5000:Add-anchor_settlement-FIXED

Conversation

@Mitch5000

Copy link
Copy Markdown

Title:
feat: add anchor_settlement_count(anchor) view function

Branch:
fix/anchor-settlement-count

Base branch:
main

================================================================================
DESCRIPTION

Problem

settlement_count_by_status(status) provides a full-history count by lifecycle state.
However, there was no equivalent function for counting settlements by anchor.

Callers who wanted to know "how many settlements has this anchor ever opened" had to
page through list_settlements_by_anchor(...) and accumulate results just to get a
length — which is inefficient and awkward.

Solution

Added a new dedicated view function:

pub fn anchor_settlement_count(env: Env, anchor: Address) -> u64
Scans the full settlement history (same O(n) loop shape as settlement_count_by_status)
Counts matches on the anchor field
Returns 0 for anchors that have never opened a settlement
Documented with the same O(n) scan cost warning as other aggregate functions
Changes Made
Added anchor_settlement_count entrypoint in src/lib.rs next to settlement_count_by_status
Added comprehensive regression tests in src/test.rs:
Zero settlements for an anchor
One settlement
Many settlements
Interleaved settlements from multiple anchors
Updated the Settlement table in README.md
Acceptance Criteria Met
anchor_settlement_count(anchor) returns the exact number of settlements ever opened by that anchor (regardless of status)
Returns 0 for anchors with no settlements
Existing list_settlements_by_anchor behavior is unchanged
Minimum 95% test coverage maintained
Clear documentation added
Security / UX Benefit
Avoids forcing callers to build large Vecs client-side just to measure activity volume.
Keeps per-call instruction cost predictable for dashboards that poll many anchors.

================================================================================
FILES CHANGED
Modified:

src/lib.rs
src/test.rs
README.md
New tests:

test_anchor_settlement_count_counts_only_that_anchor
test_anchor_settlement_count_zero_for_unknown_anchor
test_anchor_settlement_count_zero_when_none_opened
================================================================================
TESTING
All new tests pass
Existing settlement-related tests continue to pass
No breaking changes to public API or existing behavior
cargo check passes cleanly
================================================================================
Closes #114 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant