Created
April 9, 2019 09:00
-
-
Save ubaid-qureshi/67858a929e318801784db20be034251b 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.5.0; | |
import "./Utils.sol"; | |
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol"; | |
contract ERC20Basic is usingOraclize{ | |
using Utils for *; | |
string public constant name = "ERC20Basic"; | |
string public constant symbol = "BSC"; | |
uint256 totalSupply_; | |
address[] public participants_; | |
event Transfer(address indexed from, address indexed to, uint tokens); | |
mapping(address => uint256) balances; | |
mapping(address => bool) allowedTransaction; | |
mapping(address => uint) availableTokens; | |
constructor(uint256 total) public { | |
totalSupply_ = total; | |
} | |
function totalSupply() public view returns (uint256) { | |
return totalSupply_; | |
} | |
function balanceOf(address tokenOwner) public view returns (uint) { | |
return balances[tokenOwner]; | |
} | |
function addParticipants(address[] memory participants) public{ | |
participants_ = participants; | |
for (uint i=0; i < participants.length; i++) { | |
balances[participants[i]] = uint(totalSupply_) / uint(participants.length); | |
allowedTransaction[participants[i]] = true; | |
availableTokens[participants_[i]] = 1; | |
} | |
} | |
function addMoreMoney (uint amount) public { | |
for (uint i=0; i < participants_.length; i++) { | |
balances[participants_[i]] += uint(amount) / uint(participants_.length); | |
} | |
} | |
function transfer(address receiver, uint numTokens) public returns (bool) { | |
require(allowedTransaction[msg.sender]); | |
require(numTokens == availableTokens[msg.sender]); | |
balances[msg.sender] = balances[msg.sender].sub(numTokens); | |
balances[receiver] = balances[receiver].add(numTokens); | |
allowedTransaction[msg.sender] = false; | |
availableTokens[msg.sender] -= 1; | |
emit Transfer(msg.sender, receiver, numTokens); | |
return true; | |
} | |
function transferFrom(address owner, address buyer, uint numTokens) public returns (bool) { | |
require(allowedTransaction[owner]); | |
require(numTokens == availableTokens[owner]); | |
balances[owner] = balances[owner].sub(numTokens); | |
balances[buyer] = balances[buyer].add(numTokens); | |
allowedTransaction[owner] = false; | |
availableTokens[msg.sender] -= 1; | |
emit Transfer(owner, buyer, numTokens); | |
return true; | |
} | |
function __callback(bytes32 myid, string memory result) public{ | |
require(msg.sender != oraclize_cbAddress()); | |
oraclize_query(20*60, "URL", ""); | |
updateTransactions(); | |
} | |
function updateTransactions() public{ | |
for (uint i=0; i < participants_.length; i++) { | |
allowedTransaction[participants_[i]] = true; | |
availableTokens[participants_[i]] += 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.5.0; | |
library Utils { | |
function minutesToSeconds(uint timeInMin) public pure returns(uint) { | |
return timeInMin * 1 minutes; | |
} | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
assert(b <= a); | |
return a - b; | |
} | |
function add(uint256 a, uint256 b) internal pure returns (uint256) { | |
uint256 c = a + b; | |
assert(c >= a); | |
return c; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment