Created
April 4, 2018 14:53
-
-
Save ayinot/d78e37b813fde0c7a555dba55818f05b to your computer and use it in GitHub Desktop.
Related to contract upgradation
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.18; | |
import "./Proxy.sol"; | |
import "./SafeMath.sol"; | |
contract KeyValueStorage { | |
mapping(address => mapping(bytes32 => uint256)) _uintStorage; | |
mapping(address => mapping(bytes32 => address)) _addressStorage; | |
mapping(address => mapping(bytes32 => bool)) _boolStorage; | |
/**** Get Methods ***********/ | |
function getAddress(bytes32 key) public view returns (address) { | |
return _addressStorage[msg.sender][key]; | |
} | |
function getUint(bytes32 key) public view returns (uint) { | |
return _uintStorage[msg.sender][key]; | |
} | |
function getBool(bytes32 key) public view returns (bool) { | |
return _boolStorage[msg.sender][key]; | |
} | |
/**** Set Methods ***********/ | |
function setAddress(bytes32 key, address value) public { | |
_addressStorage[msg.sender][key] = value; | |
} | |
function setUint(bytes32 key, uint value) public { | |
_uintStorage[msg.sender][key] = value; | |
} | |
function setBool(bytes32 key, bool value) public { | |
_boolStorage[msg.sender][key] = value; | |
} | |
} | |
contract StorageStateful { | |
KeyValueStorage _storage; | |
} | |
contract StorageConsumer is StorageStateful { | |
function StorageConsumer(KeyValueStorage storage_) public { | |
_storage = storage_; | |
} | |
} | |
contract DetailedToken { | |
string public name; | |
string public symbol; | |
uint8 public decimals; | |
} | |
contract ShrimpCoin is StorageConsumer, Proxy, DetailedToken { | |
function ShrimpCoin(KeyValueStorage storage_) | |
public | |
StorageConsumer(storage_) | |
{ | |
name = "ShrimpCoin"; | |
symbol = "SHRMP"; | |
decimals = 18; | |
} | |
} | |
contract TokenDelegate is StorageStateful { | |
using SafeMath for uint256; | |
function transfer(address to, uint256 value) public returns (bool) { | |
require(to != address(0)); | |
require(value <= getBalance(msg.sender)); | |
subBalance(msg.sender, value); | |
addBalance(to, value); | |
return true; | |
} | |
function balanceOf(address owner) public view returns (uint256 balance) { | |
return getBalance(owner); | |
} | |
function getBalance(address balanceHolder) public view returns (uint256) { | |
return _storage.getUint(keccak256("balances", balanceHolder)); | |
} | |
function totalSupply() public view returns (uint256) { | |
return _storage.getUint("totalSupply"); | |
} | |
function addSupply(uint256 amount) internal { | |
_storage.setUint("totalSupply", totalSupply().add(amount)); | |
} | |
function addBalance(address balanceHolder, uint256 amount) internal { | |
setBalance(balanceHolder, getBalance(balanceHolder).add(amount)); | |
} | |
function subBalance(address balanceHolder, uint256 amount) internal { | |
setBalance(balanceHolder, getBalance(balanceHolder).sub(amount)); | |
} | |
function setBalance(address balanceHolder, uint256 amount) internal { | |
_storage.setUint(keccak256("balances", balanceHolder), amount); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment