Skip to content

Commit

Permalink
Refactor how AddressUtils is used
Browse files Browse the repository at this point in the history
  • Loading branch information
patitonar committed Jul 31, 2019
1 parent a6e4134 commit fe66d3f
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 32 deletions.
8 changes: 3 additions & 5 deletions contracts/ERC677BridgeToken.sol
Expand Up @@ -8,8 +8,6 @@ import "./interfaces/IBurnableMintableERC677Token.sol";
import "./upgradeable_contracts/Claimable.sol";

contract ERC677BridgeToken is IBurnableMintableERC677Token, DetailedERC20, BurnableToken, MintableToken, Claimable {
using AddressUtils for address;

address public bridgeContract;

event ContractFallbackCallFailed(address from, address to, uint256 value);
Expand All @@ -19,7 +17,7 @@ contract ERC677BridgeToken is IBurnableMintableERC677Token, DetailedERC20, Burna
}

function setBridgeContract(address _bridgeContract) external onlyOwner {
require(_bridgeContract.isContract());
require(AddressUtils.isContract(_bridgeContract));
bridgeContract = _bridgeContract;
}

Expand All @@ -32,7 +30,7 @@ contract ERC677BridgeToken is IBurnableMintableERC677Token, DetailedERC20, Burna
require(superTransfer(_to, _value));
emit Transfer(msg.sender, _to, _value, _data);

if (_to.isContract()) {
if (AddressUtils.isContract(_to)) {
require(contractFallback(msg.sender, _to, _value, _data));
}
return true;
Expand All @@ -59,7 +57,7 @@ contract ERC677BridgeToken is IBurnableMintableERC677Token, DetailedERC20, Burna
}

function callAfterTransfer(address _from, address _to, uint256 _value) internal {
if (_to.isContract() && !contractFallback(_from, _to, _value, new bytes(0))) {
if (AddressUtils.isContract(_to) && !contractFallback(_from, _to, _value, new bytes(0))) {
require(_to != bridgeContract);
emit ContractFallbackCallFailed(_from, _to, _value);
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/ERC677BridgeTokenRewardable.sol
Expand Up @@ -11,12 +11,12 @@ contract ERC677BridgeTokenRewardable is ERC677BridgeToken {
}

function setBlockRewardContract(address _blockRewardContract) external onlyOwner {
require(_blockRewardContract.isContract());
require(AddressUtils.isContract(_blockRewardContract));
blockRewardContract = _blockRewardContract;
}

function setStakingContract(address _stakingContract) external onlyOwner {
require(_stakingContract.isContract());
require(AddressUtils.isContract(_stakingContract));
stakingContract = _stakingContract;
}

Expand Down
4 changes: 1 addition & 3 deletions contracts/upgradeability/UpgradeabilityProxy.sol
Expand Up @@ -9,8 +9,6 @@ import "./UpgradeabilityStorage.sol";
* @dev This contract represents a proxy where the implementation address to which it will delegate can be upgraded
*/
contract UpgradeabilityProxy is Proxy, UpgradeabilityStorage {
using AddressUtils for address;

/**
* @dev This event will be emitted every time the implementation gets upgraded
* @param version representing the version name of the upgraded implementation
Expand All @@ -25,7 +23,7 @@ contract UpgradeabilityProxy is Proxy, UpgradeabilityStorage {
*/
function _upgradeTo(uint256 version, address implementation) internal {
require(_implementation != implementation);
require(implementation.isContract());
require(AddressUtils.isContract(implementation));
require(version > _version);
_version = version;
_implementation = implementation;
Expand Down
1 change: 0 additions & 1 deletion contracts/upgradeable_contracts/BasicBridge.sol
Expand Up @@ -11,7 +11,6 @@ import "./Claimable.sol";

contract BasicBridge is EternalStorage, Validatable, Ownable, Upgradeable, Claimable {
using SafeMath for uint256;
using AddressUtils for address;

event GasPriceChanged(uint256 gasPrice);
event RequiredBlockConfirmationChanged(uint256 requiredBlockConfirmations);
Expand Down
2 changes: 1 addition & 1 deletion contracts/upgradeable_contracts/ERC677Bridge.sol
Expand Up @@ -9,7 +9,7 @@ contract ERC677Bridge is BasicBridge {
}

function setErc677token(address _token) internal {
require(_token.isContract());
require(AddressUtils.isContract(_token));
addressStorage[keccak256(abi.encodePacked("erc677token"))] = _token;
}

Expand Down
4 changes: 1 addition & 3 deletions contracts/upgradeable_contracts/RewardableBridge.sol
Expand Up @@ -5,8 +5,6 @@ import "./Ownable.sol";
import "./FeeTypes.sol";

contract RewardableBridge is Ownable, FeeTypes {
using AddressUtils for address;

event FeeDistributedFromAffirmation(uint256 feeAmount, bytes32 indexed transactionHash);
event FeeDistributedFromSignatures(uint256 feeAmount, bytes32 indexed transactionHash);

Expand Down Expand Up @@ -49,7 +47,7 @@ contract RewardableBridge is Ownable, FeeTypes {
}

function setFeeManagerContract(address _feeManager) external onlyOwner {
require(_feeManager == address(0) || _feeManager.isContract());
require(_feeManager == address(0) || AddressUtils.isContract(_feeManager));
addressStorage[keccak256(abi.encodePacked("feeManagerContract"))] = _feeManager;
}

Expand Down
Expand Up @@ -15,7 +15,7 @@ contract BasicForeignBridgeErcToErc is BasicForeignBridge {
address _owner
) internal {
require(!isInitialized());
require(_validatorContract.isContract());
require(AddressUtils.isContract(_validatorContract));
require(_requiredBlockConfirmations != 0);
require(_gasPrice > 0);
require(_homeMaxPerTx < _homeDailyLimit);
Expand Down
Expand Up @@ -4,8 +4,6 @@ import "openzeppelin-solidity/contracts/AddressUtils.sol";
import "../BlockRewardFeeManager.sol";

contract FeeManagerErcToErcPOSDAO is BlockRewardFeeManager {
using AddressUtils for address;

function getFeeManagerMode() external pure returns (bytes4) {
return bytes4(keccak256(abi.encodePacked("manages-both-directions")));
}
Expand All @@ -15,7 +13,7 @@ contract FeeManagerErcToErcPOSDAO is BlockRewardFeeManager {
}

function setBlockRewardContract(address _blockReward) external {
require(_blockReward.isContract());
require(AddressUtils.isContract(_blockReward));

// Before store the contract we need to make sure that it is the block reward contract in actual fact,
// call a specific method from the contract that should return a specific value
Expand Down
Expand Up @@ -31,7 +31,7 @@ contract ForeignBridgeErcToErc is BasicForeignBridgeErcToErc {
}

function setErc20token(address _token) internal {
require(_token.isContract());
require(AddressUtils.isContract(_token));
addressStorage[keccak256(abi.encodePacked("erc20token"))] = _token;
}
}
Expand Up @@ -110,7 +110,7 @@ contract HomeBridgeErcToErc is
_foreignMaxPerTx,
_owner
);
require(_feeManager.isContract());
require(AddressUtils.isContract(_feeManager));
addressStorage[keccak256(abi.encodePacked("feeManagerContract"))] = _feeManager;
_setFee(_feeManager, _homeFee, HOME_FEE);
_setFee(_feeManager, _foreignFee, FOREIGN_FEE);
Expand All @@ -129,7 +129,7 @@ contract HomeBridgeErcToErc is
address _owner
) internal {
require(!isInitialized());
require(_validatorContract.isContract());
require(AddressUtils.isContract(_validatorContract));
require(_requiredBlockConfirmations > 0);
require(_minPerTx > 0 && _maxPerTx > _minPerTx && _dailyLimit > _maxPerTx);
require(_foreignMaxPerTx < _foreignDailyLimit);
Expand Down
Expand Up @@ -19,7 +19,7 @@ contract ForeignBridgeErcToNative is BasicForeignBridge {
address _owner
) external returns (bool) {
require(!isInitialized());
require(_validatorContract.isContract());
require(AddressUtils.isContract(_validatorContract));
require(_requiredBlockConfirmations != 0);
require(_gasPrice > 0);
require(_homeMaxPerTx < _homeDailyLimit);
Expand Down Expand Up @@ -60,7 +60,7 @@ contract ForeignBridgeErcToNative is BasicForeignBridge {
}

function setErc20token(address _token) private {
require(_token.isContract());
require(AddressUtils.isContract(_token));
addressStorage[keccak256(abi.encodePacked("erc20token"))] = _token;
}

Expand Down
Expand Up @@ -93,7 +93,7 @@ contract HomeBridgeErcToNative is EternalStorage, BasicHomeBridge, OverdrawManag
_foreignMaxPerTx,
_owner
);
require(_feeManager.isContract());
require(AddressUtils.isContract(_feeManager));
addressStorage[keccak256(abi.encodePacked("feeManagerContract"))] = _feeManager;
_setFee(_feeManager, _homeFee, HOME_FEE);
_setFee(_feeManager, _foreignFee, FOREIGN_FEE);
Expand All @@ -115,7 +115,7 @@ contract HomeBridgeErcToNative is EternalStorage, BasicHomeBridge, OverdrawManag
}

function setBlockRewardContract(address _blockReward) external onlyOwner {
require(_blockReward.isContract());
require(AddressUtils.isContract(_blockReward));

// Before store the contract we need to make sure that it is the block reward contract in actual fact,
// call a specific method from the contract that should return a specific value
Expand Down Expand Up @@ -143,10 +143,10 @@ contract HomeBridgeErcToNative is EternalStorage, BasicHomeBridge, OverdrawManag
address _owner
) internal {
require(!isInitialized());
require(_validatorContract.isContract());
require(AddressUtils.isContract(_validatorContract));
require(_requiredBlockConfirmations > 0);
require(_minPerTx > 0 && _maxPerTx > _minPerTx && _dailyLimit > _maxPerTx);
require(_blockReward == address(0) || _blockReward.isContract());
require(_blockReward == address(0) || AddressUtils.isContract(_blockReward));
require(_foreignMaxPerTx < _foreignDailyLimit);
require(_owner != address(0));
addressStorage[keccak256(abi.encodePacked("validatorContract"))] = _validatorContract;
Expand Down
Expand Up @@ -70,7 +70,7 @@ contract ForeignBridgeNativeToErc is
_homeMaxPerTx,
_owner
);
require(_feeManager.isContract());
require(AddressUtils.isContract(_feeManager));
addressStorage[keccak256(abi.encodePacked("feeManagerContract"))] = _feeManager;
_setFee(_feeManager, _homeFee, HOME_FEE);
setInitialize();
Expand Down Expand Up @@ -98,7 +98,7 @@ contract ForeignBridgeNativeToErc is
address _owner
) internal {
require(!isInitialized());
require(_validatorContract.isContract());
require(AddressUtils.isContract(_validatorContract));
require(_minPerTx > 0 && _maxPerTx > _minPerTx && _dailyLimit > _maxPerTx);
require(_requiredBlockConfirmations > 0);
require(_foreignGasPrice > 0);
Expand Down
Expand Up @@ -76,7 +76,7 @@ contract HomeBridgeNativeToErc is EternalStorage, BasicHomeBridge, RewardableHom
_foreignMaxPerTx,
_owner
);
require(_feeManager.isContract());
require(AddressUtils.isContract(_feeManager));
addressStorage[keccak256(abi.encodePacked("feeManagerContract"))] = _feeManager;
_setFee(_feeManager, _homeFee, HOME_FEE);
_setFee(_feeManager, _foreignFee, FOREIGN_FEE);
Expand All @@ -100,7 +100,7 @@ contract HomeBridgeNativeToErc is EternalStorage, BasicHomeBridge, RewardableHom
address _owner
) internal {
require(!isInitialized());
require(_validatorContract.isContract());
require(AddressUtils.isContract(_validatorContract));
require(_homeGasPrice > 0);
require(_requiredBlockConfirmations > 0);
require(_minPerTx > 0 && _maxPerTx > _minPerTx && _dailyLimit > _maxPerTx);
Expand Down

0 comments on commit fe66d3f

Please sign in to comment.