Skip to content

Insurance: add reactivate_policy plus a get_deactivated_policies paginated query for the one-way deactivation gap #822

Description

@Baskarayelu

📋 Description

In insurance/src/lib.rs, deactivate_policy flips Policy.active = false and removes the id from DataKey::ActivePolicies, but the policy record stays in DataKey::Policy(id) storage forever. There is no way to reactivate a policy that was deactivated by mistake, and no way to enumerate deactivated policies — get_active_policies only walks the active set, and there is no get_deactivated_policies. Deactivated policies become invisible, un-restorable storage residue.

Why this matters: insurance policies get suspended for missed payments or admin error, then resumed. A one-way deactivate with no reactivation and no visibility means an integrator must create a brand-new policy (new id, lost history) to recover — and can never audit what was deactivated. A symmetric reactivate + a deactivated-list query make the lifecycle complete and auditable.

🎯 Requirements & Context

Functional requirements

  • Add reactivate_policy(env, caller, policy_id) -> Result<bool, InsuranceError> that re-adds the id to ActivePolicies (respecting MAX_POLICIES), sets active = true, refreshes next_payment_date, and is authorised to the same set as deactivate_policy (policy owner or contract owner).
  • Add get_deactivated_policies(env, owner, cursor, limit) -> PolicyPage paginated by OwnerPolicies(owner) filtered on active == false, using clamp_limit from remitwise_common.
  • Emit a new PolicyReactivatedEvent and document it alongside the existing PolicyDeactivatedEvent in EVENTS.md.
  • Reject reactivation when it would exceed MAX_POLICIES with MaxPoliciesReached, and reject reactivating an already-active policy with a clear typed error.

Context & constraints

  • Soroban SDK 21.7.7. Keep PolicyPage (items: Vec<u32>, next_cursor, count) as the return shape used by get_active_policies.
  • Reactivation must not duplicate the id in ActivePolicies.

🛠️ Suggested Execution

1. Branch

git checkout -b feat/insurance-reactivate-and-list-deactivated

2. Implement

  • Factor the active-set add/remove into helpers shared by create_policy, deactivate_policy, and the new reactivate_policy.
  • Add /// doc-comments covering the active⇄inactive transitions and the cap interaction.

3. Test & commit

cargo test -p insurance
  • Edge cases: reactivate after deactivate restores into the active page; reactivating when contract is at MAX_POLICIES; get_deactivated_policies cursor termination and owner isolation; double-reactivate is rejected.

Example commit message

feat(insurance): add reactivate_policy and get_deactivated_policies

Makes policy deactivation reversible and auditable: reactivation respects
MAX_POLICIES, emits PolicyReactivatedEvent, and a new paginated query lists
inactive policies that were previously invisible.

✅ Acceptance Criteria & Guidelines

Requirement Target
reactivate_policy + cap/duplicate guards Required
get_deactivated_policies pagination + owner isolation Required
PolicyReactivatedEvent emitted + documented Required
Test coverage ≥ 95%
EVENTS.md updated Required
cargo test -p insurance + clippy clean Required
Timeframe 96 hours from assignment

💬 Community & Support

Questions and design discussion — join the Remitwise contributor community on Discord: https://discord.gg/CtQuPZFMA

Please comment when you pick this up. 🚀

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions