pragmasolidity 0.4.24;import"./EternalStorage.sol";
import"./OwnedUpgradeabilityProxy.sol";
/**
* @title EternalStorageProxy
* @dev This proxy holds the storage of the token contract and delegates every call to the current implementation set.
* Besides, it allows to upgrade the token's behaviour towards further implementations, and provides basic
* authorization control functionalities
*/contractCoinJuheStorageProxyisEternalStorage, OwnedUpgradeabilityProxy{}
Contract Source Code
File 2 of 7: EternalStorage.sol
pragmasolidity 0.4.24;/**
* @title EternalStorage
* @dev This contract holds all the necessary state variables to carry out the storage of any contract.
*/contractEternalStorage{
mapping(bytes32=>uint256) internal uintStorage;
mapping(bytes32=>string) internal stringStorage;
mapping(bytes32=>address) internal addressStorage;
mapping(bytes32=>bytes) internal bytesStorage;
mapping(bytes32=>bool) internal boolStorage;
mapping(bytes32=>int256) internal intStorage;
}
Contract Source Code
File 3 of 7: OwnedUpgradeabilityProxy.sol
pragmasolidity 0.4.24;import'./UpgradeabilityProxy.sol';
import'./UpgradeabilityOwnerStorage.sol';
/**
* @title OwnedUpgradeabilityProxy
* @dev This contract combines an upgradeability proxy with basic authorization control functionalities
*/contractOwnedUpgradeabilityProxyisUpgradeabilityOwnerStorage, UpgradeabilityProxy{
/**
* @dev Event to show ownership has been transferred
* @param previousOwner representing the address of the previous owner
* @param newOwner representing the address of the new owner
*/eventProxyOwnershipTransferred(address previousOwner, address newOwner);
/**
* @dev the constructor sets the original owner of the contract to the sender account.
*/constructor() public{
setUpgradeabilityOwner(msg.sender);
}
/**
* @dev Throws if called by any account other than the owner.
*/modifieronlyProxyOwner() {
require(msg.sender== proxyOwner());
_;
}
/**
* @dev Tells the address of the proxy owner
* @return the address of the proxy owner
*/functionproxyOwner() publicviewreturns (address) {
return upgradeabilityOwner();
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/functiontransferProxyOwnership(address newOwner) publiconlyProxyOwner{
require(newOwner !=address(0));
setUpgradeabilityOwner(newOwner);
emit ProxyOwnershipTransferred(proxyOwner(), newOwner);
}
/**
* @dev Allows the upgradeability owner to upgrade the current version of the proxy.
* @param version representing the version name of the new implementation to be set.
* @param implementation representing the address of the new implementation to be set.
*/functionupgradeTo(string version, address implementation) publiconlyProxyOwner{
_upgradeTo(version, implementation);
}
/**
* @dev Allows the upgradeability owner to upgrade the current version of the proxy and call the new implementation
* to initialize whatever is needed through a low level call.
* @param version representing the version name of the new implementation to be set.
* @param implementation representing the address of the new implementation to be set.
* @param data represents the msg.data to bet sent in the low level call. This parameter may include the function
* signature of the implementation to be called with the needed payload
*/functionupgradeToAndCall(string version, address implementation, bytes data) payablepubliconlyProxyOwner{
upgradeTo(version, implementation);
require(address(this).call.value(msg.value)(data));
}
}
Contract Source Code
File 4 of 7: Proxy.sol
pragmasolidity 0.4.24;/**
* @title Proxy
* @dev Gives the possibility to delegate any call to a foreign implementation.
*/contractProxy{
/**
* @dev Tells the address of the implementation where every call will be delegated.
* @return address of the implementation to which it will be delegated
*/functionimplementation() publicviewreturns (address);
/**
* @dev Fallback function allowing to perform a delegatecall to the given implementation.
* This function will return whatever the implementation call returns
*/function () payablepublic{
address _impl = implementation();
require(_impl !=address(0));
assembly {
let ptr :=mload(0x40)
calldatacopy(ptr, 0, calldatasize)
let result :=delegatecall(gas, _impl, ptr, calldatasize, 0, 0)
let size :=returndatasizereturndatacopy(ptr, 0, size)
switch result
case0 { revert(ptr, size) }
default { return(ptr, size) }
}
}
}
Contract Source Code
File 5 of 7: UpgradeabilityOwnerStorage.sol
pragmasolidity 0.4.24;/**
* @title UpgradeabilityOwnerStorage
* @dev This contract keeps track of the upgradeability owner
*/contractUpgradeabilityOwnerStorage{
// Owner of the contractaddressprivate _upgradeabilityOwner;
/**
* @dev Tells the address of the owner
* @return the address of the owner
*/functionupgradeabilityOwner() publicviewreturns (address) {
return _upgradeabilityOwner;
}
/**
* @dev Sets the address of the owner
*/functionsetUpgradeabilityOwner(address newUpgradeabilityOwner) internal{
_upgradeabilityOwner = newUpgradeabilityOwner;
}
}
Contract Source Code
File 6 of 7: UpgradeabilityProxy.sol
pragmasolidity 0.4.24;import'./Proxy.sol';
import'./UpgradeabilityStorage.sol';
/**
* @title UpgradeabilityProxy
* @dev This contract represents a proxy where the implementation address to which it will delegate can be upgraded
*/contractUpgradeabilityProxyisProxy, UpgradeabilityStorage{
/**
* @dev This event will be emitted every time the implementation gets upgraded
* @param version representing the version name of the upgraded implementation
* @param implementation representing the address of the upgraded implementation
*/eventUpgraded(string version, addressindexed implementation);
/**
* @dev Upgrades the implementation address
* @param version representing the version name of the new implementation to be set
* @param implementation representing the address of the new implementation to be set
*/function_upgradeTo(string version, address implementation) internal{
require(_implementation != implementation);
_version = version;
_implementation = implementation;
emit Upgraded(version, implementation);
}
}
Contract Source Code
File 7 of 7: UpgradeabilityStorage.sol
pragmasolidity 0.4.24;/**
* @title UpgradeabilityStorage
* @dev This contract holds all the necessary state variables to support the upgrade functionality
*/contractUpgradeabilityStorage{
// Version name of the current implementationstringinternal _version;
// Address of the current implementationaddressinternal _implementation;
/**
* @dev Tells the version name of the current implementation
* @return string representing the name of the current version
*/functionversion() publicviewreturns (string) {
return _version;
}
/**
* @dev Tells the address of the current implementation
* @return address of the current implementation
*/functionimplementation() publicviewreturns (address) {
return _implementation;
}
}