Skip to content

Commit

Permalink
improved init code
Browse files Browse the repository at this point in the history
  • Loading branch information
mudgen committed Sep 14, 2020
1 parent 1545296 commit f2fd54b
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions contracts/facets/DiamondCutFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,23 @@ contract DiamondCutFacet is IDiamondCut {
) external override {
externalCut(_diamondCut);
emit DiamondCut(_diamondCut, _init, _calldata);
if (_calldata.length > 0) {
if (_init != address(0)) {
LibDiamondCut.hasContractCode(_init, "DiamondFacet: _init address has no code");
} else {
_init = address(this);
if (_init == address(0)) {
require(_calldata.length == 0, "DiamondCutFacet: _init is address(0) but_calldata is not empty");
} else {
require(_calldata.length > 0, "DiamondCutFacet: _calldata is empty but _init is not address(0)");
if (_init != address(this)) {
LibDiamondCut.hasContractCode(_init, "DiamondCutFacet: _init address has no code");
}
(bool success, bytes memory error) = _init.delegatecall(_calldata);
if (!success) {
if (error.length > 0) {
// bubble up the error
revert(string(error));
} else {
revert("DiamondFacet: _init function reverted");
revert("DiamondCutFacet: _init function reverted");
}
}
} else if (_init != address(0)) {
// If _init is not address(0) but calldata is empty
revert("DiamondFacet: _calldata is empty");
}
// if _calldata is empty and _init is address(0)
// then skip any initialization
}

// diamondCut helper function
Expand Down

0 comments on commit f2fd54b

Please sign in to comment.