Repository navigation
feat(subscription): add check_subscriptions batch read with SubStatus - #274
Merged
Busiii-adetiba merged 1 commit intoNov 25, 2026
Conversation
Clients verifying many memberships were forced to call is_active once per plan-subscriber pair. This adds a capped, ordered batch query that returns explicit Missing / Active / Expired results in a single transaction. ## What changed ### contracts/subscription/src/lib.rs - **** ( enum) — three variants: - — no record exists for the pair - — live; value is ledgers until current_period_end - — record exists but current_period_end ≤ ledger.sequence() A cancelled-but-active subscription returns Active (paid window still open). Expiry boundary is exclusive, consistent with the workspace convention. - **** — single-pair convenience read. Extends the persistent-entry TTL when a record is found, matching is_active and get_subscription. - **** — batch read of up to MAX_BATCH_SIZE (50) pairs. Output is index-aligned with input. Missing entries return SubStatus::Missing, not an error. Empty batch returns SubNotFound; oversized batch returns BatchTooLarge. Both guards fire before any storage read so the call is a cheap no-op on rejection. - **** — cap matching access-lease's check_leases. At one persistent read per entry the worst-case ledger-entry budget stays within the Soroban per-transaction limit. - **** — new discriminant, stable and pinned by the error_codes_are_stable test. ### tests (inline mod tests) - — pins all discriminants including BatchTooLarge=14. - — four subscribers on one plan cover Active, Expired, cancelled-but-Active, and Missing; asserts index alignment and the exclusive expiry boundary. - — 50 missing pairs → 50 × Missing. - — 51 pairs → BatchTooLarge. - — 0 pairs → SubNotFound. - / / — unit coverage for the single-pair path. - — confirms the original is_active entrypoint is unaffected by the new functions. ### docs/CONTRACTS.md - Added SubStatus type and MAX_BATCH_SIZE constant to the subscription Data section. - Added sub_status and check_subscriptions rows to the Functions table. - Added sub_status / check_subscriptions semantics (variants, boundary rule, TTL behaviour, pagination guidance). - Added BatchTooLarge = 14 to the subscription Errors table. - Added sub_status / check_subscriptions to the access-control matrix (permissionless). - Added BatchTooLarge to the cross-contract error code numbering table. - Added compatibility note: purely additive — no storage changes, no migration required, existing deployments unaffected. ## Compatibility No storage keys added or removed. No existing entrypoints changed. Older clients that do not know about SubStatus simply never call the new functions. is_active remains and is unmodified.
|
@Ayilojay Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Clients verifying many memberships were forced to call is_active once per plan-subscriber pair. This adds a capped, ordered batch query that returns explicit Missing / Active / Expired results in a single transaction.
What changed
contracts/subscription/src/lib.rs
**** ( enum) — three variants:
A cancelled-but-active subscription returns Active (paid window still open).
Expiry boundary is exclusive, consistent with the workspace convention.
**** — single-pair convenience read. Extends the persistent-entry TTL when a record is found, matching is_active and get_subscription.
**** — batch read of up to MAX_BATCH_SIZE (50) pairs. Output is index-aligned with input. Missing entries return SubStatus::Missing, not an error. Empty batch returns SubNotFound; oversized batch returns BatchTooLarge. Both guards fire before any storage read so the call is a cheap no-op on rejection.
**** — cap matching access-lease's check_leases. At one persistent read per entry the worst-case ledger-entry budget stays within the Soroban per-transaction limit.
**** — new discriminant, stable and pinned by the error_codes_are_stable test.
tests (inline mod tests)
docs/CONTRACTS.md
Compatibility
No storage keys added or removed. No existing entrypoints changed. Older clients that do not know about SubStatus simply never call the new functions. is_active remains and is unmodified.
Summary
Checklist
cargo fmt --all -- --check,cargo clippy --workspace --all-targets -- -D warningsandcargo test --workspacepassdocs/CONTRACTS.mdand rustdoc updated for any interface, storage, event or error changecloses [subscription] Add bounded batch subscription status reads #231