2. Core Architecture of DMCC Tokens

DMCC tokens define two mapping objects, representing Solidity's concept of associative or key-value arrays.

solidity

mapping(address => uint256) balances;

mapping(address => mapping(address => uint256)) allowed;

The first mapping object, balances, holds the token balance of each DMCC owner account. The second mapping object, allowed, contains the sum of withdrawals authorized by all accounts and the total amount allowed for each account.

The following describes the functionalities based on the code above.

a. Get Total Token Supply

//solidity

function totalSupply() public view virtual override(IERC20, IERC777) returns (uint256) {

return _totalSupply;

}

//

This function returns the total number of DMCC tokens allocated by the contract, regardless of ownership.

b. Get Token Holder's Balance

//solidity

function balanceOf(address tokenHolder) public view virtual override(IERC20, IERC777) returns (uint256) {

return _balances[tokenHolder];

}

//

The balanceOf function returns the current DMCC token balance of the account identified by the owner's address.

c. Transfer Tokens to Another Account

//solidity

function transfer(address recipient, uint256 amount) public virtual override returns (bool) {

_send(_msgSender(), recipient, amount, "", "", false);

return true;

}

//

The transfer function moves the specified amount of tokens from the owner's balance to another user's balance. The sender of the function (msg.sender) must be the DMCC token owner to transfer DMCC to someone else.

d. SafeMath Solidity Library

The SafeMath code is DMCC's Solidity library for handling integer overflow attacks, one of the known methods by which hackers can breach contracts. The SafeMath code verifies the correctness of numbers passed to the parameters of the hacker's attack contract.

By testing for overflow before performing arithmetic operations, SafeMath prevents overflow attacks, eliminating the risk of overflow attacks. The library is small, minimizing its impact on contract size, and reduces storage usage costs. Below is an example of SafeMath code in DMCC tokens.

//solidity

SafeMath is no longer needed starting with Solidity 0.8. The compiler now has built in overflow checking.

//

The SafeMath library uses the assert statement to verify the correctness of the passed parameters. If assert fails, the function execution stops immediately, and all blockchain transactions are rolled back. The following shows how SafeMath functions are applied.

//solidity

SafeMath is no longer needed starting with Solidity 0.8. The compiler now has built in overflow checking.

//

Last updated