Skip to content

Commit

Permalink
feat(versioning-proxy): implement base contract and derived skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Feb 21, 2018
1 parent b204a42 commit b86df6e
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 0 deletions.
71 changes: 71 additions & 0 deletions contracts/standard/proxy/ArbitratorVersioningProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
pragma solidity ^0.4.15;

import "./VersioningProxy.sol";

/**
* @title ArbitratorVersioningProxy
* @author Enrique Piqueras - <epiquerass@gmail.com>
* @notice A contract derived from VersioningProxy to manage the deployment of new versions of an Arbitrator contract.
*/
contract ArbitratorVersioningProxy is VersioningProxy {
/* Enums */



/* Structs */



/* Events */



/* Storage */



/* Modifiers */



/* Constructor */



/* Fallback */



/* External */



/* External Views */



/* Public */



/* Public Views */



/* Internal */



/* Internal Views */



/* Private */



/* Private Views */



}
128 changes: 128 additions & 0 deletions contracts/standard/proxy/VersioningProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
pragma solidity ^0.4.15;

/**
* @title VersioningProxy
* @author Enrique Piqueras - <epiquerass@gmail.com>
* @notice A base contract for managing the deployment of versions of another contract.
*/
contract VersioningProxy {
/* Enums */



/* Structs */

struct Deployment {
bytes32 tag;
address _address;
}

/* Events */



/* Storage */

// Owner and Creation Metadata
address public owner = msg.sender;
uint256 public creationTime = now;

// Deployments
bytes32[] public tags; // We keep this so we can iterate over versions
mapping (bytes32 => address) public addresses;
Deployment public stable;

/* Modifiers */

/**
* @dev Makes a function only callable by the owner of the contract.
*/
modifier onlyOwner {
require(owner == msg.sender);
_;
}

/* Constructor */

/**
* @notice Constructs the version proxy with the first version of the contract, `firstTag`, at `firstAddress`.
* @param firstTag The version tag of the first version of the contract you are versioning.
* @param firstAddress The address of the associated contract.
*/
function VersioningProxy(bytes32 firstTag, address firstAddress) public {
publish(firstTag, firstAddress);
}

/* Fallback */



/* External */

/**
* @notice Rolls back 'stable' to the previous deployment, and returns true, if one exists, returns false otherwise.
*/
function rollback() external onlyOwner returns(bool) {
uint256 tagsLen = tags.length;
if (tagsLen <= 2)
return false;

bytes32 prevTag = tags[tagsLen - 2];
setStable(prevTag);
return true;
}

/* External Views */

/**
* @notice Returns all deployed version tags.
*/
function allTags() external view returns(bytes32[]) {
return tags;
}

/* Public */

/**
* @notice Publishes a new version, `newTag`, at `newAddress`.
* @param newTag The new version tag.
* @param newAddress The address of the associated contract.
*/
function publish(bytes32 newTag, address newAddress) public onlyOwner {
tags.push(newTag);
addresses[newTag] = newAddress;
stable = Deployment({tag: newTag, _address: newAddress});
}

/**
* @notice Sets the value of stable to the address of `publishedTag`.
* @param publishedTag The already published version tag.
*/
function setStable(bytes32 publishedTag) public onlyOwner {
address _address = addresses[publishedTag];
require(_address != address(0)); // Throw if not published

stable = Deployment({tag: publishedTag, _address: _address});
}

/* Public Views */



/* Internal */



/* Internal Views */



/* Private */



/* Private Views */



}

0 comments on commit b86df6e

Please sign in to comment.