Created
June 13, 2018 19:49
-
-
Save spidertwin2/84430847bb479d660bb21d7daafa46ed 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
pragma solidity ^0.4.18; | |
contract Ownable { | |
address owner; | |
modifier onlyOwner { | |
require (owner == msg.sender); | |
_; | |
} | |
constructor() public { | |
owner = msg.sender; | |
} | |
function transferOwnership (address input) onlyOwner { | |
owner = input; | |
} | |
} | |
contract Token is Ownable { | |
string public name; | |
string public symbol; | |
uint8 public decimals; | |
uint256 public totalSupply; | |
address public mintController; | |
mapping (address=>uint256) balances; | |
event MintEvent (address adr, uint256 amt); | |
event TransferEvent (address adr, address adr2, uint amt); | |
modifier onlyMintController { | |
require (mintController == msg.sender); | |
_; | |
} | |
constructor (string nameParam, string symbolParam, uint8 decimalsParam, | |
uint256 totalSupplyParam, address mintControllerParam) { | |
name = nameParam; | |
symbol = symbolParam; | |
decimals = decimalsParam; | |
totalSupply = totalSupplyParam; | |
mintController = mintControllerParam; | |
balances[msg.sender] = totalSupply; | |
} | |
function mintFunction (address inputAddr, uint256 inputAmount) onlyMintController { | |
balances[inputAddr] += inputAmount; | |
MintEvent(inputAddr, inputAmount); | |
} | |
function changeMinter (address newAddr) onlyOwner { | |
mintController = newAddr; | |
} | |
function transfer (address transferTo, uint256 sendAmount) { | |
require (balances[msg.sender] >= sendAmount); | |
balances[msg.sender] -= sendAmount; | |
balances[transferTo] += sendAmount; | |
TransferEvent(msg.sender, transferTo, sendAmount); | |
} | |
function () payable { | |
int x = 2; | |
require(x == 1); | |
} | |
} | |
contract Sale { | |
address public beneficiary; | |
uint public fundingGoal; | |
uint public deadline; | |
uint public pricePerToken; | |
Token token; | |
mapping(address=>uint256) contributions; | |
uint public amountRaised; | |
bool public fundingGoalReached; | |
bool public crowdsaleClosed; | |
modifier afterDeadline { | |
require(now > deadline); | |
_; | |
} | |
constructor (address inputBeneficiary, uint inputFundingGoal, uint durationInMinutes, | |
uint inputEtherCostPerToken, address inputTokenAddress) { | |
beneficiary = inputBeneficiary; | |
fundingGoal = inputFundingGoal * 1 ether; | |
deadline = now + (durationInMinutes * 1 minutes); | |
pricePerToken = inputEtherCostPerToken * 1 ether; | |
token = Token (inputTokenAddress); | |
} | |
function () payable { | |
throw; | |
} | |
function participate () payable { | |
if (crowdsaleClosed == true) { | |
throw; | |
} | |
else { | |
amountRaised += msg.value; | |
contributions[msg.sender] += msg.value; | |
uint x = msg.value/pricePerToken; | |
token.mintFunction(msg.sender, x); | |
} | |
} | |
function checkGoalReached () public afterDeadline { | |
crowdsaleClosed = true; | |
if (amountRaised > fundingGoal) { | |
fundingGoalReached = true; | |
} | |
} | |
function withdraw () afterDeadline { | |
if (crowdsaleClosed != true) { | |
throw; | |
} | |
if (fundingGoalReached != true) { | |
address target = msg.sender; | |
require (contributions[msg.sender] > 0); | |
revert('withdraw invalid'); | |
contributions[msg.sender] = 0; | |
target.send(contributions[msg.sender]); | |
} | |
else { | |
beneficiary.send(amountRaised); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment