Skip to content

refactor: Extract shared require_admin pattern into router-common crate (#128)#172

Merged
Maki-Zeninn merged 2 commits intoMaki-Zeninn:mainfrom
onahiOMOTI:tasks
Mar 30, 2026
Merged

refactor: Extract shared require_admin pattern into router-common crate (#128)#172
Maki-Zeninn merged 2 commits intoMaki-Zeninn:mainfrom
onahiOMOTI:tasks

Conversation

@onahiOMOTI
Copy link
Copy Markdown
Contributor

@onahiOMOTI onahiOMOTI commented Mar 30, 2026

Closes #128


Description

This PR implements Issue #128 - Refactor: extract shared require_admin pattern into a shared module or macro.

Problem

All six contracts had nearly identical require_admin functions with only minor differences in error types. This caused significant code duplication (DRY violation), making maintenance error-prone.

Solution

  • Created a new workspace crate contracts/router-common
  • Added two reusable macros:
    • require_admin! — flexible version with custom error types
    • require_admin_simple! — simpler version when error variants are standardized
  • Added router-common as a dependency to all contracts
  • Replaced repetitive admin authorization code with the shared macro

Changes

  • New crate: contracts/router-common
    • src/lib.rs with admin guard macros
  • Updated workspace Cargo.toml
  • Updated Cargo.toml in all contract crates
  • Refactored admin checks in multiple contracts (registry, core, access-control, etc.)

Benefits

  • Eliminates code duplication
  • Makes future admin logic changes consistent across all contracts
  • Reduces chance of bugs from missed updates
  • Cleaner and more maintainable codebase
  • All existing tests continue to pass

…mmon crate

- Created new workspace crate `contracts/router-common`
- Added `require_admin!` and `require_admin_simple!` macros to eliminate code duplication
- Updated all contracts to depend on `router-common`
- Replaced repetitive admin check boilerplate with the shared macro
- Improves maintainability and reduces risk of inconsistent admin logic

Closes Maki-Zeninn#128
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 30, 2026

@onahiOMOTI Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Maki-Zeninn Maki-Zeninn merged commit 7197c74 into Maki-Zeninn:main Mar 30, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: extract shared require_admin pattern into a shared module or macro

2 participants