100 lines
3.8 KiB
Solidity
100 lines
3.8 KiB
Solidity
|
// SPDX-License-Identifier: Proprietary
|
||
|
|
||
|
pragma solidity ^0.8.0;
|
||
|
|
||
|
import "./Owned.sol";
|
||
|
import "./IERC20.sol";
|
||
|
|
||
|
interface FoolsGransRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes calldata _extraData) external; }
|
||
|
|
||
|
contract FoolsGrans is IERC20, Owned {
|
||
|
|
||
|
string public name = "FoolsGrans";
|
||
|
string public symbol = "FOOL";
|
||
|
uint256 public override decimals = 18;
|
||
|
uint256 public override totalSupply = 15000000000000000015000;
|
||
|
|
||
|
/* This creates an array with all balances */
|
||
|
mapping (address => uint256) public override balanceOf;
|
||
|
mapping (address => mapping (address => uint256)) public override allowance;
|
||
|
mapping (address => bool) public frozenAccount;
|
||
|
|
||
|
/* This generates a public event on the blockchain that will notify clients */
|
||
|
event Transfer(address indexed from, address indexed to, uint256 value);
|
||
|
|
||
|
/* If an account is frozen or unfrozen */
|
||
|
event FrozenFunds(address target, bool frozen);
|
||
|
|
||
|
/* Initializes contract with initial supply tokens to the creator of the contract */
|
||
|
constructor() {
|
||
|
contractOwner = msg.sender;
|
||
|
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
|
||
|
}
|
||
|
|
||
|
/* Send coins */
|
||
|
function transfer(address _to, uint256 _value) public override returns(bool success) {
|
||
|
require(balanceOf[msg.sender] >= _value, "not enough to transfer");
|
||
|
require(!frozenAccount[msg.sender], "sender account frozen");
|
||
|
|
||
|
balanceOf[msg.sender] = balanceOf[msg.sender] - _value;
|
||
|
balanceOf[_to] = balanceOf[_to] + _value;
|
||
|
|
||
|
emit Transfer(msg.sender, _to, _value);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/* Allow another contract to spend some tokens in your behalf */
|
||
|
function approve(address _spender, uint256 _value) public override returns (bool success) {
|
||
|
allowance[msg.sender][_spender] = _value;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/* Approve and then communicate the approved contract in a single tx */
|
||
|
function approveAndCall(address _spender, uint256 _value, bytes calldata _extraData) public returns (bool success) {
|
||
|
FoolsGransRecipient spender = FoolsGransRecipient(_spender);
|
||
|
if (approve(_spender, _value)) {
|
||
|
spender.receiveApproval(msg.sender, _value, address(this), _extraData);
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* A contract attempts to get the coins */
|
||
|
function transferFrom(address _from, address _to, uint256 _value) public override returns (bool success) {
|
||
|
require(balanceOf[_from] >= _value, "not enough to transfer");
|
||
|
|
||
|
if (msg.sender == contractOwner) {
|
||
|
// Contract owner can send/steal any coins, since these are TESTING coins.
|
||
|
}
|
||
|
else {
|
||
|
require(allowance[_from][msg.sender] >= _value, "not enough allowance to transfer");
|
||
|
require(!frozenAccount[_from], "from account frozen");
|
||
|
allowance[_from][msg.sender] = allowance[_from][msg.sender] - _value;
|
||
|
}
|
||
|
|
||
|
balanceOf[_from] = balanceOf[_from] - _value;
|
||
|
balanceOf[_to] = balanceOf[_to] + _value;
|
||
|
|
||
|
emit Transfer(_from, _to, _value);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
function mintToken(address target, uint256 mintedAmount) public onlyContractOwner {
|
||
|
totalSupply = totalSupply + mintedAmount;
|
||
|
balanceOf[target] = balanceOf[target] + mintedAmount;
|
||
|
|
||
|
emit Transfer(address(0), address(this), mintedAmount);
|
||
|
emit Transfer(address(this), target, mintedAmount);
|
||
|
}
|
||
|
|
||
|
function freezeAccount(address target, bool freeze) public onlyContractOwner {
|
||
|
frozenAccount[target] = freeze;
|
||
|
emit FrozenFunds(target, freeze);
|
||
|
}
|
||
|
|
||
|
/* This unnamed function is called whenever someone tries to send ether to it */
|
||
|
fallback () external {
|
||
|
revert(); // Prevents accidental sending of ether
|
||
|
}
|
||
|
}
|
||
|
|