Skip to content

feat(roles): add on-chain role management with events - #842

Merged
dzekojohn4 merged 1 commit into
UnityChainxx:mainfrom
ameeribro4-sudo:feat/issue-676-role-management
Oct 20, 2026
Merged

dzekojohn4 merged 1 commit into
UnityChainxx:mainfrom
ameeribro4-sudo:feat/issue-676-role-management

Conversation

@ameeribro4-sudo

Copy link
Copy Markdown
Contributor

Summary

Adds on-chain role management to the stellar_hunts contract, introducing Minter and Upgrader roles on top of the existing single-admin model. This lets privileged responsibilities be delegated without transferring full admin control.

Problem

Previously the contract distinguished only admins from everyone else. Any privileged action required the single admin key, so delegating narrow capabilities such as badge minting or schema upgrades meant sharing full control. There was no way to grant or revoke a scoped capability and no on-chain record of who holds one.

Changes Made

  • Added a Role enum with Minter and Upgrader variants.
  • Added a DataKey::Role(Address, Role) storage key that records whether an account holds a given role.
  • Added grant_role, revoke_role, and has_role entrypoints:
    • grant_role and revoke_role are admin-gated via the existing require_admin helper.
    • Both emit events (role_granted, role_revoked) so off-chain indexers can track changes.
    • has_role returns true for the admin implicitly, otherwise reads the stored flag.

Only onchain/contracts/stellar_hunts/src/lib.rs was modified.

Implementation Details

Roles are stored in persistent storage under DataKey::Role(account, role) and set to true only while granted; revoke_role removes the entry. The admin implicitly holds every role, so has_role short-circuits to true when the queried account is the admin. Transitions publish events carrying the (account, role) tuple so consumers can reconstruct role state without replaying raw storage.

Closes #672

Closes #673

Closes #674

Closes #676

@drips-wave

drips-wave Bot commented Oct 20, 2026

Copy link
Copy Markdown

@ameeribro4-sudo 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

@dzekojohn4 dzekojohn4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dzekojohn4
dzekojohn4 merged commit e0f405f into UnityChainxx:main Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants