refactor: extract shared admin-auth and pause-gate helpers#61
Open
Baskarayelu wants to merge 1 commit into
Open
refactor: extract shared admin-auth and pause-gate helpers#61Baskarayelu wants to merge 1 commit into
Baskarayelu wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
thanks for this @Baskarayelu — the shared admin-auth + pause-gate cleanup is a good direction 🙌 since you opened it, a batch of feature PRs has landed on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pure refactor extracting the two access-control patterns that were duplicated across the escrow contract into shared module-level helpers, placed next to
read_flag/write_flag:require_admin(env) -> Address— loadsDataKey::Admin, panicsNotInitialized(Enforce the documented 256-byte service-description cap in set_service_metadata #3) if unset, callsadmin.require_auth(), returns the admin. Replaces the repeated admin-load + auth block in every admin-gated entrypoint.ensure_not_paused(env)— panicsContractPaused(Emit structured events on admin, price, and registration state changes #4) when thePausedflag is set. Replaces the inline pause checks.A short module comment documents the helper pattern (plain
fns, called directly, not viaSelf::) for future contributors.Closes #29
Pure refactor — no behaviour change
This is a behaviour-preserving cleanup. No public signatures changed and the helpers reproduce the exact prior logic:
NotInitialized(Enforce the documented 256-byte service-description cap in set_service_metadata #3) for missing admin,ContractPaused(Emit structured events on admin, price, and registration state changes #4) for paused calls.settleandrecord_usagethe pause check stays first; intransfer_service_ownershipthe pause check stays beforecaller.require_auth()(its admin load stays manual since it authorizes the caller, not the admin).transfer_service_ownershippreviously read the pause flag via the inline.get(&DataKey::Paused).unwrap_or(false)variant;ensure_not_pausedreads the same persistent slot with the sameunwrap_or(false)default, so behaviour is identical.initkeeps its ownAlreadyInitializedflow;accept_admin_transferkeepscaller.require_auth().Security notes
require_auth, now via the single auditedrequire_adminhelper.Tests
Existing suite unchanged and passing. Added two small regression tests confirming the helpers preserve behaviour:
set_service_pricestill panicsNotInitialized(#3) before init, andrecord_usagestill panicsContractPaused(#4) while paused.