-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storage #34
base: master
Are you sure you want to change the base?
Storage #34
Changes from 13 commits
0434e02
3f42c3a
f1d1da7
4f51fd2
e895663
25c3f13
65de82a
22de33f
8054882
ac68ef2
bfbe61f
92925cb
5da358e
8b6fdad
0f5a05e
9705e48
144bc72
9eb75e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
pragma solidity ^0.4.19; | ||
import "./TokenStorage.sol"; | ||
/*The upgraded contract*/ | ||
/** | ||
* @title ERC20Basic | ||
* @dev Simpler version of ERC20 interface | ||
* @dev see https://github.com/ethereum/EIPs/issues/179 | ||
*/ | ||
contract ERC20Basic { | ||
uint256 public totalSupply; | ||
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); | ||
} | ||
|
||
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); | ||
} | ||
|
||
contract Ownable { | ||
address public owner; | ||
|
||
|
||
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | ||
|
||
|
||
/** | ||
* @dev The Ownable constructor sets the original `owner` of the contract to the sender | ||
* account. | ||
*/ | ||
function Ownable() { | ||
owner = msg.sender; | ||
} | ||
|
||
|
||
/** | ||
* @dev Throws if called by any account other than the owner. | ||
*/ | ||
modifier onlyOwner() { | ||
require(msg.sender == owner); | ||
_; | ||
} | ||
|
||
|
||
/** | ||
* @dev Allows the current owner to transfer control of the contract to a newOwner. | ||
* @param newOwner The address to transfer ownership to. | ||
*/ | ||
function transferOwnership(address newOwner) onlyOwner public { | ||
require(newOwner != address(0)); | ||
OwnershipTransferred(owner, newOwner); | ||
owner = newOwner; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @title Pausable | ||
* @dev Base contract which allows children to implement an emergency stop mechanism. | ||
*/ | ||
contract Pausable is Ownable { | ||
event Pause(); | ||
event Unpause(); | ||
|
||
bool public paused = false; | ||
|
||
|
||
/** | ||
* @dev Modifier to make a function callable only when the contract is not paused. | ||
*/ | ||
modifier whenNotPaused() { | ||
require(!paused); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev Modifier to make a function callable only when the contract is paused. | ||
*/ | ||
modifier whenPaused() { | ||
require(paused); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev called by the owner to pause, triggers stopped state | ||
*/ | ||
function pause() onlyOwner whenNotPaused public { | ||
paused = true; | ||
Pause(); | ||
} | ||
|
||
/** | ||
* @dev called by the owner to unpause, returns to normal state | ||
*/ | ||
function unpause() onlyOwner whenPaused public { | ||
paused = false; | ||
Unpause(); | ||
} | ||
} | ||
contract StandardToken is ERC20,Pausable { | ||
using SafeMath for uint256; | ||
TokenStorage public Tstore; | ||
//constructor | ||
function StandardToken(address Tstore_address) { | ||
Tstore=TokenStorage(Tstore_address); | ||
} | ||
/** | ||
* @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) whenNotPaused returns (bool success) { | ||
require(Tstore.getBalanceFromAddress(msg.sender)>=_value&&Tstore.getBalanceFromAddress(_to)+_value>Tstore.getBalanceFromAddress(_to)); | ||
Tstore.setBalance(msg.sender,Tstore.getBalanceFromAddress(msg.sender).sub(_value)); | ||
Tstore.setBalance(_to,Tstore.getBalanceFromAddress(_to).add(_value)); | ||
emit Transfer(msg.sender, _to, _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 amout of tokens to be transfered | ||
*/ | ||
function transferFrom(address _from, address _to, uint256 _value) whenNotPaused returns (bool success) { | ||
require(Tstore.getBalanceFromAddress(_from)>=_value && Tstore.getAmountFromAddress(_from,msg.sender)>=_value && Tstore.getBalanceFromAddress(_from)+_value>Tstore.getBalanceFromAddress(_from)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where did you check if its approved to transfer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kpulkit29 lets change the name of getAmountFromAddress to getAllowedAmount for better naming convention. |
||
Tstore.setBalance(_to,Tstore.getBalanceFromAddress(_to).add(_value)); | ||
Tstore.setBalance(_from,Tstore.getBalanceFromAddress(_from).sub(_value)); | ||
Tstore.setAllowedAmount(_from,msg.sender,Tstore.getAmountFromAddress(_from,msg.sender).sub(_value)); | ||
emit Transfer(_from, _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) constant returns (uint256 balance) { | ||
return Tstore.getBalanceFromAddress(_owner); | ||
} | ||
|
||
/** | ||
* @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender. | ||
* This only works when the allowance is 0. Cannot be used to change allowance. | ||
* https://github.com/ethereum/EIPs/issues/738#issuecomment-336277632 | ||
* @param _spender The address which will spend the funds. | ||
* @param _value The amount of tokens to be spent. | ||
*/ | ||
function approve(address _spender, uint256 _value) whenNotPaused returns (bool success) { | ||
require(Tstore.getAmountFromAddress(msg.sender,_spender)==0); | ||
Tstore.setAllowedAmount(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 specifing the amount of tokens still available for the spender. | ||
*/ | ||
function allowance(address _owner, address _spender) constant returns (uint256 remaining) { | ||
return Tstore.getAmountFromAddress(_owner,_spender); | ||
} | ||
|
||
/** | ||
* To increment allowed value is better to use this function. | ||
* From MonolithDAO Token.sol | ||
*/ | ||
function increaseApproval(address _spender, uint _addedValue) whenNotPaused public returns (bool) { | ||
Tstore.setAllowedAmount(msg.sender,_spender,Tstore.getAmountFromAddress(msg.sender,_spender).add(_addedValue)); | ||
emit Approval(msg.sender, _spender,Tstore.getAmountFromAddress(msg.sender,_spender)); | ||
return true; | ||
} | ||
|
||
function decreaseApproval(address _spender, uint _subtractedValue) whenNotPaused public returns (bool) { | ||
uint oldValue = Tstore.getAmountFromAddress(msg.sender,_spender); | ||
if (_subtractedValue > oldValue) { | ||
Tstore.setAllowedAmount(msg.sender,_spender,0); | ||
} else { | ||
Tstore.setAllowedAmount(msg.sender,_spender,oldValue.sub(_subtractedValue)); | ||
} | ||
emit Approval(msg.sender, _spender,Tstore.getAmountFromAddress(msg.sender,_spender)); | ||
return true; | ||
} | ||
} | ||
library SafeMath { | ||
function mul(uint256 a, uint256 b) internal constant returns (uint256) { | ||
uint256 c = a * b; | ||
assert(a == 0 || c / a == b); | ||
return c; | ||
} | ||
|
||
function div(uint256 a, uint256 b) internal constant 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; | ||
} | ||
|
||
function sub(uint256 a, uint256 b) internal constant returns (uint256) { | ||
assert(b <= a); | ||
return a - b; | ||
} | ||
|
||
function add(uint256 a, uint256 b) internal constant returns (uint256) { | ||
uint256 c = a + b; | ||
assert(c >= a); | ||
return c; | ||
} | ||
} | ||
/* Contract class to mint tokens and transfer */ | ||
contract SPRINGToken_Upgrade is StandardToken { | ||
using SafeMath for uint256; | ||
|
||
string constant public name = 'SPRING Token'; | ||
string constant public symbol = 'SPRING'; | ||
uint constant public decimals = 18; | ||
uint256 public totalSupply; | ||
uint256 public maxSupply; | ||
|
||
/* Contructor function to set maxSupply*/ | ||
function SPRINGToken_Upgrade(uint256 _maxSupply,address Tstore_address) StandardToken(Tstore_address) { | ||
maxSupply = _maxSupply.mul(10**decimals); | ||
} | ||
|
||
/** | ||
* @dev Function to mint tokens | ||
* @param _amount The amount of tokens to mint. | ||
* @return A boolean that indicates if the operation was successful. | ||
*/ | ||
function mint(uint256 _amount) onlyOwner public returns (bool) { | ||
require (maxSupply >= (totalSupply.add(_amount))); | ||
totalSupply = totalSupply.add(_amount); | ||
Tstore.setBalance(msg.sender,Tstore.getBalanceFromAddress(msg.sender).add(_amount)); | ||
emit Transfer(address(0), msg.sender, _amount); | ||
return true; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
pragma solidity ^0.4.19; | ||
contract Ownable2 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets keep this as ownable |
||
address public owner; | ||
/** | ||
* @dev The Ownable constructor sets the original `owner` of the contract to the sender | ||
* account. | ||
*/ | ||
function Ownable2() { | ||
owner = msg.sender; | ||
} | ||
/** | ||
* @dev Throws if called by any account other than the owner. | ||
*/ | ||
modifier onlyOwner2() { | ||
require(msg.sender == owner); | ||
_; | ||
} | ||
} | ||
contract TokenStorage is Ownable2 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ownable2? |
||
//to keep track of balances | ||
mapping (address => uint256) public balances; | ||
//to keep track of allowed addresses | ||
mapping (address => mapping (address => uint256)) public allowed; | ||
//mapping to allow access to only some addresses | ||
mapping(address => bool) Access_allowed; | ||
//to check that the request is actually coming from the vanity contract | ||
modifier checkVanity(address _add) { | ||
require(Access_allowed[_add]==true); | ||
_; | ||
} | ||
//to set the contract address | ||
function allowAccess(address newAddr) onlyOwner2 public { | ||
Access_allowed[newAddr]=true; | ||
} | ||
//function to get balance from address | ||
function getBalanceFromAddress(address _add) constant public returns(uint256) { | ||
return balances[_add]; | ||
} | ||
//function to get amount from addresses | ||
function getAmountFromAddress(address _add1,address _add2) constant public returns(uint256) { | ||
return allowed[_add1][_add2]; | ||
} | ||
//function to set balance from address | ||
function setBalance(address _add,uint256 amt) checkVanity(msg.sender) public { | ||
balances[_add]=amt; | ||
} | ||
//function to set amount allowed | ||
function setAllowedAmount(address _add1,address _add2,uint256 amt) checkVanity(msg.sender) public { | ||
allowed[_add1][_add2]=amt; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not check if _value is positive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The checks are same as in the original contract just changed them to what they should be according to the storage contract