Skip to content

Commit

Permalink
Fixed linting, added solhint
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsam4 committed Aug 25, 2018
1 parent 0afe550 commit 5434e82
Show file tree
Hide file tree
Showing 23 changed files with 1,174 additions and 428 deletions.
7 changes: 4 additions & 3 deletions contracts/EventCaller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

pragma solidity 0.4.24;


contract EventCaller {

/// @dev VoteCast event is called whenever a vote is cast that can potentially close the proposal.
Expand All @@ -34,15 +35,15 @@ contract EventCaller {
/// @dev CloseProposalOnTime event is called whenever a proposal is created or updated to close it on time.
/// closeProposalAddress is used to call closeProposal(proposalId) if proposal is ready to be closed.
event CloseProposalOnTime (
uint256 proposalId,
uint256 proposalId,
address closeProposalAddress,
uint256 time
);

/// @dev ActionSuccess event is called whenever an onchain action is executed.
/// closeProposalAddress is used to know which action.
event ActionSuccess (
uint256 proposalId,
uint256 proposalId,
address closeProposalAddress
);

Expand Down Expand Up @@ -76,6 +77,6 @@ contract EventCaller {
/// @dev calls ActionSuccess event
/// @param _proposalId Proposal ID for which the action is executed
function callActionSuccess (uint256 _proposalId) external {
emit ActionSuccess(_proposalId, msg.sender);
emit ActionSuccess(_proposalId, msg.sender);
}
}
8 changes: 2 additions & 6 deletions contracts/GBTStandardToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import "./imports/lockable-token/ERC1132.sol";
import "./imports/openzeppelin-solidity/contracts/token/ERC20/MintableToken.sol";
import "./imports/openzeppelin-solidity/contracts/token/ERC20/DetailedERC20.sol";


contract GBTStandardToken is ERC1132, MintableToken, DetailedERC20 {
uint public tokenPrice;

/// @dev constructor
constructor() DetailedERC20("GovBlocks Standard Token", "GBT", 18) public {
constructor() public DetailedERC20("GovBlocks Standard Token", "GBT", 18) {
owner = msg.sender;
totalSupply_ = 10 ** 20;
balances[address(msg.sender)] = totalSupply_;
Expand All @@ -38,9 +39,4 @@ contract GBTStandardToken is ERC1132, MintableToken, DetailedERC20 {
emit Mint(msg.sender, actualAmount);
emit Transfer(address(0), msg.sender, actualAmount);
}

/*/// @dev function to change Token price
function changeTokenPrice(uint _price) public onlyOwner {
tokenPrice = _price;
}*/
}
53 changes: 29 additions & 24 deletions contracts/GovBlocksMaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,21 @@ contract GovBlocksMaster is Ownable {
string internal byteCodeHash;
string internal contractsAbiHash;

/// @dev Initializes GovBlocks master
/// @param _gbtAddress GBT standard token address
function govBlocksMasterInit(address _gbtAddress, address _eventCaller) public {
require(!initialized);

require (owner != address(0));

gbtAddress = _gbtAddress;
eventCaller = _eventCaller;
Governed govern = new Governed();
governChecker = GovernChecker(govern.governChecker());
masterByteCode = "0x496e6974616c697a65";
if(address(governChecker) != address(0))
governChecker.updateGBMAdress(address(this));
initialized = true;
}

/// @dev Updates GBt standard token address
/// @param _gbtContractAddress New GBT standard token contract address
function updateGBTAddress(address _gbtContractAddress) external onlyOwner {
gbtAddress = _gbtContractAddress;
for (uint i = 0; i < allGovBlocksUsers.length; i++) {
address masterAddress = govBlocksDapps[allGovBlocksUsers[i]].masterAddress;
Master master = Master(masterAddress);
/* solhint-disable */
if (master.getCurrentVersion() > 0) {
//Master can re enter but we don't expect to use this function ever on the public network
if (address(master).call(bytes4(keccak256("changeGBTSAddress(address)")), _gbtContractAddress)) {
//just to silence the compiler warning
}
}
}
/* solhint-enable */
}
}

Expand All @@ -78,14 +63,16 @@ contract GovBlocksMaster is Ownable {
for (uint i = 0; i < allGovBlocksUsers.length; i++) {
address masterAddress = govBlocksDapps[allGovBlocksUsers[i]].masterAddress;
Master master = Master(masterAddress);
/* solhint-disable */
if (master.getCurrentVersion() > 0) {
//Master can re enter but we don't expect to use this function ever on the public network
if(address(master).call(bytes4(keccak256("changeGBMAddress(address)")), _newGBMAddress)) {
if (address(master).call(bytes4(keccak256("changeGBMAddress(address)")), _newGBMAddress)) {
//just to silence the compiler warning
}
}
}
/* solhint-enable */
}
if(address(governChecker) != address(0))
if (address(governChecker) != address(0))
governChecker.updateGBMAdress(_newGBMAddress);
}

Expand All @@ -108,7 +95,7 @@ contract GovBlocksMaster is Ownable {
/// @param _gbUserName dApp name
/// @param _newMasterAddress dApp new master address
function changeDappMasterAddress(bytes32 _gbUserName, address _newMasterAddress) external {
if(address(governChecker) != address(0)) // Owner for debugging only, will be removed before launch
if (address(governChecker) != address(0)) // Owner for debugging only, will be removed before launch
require(governChecker.authorizedAddressNumber(_gbUserName, msg.sender) > 0 || owner == msg.sender);
else
require(owner == msg.sender);
Expand All @@ -120,7 +107,7 @@ contract GovBlocksMaster is Ownable {
/// @param _gbUserName dApp name
/// @param _descHash dApp new desc hash
function changeDappDescHash(bytes32 _gbUserName, string _descHash) external {
if(address(governChecker) != address(0)) // Owner for debugging only, will be removed before launch
if (address(governChecker) != address(0)) // Owner for debugging only, will be removed before launch
require(governChecker.authorizedAddressNumber(_gbUserName, msg.sender) > 0 || owner == msg.sender);
else
require(owner == msg.sender);
Expand All @@ -131,7 +118,7 @@ contract GovBlocksMaster is Ownable {
/// @param _gbUserName dApp name
/// @param _dappTokenAddress dApp new token address
function changeDappTokenAddress(bytes32 _gbUserName, address _dappTokenAddress) external {
if(address(governChecker) != address(0)) // Owner for debugging only, will be removed before launch
if (address(governChecker) != address(0)) // Owner for debugging only, will be removed before launch
require(governChecker.authorizedAddressNumber(_gbUserName, msg.sender) > 0 || owner == msg.sender);
else
require(owner == msg.sender);
Expand Down Expand Up @@ -162,6 +149,22 @@ contract GovBlocksMaster is Ownable {
eventCaller = _eventCaller;
}

/// @dev Initializes GovBlocks master
/// @param _gbtAddress GBT standard token address
function govBlocksMasterInit(address _gbtAddress, address _eventCaller) public {
require(!initialized);
require(owner != address(0));

gbtAddress = _gbtAddress;
eventCaller = _eventCaller;
Governed govern = new Governed();
governChecker = GovernChecker(govern.governChecker());
masterByteCode = "0x496e6974616c697a65";
if (address(governChecker) != address(0))
governChecker.updateGBMAdress(address(this));
initialized = true;
}

/// @dev Gets byte code and abi hash
function getByteCodeAndAbi() public view returns(string, string) {
return (byteCodeHash, contractsAbiHash);
Expand Down Expand Up @@ -295,9 +298,11 @@ contract GovBlocksMaster is Ownable {

/// @dev Deploys a new Master
function deployMaster(bytes32 _gbUserName, bytes _masterByteCode) internal returns(address deployedAddress) {
/* solhint-disable */
assembly {
deployedAddress := create(0, add(_masterByteCode, 0x20), mload(_masterByteCode)) // deploys contract
}
/* solhint-enable */
Master master = Master(deployedAddress);
master.initMaster(msg.sender, _gbUserName);
}
Expand Down
120 changes: 60 additions & 60 deletions contracts/GovernCheckerContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,69 +17,69 @@ pragma solidity 0.4.24;


contract GBM {
function getDappMasterAddress(bytes32 _gbUserName) public view returns(address masterAddress);
function getDappMasterAddress(bytes32 _gbUserName) public view returns(address masterAddress);
}


contract GovernCheckerContract {

mapping (bytes32 => address[]) public authorized; //Mapping to store authorized address of every dApp

GBM internal govBlockMaster; //GovBlockMaster instance to prevent registeration of non existant dApps.

/// @dev Updates GBM address, can only be called by current GBM
/// @param _govBlockMaster new govBlockMaster address
function updateGBMAdress(address _govBlockMaster) public {
require(address(govBlockMaster) == msg.sender || address(govBlockMaster) == address(0));
govBlockMaster = GBM(_govBlockMaster);
}

/// @dev Allows dApp's master to add authorized address for initalization
/// @param _dAppName new dApp's name
/// @param _authorizedAddress authorized address of the new dapp
function initializeAuthorized(bytes32 _dAppName, address _authorizedAddress) public {
require(authorized[_dAppName].length == 0);
if(address(govBlockMaster) != address(0))
require(govBlockMaster.getDappMasterAddress(_dAppName) == msg.sender);
authorized[_dAppName].push(_authorizedAddress);
}

/// @dev Allows the authorized address to pass on the authorized to someone else
/// @param _dAppName dApp's name whose _authorizedAddress has to be changed
/// @param _authorizedAddress new authorized address of the dapp
function updateAuthorized(bytes32 _dAppName, address _authorizedAddress) public {
uint authNumber = authorizedAddressNumber(_dAppName, msg.sender);
require(authNumber > 0);
authorized[_dAppName][authNumber - 1] = _authorizedAddress;
}

/// @dev add authorized address (a new voting type)
/// @param _dAppName dApp's name whose _authorizedAddress has to be changed
/// @param _authorizedAddress new authorized address of the dapp
function addAuthorized(bytes32 _dAppName, address _authorizedAddress) public {
uint authNumber = authorizedAddressNumber(_dAppName, msg.sender);
require(authNumber > 0);
authNumber = authorizedAddressNumber(_dAppName, _authorizedAddress);
if(authNumber == 0)
authorized[_dAppName].push(_authorizedAddress);
}

/// @dev checks if an address is authprized and returns its authorized number.
/// returns 0 if not authorized.
function authorizedAddressNumber(bytes32 _dAppName, address _authorizedAddress)
public
view
returns(uint authorizationNumber)
{
for(uint i = 0; i < authorized[_dAppName].length; i++) {
if(authorized[_dAppName][i] == _authorizedAddress) {
return(i + 1);
}
}
}

/// @dev Returns govBlockMaster Address
function GetGovBlockMasterAddress() public view returns(address) {
return address(govBlockMaster);
}
mapping (bytes32 => address[]) public authorized; //Mapping to store authorized address of every dApp

GBM internal govBlockMaster; //GovBlockMaster instance to prevent registeration of non existant dApps.

/// @dev Updates GBM address, can only be called by current GBM
/// @param _govBlockMaster new govBlockMaster address
function updateGBMAdress(address _govBlockMaster) public {
require(address(govBlockMaster) == msg.sender || address(govBlockMaster) == address(0));
govBlockMaster = GBM(_govBlockMaster);
}

/// @dev Allows dApp's master to add authorized address for initalization
/// @param _dAppName new dApp's name
/// @param _authorizedAddress authorized address of the new dapp
function initializeAuthorized(bytes32 _dAppName, address _authorizedAddress) public {
require(authorized[_dAppName].length == 0);
if (address(govBlockMaster) != address(0))
require(govBlockMaster.getDappMasterAddress(_dAppName) == msg.sender);
authorized[_dAppName].push(_authorizedAddress);
}

/// @dev Allows the authorized address to pass on the authorized to someone else
/// @param _dAppName dApp's name whose _authorizedAddress has to be changed
/// @param _authorizedAddress new authorized address of the dapp
function updateAuthorized(bytes32 _dAppName, address _authorizedAddress) public {
uint authNumber = authorizedAddressNumber(_dAppName, msg.sender);
require(authNumber > 0);
authorized[_dAppName][authNumber - 1] = _authorizedAddress;
}

/// @dev add authorized address (a new voting type)
/// @param _dAppName dApp's name whose _authorizedAddress has to be changed
/// @param _authorizedAddress new authorized address of the dapp
function addAuthorized(bytes32 _dAppName, address _authorizedAddress) public {
uint authNumber = authorizedAddressNumber(_dAppName, msg.sender);
require(authNumber > 0);
authNumber = authorizedAddressNumber(_dAppName, _authorizedAddress);
if (authNumber == 0)
authorized[_dAppName].push(_authorizedAddress);
}

/// @dev checks if an address is authprized and returns its authorized number.
/// returns 0 if not authorized.
function authorizedAddressNumber(bytes32 _dAppName, address _authorizedAddress)
public
view
returns(uint authorizationNumber)
{
for (uint i = 0; i < authorized[_dAppName].length; i++) {
if (authorized[_dAppName][i] == _authorizedAddress) {
return(i + 1);
}
}
}

/// @dev Returns govBlockMaster Address
function getGovBlockMasterAddress() public view returns(address) {
return address(govBlockMaster);
}
}
Loading

0 comments on commit 5434e82

Please sign in to comment.