Refactor repeated admin-auth and pause checks into shared helpers
Description
Nearly every admin entrypoint in contracts/escrow/src/lib.rs repeats the same block: read DataKey::Admin, unwrap_or_else panic with NotInitialized, then admin.require_auth(). The pause check (get(&DataKey::Paused).unwrap_or(false) → panic #4) is likewise copy-pasted. This duplication is error-prone — a new entrypoint can easily forget a check. This issue centralises both into private helpers.
Requirements and context
- Repository scope:
Agentpay-Org/Agentpay-contracts only.
- Add private helpers, e.g.
fn require_admin(env: &Env) -> Address and fn ensure_not_paused(env: &Env), and route all existing entrypoints through them.
- Behaviour must be byte-for-byte identical: same error codes, same ordering of auth vs. pause checks, same panics.
- This is a pure refactor — no new public API, no semantic change; the existing test suite must pass unchanged.
- Add a short rationale comment explaining the helper pattern for future contributors.
Suggested execution
- Fork the repo and create a branch
git checkout -b refactor/contracts-29-auth-pause-helpers
- Implement changes
- Write code in:
contracts/escrow/src/lib.rs — introduce helpers, replace duplicated blocks.
- Write comprehensive tests in:
contracts/escrow/src/test.rs — existing tests must pass; add a regression test confirming a representative entrypoint still panics identically when paused/unauthorized.
- Add documentation: note the helper convention in a module comment.
- Include NatSpec-style doc comments (
///) on the helpers.
- Validate security: 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: confirm
NotInitialized (#3) and ContractPaused (#4) still fire from the helpers.
- Include the full
cargo test output and a short security notes section in the PR description.
Example commit message
refactor: extract shared admin-auth and pause-gate helpers
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.
Refactor repeated admin-auth and pause checks into shared helpers
Description
Nearly every admin entrypoint in
contracts/escrow/src/lib.rsrepeats the same block: readDataKey::Admin,unwrap_or_elsepanic withNotInitialized, thenadmin.require_auth(). The pause check (get(&DataKey::Paused).unwrap_or(false)→ panic#4) is likewise copy-pasted. This duplication is error-prone — a new entrypoint can easily forget a check. This issue centralises both into private helpers.Requirements and context
Agentpay-Org/Agentpay-contractsonly.fn require_admin(env: &Env) -> Addressandfn ensure_not_paused(env: &Env), and route all existing entrypoints through them.Suggested execution
git checkout -b refactor/contracts-29-auth-pause-helperscontracts/escrow/src/lib.rs— introduce helpers, replace duplicated blocks.contracts/escrow/src/test.rs— existing tests must pass; add a regression test confirming a representative entrypoint still panics identically when paused/unauthorized.///) on the helpers.Test and commit
cargo fmt --all -- --check,cargo build, andcargo test.NotInitialized (#3)andContractPaused (#4)still fire from the helpers.cargo testoutput and a short security notes section in the PR description.Example commit message
refactor: extract shared admin-auth and pause-gate helpersGuidelines
Community & contribution rewards