Skip to content

Commit

Permalink
(Refactor) Update to Solidity v0.4.23
Browse files Browse the repository at this point in the history
  • Loading branch information
varasev committed May 15, 2018
1 parent 17ee6ba commit 9fef157
Show file tree
Hide file tree
Showing 44 changed files with 6,441 additions and 1,889 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ It will show the bytecode of `PoaNetworkConsensus` contract. Copy the bytecode a
### Add Contracts to Parity UI.

Start Parity UI. In the contracts section press `Develop` button.
Select `0.4.18` Solidity compiler version. Set `Optimize` to `true`.
Select `0.4.23` Solidity compiler version. Set `Optimize` to `true`.

- In Parity UI `Contracts` tab choose watch custom contract. Paste bytecode and ABI of `PoaNetworkConsensus` contract from Remix.

Expand Down
4 changes: 2 additions & 2 deletions contracts/BallotsStorage.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.23;
import "./interfaces/IBallotsStorage.sol";
import "./interfaces/IProxyStorage.sol";
import "./interfaces/IPoaNetworkConsensus.sol";
Expand Down Expand Up @@ -63,7 +63,7 @@ contract BallotsStorage is EternalStorage, IBallotsStorage {
require(_newValue > 0);
require(_newValue != getBallotThreshold(_thresholdType));
_setThreshold(_newValue, _thresholdType);
ThresholdChanged(_thresholdType, _newValue);
emit ThresholdChanged(_thresholdType, _newValue);
}

function getBallotThreshold(uint8 _ballotType) public view returns(uint256) {
Expand Down
71 changes: 49 additions & 22 deletions contracts/KeysManager.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.23;

import "./libs/SafeMath.sol";
import "./interfaces/IPoaNetworkConsensus.sol";
Expand All @@ -12,11 +12,22 @@ contract KeysManager is EternalStorage, IKeysManager {

enum InitialKeyState {Invalid, Activated, Deactivated}

event PayoutKeyChanged(address key, address indexed miningKey, string action);
event VotingKeyChanged(address key, address indexed miningKey, string action);
event MiningKeyChanged(address key, string action);
event ValidatorInitialized(address indexed miningKey, address indexed votingKey, address indexed payoutKey);
event InitialKeyCreated(address indexed initialKey, uint256 time, uint256 initialKeysCount);
event VotingKeyChanged(address key, address indexed miningKey, string action);
event PayoutKeyChanged(address key, address indexed miningKey, string action);

event ValidatorInitialized(
address indexed miningKey,
address indexed votingKey,
address indexed payoutKey
);

event InitialKeyCreated(
address indexed initialKey,
uint256 time,
uint256 initialKeysCount
);

event Migrated(string name, address key);

modifier onlyOwner() {
Expand Down Expand Up @@ -120,7 +131,7 @@ contract KeysManager is EternalStorage, IKeysManager {
_setIsVotingActive(false, _masterOfCeremony);
_setIsPayoutActive(false, _masterOfCeremony);
_setSuccessfulValidatorClone(true, _masterOfCeremony);
Migrated("miningKey", _masterOfCeremony);
emit Migrated("miningKey", _masterOfCeremony);
if (_previousKeysManager != address(0)) {
_setPreviousKeysManager(_previousKeysManager);
IKeysManager previous = IKeysManager(_previousKeysManager);
Expand Down Expand Up @@ -153,7 +164,7 @@ contract KeysManager is EternalStorage, IKeysManager {
_setMiningKeyHistory(currentMiningKey, oldMiningKey);
currentMiningKey = oldMiningKey;
}
Migrated("miningKey", _miningKey);
emit Migrated("miningKey", _miningKey);
}

function migrateInitialKey(address _initialKey) public {
Expand All @@ -167,7 +178,7 @@ contract KeysManager is EternalStorage, IKeysManager {
status == uint8(InitialKeyState.Deactivated)
);
_setInitialKeyStatus(_initialKey, status);
Migrated("initialKey", _initialKey);
emit Migrated("initialKey", _initialKey);
}

function initiateKeys(address _initialKey) public {
Expand All @@ -180,13 +191,26 @@ contract KeysManager is EternalStorage, IKeysManager {
_setInitialKeyStatus(_initialKey, uint8(InitialKeyState.Activated));
_initialKeysCount = _initialKeysCount.add(1);
_setInitialKeysCount(_initialKeysCount);
InitialKeyCreated(_initialKey, getTime(), _initialKeysCount);
emit InitialKeyCreated(_initialKey, getTime(), _initialKeysCount);
}

function createKeys(address _miningKey, address _votingKey, address _payoutKey) public onlyValidInitialKey {
require(_miningKey != address(0) && _votingKey != address(0) && _payoutKey != address(0));
require(_miningKey != _votingKey && _miningKey != _payoutKey && _votingKey != _payoutKey);
require(_miningKey != msg.sender && _votingKey != msg.sender && _payoutKey != msg.sender);
function createKeys(
address _miningKey,
address _votingKey,
address _payoutKey
)
public
onlyValidInitialKey
{
require(_miningKey != address(0));
require(_votingKey != address(0));
require(_payoutKey != address(0));
require(_miningKey != _votingKey);
require(_miningKey != _payoutKey);
require(_votingKey != _payoutKey);
require(_miningKey != msg.sender);
require(_votingKey != msg.sender);
require(_payoutKey != msg.sender);
_setVotingKey(_votingKey, _miningKey);
_setPayoutKey(_payoutKey, _miningKey);
_setIsMiningActive(true, _miningKey);
Expand All @@ -195,7 +219,7 @@ contract KeysManager is EternalStorage, IKeysManager {
_setMiningKeyByVoting(_votingKey, _miningKey);
_setInitialKeyStatus(msg.sender, uint8(InitialKeyState.Deactivated));
IPoaNetworkConsensus(poaNetworkConsensus()).addValidator(_miningKey, true);
ValidatorInitialized(_miningKey, _votingKey, _payoutKey);
emit ValidatorInitialized(_miningKey, _votingKey, _payoutKey);
}

function getTime() public view returns(uint256) {
Expand Down Expand Up @@ -267,7 +291,10 @@ contract KeysManager is EternalStorage, IKeysManager {
_removePayoutKey(_miningKey);
}

function swapMiningKey(address _key, address _oldMiningKey) public onlyVotingToChangeKeys {
function swapMiningKey(address _key, address _oldMiningKey)
public
onlyVotingToChangeKeys
{
_setMiningKeyHistory(_key, _oldMiningKey);
address votingKey = getVotingByMining(_oldMiningKey);
require(isMiningActive(_oldMiningKey));
Expand All @@ -283,7 +310,7 @@ contract KeysManager is EternalStorage, IKeysManager {
_setIsVotingActive(false, _oldMiningKey);
_setIsPayoutActive(false, _oldMiningKey);
_setMiningKeyByVoting(votingKey, _key);
MiningKeyChanged(_key, "swapped");
emit MiningKeyChanged(_key, "swapped");
}

function swapVotingKey(address _key, address _miningKey) public onlyVotingToChangeKeys {
Expand Down Expand Up @@ -311,7 +338,7 @@ contract KeysManager is EternalStorage, IKeysManager {
_setIsVotingActive(false, _key);
_setIsPayoutActive(false, _key);
IPoaNetworkConsensus(poaNetworkConsensus()).addValidator(_key, true);
MiningKeyChanged(_key, "added");
emit MiningKeyChanged(_key, "added");
}

function _addVotingKey(address _key, address _miningKey) private {
Expand All @@ -324,7 +351,7 @@ contract KeysManager is EternalStorage, IKeysManager {
_setVotingKey(_key, _miningKey);
_setIsVotingActive(true, _miningKey);
_setMiningKeyByVoting(_key, _miningKey);
VotingKeyChanged(_key, _miningKey, "added");
emit VotingKeyChanged(_key, _miningKey, "added");
}
}

Expand All @@ -337,7 +364,7 @@ contract KeysManager is EternalStorage, IKeysManager {
} else {
_setPayoutKey(_key, _miningKey);
_setIsPayoutActive(true, _miningKey);
PayoutKeyChanged(_key, _miningKey, "added");
emit PayoutKeyChanged(_key, _miningKey, "added");
}
}

Expand All @@ -350,7 +377,7 @@ contract KeysManager is EternalStorage, IKeysManager {
_setIsVotingActive(false, _key);
_setIsPayoutActive(false, _key);
IPoaNetworkConsensus(poaNetworkConsensus()).removeValidator(_key, true);
MiningKeyChanged(_key, "removed");
emit MiningKeyChanged(_key, "removed");
}

function _removeVotingKey(address _miningKey) private {
Expand All @@ -359,15 +386,15 @@ contract KeysManager is EternalStorage, IKeysManager {
_setVotingKey(address(0), _miningKey);
_setIsVotingActive(false, _miningKey);
_setMiningKeyByVoting(oldVoting, address(0));
VotingKeyChanged(oldVoting, _miningKey, "removed");
emit VotingKeyChanged(oldVoting, _miningKey, "removed");
}

function _removePayoutKey(address _miningKey) private {
require(isPayoutActive(_miningKey));
address oldPayout = getPayoutByMining(_miningKey);
_setPayoutKey(address(0), _miningKey);
_setIsPayoutActive(false, _miningKey);
PayoutKeyChanged(oldPayout, _miningKey, "removed");
emit PayoutKeyChanged(oldPayout, _miningKey, "removed");
}

function _setMasterOfCeremony(address _moc) private {
Expand Down
4 changes: 2 additions & 2 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.23;


contract Migrations {
Expand All @@ -9,7 +9,7 @@ contract Migrations {
if (msg.sender == owner) _;
}

function Migrations() public {
constructor() public {
owner = msg.sender;
}

Expand Down
20 changes: 12 additions & 8 deletions contracts/PoaNetworkConsensus.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.23;

import "./interfaces/IPoaNetworkConsensus.sol";
import "./interfaces/IProxyStorage.sol";
Expand Down Expand Up @@ -57,7 +57,7 @@ contract PoaNetworkConsensus is IPoaNetworkConsensus {
_;
}

function PoaNetworkConsensus(address _masterOfCeremony, address[] validators) public {
constructor(address _masterOfCeremony, address[] validators) public {
// TODO: When you deploy this contract, make sure you hardcode items below
// Make sure you have those addresses defined in spec.json
require(_masterOfCeremony != address(0));
Expand Down Expand Up @@ -95,10 +95,14 @@ contract PoaNetworkConsensus is IPoaNetworkConsensus {
finalized = true;
currentValidators = pendingList;
currentValidatorsLength = currentValidators.length;
ChangeFinalized(getValidators());
emit ChangeFinalized(getValidators());
}

function addValidator(address _validator, bool _shouldFireEvent) public onlyKeysManager isNewValidator(_validator) {
function addValidator(address _validator, bool _shouldFireEvent)
public
onlyKeysManager
isNewValidator(_validator)
{
require(_validator != address(0));
validatorsState[_validator] = ValidatorState({
isValidator: true,
Expand All @@ -107,7 +111,7 @@ contract PoaNetworkConsensus is IPoaNetworkConsensus {
pendingList.push(_validator);
finalized = false;
if (_shouldFireEvent) {
InitiateChange(block.blockhash(block.number - 1), pendingList);
emit InitiateChange(blockhash(block.number - 1), pendingList);
}
}

Expand All @@ -130,15 +134,15 @@ contract PoaNetworkConsensus is IPoaNetworkConsensus {
validatorsState[_validator].isValidator = false;
finalized = false;
if (_shouldFireEvent) {
InitiateChange(block.blockhash(block.number - 1), pendingList);
emit InitiateChange(blockhash(block.number - 1), pendingList);
}
}

function swapValidatorKey(address _newKey, address _oldKey) public onlyKeysManager {
require(isValidator(_oldKey));
removeValidator(_oldKey, false);
addValidator(_newKey, false);
InitiateChange(block.blockhash(block.number - 1), pendingList);
emit InitiateChange(blockhash(block.number - 1), pendingList);
}

function setProxyStorage(address _newAddress) public {
Expand All @@ -148,7 +152,7 @@ contract PoaNetworkConsensus is IPoaNetworkConsensus {
require(_newAddress != address(0));
proxyStorage = IProxyStorage(_newAddress);
isMasterOfCeremonyInitialized = true;
MoCInitializedProxyStorage(proxyStorage);
emit MoCInitializedProxyStorage(proxyStorage);
}

function isValidator(address _someone) public view returns(bool) {
Expand Down
6 changes: 3 additions & 3 deletions contracts/ProxyStorage.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.4.23;

import "./interfaces/IProxyStorage.sol";
import "./interfaces/IPoaNetworkConsensus.sol";
Expand Down Expand Up @@ -107,7 +107,7 @@ contract ProxyStorage is EternalStorage, IProxyStorage {
addressStorage[keccak256("validatorMetadataEternalStorage")] =
_validatorMetadataEternalStorage;
boolStorage[keccak256("mocInitialized")] = true;
ProxyInitialized(
emit ProxyInitialized(
_keysManagerEternalStorage,
_votingToChangeKeysEternalStorage,
_votingToChangeMinThresholdEternalStorage,
Expand Down Expand Up @@ -151,7 +151,7 @@ contract ProxyStorage is EternalStorage, IProxyStorage {
} else if (_contractType == uint8(ContractTypes.ProxyStorage)) {
IEternalStorageProxy(this).upgradeTo(_contractAddress);
}
AddressSet(_contractType, _contractAddress);
emit AddressSet(_contractType, _contractAddress);
}

function isValidator(address _validator) public view returns(bool) {
Expand Down
Loading

0 comments on commit 9fef157

Please sign in to comment.