Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*/build/*
node_modules/
build/
.idea
12 changes: 11 additions & 1 deletion upgradeability_using_inherited_storage/contracts/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ pragma solidity ^0.4.18;
import './IRegistry.sol';
import './Upgradeable.sol';
import './UpgradeabilityProxy.sol';
import './ownership/Ownable.sol';

/**
* @title Registry
* @dev This contract works as a registry of versions, it holds the implementations for the registered versions.
*/
contract Registry is IRegistry {
contract Registry is IRegistry, Ownable {
// Mapping of versions to implementations of different functions
mapping (string => address) internal versions;

Expand Down Expand Up @@ -43,4 +44,13 @@ contract Registry is IRegistry {
ProxyCreated(proxy);
return proxy;
}

/**
* @dev Creates an upgradeable proxy
* @param proxy value returned from createProxy
* @param newowner proxy contract's new owner
*/
function transferProxyOwnership(address proxy, address newowner) onlyOwner public payable {
Ownable(proxy).transferOwnership(newowner);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract UpgradeabilityProxy is Proxy, UpgradeabilityStorage {
* @dev Upgrades the implementation to the requested version
* @param _version representing the version name of the new implementation to be set
*/
function upgradeTo(string _version) public {
function upgradeTo(string _version) public onlyOwner {
_implementation = registry.getVersion(_version);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
pragma solidity ^0.4.18;

import './IRegistry.sol';
import './ownership/Ownable.sol';

/**
* @title UpgradeabilityStorage
* @dev This contract holds all the necessary state variables to support the upgrade functionality
*/
contract UpgradeabilityStorage {
contract UpgradeabilityStorage is Ownable {
// Versions registry
IRegistry internal registry;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
pragma solidity ^0.4.18;

import './OwnableStorage.sol';

/**
* @title Ownable
* @dev This contract has the owner address providing basic authorization control
*/
contract Ownable is OwnableStorage {
/**
* @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
*/
event OwnershipTransferred(address previousOwner, address newOwner);

/**
* @dev The constructor sets the original owner of the contract to the sender account.
*/
function Ownable() public {
setOwner(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) public onlyOwner {
require(newOwner != address(0));
OwnershipTransferred(owner(), newOwner);
setOwner(newOwner);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pragma solidity ^0.4.18;

/**
* @title OwnableStorage
* @dev This contract keeps track of the owner's address
*/
contract OwnableStorage {
// Owner of the contract
address private _owner;

/**
* @dev Tells the address of the owner
* @return the address of the owner
*/
function owner() public view returns (address) {
return _owner;
}

/**
* @dev Sets a new owner address
*/
function setOwner(address newOwner) internal {
_owner = newOwner;
}
}