-
Notifications
You must be signed in to change notification settings - Fork 7
Implement Stale Booking Reclaim (User Safety) #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Stale Booking Reclaim (User Safety) #20
Conversation
Add created_at timestamp to Booking struct and Reclaimed variant to BookingStatus enum for stale booking reclaim functionality. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add error variant for when users try to reclaim funds before the 24-hour timeout has elapsed. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add event emission for when users reclaim funds from stale bookings. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add reclaim_stale_session function allowing users to reclaim their deposit after 24 hours if booking is still pending. Includes: - User authorization check - Booking ownership verification - 24-hour timeout enforcement - Token transfer back to user - Status update to Reclaimed Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Expose reclaim_stale_session in contract interface allowing users to reclaim stuck funds from stale bookings. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add tests for reclaim_stale_session functionality: - test_reclaim_stale_session_too_early: fails before 24h - test_reclaim_stale_session_success: succeeds after 25h - test_reclaim_stale_session_wrong_user: fails for non-owner - test_reclaim_already_finalized: fails for completed bookings Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds a 24-hour reclaim flow letting booking owners recover deposits from long-pending bookings: records booking creation time, new reclaim API and contract logic, new event and error, booking status variant for reclaimed, and tests covering reclaim scenarios. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Contract
participant Storage
participant Ledger
participant Events
User->>Contract: reclaim_stale_session(booking_id)
Contract->>User: require_auth()
User-->>Contract: authorized
Contract->>Storage: get booking by id
Storage-->>Contract: booking { owner, status=Pending, created_at, total_deposit }
Contract->>Ledger: current_ts = ledger.timestamp()
Ledger-->>Contract: current_ts
Contract->>Contract: check current_ts > created_at + RECLAIM_TIMEOUT
alt timeout elapsed
Contract->>Contract: transfer total_deposit -> user
Contract->>Storage: update booking.status = Reclaimed
Storage-->>Contract: updated
Contract->>Events: emit session_reclaimed(booking_id, amount)
Events-->>Contract: published
Contract->>User: Ok(())
else too early
Contract->>User: Err(ReclaimTooEarly)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Integrate stale booking reclaim feature with main branch changes: - Add Reclaimed status and created_at to BookingRecord in types.rs - Combine DataKeys from both branches in storage.rs - Include all public functions in lib.rs - Merge all tests from both branches Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
contracts/payment-vault-contract/src/storage.rs (1)
15-32: Storage schema upgrade may break existing bookings if migrating from an earlier contract version.
Adding thecreated_atfield to theBookingstruct (a#[contracttype]named-field struct) will break deserialization of pre-existingBookingrecords stored on-chain. The derived decoder expects all struct fields; old records missingcreated_atwill fail to decode. If this contract is being upgraded from a version withoutcreated_at, add a migration path (e.g., versioned storage keys, an upgrade function that rebuilds records, or custom deserialization with defaults). Note: AddingBookingStatus::Reclaimedis safe—new enum variants are backward-compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
contracts/payment-vault-contract/src/types.rs (1)
7-25: Storage compatibility breaks deserialization when adding non-optionalcreated_atfield.Adding a non-optional field to an already-deployed
#[contracttype]struct will fail deserialization on existing storedBookingRecordentries. Soroban's#[contracttype]macro encodes structs as maps keyed by field name and errors if any field key is missing during decoding—Rust'sDefaultis not applied.If this contract has live deployments with stored bookings:
- Wrap
created_atinOption<u64>to handle missing keys gracefully, or- Implement a versioned storage strategy (e.g.,
BookingRecordV2+ migration code) or- Add a state migration function to backfill the field before contract upgrade
Choose one of these patterns before deploying an update.
🧠 SkillSphere Pull Request 🌐
Mark with an
xall the checkboxes that apply (like[x])cargo test(All tests passed)📌 Type of Change
📝 Changes Description
Implement time-based mechanism for users to reclaim funds if booking stays in
Pendingstatus for more than 24 hours (protects users when Oracle/backend crashes):Reclaimedstatus toBookingStatusenum andcreated_at: u64field toBookingRecordReclaimTooEarlyerror for premature reclaim attemptssession_reclaimedevent emissioncreated_atinbook_sessionand implementreclaim_stale_sessionwith user auth, ownership check, and 24h timeoutreclaim_stale_sessionas public contract function📸 Evidence
Summary by CodeRabbit
New Features
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.