- <b>contract StorageStructure {
- address public implementation;: `+ o' a5 F! f% Y9 C
- address public owner;
- mapping (address => uint) internal points;
- uint internal totalPlayers; i9 L, u7 l5 k* w5 I! q+ u9 x
- }</b>
- contract ImplementationV1 is StorageStructure {
- modifier onlyOwner() {: N5 x, ?3 [6 X9 B. y: L
- require (msg.sender == owner);+ N2 X/ T; J1 Z. [5 J/ J
- _;0 x* t4 h; V- S* i
- }
- function addPlayer(address _player, uint _points), y1 ^# F, Z% \
- public onlyOwner3 O% D' E; N0 k9 A0 R
- {4 D! Q4 Q5 R p/ U
- require (points[_player] == 0);9 X+ e1 N* ~, x" l& \
- points[_player] = _points;
- }
- function setPoints(address _player, uint _points)
- public onlyOwner% I/ I3 V* b" |5 i, f4 _$ ]* x
- {. `4 ^/ ]0 ~' g# l. G
- require (points[_player] != 0);, Q2 m2 C K- V$ K& b- c# q
- points[_player] = _points;
- }! D8 V# W( Q& ~3 {" I l
- }
- contract Proxy is StorageStructure {
- modifier onlyOwner() {$ o' x. C0 y4 L. f$ J
- require (msg.sender == owner);
- _;
- }
- /**
- * @dev constructor that sets the owner address
- */5 O) Z( W7 q9 a3 W- Q
- constructor() public {0 U- K; v. U. T7 |+ Z: ?
- owner = msg.sender;
- }
- /**8 m7 x1 k7 R! k
- * @dev Upgrades the implementation address$ R0 E% ^! k6 u, Q/ V! w
- * @param _newImplementation address of the new implementation
- */$ w3 F* e+ R$ l+ F- k3 |
- function upgradeTo(address _newImplementation)
- external onlyOwner) ?4 l' F* b4 N, o
- {+ b7 o6 R) n. _7 O8 A
- require(implementation != _newImplementation); V' k. H- k) X
- _setImplementation(_newImplementation);# {1 y# d' s; O: n! Y1 Y( ~; p7 x f
- }
- /**
- * @dev Fallback function allowing to perform a delegatecall
- * to the given implementation. This function will return2 H' e W% s7 G9 h5 r9 U1 t
- * whatever the implementation call returns
- */
- function () payable public {
- address impl = implementation;
- require(impl != address(0));
- assembly {
- let ptr := mload(0x40)# W& M* w4 a+ W& u; i
- calldatacopy(ptr, 0, calldatasize)
- let result := delegatecall(gas, impl, ptr, calldatasize, 0, 0)) P* c& J& C! W9 N; V# f
- let size := returndatasize& |, W* u& Z W: K
- returndatacopy(ptr, 0, size)
- switch result9 m L& R/ Z! N$ j9 T4 d2 V
- case 0 { revert(ptr, size) }
- default { return(ptr, size) }
- }
- }6 i. H, u1 H$ n
- # x; ^! x+ U3 Q. c. o1 |
- /**
- * @dev Sets the address of the current implementation
- * @param _newImp address of the new implementation5 }( r. a+ N; m, K" F/ v- t
- */ _0 l+ R$ y; k5 b. J9 V% X
- function _setImplementation(address _newImp) internal {$ q* s- X4 i: ~1 r2 |. E- Z
- implementation = _newImp;6 b0 C8 Z* F, e9 [
- }
- }
- contract ImplementationV2 is ImplementationV1 {' O, B9 `. |. I
- " O7 Y7 v) B% o0 e3 B; z
- function addPlayer(address _player, uint _points)) T4 X/ p- |5 [5 o
- public onlyOwner5 `; s1 T3 j9 D1 [: k2 u
- {0 a. x/ s" ]6 c1 S$ u/ l ]1 E
- require (points[_player] == 0);7 A4 o2 E) a5 e) Y4 r
- points[_player] = _points;
- totalPlayers++;. D, ~) A! X9 G0 M! M$ K- j
- }
- }
- contract UnstructuredProxy {
- " r" [% V6 l) i2 l
- // Storage position of the address of the current implementation! E$ N I2 v* z" P7 h1 P8 P
- bytes32 private constant implementationPosition =
- keccak256("org.govblocks.implementation.address");) k% z2 h7 O) _2 d% l0 v
- // Storage position of the owner of the contract
- bytes32 private constant proxyOwnerPosition =
- keccak256("org.govblocks.proxy.owner");
- /*** u. ?9 M/ r- e" K, w" j" w
- * @dev Throws if called by any account other than the owner.' ~0 } \% ^: K6 s0 y
- */
- modifier onlyProxyOwner() {4 b+ D9 V! n+ W0 B$ _# I, [! h
- require (msg.sender == proxyOwner());$ ^6 q$ W, C0 R; U3 t+ M
- _;
- }1 g' v" W8 w1 ?5 h
- /**- h' Q% T, e$ `5 G7 i5 |
- * @dev the constructor sets owner0 _/ |4 c/ [$ ?9 i; C4 b$ r
- */( Z* ~. j+ ?! r! W
- constructor() public {
- _setUpgradeabilityOwner(msg.sender);
- }
- /**, K: \7 t; _) o) k0 C4 o
- * @dev Allows the current owner to transfer ownership( d: e4 }+ f3 y
- * @param _newOwner The address to transfer ownership to% R2 o/ z2 t) ^ o k
- */
- function transferProxyOwnership(address _newOwner)
- public onlyProxyOwner8 s! I1 l" ^4 N; L4 b: @7 I
- {
- require(_newOwner != address(0));
- _setUpgradeabilityOwner(_newOwner);
- }
- /**
- * @dev Allows the proxy owner to upgrade the implementation' h0 |$ D, c( B4 I9 n: N }
- * @param _implementation address of the new implementation
- */: C; S; A( H; p
- function upgradeTo(address _implementation): M4 k% c; @: i5 d
- public onlyProxyOwner& ^! w$ c. k/ Y V/ |7 d4 \
- {
- _upgradeTo(_implementation);
- }
- /**
- * @dev Tells the address of the current implementation
- * @return address of the current implementation g1 n! j5 s: G% H1 s& j
- */6 G1 _2 E# o) g
- function implementation() public view returns (address impl) {
- bytes32 position = implementationPosition;
- assembly {+ ]! V/ T" X x& ]1 N5 q
- impl := sload(position)
- }6 D/ W: H" [: }$ K
- }
- /**
- * @dev Tells the address of the owner9 H4 |. X+ U) a& z" A; I
- * @return the address of the owner
- */
- function proxyOwner() public view returns (address owner) {
- bytes32 position = proxyOwnerPosition;
- assembly {
- owner := sload(position)
- }. Z3 v- z0 ]# N* @! p
- }0 x# U* k8 @, a: L; \
- /*** P6 L8 C( s' G! U4 @$ \7 e6 y
- * @dev Sets the address of the current implementation6 ?7 ]# @( Q0 w z4 J
- * @param _newImplementation address of the new implementation
- */
- function _setImplementation(address _newImplementation)3 h* w0 M8 |" \1 G7 O1 l5 N
- internal
- {
- bytes32 position = implementationPosition;
- assembly {; R* V7 [( d( m$ m
- sstore(position, _newImplementation)( _, `2 X" B* {) ~; q5 F z0 X
- }4 B F2 G6 ]4 C/ X( W
- }- Z1 r( K% w0 D; _2 T
- /**! y y7 L8 ]0 Q4 p" J% o; f
- * @dev Upgrades the implementation address
- * @param _newImplementation address of the new implementation
- */
- function _upgradeTo(address _newImplementation) internal {# G. W1 u' l! M; ?3 @& G4 q9 k
- address currentImplementation = implementation();
- require(currentImplementation != _newImplementation);2 ?. V4 I: g- F9 M/ H
- _setImplementation(_newImplementation);' {4 x; @; J, {* M! P
- }
- # b9 N N: j* ^
- /**
- * @dev Sets the address of the owner6 @" Y" g/ t- d& b4 }8 }, c. ?( `. F
- */
- function _setUpgradeabilityOwner(address _newProxyOwner)7 x% [0 X {! R
- internal
- {5 {$ u# e6 y4 S ^/ s V
- bytes32 position = proxyOwnerPosition;( S( j# h0 D G, c" A: t; E* c
- assembly {% Z* T$ x$ W/ L% a, ]
- sstore(position, _newProxyOwner)8 R1 I4 A9 T" N `
- }
- }0 E& g; {+ @% _, O) W, F
- }
- contract ImplementationV1 {
- address public owner;
- mapping (address => uint) internal points;
- modifier onlyOwner() {
- require (msg.sender == owner);/ N' `7 U2 b* Z- G1 C. x
- _;$ W: `4 q) A" C% u) Q
- }" n8 {. x+ i/ a3 H
- function initOwner() external {+ E6 H) N( a3 C7 V6 {6 E# k# W
- require (owner == address(0));
- owner = msg.sender;
- }
- function addPlayer(address _player, uint _points), o2 s' B# U! [& j
- public onlyOwner
- {- [, Z/ }1 N1 t7 N' x1 v
- require (points[_player] == 0);
- points[_player] = _points;) y/ W! i; I( b. l0 D5 K% V* x
- }) U3 v" }( f7 V# I. R8 R8 j# @
- function setPoints(address _player, uint _points)
- public onlyOwner( u2 n+ R, H9 t1 Y- E0 ?4 R
- {6 c; h( X: v' X4 y* O: Q! c
- require (points[_player] != 0);, w: s* b; q0 G' ]2 F" o6 F
- points[_player] = _points;
- }
- }
- contract ImplementationV2 is ImplementationV1 {
- uint public totalPlayers;
- 9 r/ n4 \) Y* G: D
- - @' e3 q, K4 i2 m+ J e) z) p
- function addPlayer(address _player, uint _points)
- public onlyOwner8 V3 x; A1 l% T* X6 O. _& ]
- {! H5 k: b4 o" c
- require (points[_player] == 0);
- points[_player] = _points;* L( D! y. b) z0 [
- totalPlayers++; f- X t! n$ R# Y3 X/ G
- }
- }