Skip to content

feature(contract): Ownable Patter nof RsTokenContract#183

Merged
ayomideadeniran merged 2 commits intoStellarDevHub:mainfrom
anonfedora:feature/ownable-pattern-for-rstokencontract
Mar 30, 2026
Merged

feature(contract): Ownable Patter nof RsTokenContract#183
ayomideadeniran merged 2 commits intoStellarDevHub:mainfrom
anonfedora:feature/ownable-pattern-for-rstokencontract

Conversation

@anonfedora
Copy link
Copy Markdown
Contributor

Description

This PR introduces a formal Ownable pattern to the RsTokenContract, enabling secure ownership management and the ability to update the authorized minter (the CertificateContract). This ensures that the token contract can adapt to upgrades in the certificate issuance logic without requiring a full token redeployment.

Requirements

  • Implement transfer_ownership(new_owner: Address).
  • Use require_auth() for owner-only actions.
  • Add an only_owner helper to centralize authorization logic.
  • Implement set_certificate_contract to allow updating the authorized minter.
  • Update existing owner-only functions (update_uri, burn) to use the new pattern.

Closes #137

Changes

Contract Logic (token.rs)

  • Ownership State: Added DataKey::Owner to manage the contract owner (initially set to the certificate_contract during init).
  • Authorization Helpers:
    • only_owner: Standardized check that calls require_auth() and verifies the caller is the current owner.
    • check_owner: Internal helper for scenarios where require_auth() might have already been called (e.g., in burn).
  • Administrative Functions:
    • transfer_ownership: Securely migrates ownership to a new address.
    • set_certificate_contract: Updates the address allowed to call mint and set_mint_pause.
  • Refactoring:
    • Updated update_uri to use only_owner.
    • Updated burn to allow either the contract owner or the student to burn tokens using the new check_owner helper.

Clippy & Code Quality

  • Fixed several unnecessary_cast warnings in lib.rs.
  • Refactored a needless_range_loop in tests.rs to use idiomatic iterators.

Verification Results

Ran 24 unit tests in token::tests with 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.

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 29, 2026

@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! 🚀

Learn more about application limits

@ayomideadeniran
Copy link
Copy Markdown
Contributor

Pr under review.

@ayomideadeniran ayomideadeniran merged commit c5df738 into StellarDevHub:main Mar 30, 2026
0 of 5 checks passed
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.

[Contract] Implement Ownable Pattern for RsTokenContract

2 participants