-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTokenStorage.sol
89 lines (67 loc) · 2.88 KB
/
TokenStorage.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
pragma solidity >=0.4.21 <0.6.0;
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import './Ownable.sol';
/**
* @author Arvind Kalra (github.com/arvindkalra) and Pranav Singhal (github.com/pranav-singhal)
* @title TokenStorage
*/
contract TokenStorage is Ownable{
using SafeMath for uint256;
// mapping (address => bool) internal _allowedAccess;
// Access Modifier for Storage contract
address internal _registryContract;
constructor() public {
_owner = msg.sender;
}
function setProxyContract(address proxyContract) onlyOwner public{
require(proxyContract != address(0), "InvalidAddress: invalid address passed for proxy contract");
_registryContract = proxyContract;
}
function getRegistryContract() view public returns(address){
return _registryContract;
}
// function addDeligateContract(address upgradedDeligatee) public{
// require(msg.sender == _registryContract, "AccessDenied: only registry contract allowed access");
// _allowedAccess[upgradedDeligatee] = true;
// }
modifier onlyAllowedAccess() {
require(msg.sender == _registryContract, "AccessDenied: This address is not allowed to access the storage");
_;
}
// Allowances with its Getter and Setter
mapping (address => mapping (address => uint256)) internal _allowances;
function setAllowance(address _tokenHolder, address _spender, uint256 _value) public onlyAllowedAccess {
_allowances[_tokenHolder][_spender] = _value;
}
function getAllowance(address _tokenHolder, address _spender) public view onlyAllowedAccess returns(uint256){
return _allowances[_tokenHolder][_spender];
}
// Balances with its Getter and Setter
mapping (address => uint256) internal _balances;
function addBalance(address _addr, uint256 _value) public onlyAllowedAccess {
_balances[_addr] = _balances[_addr].add(_value);
}
function subBalance(address _addr, uint256 _value) public onlyAllowedAccess {
_balances[_addr] = _balances[_addr].sub(_value);
}
function setBalance(address _addr, uint256 _value) public onlyAllowedAccess {
_balances[_addr] = _value;
}
function getBalance(address _addr) public view onlyAllowedAccess returns(uint256){
return _balances[_addr];
}
// Total Supply with Getter and Setter
uint256 internal _totalSupply = 0;
function addTotalSupply(uint256 _value) public onlyAllowedAccess {
_totalSupply = _totalSupply.add(_value);
}
function subTotalSupply(uint256 _value) public onlyAllowedAccess {
_totalSupply = _totalSupply.sub(_value);
}
function setTotalSupply(uint256 _value) public onlyAllowedAccess {
_totalSupply = _value;
}
function getTotalSupply() public view onlyAllowedAccess returns(uint256) {
return(_totalSupply);
}
}