Last active
November 19, 2021 13:29
-
-
Save mfornet/5dbb67cba05e0cffd7e3a923b43a17ea to your computer and use it in GitHub Desktop.
Multicontract Update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: CC0-1.0 | |
pragma solidity ^0.8.7; | |
interface Router { | |
function get_implementatino_address() external returns (address); | |
} | |
contract Front { | |
Router router; | |
uint value; | |
constructor(Router _router) { | |
router = _router; | |
} | |
/// Use this function to call functions in the implementation | |
function makeCall(bytes memory data) public payable returns (bytes memory) | |
{ | |
address implementation = router.get_implementatino_address(); | |
(bool success, bytes memory rdata) = implementation.delegatecall(data); | |
require(success); | |
return rdata; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: CC0-1.0 | |
pragma solidity ^0.8.7; | |
interface Router { | |
function get_implementatino_address() external returns (address); | |
} | |
contract Implementation { | |
/// Must have the same layout as Front | |
Router router; | |
uint value; | |
// Doesn't need a constructor | |
function updateValue() public { | |
value += 1; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: CC0-1.0 | |
pragma solidity ^0.8.7; | |
contract Router { | |
address implementation; | |
constructor(address _implementation) { | |
implementation = _implementation; | |
} | |
function get_implementatino_address() public view returns (address) { | |
return implementation; | |
} | |
/// Call this function for upgrading the contracts using this router | |
/// Make sure this function can only be called by owner. | |
function set_implementation_address(address _implementation) public { | |
implementation = _implementation; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment