Skip to content

Add a contract-existence reader (contract_exists) to avoid panicking probe calls #560

Description

@mikewheeleer

Add a contract-existence reader (contract_exists) to avoid panicking probe calls

Description

The only way to check whether a contract_id exists today is to call get_contract, which panics with ContractNotFound for unknown ids (per contracts/escrow/src/lib.rs). Clients and indexers iterating an id range must catch panics or pre-know the range, which is awkward and wasteful.

This issue adds a cheap, non-panicking contract_exists(contract_id) -> bool so callers can probe ids safely.

Requirements and context

  • Repository scope: Talenttrust/Talenttrust-Contracts only.
  • Add contract_exists returning env.storage().persistent().has(&DataKey::Contract(contract_id)).
  • Do not extend TTL on a pure existence probe (document this), so probing cannot be abused to keep entries alive.
  • Add a companion get_next_contract_id() reader so indexers know the allocation high-water mark.
  • Document both readers.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b feature/contracts-existence-reader
  • Implement changes
  • Test and commit

Test and commit

  • Run cargo fmt --all -- --check, cargo build, and cargo test.
  • Cover existing id, missing id, and next-id high-water mark.
  • Include the full cargo test output in the PR description.

Example commit message

feat: add contract_exists and get_next_contract_id readers

Guidelines

  • Minimum 95 percent test coverage for impacted modules.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the TalentTrust community on Discord for questions, reviews, and faster merges: https://discord.gg/WqnGpcPx
  • ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.

Metadata

Metadata

Fields

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions