feature(contract): Ownable Patter nof RsTokenContract#183
Merged
ayomideadeniran merged 2 commits intoStellarDevHub:mainfrom Mar 30, 2026
Merged
Conversation
|
@anonfedora 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! 🚀 |
Contributor
|
Pr under review. |
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.
Description
This PR introduces a formal Ownable pattern to the
RsTokenContract, enabling secure ownership management and the ability to update the authorized minter (theCertificateContract). This ensures that the token contract can adapt to upgrades in the certificate issuance logic without requiring a full token redeployment.Requirements
transfer_ownership(new_owner: Address).require_auth()for owner-only actions.only_ownerhelper to centralize authorization logic.set_certificate_contractto allow updating the authorized minter.update_uri,burn) to use the new pattern.Closes #137
Changes
Contract Logic (token.rs)
DataKey::Ownerto manage the contract owner (initially set to thecertificate_contractduringinit).only_owner: Standardized check that callsrequire_auth()and verifies the caller is the current owner.check_owner: Internal helper for scenarios whererequire_auth()might have already been called (e.g., inburn).transfer_ownership: Securely migrates ownership to a new address.set_certificate_contract: Updates the address allowed to callmintandset_mint_pause.update_urito useonly_owner.burnto allow either the contract owner or the student to burn tokens using the newcheck_ownerhelper.Clippy & Code Quality
unnecessary_castwarnings in lib.rs.needless_range_loopin tests.rs to use idiomatic iterators.Verification Results
Ran 24 unit tests in
token::testswith 100% success rate:test_ownership_transfer: Verified successful migration and updated access control.test_set_certificate_contract: Confirmed the ability to rotate the authorized minter.test_unauthorized_ownership_transfer: Verified that non-owners cannot hijack the contract.owner_can_burn_student_tokens: Re-verified that administrative burning still works with the new owner state.