Created
October 19, 2018 05:15
-
-
Save rohitsethii/aef1c2e0a8324834f2c479bed87adca8 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=true&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 view 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.7; | |
import "remix_tests.sol"; // this import is automatically injected by Remix. | |
import "./ballot.sol"; | |
contract test3 { | |
Ballot ballotToTest; | |
function beforeAll () { | |
ballotToTest = new Ballot(2); | |
} | |
function checkWinningProposal () public { | |
ballotToTest.vote(1); | |
Assert.equal(ballotToTest.winningProposal(), uint(1), "1 should be the winning proposal"); | |
} | |
function checkWinninProposalWithReturnValue () public constant returns (bool) { | |
return ballotToTest.winningProposal() == 1; | |
} | |
} |
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; | |
import "./TokenERC20.sol"; | |
import "./SafeMath.sol"; | |
contract Booking { | |
uint bookingId; | |
address propertyOwner; | |
address user; | |
address admin; | |
uint amount; | |
uint bookingStartTime; | |
using SafeMath for *; | |
bool bookingActive; | |
bool bookingCancel; | |
address tokenAddress; | |
TokenERC20 token; | |
event Book( uint _bookingId, | |
address _propertyOwner, | |
address _user, | |
address _admin, | |
uint _amount, | |
uint _bookingStartTime); | |
// 1,"0xca35b7d915458ef540ade6068dfe2f44e8fa733c","0x14723a09acff6d2a60dcdf7aa4aff308fddc160c","0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db",50, | |
constructor(uint _bookingId, | |
address _propertyOwner, | |
address _user, | |
address _admin, | |
uint _amount, | |
uint _bookingStartTime, | |
address _tokenAddr | |
) public { | |
bookingId = _bookingId; | |
propertyOwner = _propertyOwner; | |
user = _user; | |
admin = _admin; | |
amount = _amount; | |
bookingStartTime = _bookingStartTime; | |
tokenAddress = _tokenAddr; | |
token = TokenERC20(tokenAddress); | |
emit Book( _bookingId,_propertyOwner,_user,_admin,_amount,_bookingStartTime); | |
} | |
function releaseToken() public { | |
require((msg.sender == propertyOwner || msg.sender == admin ) && now > bookingStartTime + 24 hours,"only propertyOwner or admin can releaseToken after 24 hours of bookingStartTime "); | |
uint adminFees = amount.div(20); | |
uint propertyOwnerFees = amount.mul(95).div(100); | |
require(token.transfer(admin,adminFees),"adminFees transfer failed"); | |
require(token.transfer(propertyOwner,propertyOwnerFees),"propertyOwnerFees transfer failed"); | |
} | |
function cancelBooking() public { | |
require(msg.sender == admin || (msg.sender == user && now < bookingStartTime - 24 hours),"cannot cancel Booking now"); | |
require(token.transfer(user,amount),"refund failed"); | |
} | |
function receiveApproval(address from, uint256 value, address _token, bytes extraData) public { | |
require(token == tokenAddress,"token address do not match"); | |
require(token.transferFrom(from,this,value),"token transfer to contract failed "); | |
} | |
function getTokenBalance() public view returns (uint) { | |
return token.balanceOf(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.24; | |
//pragma solidity ^0.4.24; | |
//import "./TokenERC20.sol"; | |
import "./SafeMath.sol"; | |
/** | |
* @title ERC20 interface | |
* @dev see https://github.com/ethereum/EIPs/issues/20 | |
*/ | |
contract IERC20 { | |
function totalSupply() external view returns (uint256); | |
function balanceOf(address who) external view returns (uint256); | |
function allowance(address owner, address spender) | |
external view returns (uint256); | |
function transfer(address to, uint256 value) external returns (bool); | |
function approve(address spender, uint256 value) | |
external returns (bool); | |
function transferFrom(address from, address to, uint256 value) | |
external returns (bool); | |
event Transfer( | |
address indexed from, | |
address indexed to, | |
uint256 value | |
); | |
event Approval( | |
address indexed owner, | |
address indexed spender, | |
uint256 value | |
); | |
} | |
contract Booking { | |
uint bookingId; | |
address propertyOwner; | |
address user; | |
address admin; | |
uint amount; | |
uint bookingStartTime; | |
using SafeMath for *; | |
address tokenAddress; | |
IERC20 token; | |
// 1,"0xca35b7d915458ef540ade6068dfe2f44e8fa733c","0x14723a09acff6d2a60dcdf7aa4aff308fddc160c","0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db",50, | |
constructor(uint _bookingId, | |
address _propertyOwner, | |
address _user, | |
address _admin, | |
uint _amount, | |
uint _bookingStartTime, | |
address _tokenAddr | |
) public { | |
bookingId = _bookingId; | |
propertyOwner = _propertyOwner; | |
user = _user; | |
admin = _admin; | |
amount = _amount; | |
bookingStartTime = _bookingStartTime; | |
tokenAddress = _tokenAddr; | |
token = IERC20(tokenAddress); | |
} | |
function releaseToken() public { | |
require(msg.sender == propertyOwner && now > bookingStartTime + 24 hours,"only propertyOwner can releaseToken after 24 hours of bookingStartTime "); | |
uint adminFees = amount.div(20); | |
uint propertyOwnerFees = amount.mul(95).div(100); | |
require(token.transfer(admin,adminFees),"adminFees transfer failed"); | |
require(token.transfer(propertyOwner,propertyOwnerFees),"propertyOwnerFees transfer failed"); | |
} | |
function cancelBooking() public { | |
require(msg.sender == admin || (msg.sender == user && now < bookingStartTime - 24 hours),"cannot cancel Booking now"); | |
require(token.transfer(user,amount),"refund failed"); | |
} | |
// function receiveApproval(address from, uint256 value, address _token, bytes extraData) public { | |
// require(token == tokenAddress,"token address do not match"); | |
// require(token.transferFrom(from,this,value),"token transfer to contract failed "); | |
// } | |
function getTokenBalance() public view returns (uint) { | |
return token.balanceOf(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.24; | |
import "./IERC20.sol"; | |
import "./SafeMath.sol"; | |
/** | |
* @title Standard ERC20 token | |
* | |
* @dev Implementation of the basic standard token. | |
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md | |
* Originally based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol | |
*/ | |
contract ERC20 is IERC20 { | |
using SafeMath for uint256; | |
mapping (address => uint256) private _balances; | |
mapping (address => mapping (address => uint256)) private _allowed; | |
uint256 private _totalSupply; | |
/** | |
* @dev Total number of tokens in existence | |
*/ | |
function totalSupply() public view returns (uint256) { | |
return _totalSupply; | |
} | |
/** | |
* @dev Gets the balance of the specified address. | |
* @param owner The address to query the balance of. | |
* @return An uint256 representing the amount owned by the passed address. | |
*/ | |
function balanceOf(address owner) public view returns (uint256) { | |
return _balances[owner]; | |
} | |
/** | |
* @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 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) { | |
_transfer(msg.sender, 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) { | |
require(spender != address(0)); | |
_allowed[msg.sender][spender] = value; | |
emit Approval(msg.sender, spender, value); | |
return true; | |
} | |
/** | |
* @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(value <= _allowed[from][msg.sender]); | |
_allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value); | |
_transfer(from, to, value); | |
return true; | |
} | |
/** | |
* @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 increaseAllowance( | |
address spender, | |
uint256 addedValue | |
) | |
public | |
returns (bool) | |
{ | |
require(spender != address(0)); | |
_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 decreaseAllowance( | |
address spender, | |
uint256 subtractedValue | |
) | |
public | |
returns (bool) | |
{ | |
require(spender != address(0)); | |
_allowed[msg.sender][spender] = ( | |
_allowed[msg.sender][spender].sub(subtractedValue)); | |
emit Approval(msg.sender, spender, _allowed[msg.sender][spender]); | |
return true; | |
} | |
/** | |
* @dev Transfer token for a specified addresses | |
* @param from The address to transfer from. | |
* @param to The address to transfer to. | |
* @param value The amount to be transferred. | |
*/ | |
function _transfer(address from, address to, uint256 value) internal { | |
require(value <= _balances[from]); | |
require(to != address(0)); | |
_balances[from] = _balances[from].sub(value); | |
_balances[to] = _balances[to].add(value); | |
emit Transfer(from, to, value); | |
} | |
/** | |
* @dev Internal function that mints an amount of the token and assigns it to | |
* an account. This encapsulates the modification of balances such that the | |
* proper events are emitted. | |
* @param account The account that will receive the created tokens. | |
* @param value The amount that will be created. | |
*/ | |
function _mint(address account, uint256 value) internal { | |
require(account != 0); | |
_totalSupply = _totalSupply.add(value); | |
_balances[account] = _balances[account].add(value); | |
emit Transfer(address(0), account, value); | |
} | |
/** | |
* @dev Internal function that burns an amount of the token of a given | |
* account. | |
* @param account The account whose tokens will be burnt. | |
* @param value The amount that will be burnt. | |
*/ | |
function _burn(address account, uint256 value) internal { | |
require(account != 0); | |
require(value <= _balances[account]); | |
_totalSupply = _totalSupply.sub(value); | |
_balances[account] = _balances[account].sub(value); | |
emit Transfer(account, address(0), value); | |
} | |
/** | |
* @dev Internal function that burns an amount of the token of a given | |
* account, deducting from the sender's allowance for said account. Uses the | |
* internal burn function. | |
* @param account The account whose tokens will be burnt. | |
* @param value The amount that will be burnt. | |
*/ | |
function _burnFrom(address account, uint256 value) internal { | |
require(value <= _allowed[account][msg.sender]); | |
// Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted, | |
// this function needs to emit an event with the updated approval. | |
_allowed[account][msg.sender] = _allowed[account][msg.sender].sub( | |
value); | |
_burn(account, 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.24; | |
import "./ERC20.sol"; | |
/** | |
* @title Burnable Token | |
* @dev Token that can be irreversibly burned (destroyed). | |
*/ | |
contract ERC20Burnable is ERC20 { | |
/** | |
* @dev Burns a specific amount of tokens. | |
* @param value The amount of token to be burned. | |
*/ | |
function burn(uint256 value) public { | |
_burn(msg.sender, value); | |
} | |
/** | |
* @dev Burns a specific amount of tokens from the target address and decrements allowance | |
* @param from address The address which you want to send tokens from | |
* @param value uint256 The amount of token to be burned | |
*/ | |
function burnFrom(address from, uint256 value) public { | |
_burnFrom(from, 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.24; | |
import "./ERC20Mintable.sol"; | |
/** | |
* @title Capped token | |
* @dev Mintable token with a token cap. | |
*/ | |
contract ERC20Capped is ERC20Mintable { | |
uint256 private _cap; | |
constructor(uint256 cap) | |
public | |
{ | |
require(cap > 0); | |
_cap = cap; | |
} | |
/** | |
* @return the cap for the token minting. | |
*/ | |
function cap() public view returns(uint256) { | |
return _cap; | |
} | |
/** | |
* @dev Function to mint tokens | |
* @param to The address that will receive the minted tokens. | |
* @param value The amount of tokens to mint. | |
* @return A boolean that indicates if the operation was successful. | |
*/ | |
function mint( | |
address to, | |
uint256 value | |
) | |
public | |
returns (bool) | |
{ | |
require(totalSupply().add(value) <= _cap); | |
return super.mint(to, 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.24; | |
import "./IERC20.sol"; | |
/** | |
* @title ERC20Detailed token | |
* @dev The decimals are only for visualization purposes. | |
* All the operations are done using the smallest and indivisible token unit, | |
* just as on Ethereum all the operations are done in wei. | |
*/ | |
contract ERC20Detailed is IERC20 { | |
string private _name; | |
string private _symbol; | |
uint8 private _decimals; | |
constructor(string name, string symbol, uint8 decimals) public { | |
_name = name; | |
_symbol = symbol; | |
_decimals = decimals; | |
} | |
/** | |
* @return the name of the token. | |
*/ | |
function name() public view returns(string) { | |
return _name; | |
} | |
/** | |
* @return the symbol of the token. | |
*/ | |
function symbol() public view returns(string) { | |
return _symbol; | |
} | |
/** | |
* @return the number of decimals of the token. | |
*/ | |
function decimals() public view returns(uint8) { | |
return _decimals; | |
} | |
} |
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; | |
import "./ERC20.sol"; | |
import "../../access/roles/MinterRole.sol"; | |
/** | |
* @title ERC20Mintable | |
* @dev ERC20 minting logic | |
*/ | |
contract ERC20Mintable is ERC20, MinterRole { | |
/** | |
* @dev Function to mint tokens | |
* @param to The address that will receive the minted tokens. | |
* @param value The amount of tokens to mint. | |
* @return A boolean that indicates if the operation was successful. | |
*/ | |
function mint( | |
address to, | |
uint256 value | |
) | |
public | |
onlyMinter | |
returns (bool) | |
{ | |
_mint(to, value); | |
return true; | |
} | |
} |
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; | |
import "./ERC20.sol"; | |
import "../../lifecycle/Pausable.sol"; | |
/** | |
* @title Pausable token | |
* @dev ERC20 modified with pausable transfers. | |
**/ | |
contract ERC20Pausable is ERC20, Pausable { | |
function transfer( | |
address to, | |
uint256 value | |
) | |
public | |
whenNotPaused | |
returns (bool) | |
{ | |
return super.transfer(to, value); | |
} | |
function transferFrom( | |
address from, | |
address to, | |
uint256 value | |
) | |
public | |
whenNotPaused | |
returns (bool) | |
{ | |
return super.transferFrom(from, to, value); | |
} | |
function approve( | |
address spender, | |
uint256 value | |
) | |
public | |
whenNotPaused | |
returns (bool) | |
{ | |
return super.approve(spender, value); | |
} | |
function increaseAllowance( | |
address spender, | |
uint addedValue | |
) | |
public | |
whenNotPaused | |
returns (bool success) | |
{ | |
return super.increaseAllowance(spender, addedValue); | |
} | |
function decreaseAllowance( | |
address spender, | |
uint subtractedValue | |
) | |
public | |
whenNotPaused | |
returns (bool success) | |
{ | |
return super.decreaseAllowance(spender, subtractedValue); | |
} | |
} |
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; | |
/** | |
* @title ERC20 interface | |
* @dev see https://github.com/ethereum/EIPs/issues/20 | |
*/ | |
interface IERC20 { | |
function totalSupply() external view returns (uint256); | |
function balanceOf(address who) external view returns (uint256); | |
function allowance(address owner, address spender) | |
external view returns (uint256); | |
function transfer(address to, uint256 value) external returns (bool); | |
function approve(address spender, uint256 value) | |
external returns (bool); | |
function transferFrom(address from, address to, uint256 value) | |
external returns (bool); | |
event Transfer( | |
address indexed from, | |
address indexed to, | |
uint256 value | |
); | |
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.24; | |
import "./ERC20.sol"; | |
import "./IERC20.sol"; | |
/** | |
* @title SafeERC20 | |
* @dev Wrappers around ERC20 operations that throw on failure. | |
* To use this library you can add a `using SafeERC20 for ERC20;` statement to your contract, | |
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc. | |
*/ | |
library SafeERC20 { | |
function safeTransfer( | |
IERC20 token, | |
address to, | |
uint256 value | |
) | |
internal | |
{ | |
require(token.transfer(to, value)); | |
} | |
function safeTransferFrom( | |
IERC20 token, | |
address from, | |
address to, | |
uint256 value | |
) | |
internal | |
{ | |
require(token.transferFrom(from, to, value)); | |
} | |
function safeApprove( | |
IERC20 token, | |
address spender, | |
uint256 value | |
) | |
internal | |
{ | |
require(token.approve(spender, 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.24; | |
/** | |
* @title SafeMath | |
* @dev Math operations with safety checks that revert on error | |
*/ | |
library SafeMath { | |
/** | |
* @dev Multiplies two numbers, reverts on overflow. | |
*/ | |
function mul(uint256 a, uint256 b) internal pure returns (uint256) { | |
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the | |
// benefit is lost if 'b' is also tested. | |
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 | |
if (a == 0) { | |
return 0; | |
} | |
uint256 c = a * b; | |
require(c / a == b); | |
return c; | |
} | |
/** | |
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero. | |
*/ | |
function div(uint256 a, uint256 b) internal pure returns (uint256) { | |
require(b > 0); // Solidity only automatically asserts 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 Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend). | |
*/ | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
require(b <= a); | |
uint256 c = a - b; | |
return c; | |
} | |
/** | |
* @dev Adds two numbers, reverts on overflow. | |
*/ | |
function add(uint256 a, uint256 b) internal pure returns (uint256) { | |
uint256 c = a + b; | |
require(c >= a); | |
return c; | |
} | |
/** | |
* @dev Divides two numbers and returns the remainder (unsigned integer modulo), | |
* reverts when dividing by zero. | |
*/ | |
function mod(uint256 a, uint256 b) internal pure returns (uint256) { | |
require(b != 0); | |
return a % b; | |
} | |
} |
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
import "./SafeMath.sol"; | |
contract Time{ | |
using SafeMath for uint; | |
function getBookingStartTime() public returns(uint){ | |
uint a; | |
uint b =5; | |
a = b.div(2); | |
return a; | |
} | |
} |
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.16; | |
import "./Booking1.sol"; | |
contract TokenERC20 { | |
// Public variables of the token | |
string public name; | |
string public symbol; | |
uint8 public decimals = 18; | |
// 18 decimals is the strongly suggested default, avoid changing it | |
uint256 public totalSupply; | |
// This creates an array with all balances | |
mapping (address => uint256) public balanceOf; | |
mapping (address => mapping (address => uint256)) public allowance; | |
// This generates a public event on the blockchain that will notify clients | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
// This generates a public event on the blockchain that will notify clients | |
event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
// This notifies clients about the amount burnt | |
event Burn(address indexed from, uint256 value); | |
/** | |
* Constructor function | |
* | |
* Initializes contract with initial supply tokens to the creator of the contract | |
*/ | |
constructor ( | |
uint256 initialSupply, | |
string tokenName, | |
string tokenSymbol | |
) public { | |
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount | |
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens | |
name = tokenName; // Set the name for display purposes | |
symbol = tokenSymbol; // Set the symbol for display purposes | |
} | |
/** | |
* Internal transfer, only can be called by this contract | |
*/ | |
function _transfer(address _from, address _to, uint _value) internal { | |
// Prevent transfer to 0x0 address. Use burn() instead | |
require(_to != 0x0); | |
// Check if the sender has enough | |
require(balanceOf[_from] >= _value); | |
// Check for overflows | |
require(balanceOf[_to] + _value >= balanceOf[_to]); | |
// Save this for an assertion in the future | |
uint previousBalances = balanceOf[_from] + balanceOf[_to]; | |
// Subtract from the sender | |
balanceOf[_from] -= _value; | |
// Add the same to the recipient | |
balanceOf[_to] += _value; | |
emit Transfer(_from, _to, _value); | |
// Asserts are used to use static analysis to find bugs in your code. They should never fail | |
assert(balanceOf[_from] + balanceOf[_to] == previousBalances); | |
} | |
/** | |
* Transfer tokens | |
* | |
* Send `_value` tokens to `_to` from your account | |
* | |
* @param _to The address of the recipient | |
* @param _value the amount to send | |
*/ | |
function transfer(address _to, uint256 _value) public returns (bool success) { | |
_transfer(msg.sender, _to, _value); | |
return true; | |
} | |
/** | |
* Transfer tokens from other address | |
* | |
* Send `_value` tokens to `_to` on behalf of `_from` | |
* | |
* @param _from The address of the sender | |
* @param _to The address of the recipient | |
* @param _value the amount to send | |
*/ | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { | |
require(_value <= allowance[_from][msg.sender]); // Check allowance | |
allowance[_from][msg.sender] -= _value; | |
_transfer(_from, _to, _value); | |
return true; | |
} | |
/** | |
* Set allowance for other address | |
* | |
* Allows `_spender` to spend no more than `_value` tokens on your behalf | |
* | |
* @param _spender The address authorized to spend | |
* @param _value the max amount they can spend | |
*/ | |
function approve(address _spender, uint256 _value) public | |
returns (bool success) { | |
allowance[msg.sender][_spender] = _value; | |
emit Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
/** | |
* Set allowance for other address and notify | |
* | |
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it | |
* | |
* @param _spender The address authorized to spend | |
* @param _value the max amount they can spend | |
* @param _extraData some extra information to send to the approved contract | |
*/ | |
// function approveAndCall(address _spender, uint256 _value, bytes _extraData) | |
// public | |
// returns (bool success) { | |
// tokenRecipient spender = tokenRecipient(_spender); | |
// if (approve(_spender, _value)) { | |
// spender.receiveApproval(msg.sender, _value, this, _extraData); | |
// return true; | |
// } | |
// } | |
/** | |
* Destroy tokens | |
* | |
* Remove `_value` tokens from the system irreversibly | |
* | |
* @param _value the amount of money to burn | |
*/ | |
function burn(uint256 _value) public returns (bool success) { | |
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough | |
balanceOf[msg.sender] -= _value; // Subtract from the sender | |
totalSupply -= _value; // Updates totalSupply | |
emit Burn(msg.sender, _value); | |
return true; | |
} | |
/** | |
* Destroy tokens from other account | |
* | |
* Remove `_value` tokens from the system irreversibly on behalf of `_from`. | |
* | |
* @param _from the address of the sender | |
* @param _value the amount of money to burn | |
*/ | |
function burnFrom(address _from, uint256 _value) public returns (bool success) { | |
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough | |
require(_value <= allowance[_from][msg.sender]); // Check allowance | |
balanceOf[_from] -= _value; // Subtract from the targeted balance | |
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance | |
totalSupply -= _value; // Update totalSupply | |
emit Burn(_from, _value); | |
return true; | |
} | |
function CreateAndSendTokenToBookingContract( | |
uint _bookingId, | |
address _propertyOwner, | |
address _user, | |
address _admin, | |
uint _amount, | |
uint _bookingStartTime, | |
address _tokenAddr) public returns (address _book) { | |
Booking book = new Booking(_bookingId, | |
_propertyOwner, | |
_user, | |
_admin, | |
_amount, | |
_bookingStartTime, | |
_tokenAddr | |
); | |
require(transfer(book,5),"Token Transfer failed"); | |
return book; | |
} | |
} | |
contract A{ | |
function a() public view returns (uint) { | |
return now + 25 hours; | |
} | |
} |
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.16; | |
import "./Booking1.sol"; | |
interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; } | |
contract TokenERC20 { | |
// Public variables of the token | |
string public name; | |
string public symbol; | |
uint8 public decimals = 18; | |
// 18 decimals is the strongly suggested default, avoid changing it | |
uint256 public totalSupply; | |
// This creates an array with all balances | |
mapping (address => uint256) public balanceOf; | |
mapping (address => mapping (address => uint256)) public allowance; | |
// This generates a public event on the blockchain that will notify clients | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
// This generates a public event on the blockchain that will notify clients | |
event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
// This notifies clients about the amount burnt | |
event Burn(address indexed from, uint256 value); | |
/** | |
* Constructor function | |
* | |
* Initializes contract with initial supply tokens to the creator of the contract | |
*/ | |
function TokenERC20( | |
uint256 initialSupply, | |
string tokenName, | |
string tokenSymbol | |
) public { | |
totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount | |
balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens | |
name = tokenName; // Set the name for display purposes | |
symbol = tokenSymbol; // Set the symbol for display purposes | |
} | |
/** | |
* Internal transfer, only can be called by this contract | |
*/ | |
function _transfer(address _from, address _to, uint _value) internal { | |
// Prevent transfer to 0x0 address. Use burn() instead | |
require(_to != 0x0); | |
// Check if the sender has enough | |
require(balanceOf[_from] >= _value); | |
// Check for overflows | |
require(balanceOf[_to] + _value >= balanceOf[_to]); | |
// Save this for an assertion in the future | |
uint previousBalances = balanceOf[_from] + balanceOf[_to]; | |
// Subtract from the sender | |
balanceOf[_from] -= _value; | |
// Add the same to the recipient | |
balanceOf[_to] += _value; | |
emit Transfer(_from, _to, _value); | |
// Asserts are used to use static analysis to find bugs in your code. They should never fail | |
assert(balanceOf[_from] + balanceOf[_to] == previousBalances); | |
} | |
/** | |
* Transfer tokens | |
* | |
* Send `_value` tokens to `_to` from your account | |
* | |
* @param _to The address of the recipient | |
* @param _value the amount to send | |
*/ | |
function transfer(address _to, uint256 _value) public returns (bool success) { | |
_transfer(msg.sender, _to, _value); | |
return true; | |
} | |
/** | |
* Transfer tokens from other address | |
* | |
* Send `_value` tokens to `_to` on behalf of `_from` | |
* | |
* @param _from The address of the sender | |
* @param _to The address of the recipient | |
* @param _value the amount to send | |
*/ | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { | |
require(_value <= allowance[_from][msg.sender]); // Check allowance | |
allowance[_from][msg.sender] -= _value; | |
_transfer(_from, _to, _value); | |
return true; | |
} | |
/** | |
* Set allowance for other address | |
* | |
* Allows `_spender` to spend no more than `_value` tokens on your behalf | |
* | |
* @param _spender The address authorized to spend | |
* @param _value the max amount they can spend | |
*/ | |
function approve(address _spender, uint256 _value) public | |
returns (bool success) { | |
allowance[msg.sender][_spender] = _value; | |
emit Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
/** | |
* Set allowance for other address and notify | |
* | |
* Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it | |
* | |
* @param _spender The address authorized to spend | |
* @param _value the max amount they can spend | |
* @param _extraData some extra information to send to the approved contract | |
*/ | |
function approveAndCall(address _spender, uint256 _value, bytes _extraData) | |
public | |
returns (bool success) { | |
tokenRecipient spender = tokenRecipient(_spender); | |
if (approve(_spender, _value)) { | |
spender.receiveApproval(msg.sender, _value, this, _extraData); | |
return true; | |
} | |
} | |
/** | |
* Destroy tokens | |
* | |
* Remove `_value` tokens from the system irreversibly | |
* | |
* @param _value the amount of money to burn | |
*/ | |
function burn(uint256 _value) public returns (bool success) { | |
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough | |
balanceOf[msg.sender] -= _value; // Subtract from the sender | |
totalSupply -= _value; // Updates totalSupply | |
emit Burn(msg.sender, _value); | |
return true; | |
} | |
/** | |
* Destroy tokens from other account | |
* | |
* Remove `_value` tokens from the system irreversibly on behalf of `_from`. | |
* | |
* @param _from the address of the sender | |
* @param _value the amount of money to burn | |
*/ | |
function burnFrom(address _from, uint256 _value) public returns (bool success) { | |
require(balanceOf[_from] >= _value); // Check if the targeted balance is enough | |
require(_value <= allowance[_from][msg.sender]); // Check allowance | |
balanceOf[_from] -= _value; // Subtract from the targeted balance | |
allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance | |
totalSupply -= _value; // Update totalSupply | |
emit Burn(_from, _value); | |
return true; | |
} | |
function CreatAndSendTokenToBookingContract(uint _bookingId, | |
address _propertyOwner, | |
address _user, | |
address _admin, | |
uint _amount, | |
uint _bookingStartTime, | |
address _tokenAddr) public { | |
Booking book = new Booking(_bookingId, | |
_propertyOwner, | |
_user, | |
_admin, | |
_amount, | |
_bookingStartTime, | |
_tokenAddr); | |
transfer(book,_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.24; | |
import "./SafeERC20.sol"; | |
/** | |
* @title TokenTimelock | |
* @dev TokenTimelock is a token holder contract that will allow a | |
* beneficiary to extract the tokens after a given release time | |
*/ | |
contract TokenTimelock { | |
using SafeERC20 for IERC20; | |
// ERC20 basic token contract being held | |
IERC20 private _token; | |
// beneficiary of tokens after they are released | |
address private _beneficiary; | |
// timestamp when token release is enabled | |
uint256 private _releaseTime; | |
constructor( | |
IERC20 token, | |
address beneficiary, | |
uint256 releaseTime | |
) | |
public | |
{ | |
// solium-disable-next-line security/no-block-members | |
require(releaseTime > block.timestamp); | |
_token = token; | |
_beneficiary = beneficiary; | |
_releaseTime = releaseTime; | |
} | |
/** | |
* @return the token being held. | |
*/ | |
function token() public view returns(IERC20) { | |
return _token; | |
} | |
/** | |
* @return the beneficiary of the tokens. | |
*/ | |
function beneficiary() public view returns(address) { | |
return _beneficiary; | |
} | |
/** | |
* @return the time when the tokens are released. | |
*/ | |
function releaseTime() public view returns(uint256) { | |
return _releaseTime; | |
} | |
/** | |
* @notice Transfers tokens held by timelock to beneficiary. | |
*/ | |
function release() public { | |
// solium-disable-next-line security/no-block-members | |
require(block.timestamp >= _releaseTime); | |
uint256 amount = _token.balanceOf(address(this)); | |
require(amount > 0); | |
_token.safeTransfer(_beneficiary, 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.25; | |
contract A{ | |
uint256 a; | |
function b() returns (uint){ | |
return a; | |
} | |
} | |
contract B { | |
bool a; | |
function c() returns (bool) { | |
return a; | |
} | |
} | |
contract C { | |
enum A{ | |
today, | |
tomoroww | |
} | |
A a; | |
function d() returns (A) { | |
return a; | |
} | |
function get() returns(uint) { | |
return now + 25 hours; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment