Skip to content
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

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
build
Binary file added contracts/.DS_Store
Binary file not shown.
19 changes: 8 additions & 11 deletions contracts/SPRINGToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract Ownable {
*/
function transferOwnership(address newOwner) onlyOwner public {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}

Expand Down Expand Up @@ -89,24 +89,22 @@ contract Pausable is Ownable {
*/
function pause() onlyOwner whenNotPaused public {
paused = true;
Pause();
Pause();
}

/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused public {
paused = false;
Unpause();
Unpause();
}
}

contract StandardToken is ERC20,Pausable {
using SafeMath for uint256;

mapping (address => uint256) public balances;
mapping (address => mapping (address => uint256)) public allowed;

/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
Expand All @@ -119,7 +117,6 @@ contract StandardToken is ERC20,Pausable {
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
Expand All @@ -131,7 +128,7 @@ contract StandardToken is ERC20,Pausable {
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
Transfer(_from, _to, _value);
return true;
}

Expand All @@ -154,7 +151,7 @@ contract StandardToken is ERC20,Pausable {
function approve(address _spender, uint256 _value) whenNotPaused returns (bool success) {
require(allowed[msg.sender][_spender] == 0);
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
Approval(msg.sender, _spender, _value);
return true;
}

Expand All @@ -174,7 +171,7 @@ contract StandardToken is ERC20,Pausable {
*/
function increaseApproval(address _spender, uint _addedValue) whenNotPaused public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}

Expand All @@ -185,7 +182,7 @@ contract StandardToken is ERC20,Pausable {
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
Expand Down Expand Up @@ -228,7 +225,7 @@ contract SPRINGToken is StandardToken {
uint256 public maxSupply;

/* Contructor function to set maxSupply*/
function SPRINGToken(uint256 _maxSupply){
function SPRINGToken(uint256 _maxSupply) {
maxSupply = _maxSupply.mul(10**decimals);
}

Expand Down
244 changes: 244 additions & 0 deletions contracts/SPRINGToken_Upgrade.sol
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));
Copy link
Contributor

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?

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

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did you check if its approved to transfer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}

}
51 changes: 51 additions & 0 deletions contracts/TokenStorage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
pragma solidity ^0.4.19;
contract Ownable2 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
}
}
Loading