- <b>contract StorageStructure {
- address public implementation;
- address public owner;
- mapping (address => uint) internal points;
- uint internal totalPlayers;3 b) t3 G4 U2 {" E" F
- }</b>
- contract ImplementationV1 is StorageStructure {. L4 H3 Q2 y2 ^+ p7 z
- modifier onlyOwner() {( \6 C: F1 t( e! A- x- c
- require (msg.sender == owner);0 W% ~- y( o1 R" m, z& K& Y1 o3 C
- _;
- }
- function addPlayer(address _player, uint _points)
- public onlyOwner
- {
- require (points[_player] == 0);
- points[_player] = _points; }6 _" x; i1 v l: u
- }
- function setPoints(address _player, uint _points)6 N' h* J% a: |
- public onlyOwner- U6 b* x( H# u9 F% R5 n
- {6 @5 D: p M2 d% B7 @
- require (points[_player] != 0);
- points[_player] = _points;) K' u; P$ g6 w* d G/ N
- }: I" V) G/ p4 P6 R0 w5 L/ v6 i
- }
- contract Proxy is StorageStructure {" t# c, }8 k/ V; I$ u
- / V. m( B" v+ G: i' Z6 s1 E6 D& z
- modifier onlyOwner() {: t, F- }6 ]4 f0 }. o5 Z( O J
- require (msg.sender == owner);
- _;: s& e* @! E0 v
- }" l3 T( L* p0 V* O3 ^# t
- /**
- * @dev constructor that sets the owner address
- */3 Z$ z! ]- C, z; h- b
- constructor() public {! [( @4 ]+ l r- e% P [' E
- owner = msg.sender;
- }: n- X* I1 l. o' ?
- /**. I) U7 J' V1 ?* y8 I
- * @dev Upgrades the implementation address6 J5 D8 a' q3 g3 M- B* j) h7 {
- * @param _newImplementation address of the new implementation% `0 g( l, A: T1 f( P
- */# s0 n* s8 s7 O# X! R2 j
- function upgradeTo(address _newImplementation)* q# |5 q4 C6 U: P7 Y. ~
- external onlyOwner+ b" c9 z8 Y& N. x `5 Z
- {
- require(implementation != _newImplementation);9 c+ a; q8 }- ^7 _) }5 f# M0 a
- _setImplementation(_newImplementation);
- }
- /**
- * @dev Fallback function allowing to perform a delegatecall1 _% P/ f7 G4 a
- * to the given implementation. This function will return
- * whatever the implementation call returns
- */
- function () payable public {
- address impl = implementation;
- require(impl != address(0));
- assembly {" h2 J1 L* i( M
- let ptr := mload(0x40)/ i' |7 b6 F q/ g T
- calldatacopy(ptr, 0, calldatasize), b: u1 d5 n7 n: j' c* M4 n9 I* b
- let result := delegatecall(gas, impl, ptr, calldatasize, 0, 0) i! ?" P7 y* V7 ?) S
- let size := returndatasize
- returndatacopy(ptr, 0, size)
- switch result
- case 0 { revert(ptr, size) }; }! Q- g" ?: u) |/ _! u
- default { return(ptr, size) }$ d& N+ M$ A& m; m
- }: i" s9 j) o% m/ b% \( c; I
- }4 V2 ^6 u- t4 W- f
- /*** v1 {, e$ a% V3 \8 m; j8 ~# H0 f
- * @dev Sets the address of the current implementation- \- H/ E5 x) @9 g2 F3 r' y& |
- * @param _newImp address of the new implementation
- */
- function _setImplementation(address _newImp) internal {9 G1 p) B5 i. f* \9 ?
- implementation = _newImp;
- }) F3 E8 w( [" Z! v' A# F" p
- }
- contract ImplementationV2 is ImplementationV1 {
- function addPlayer(address _player, uint _points)5 N1 K8 }! `$ L& \, j
- public onlyOwner$ w3 h, ]6 q' p
- {8 x. A' z) \' w* j8 y+ S/ |
- require (points[_player] == 0);! O3 G% e+ y" G$ M' `* e7 w
- points[_player] = _points;
- totalPlayers++;0 a# ]6 l2 j; I$ o
- }
- }
- contract UnstructuredProxy {' y w/ b5 E/ r
- ' w$ E) ~$ Q5 \
- // Storage position of the address of the current implementation
- bytes32 private constant implementationPosition =4 S0 \, z( E7 N2 [5 Z( H' B
- keccak256("org.govblocks.implementation.address");. O$ m: @) _, O; F K
- // Storage position of the owner of the contract
- bytes32 private constant proxyOwnerPosition =& e) t1 F: \+ D8 K
- keccak256("org.govblocks.proxy.owner");
- /**
- * @dev Throws if called by any account other than the owner.- e( q$ r# m6 @! G* h' t
- */
- modifier onlyProxyOwner() {
- require (msg.sender == proxyOwner());/ Y& n6 G! |( [6 R- x2 R
- _;
- } c& u+ J, {3 l9 x. \
- /**
- * @dev the constructor sets owner7 P |# O9 q3 l# a1 l
- */
- constructor() public {
- _setUpgradeabilityOwner(msg.sender);+ f3 f5 I& ~5 d4 u- D; h
- }6 i0 C' \' j; U. p+ j$ X* _- f
- /**" x, X3 e" t/ E' C& `& Q" \; r o
- * @dev Allows the current owner to transfer ownership$ N9 ]& L! Y" k+ n3 z
- * @param _newOwner The address to transfer ownership to
- */8 J: s- Z+ X- n' ]2 r3 h
- function transferProxyOwnership(address _newOwner)/ B( f9 W" }; d, [( h' e
- public onlyProxyOwner
- { I; ^+ J$ S i W- n: B. m
- require(_newOwner != address(0));& Q( U( o3 e1 j* \/ ~: q1 G
- _setUpgradeabilityOwner(_newOwner);! W5 a/ B. _- a% g1 m& B
- }! I, `% F! N) |
- /**: y3 p! W& @% |
- * @dev Allows the proxy owner to upgrade the implementation% Z# I/ \& V$ ^, K% h
- * @param _implementation address of the new implementation* ?9 d3 u! h' W' c) `4 a
- */) r! L# E8 T( o: M( \3 n
- function upgradeTo(address _implementation)
- public onlyProxyOwner
- {
- _upgradeTo(_implementation);. w& a% W7 P* s7 G& o" y
- }; b1 L. K1 O' y- F
- /**
- * @dev Tells the address of the current implementation' ^+ P/ \5 l% E9 w
- * @return address of the current implementation
- */
- function implementation() public view returns (address impl) {" E! e; W3 G. [+ O2 a8 h
- bytes32 position = implementationPosition;& g ^. p( ^& P
- assembly {3 c+ B% _5 f! G6 v) h# S* P
- impl := sload(position)
- }
- }
- /**
- * @dev Tells the address of the owner
- * @return the address of the owner+ s- E( m3 N8 s# }/ ]1 K& k
- */1 b/ [& H& M: [7 P
- function proxyOwner() public view returns (address owner) {6 n3 w. o1 M. l2 V- P
- bytes32 position = proxyOwnerPosition;- C$ W3 {" ^7 T+ S0 o# E4 x
- assembly {5 ?" N& D0 B- F1 k
- owner := sload(position)$ p f: F1 l3 {5 Y A3 }, n: H
- }, y/ F) b [) D3 B
- }* K* [- i- Y) H. N/ L
- /**
- * @dev Sets the address of the current implementation
- * @param _newImplementation address of the new implementation- k5 `7 F {: h/ \9 I* a
- */
- function _setImplementation(address _newImplementation)
- internal
- {
- bytes32 position = implementationPosition;
- assembly {
- sstore(position, _newImplementation)
- }9 p1 S4 l8 \- H/ y3 }* a2 ?
- }
- /**/ X9 ]* `/ a3 w
- * @dev Upgrades the implementation address
- * @param _newImplementation address of the new implementation1 v+ p+ M5 ~$ @3 d6 p1 }
- */
- function _upgradeTo(address _newImplementation) internal {
- address currentImplementation = implementation();
- require(currentImplementation != _newImplementation);
- _setImplementation(_newImplementation);
- }% G' i4 q) B3 A8 J
- /**
- * @dev Sets the address of the owner
- */% w% e7 w5 }' `1 T# S. c
- function _setUpgradeabilityOwner(address _newProxyOwner)
- internal
- {+ F0 ^ r e# C+ g. h6 F
- bytes32 position = proxyOwnerPosition;# h! w+ d- W1 n# }/ g
- assembly {. h0 B" l" A8 W3 V3 ~- l
- sstore(position, _newProxyOwner), W! _! _# L3 j5 v! F
- }
- }
- }
- contract ImplementationV1 {4 a5 S; ^! c7 P* }0 [/ O! L' Q! e+ e
- address public owner;4 }5 t2 I) w' b. [# C
- mapping (address => uint) internal points;
- modifier onlyOwner() {3 m6 @) N0 O7 g+ w( n0 A' ^. ]) V* R( R
- require (msg.sender == owner);* W" X- ?$ m( h G0 {9 P) Q
- _;
- }
- function initOwner() external {1 C! w3 T; m. W9 Q& J, V
- require (owner == address(0));
- owner = msg.sender;2 H+ @6 B* X$ d d' p, j/ D
- }
- function addPlayer(address _player, uint _points)2 N: n" J2 x! W. ~2 @
- public onlyOwner
- {
- require (points[_player] == 0);: H0 y( }+ o) X8 m) d. V5 A$ H
- points[_player] = _points;
- }
- function setPoints(address _player, uint _points)5 D- `, a, Y5 _, j
- public onlyOwner
- {
- require (points[_player] != 0);
- points[_player] = _points;
- }
- }
- contract ImplementationV2 is ImplementationV1 {6 c+ C) q5 [( F) l0 j# j9 w2 h; ]
- uint public totalPlayers;- H1 K3 i* Y+ x6 {; ]- ]
- function addPlayer(address _player, uint _points)
- public onlyOwner# {8 d& \! T2 P0 D4 n
- {
- require (points[_player] == 0);' @6 T- K7 O8 K" R8 H, J/ Z: M- e
- points[_player] = _points;
- totalPlayers++;8 x# ^* x, J: G( w# R( P
- }4 O9 y+ R) Y" E$ |7 o# N; O
- }