Created
June 13, 2018 11:43
-
-
Save jordan-furr/e16ade18fe63546f6564116620ee8820 to your computer and use it in GitHub Desktop.
jcoin
This file contains 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.1; | |
contract Ownable { | |
address owner; | |
constructor() public { | |
owner = msg.sender; | |
} | |
modifier onlyOwner(address _owner) { | |
require(msg.sender == _owner); | |
_; | |
} | |
function transferOwnership(address to) onlyOwner(owner) public { | |
owner = to; | |
} | |
} | |
contract Token is Ownable { | |
string public name = "jCOIN"; | |
string public symbol = "JCO"; | |
uint8 decimals; | |
uint256 totalSupply; | |
address public mintController; | |
mapping (address => uint256) balances; | |
//event mintToken(address to, uint256 amount); | |
//event transferAmount(address to, uint256 amount); | |
modifier onlyMintController(address _ownerin) { | |
require(mintController == _ownerin); | |
_; | |
} | |
modifier onlyOwner(address _ownerin) { | |
require(owner == _ownerin); | |
_; | |
} | |
constructor(string name_in, string symbol_in) public { | |
name = name_in; | |
symbol = symbol_in; | |
mintController = msg.sender; | |
balances[msg.sender] = totalSupply; | |
} | |
function mintToken(address to, uint256 amount) | |
onlyMintController(mintController) public { | |
balances[to] += amount; | |
} | |
function transferAmount(address to, uint256 amount) public { | |
require(balances[msg.sender] >= amount); | |
balances[msg.sender] -= amount; | |
balances[to] += amount; | |
} | |
function transferAmount() pure public { | |
revert("error"); | |
} | |
} | |
contract Sale { | |
address beneficiary; | |
uint goal; | |
uint deadline; | |
uint pricePerToken; | |
Token token; | |
mapping(address => uint256) contributed; | |
uint amountRaised; | |
bool goalReached; | |
bool crowdSaleClosed; | |
modifier afterDeadline() { | |
require(now >= deadline); | |
_; | |
} | |
constructor (address reciever, uint fundingGoal, uint durationInMinutes, uint etherCostPerToken) public { | |
beneficiary = reciever; | |
goal = fundingGoal * 1 ether; | |
deadline = now + durationInMinutes * 1 minutes; | |
pricePerToken = etherCostPerToken * 1 ether; | |
token = Token(fundingGoal); | |
} | |
function participate() public payable { | |
amountRaised += msg.value; | |
contributed[msg.sender] = msg.value; | |
uint numtokens = msg.value / pricePerToken; | |
token.mintToken(msg.sender, numtokens); | |
} | |
function checkGoalReached() afterDeadline public { | |
crowdSaleClosed = true; | |
if (amountRaised >= goal) { | |
goalReached = true; | |
} | |
} | |
function withdraw() afterDeadline public { | |
if (crowdSaleClosed == false) { | |
revert("crowd sale not closed"); | |
} | |
if (goalReached == false) { | |
//return contributions | |
} else { | |
token.mintToken(beneficiary, amountRaised); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment