Skip to content

Extract typed boolean-flag storage accessors to remove unwrap_or(false) duplication #47

Description

@mikewheeleer

Refactor repeated persistent boolean-flag reads into shared accessors

Description

contracts/escrow/src/lib.rs repeats the same env.storage().persistent().get(&DataKey::SomeFlag).unwrap_or(false) pattern across many sites — the Paused check in both record_usage and settle, RequireServiceRegistration, ServiceRegistered, ServiceDisabled, AllowlistEnabled, AgentAllowed, and the is_* getters. This copy-paste makes it easy to typo a default or forget a check, and any new boolean flag re-introduces the same boilerplate. This issue centralises the read/write of boolean flags into small private helpers.

Requirements and context

  • Repository scope: Agentpay-Org/Agentpay-contracts only.
  • Add private helpers, e.g. fn read_flag(env: &Env, key: &DataKey) -> bool (defaulting to false) and fn write_flag(env: &Env, key: &DataKey, value: bool), and route the boolean reads/writes in record_usage, settle, the set_*/is_* flag entrypoints through them.
  • Behaviour must be byte-for-byte identical: same defaults, same error codes, same ordering of checks; this is a pure refactor with no public API or semantic change.
  • The existing test suite must pass unchanged; add a regression test confirming a representative flag still reads/writes/defaults identically.
  • Add a short rationale comment so future flags use the helper.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b refactor/contracts-bool-flag-accessors
  • Implement changes
    • Write code in: contracts/escrow/src/lib.rs — introduce read_flag/write_flag, replace duplicated boolean reads/writes.
    • Write comprehensive tests in: contracts/escrow/src/test.rs — existing tests pass; add a default-and-round-trip test for a representative flag.
    • Add documentation: note the helper convention in a module comment.
    • Include NatSpec-style doc comments (///) on the helpers.
    • Validate security: no flag default flipped, no check accidentally dropped during extraction.
  • Test and commit

Test and commit

  • Run cargo fmt --all -- --check, cargo build, and cargo test.
  • Cover edge cases: unset flag defaults to false, set-true then set-false round-trip, paused gate still fires #4.
  • Include the full cargo test output and a short security notes section in the PR description.

Example commit message

refactor: extract typed boolean-flag storage accessors

Guidelines

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

Community & contribution rewards

  • 💬 Join the AgentPay community on Discord for questions, reviews, and faster merges: https://discord.gg/eXvRKkgcv
  • ⭐ 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

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions