Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement custom minting and burning with access control checks
  • Loading branch information
Michal Handzlik committed Oct 11, 2022
commit dc0425e5beccf3d90fdf2cae518288c2dabbd02f
26 changes: 24 additions & 2 deletions contracts/game_token/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,30 @@ pub mod game_token {
impl PSP22 for GameToken {}

impl PSP22Metadata for GameToken {}
impl PSP22Mintable for GameToken {}
impl PSP22Burnable for GameToken {}

impl PSP22Mintable for GameToken {
#[ink(message)]
fn mint(&mut self, account: AccountId, amount: Balance) -> Result<()> {
let caller = self.env().caller();
let this = self.env().account_id();
let required_role = Role::Minter(this);

self.check_role(caller, required_role)?;
self._mint_to(account, amount)
}
}

impl PSP22Burnable for GameToken {
#[ink(message)]
fn burn(&mut self, account: AccountId, amount: Balance) -> Result<()> {
let caller = self.env().caller();
let this = self.env().account_id();
let required_role = Role::Burner(this);

self.check_role(caller, required_role)?;
self._burn_from(account, amount)
}
}

// emit events
// https://github.com/w3f/PSPs/blob/master/PSPs/psp-22.md
Expand Down