Feat/registry campaign enumeration 151 - #195
Merged
Dannyswiss1 merged 3 commits intoAug 30, 2026
Merged
Conversation
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes the registry answer "what campaigns exist?" on-chain.
DataKey::FarmerCountandDataKey::CampaignCountwere declared but never read or written anywhere in the crate —they are now actually populated, backed by a sequential index that supports paginated
enumeration of both campaigns and farmers.
This removes the need for the event-log scanning workaround in
client/src/hooks/useAdminCampaigns.ts, which silently drops campaigns created before thelookback window or before whatever history the configured RPC provider retains.
New contract methods
get_campaign_count()u64get_campaign_ids(offset, limit)Vec<u64>limitclamped to 100get_farmer_count()u64get_farmers(offset, limit)Vec<Address>limitclamped to 100Semantics: ids come back in registration order with stable indices; an
offsetat or pastthe count returns an empty vector (the termination signal when paging); a
limitabove 100is clamped rather than rejected, so a short page does not by itself mean end-of-list.
Changes
registry/src/types.rsCampaignIndex(u64),CampaignIndexed(u64),FarmerIndex(u64)registry/src/storage.rsMAX_PAGE_LIMIT = 100registry/src/campaign.rsregister_campaignandlink_campaign_escrowregistry/src/farmer.rsregister_farmerregistry/src/lib.rsregistry/src/test.rsINTEGRATION.mdDesign notes
Per-index storage keys, not one append-only
Vec<u64>. The issue flagged theunbounded-growth concern from Issue 9. A single
Vecin one storage entry means everyregistration rewrites an ever-larger blob and eventually hits entry size limits.
CampaignIndex(u64) -> u64keeps each write constant-cost regardless of registry size.Both entry points index, counted once. The issue suggested incrementing in
register_campaign"and/orlink_campaign_escrow". Neither alone is sufficient:link_campaign_escrowdoes not require prior registration, so indexing only inregister_campaignwould leave linked-but-unregistered campaigns invisible — precisely thegap being closed. Both index, and a
CampaignIndexed(u64)marker makesindex_campaignidempotent so a campaign travelling both paths is counted exactly once.
Acceptance criteria
CampaignCount/FarmerCountpopulated and accurateINTEGRATION.mddocuments discovery as the recommended path over event scanningVerification
wasm32-unknown-unknown, exit 0) — deployable, not merelytest-passing.
Pre-existing failure (not from this PR)
cargo test --workspacefails to compileproduction_escrow(E0308,E0277oni128 * i64). Untouched crate, no dependency edge toregistry, byte-identical errorswith these changes stashed. Workspace CI is red independently of this work.
Follow-up
client/src/hooks/useAdminCampaigns.tscan now drop its bounded-lookback event scan.Left out to keep the contract change reviewable on its own.
Closes #151