Skip to content

feat: escrow balance guard, mark_in_transit, delivery state machine, and dispute trigger - #43

Merged
Tybravo merged 3 commits into
SwiftChainn:mainfrom
noevidence1017:main
Apr 27, 2026
Merged

feat: escrow balance guard, mark_in_transit, delivery state machine, and dispute trigger#43
Tybravo merged 3 commits into
SwiftChainn:mainfrom
noevidence1017:main

Conversation

@noevidence1017

Copy link
Copy Markdown
Contributor

Summary

  • closes Smart Contract: Implement Escrow Balance Verification Guard #17 — Added InsufficientFunds error and a pre-transfer balance verification guard in release_escrow and refund_escrow. The guard queries the contract's own token balance via token::Client::balance after all state validations but before any state mutation. Also added the previously-missing EscrowStatus, EscrowRecord, helper functions, and constants module required for the escrow contract to compile. Underfunded scenario unit tests use env.as_contract to artificially inflate the stored escrow amount beyond the actual contract balance.

  • closes Smart Contract: Implement Mark In-Transit Status Update #22 — Implemented mark_in_transit(env, driver, delivery_id) which requires driver auth, verifies the caller matches DeliveryRecord.driver, validates the Active → InTransit transition via the state machine, records transit_started_at ledger timestamp, extends TTL, and emits a DeliveryInTransit event.

  • closes Smart Contract: Implement Delivery State Machine Enforcement Layer #25 — Implemented a standalone validate_transition(from, to) -> Result<(), DeliveryError> function encoding the full transition matrix (Pending→Active/Cancelled, Active→InTransit/Disputed/Cancelled, InTransit→Delivered/Disputed, Disputed→Delivered/Cancelled, terminal states block all transitions). All state-mutating contract functions now call this helper. Unit tests cover every valid and invalid transition pair.

  • closes Smart Contract: Implement Delivery Dispute Trigger with Cross-Contract Escrow Pause #27 — Implemented raise_dispute(env, caller, delivery_id) restricted to sender or recipient, validates Active/InTransit → Disputed via the state machine, makes the cross-contract escrow pause call before mutating delivery state (so a failing escrow call leaves delivery state untouched), then updates storage and emits delivery_disputed.

@drips-wave

drips-wave Bot commented Apr 25, 2026

Copy link
Copy Markdown

@noevidence1017 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! 🚀

Learn more about application limits

@Tybravo

Tybravo commented Apr 26, 2026

Copy link
Copy Markdown
Collaborator

@noevidence1017 Please ensure you open an individual PR for their issues implementation, respectively.

noevidence1017 and others added 2 commits April 26, 2026 15:03
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- shared_types: add missing Address import (used by EscrowRecord)
- escrow_contract/lib.rs: import EscrowRecord/EscrowStatus from shared_types,
  remove local duplicate definitions, keep InsufficientFunds guard and pub mod constants
- escrow_contract/test.rs: use register_stellar_asset_contract_v2, check events
  before subsequent client calls (env.events().all() is cleared per invocation)
- delivery_contract/test.rs: move events check before env.as_contract() call
  to avoid event queue being cleared

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@Tybravo
Tybravo merged commit d22c35d into SwiftChainn:main Apr 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants