However when the time is up or the funding goal is reached I can keep sending funds to the contract and create new tokens isas if the conditions i coded didn't matter.
However when the time is up or the funding goal is reached I can keep sending funds to the contract and create new tokens is if the conditions i coded didn't matter.
However when the time is up or the funding goal is reached I can keep sending funds to the contract and create new tokens as if the conditions i coded didn't matter.
pragma solidity ^0.4.11;
import './IERC20.sol'; import './SafeMath.sol';
contract TestToken4 is IERC20 {
import './IERC20.sol';
import './SafeMath.sol';
contract TestToken4 is IERC20 {
using SafeMath for uint256;
uint public _totalSupply = 0;
uint public fundingGoal;
uint public deadline;
uint public amountRaised = 0;
string public constant symbol = "TST4";
string public constant name = "TestToken4";
uint8 public constant decimals = 18;
bool isEnabled;
bool GoalReached = false;
bool TokenSaleEnded = false;
// 1 ether = 2000 tst3
uint256 public RATE = 2000;
address public owner;
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) allowed;
modifier isOwner() {
require(msg.sender == owner);
_;
}
function toggle() isOwner {
isEnabled = !isEnabled;
}
function () payable {
createTokens();
}
function TestToken4() {
owner = msg.sender;
}
function createTokens() payable {
require(
msg.value > 0
&& isEnabled
&& !GoalReached
&& !TokenSaleEnded);
uint256 tokens = msg.value.mul(RATE);
balances[msg.sender] = balances[msg.sender].add(tokens);
_totalSupply = _totalSupply.add(tokens);
amountRaised = amountRaised.add(msg.value);
owner.transfer(msg.value);
}
function setCrowdsale (
uint fundingGoalInEthers,
uint durationInMinutes,
uint tokensPerEth
) isOwner {
fundingGoal = fundingGoalInEthers.mul(1 ether);
deadline = now + durationInMinutes * 1 minutes;
RATE = tokensPerEth;
}
function checkGoalReached() {
if (amountRaised >= fundingGoal) {
GoalReached = true;
}
if (now >= deadline) {
TokenSaleEnded = true;
}
else {
GoalReached = false;
TokenSaleEnded = false;
}
}
function totalSupply () constant returns (uint256 totalSupply) {
return _totalSupply;
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances [_owner];
}
function transfer(address _to, uint256 _value) returns (bool success) {
require(
balances[msg.sender] >= _value
&& _value > 0
);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
require(
allowed[_from][msg.sender] >= _value
&& balances[_from] >= _value
&& _value > 0
);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
function burn(uint256 _value) isOwner returns (bool success) {
require(
balances[msg.sender] >= _value
&& _value > 0
);
balances[msg.sender] = balances[msg.sender].sub(_value);
_totalSupply = _totalSupply.sub(_value);
Burn (msg.sender, _value);
return true;
}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
event Burn(address indexed from, uint256 value);
}
}
pragma solidity ^0.4.11;
import './IERC20.sol'; import './SafeMath.sol';
contract TestToken4 is IERC20 {
using SafeMath for uint256;
uint public _totalSupply = 0;
uint public fundingGoal;
uint public deadline;
uint public amountRaised = 0;
string public constant symbol = "TST4";
string public constant name = "TestToken4";
uint8 public constant decimals = 18;
bool isEnabled;
bool GoalReached = false;
bool TokenSaleEnded = false;
// 1 ether = 2000 tst3
uint256 public RATE = 2000;
address public owner;
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) allowed;
modifier isOwner() {
require(msg.sender == owner);
_;
}
function toggle() isOwner {
isEnabled = !isEnabled;
}
function () payable {
createTokens();
}
function TestToken4() {
owner = msg.sender;
}
function createTokens() payable {
require(
msg.value > 0
&& isEnabled
&& !GoalReached
&& !TokenSaleEnded);
uint256 tokens = msg.value.mul(RATE);
balances[msg.sender] = balances[msg.sender].add(tokens);
_totalSupply = _totalSupply.add(tokens);
amountRaised = amountRaised.add(msg.value);
owner.transfer(msg.value);
}
function setCrowdsale (
uint fundingGoalInEthers,
uint durationInMinutes,
uint tokensPerEth
) isOwner {
fundingGoal = fundingGoalInEthers.mul(1 ether);
deadline = now + durationInMinutes * 1 minutes;
RATE = tokensPerEth;
}
function checkGoalReached() {
if (amountRaised >= fundingGoal) {
GoalReached = true;
}
if (now >= deadline) {
TokenSaleEnded = true;
}
else {
GoalReached = false;
TokenSaleEnded = false;
}
}
function totalSupply () constant returns (uint256 totalSupply) {
return _totalSupply;
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances [_owner];
}
function transfer(address _to, uint256 _value) returns (bool success) {
require(
balances[msg.sender] >= _value
&& _value > 0
);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
require(
allowed[_from][msg.sender] >= _value
&& balances[_from] >= _value
&& _value > 0
);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
function burn(uint256 _value) isOwner returns (bool success) {
require(
balances[msg.sender] >= _value
&& _value > 0
);
balances[msg.sender] = balances[msg.sender].sub(_value);
_totalSupply = _totalSupply.sub(_value);
Burn (msg.sender, _value);
return true;
}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
event Burn(address indexed from, uint256 value);
}
pragma solidity ^0.4.11;
import './IERC20.sol';
import './SafeMath.sol';
contract TestToken4 is IERC20 {
using SafeMath for uint256;
uint public _totalSupply = 0;
uint public fundingGoal;
uint public deadline;
uint public amountRaised = 0;
string public constant symbol = "TST4";
string public constant name = "TestToken4";
uint8 public constant decimals = 18;
bool isEnabled;
bool GoalReached = false;
bool TokenSaleEnded = false;
// 1 ether = 2000 tst3
uint256 public RATE = 2000;
address public owner;
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) allowed;
modifier isOwner() {
require(msg.sender == owner);
_;
}
function toggle() isOwner {
isEnabled = !isEnabled;
}
function () payable {
createTokens();
}
function TestToken4() {
owner = msg.sender;
}
function createTokens() payable {
require(
msg.value > 0
&& isEnabled
&& !GoalReached
&& !TokenSaleEnded);
uint256 tokens = msg.value.mul(RATE);
balances[msg.sender] = balances[msg.sender].add(tokens);
_totalSupply = _totalSupply.add(tokens);
amountRaised = amountRaised.add(msg.value);
owner.transfer(msg.value);
}
function setCrowdsale (
uint fundingGoalInEthers,
uint durationInMinutes,
uint tokensPerEth
) isOwner {
fundingGoal = fundingGoalInEthers.mul(1 ether);
deadline = now + durationInMinutes * 1 minutes;
RATE = tokensPerEth;
}
function checkGoalReached() {
if (amountRaised >= fundingGoal) {
GoalReached = true;
}
if (now >= deadline) {
TokenSaleEnded = true;
}
else {
GoalReached = false;
TokenSaleEnded = false;
}
}
function totalSupply () constant returns (uint256 totalSupply) {
return _totalSupply;
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances [_owner];
}
function transfer(address _to, uint256 _value) returns (bool success) {
require(
balances[msg.sender] >= _value
&& _value > 0
);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
require(
allowed[_from][msg.sender] >= _value
&& balances[_from] >= _value
&& _value > 0
);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
function burn(uint256 _value) isOwner returns (bool success) {
require(
balances[msg.sender] >= _value
&& _value > 0
);
balances[msg.sender] = balances[msg.sender].sub(_value);
_totalSupply = _totalSupply.sub(_value);
Burn (msg.sender, _value);
return true;
}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
event Burn(address indexed from, uint256 value);
}
Crowdsale not stoping
I'm trying to create a token sale for a colection. The idea is to restart the crowdsale everytime we grow funds to amplify the collection, the tokens are burnable to purchase items from the colection. The sales should have a funding cap and a time cap.
However when the time is up or the funding goal is reached I can keep sending funds to the contract and create new tokens is if the conditions i coded didn't matter.
Here's my code :
pragma solidity ^0.4.11;
import './IERC20.sol'; import './SafeMath.sol';
contract TestToken4 is IERC20 {
using SafeMath for uint256;
uint public _totalSupply = 0;
uint public fundingGoal;
uint public deadline;
uint public amountRaised = 0;
string public constant symbol = "TST4";
string public constant name = "TestToken4";
uint8 public constant decimals = 18;
bool isEnabled;
bool GoalReached = false;
bool TokenSaleEnded = false;
// 1 ether = 2000 tst3
uint256 public RATE = 2000;
address public owner;
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) allowed;
modifier isOwner() {
require(msg.sender == owner);
_;
}
function toggle() isOwner {
isEnabled = !isEnabled;
}
function () payable {
createTokens();
}
function TestToken4() {
owner = msg.sender;
}
function createTokens() payable {
require(
msg.value > 0
&& isEnabled
&& !GoalReached
&& !TokenSaleEnded);
uint256 tokens = msg.value.mul(RATE);
balances[msg.sender] = balances[msg.sender].add(tokens);
_totalSupply = _totalSupply.add(tokens);
amountRaised = amountRaised.add(msg.value);
owner.transfer(msg.value);
}
function setCrowdsale (
uint fundingGoalInEthers,
uint durationInMinutes,
uint tokensPerEth
) isOwner {
fundingGoal = fundingGoalInEthers.mul(1 ether);
deadline = now + durationInMinutes * 1 minutes;
RATE = tokensPerEth;
}
function checkGoalReached() {
if (amountRaised >= fundingGoal) {
GoalReached = true;
}
if (now >= deadline) {
TokenSaleEnded = true;
}
else {
GoalReached = false;
TokenSaleEnded = false;
}
}
function totalSupply () constant returns (uint256 totalSupply) {
return _totalSupply;
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances [_owner];
}
function transfer(address _to, uint256 _value) returns (bool success) {
require(
balances[msg.sender] >= _value
&& _value > 0
);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
require(
allowed[_from][msg.sender] >= _value
&& balances[_from] >= _value
&& _value > 0
);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
function burn(uint256 _value) isOwner returns (bool success) {
require(
balances[msg.sender] >= _value
&& _value > 0
);
balances[msg.sender] = balances[msg.sender].sub(_value);
_totalSupply = _totalSupply.sub(_value);
Burn (msg.sender, _value);
return true;
}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
event Burn(address indexed from, uint256 value);
}