Last active
May 13, 2021 11:57
-
-
Save percybolmer/08e9c7a061244393f3b466a127b2e370 to your computer and use it in GitHub Desktop.
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
/** | |
* @notice balanceOf will return the account balance for the given account | |
*/ | |
function balanceOf(address account) external view returns (uint256) { | |
return _balances[account]; | |
} | |
/** | |
* @notice mint will create tokens on the address inputted and then increase the total supply | |
* | |
* It will also emit an Transfer event, with sender set to zero address (adress(0)) | |
* | |
* Requires that the address that is recieveing the tokens is not zero address | |
*/ | |
function mint(address account, uint256 amount) public { | |
require(account != address(0), "DevToken: cannot mint to zero address"); | |
// Increase total supply | |
_totalSupply = _totalSupply + (amount); | |
// Add amount to the account balance using the balance mapping | |
_balances[account] = _balances[account] + amount; | |
// Emit our event to log the action | |
emit Transfer(address(0), account, amount); | |
} | |
/** | |
* @notice burn will destroy tokens from an address inputted and then decrease total supply | |
* An Transfer event will emit with receiever set to zero address | |
* | |
* Requires | |
* - Account cannot be zero | |
* - Account balance has to be bigger or equal to amount | |
*/ | |
function burn(address account, uint256 amount) public { | |
require(account != address(0), "DevToken: cannot burn from zero address"); | |
require(_balances[account] >= amount, "DevToken: Cannot burn more than the account owns"); | |
// Remove the amount from the account balance | |
_balances[account] = _balances[account] - amount; | |
// Decrease totalSupply | |
_totalSupply = _totalSupply - amount; | |
// Emit event, use zero address as reciever | |
emit Transfer(account, address(0), amount); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment