-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathproxy_storage.sol
More file actions
31 lines (26 loc) · 1.18 KB
/
proxy_storage.sol
File metadata and controls
31 lines (26 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
contract Version1 { event LogStr(string);string public V;function version() external { V="Version1";emit LogStr(V); }}
contract Version2 { event LogStr(string);string public V;function version() external { V="Version2";emit LogStr(V); }}
contract Proxy_Storage {
bytes32 private constant implementationPosition = keccak256("web3examples");
string public V="proxy";
event LogAdr(address);
function setV1() public { SetRelay(address(new Version1())); }
function setV2() public { SetRelay(address(new Version2())); }
function SetRelay(address newVersion) public {
bytes32 slot = implementationPosition;
assembly { sstore(slot, newVersion) }
}
function GetRelay() public view returns(address implementation) {
bytes32 slot = implementationPosition;
assembly { implementation := sload(slot) }
}
fallback() external payable {
address implementation = GetRelay();
emit LogAdr(implementation);
(bool success, /*bytes memory data*/)=implementation.delegatecall(msg.data);
require(success,"error");
}
receive() external payable {}
}