refactor(settlement): extract shared check helper - #440
Merged
mikewheeleer merged 1 commit intoJul 29, 2026
Conversation
settle and settle_all each repeated the same "caller is admin or the service's ServiceMetadata.owner" check inline, including duplicated error handling for a missing ServiceMetadata entry. Extracted into require_settlement_authorized, which takes the caller-specific rejection code as a parameter so each entrypoint keeps its existing typed error (settle: NotPendingAdmin, settle_all: Unauthorized) -- no ABI or rejection-behaviour change. Added regression tests for the unauthorized and missing-metadata paths on both entrypoints, which had no direct coverage before this extraction. Closes Agentpay-Org#300
Contributor
|
clean work @thlpkee20-wq — CI green, merging 🎉 |
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
settleandsettle_alleach repeated the same "caller is admin or the service'sServiceMetadata.owner" check inline, including duplicated error handling for a missingServiceMetadataentry.require_settlement_authorizedhelper. Each entrypoint passes its own existing rejection code (settle→NotPendingAdmin,settle_all→Unauthorized), so behaviour and typed error codes are unchanged — no ABI change.ServiceMetadatarejection paths for bothsettleandsettle_all, which had no direct test coverage before this extraction.Test plan
cargo fmt --check: cleancargo clippy --all-targets -- -D warnings: cleantest_settle_unauthorized_non_owner_panics(Introduce role-based access control beyond the single-admin model #6),test_settle_service_metadata_not_found_panics(Support per-service owner authorization for self-service settlement #13),test_settle_all_unauthorized_non_owner_panics(Document the full escrow entrypoint reference and error code catalogue #26),test_settle_all_service_metadata_not_found_panics(Support per-service owner authorization for self-service settlement #13)Closes #300