- <b>contract StorageStructure {
- address public implementation;
- address public owner;
- mapping (address => uint) internal points;
- uint internal totalPlayers;
- }</b>
- contract ImplementationV1 is StorageStructure {
- modifier onlyOwner() {( N, U4 ^& O) G y2 F$ m
- require (msg.sender == owner);
- _;
- }' u" B0 |7 G3 I& k
- function addPlayer(address _player, uint _points)' j% E. P5 {2 b3 p5 z: y' }1 t
- public onlyOwner/ t. g: {- k/ s1 t1 X
- {# j+ _( u0 q5 m' {: t5 }" V% |6 k
- require (points[_player] == 0);
- points[_player] = _points;
- }& b! x. @7 ?) V2 U8 L$ Y
- function setPoints(address _player, uint _points)
- public onlyOwner% v( v; ]6 H' a* y) L* b A: S
- {
- require (points[_player] != 0);
- points[_player] = _points;; p! G- w2 O( G/ g* H, G* u
- }4 o9 l# D# b' z/ i$ ~5 x$ T7 Q
- }
- contract Proxy is StorageStructure {
- h$ } s8 t; q' D5 I
- modifier onlyOwner() {
- require (msg.sender == owner);; k5 h6 C: x" f* y" J; M6 ^
- _;* t* a) o. T! v4 E. \. `
- }
- /**
- * @dev constructor that sets the owner address2 `3 U) `6 L8 ~2 h4 ~# _
- */ z; l; u: J. J
- constructor() public {5 o7 n0 d3 K# t, ^
- owner = msg.sender;. }7 X/ e2 t1 m1 {+ Z
- }
- /**
- * @dev Upgrades the implementation address5 C+ b7 R( o0 I
- * @param _newImplementation address of the new implementation% \0 K- C3 l) B" x9 Y* N+ p
- */$ F9 B1 t$ e- j) k L
- function upgradeTo(address _newImplementation)
- external onlyOwner
- {
- require(implementation != _newImplementation);
- _setImplementation(_newImplementation);% s7 a9 y- m! Y0 e+ I
- }
- /** Y6 i r0 |* G$ z" t
- * @dev Fallback function allowing to perform a delegatecall& L) k: h8 C p$ O5 O5 N0 X$ E
- * to the given implementation. This function will return
- * whatever the implementation call returns
- */
- function () payable public {, V4 }( H! u ~
- address impl = implementation;
- require(impl != address(0));- I+ Z% Y& s8 g4 M8 K; A1 D6 {8 R
- assembly {+ v8 ^- W% ]8 _& d
- let ptr := mload(0x40)# F/ ]" u: C. ^$ w' u
- calldatacopy(ptr, 0, calldatasize)4 Q* e4 g" R" Q( G; A* t3 n
- let result := delegatecall(gas, impl, ptr, calldatasize, 0, 0)
- let size := returndatasize
- returndatacopy(ptr, 0, size)# D- R& z# ]' u) v6 ` I3 z
- switch result
- case 0 { revert(ptr, size) }
- default { return(ptr, size) }. A& c2 T2 u# x1 Q- {
- }
- }& X& U! b) r5 }9 g4 q( B9 Y# m
- /**
- * @dev Sets the address of the current implementation5 A# h$ L" l0 W, g/ G
- * @param _newImp address of the new implementation
- */
- function _setImplementation(address _newImp) internal {
- implementation = _newImp;
- }* C5 K3 D; C/ Z+ O! T7 _ l2 S
- }
- contract ImplementationV2 is ImplementationV1 {
- 5 |# _3 { R m) _
- function addPlayer(address _player, uint _points)
- public onlyOwner1 c. U/ v7 ~3 C( _6 F3 w9 \2 ~
- {2 r# e, O0 r3 v* X
- require (points[_player] == 0);6 q o% A. A2 _! H2 F! n2 z3 n
- points[_player] = _points;( m& ]$ u% a( t3 Y
- totalPlayers++;
- }
- }
- contract UnstructuredProxy {2 U; x7 q. X: R8 v# `2 G4 n* S
- ! I x& y h# v6 S9 z. |$ B
- // Storage position of the address of the current implementation
- bytes32 private constant implementationPosition =
- keccak256("org.govblocks.implementation.address");2 b2 D0 y( [: G& l5 P9 u
- // Storage position of the owner of the contract- t* z; c6 h/ c
- bytes32 private constant proxyOwnerPosition =
- keccak256("org.govblocks.proxy.owner");' C* L5 B# H+ u' J2 y
- /**5 D. U E) G/ y& T; d/ f
- * @dev Throws if called by any account other than the owner.
- */1 X2 s8 J) J, H: H" R2 G
- modifier onlyProxyOwner() {6 [8 e+ O4 o# H" z3 y
- require (msg.sender == proxyOwner());5 ~3 Z l5 a7 ~ M/ u$ q
- _;$ c; X' C% \/ D5 F/ H
- }
- /**
- * @dev the constructor sets owner
- */
- constructor() public {
- _setUpgradeabilityOwner(msg.sender);
- }: g" C; o# A. D# I
- /**# X$ v" `4 V7 X/ h" g
- * @dev Allows the current owner to transfer ownership
- * @param _newOwner The address to transfer ownership to
- */
- function transferProxyOwnership(address _newOwner)
- public onlyProxyOwner
- {! D$ G6 }+ @7 L. m' n$ e1 Z9 c
- require(_newOwner != address(0));
- _setUpgradeabilityOwner(_newOwner);
- }( v9 M8 B b2 _* N8 j& f, e
- /**1 [: P8 T$ w( @4 ?/ C
- * @dev Allows the proxy owner to upgrade the implementation
- * @param _implementation address of the new implementation
- */! s0 K/ U/ Y R6 E) J; ^
- function upgradeTo(address _implementation)% ?& f8 C( _* c; k: v9 @
- public onlyProxyOwner P( n! ^- h/ }! t! ~. l. z& V' {$ L
- {3 D1 k4 |% o' A6 m4 ?! b3 n
- _upgradeTo(_implementation);/ V2 V. g, f7 D% }" r# q2 n
- }
- /**
- * @dev Tells the address of the current implementation2 y% U3 S+ U) F* O2 W
- * @return address of the current implementation
- */& {3 F Y3 z* Q
- function implementation() public view returns (address impl) {& f! s2 ~. z# ~/ p- ?
- bytes32 position = implementationPosition;: y; t; X# f! L
- assembly {
- impl := sload(position)
- }4 g) K8 [: M# w {, v* z5 Z) \! C
- }
- /**
- * @dev Tells the address of the owner
- * @return the address of the owner7 }( v& p5 H3 l/ J; {
- */
- function proxyOwner() public view returns (address owner) {! K4 B; L$ p! W0 ]- x& }) J
- bytes32 position = proxyOwnerPosition;
- assembly {
- owner := sload(position)* Y* U9 s! N; V# D6 `8 s4 c/ o% K
- }
- }
- /**
- * @dev Sets the address of the current implementation
- * @param _newImplementation address of the new implementation
- */
- function _setImplementation(address _newImplementation)
- internal
- {) w) ]5 K; V. S% k6 V3 w
- bytes32 position = implementationPosition;9 G7 S; _# `" i1 R
- assembly {
- sstore(position, _newImplementation)3 @& K# z: y: b4 B
- }9 q3 X$ z/ L% _9 L7 X6 L
- }! L$ e- y6 G$ A4 n! \: n3 q# H0 T
- /**7 X+ m& w. |+ i
- * @dev Upgrades the implementation address
- * @param _newImplementation address of the new implementation5 d0 q. e! o/ Q
- */; b+ W5 N: |4 B: Q# K
- function _upgradeTo(address _newImplementation) internal {2 l3 H2 ]6 b) F, i4 f1 z
- address currentImplementation = implementation();: P" _1 J4 I! u
- require(currentImplementation != _newImplementation);0 t g! l9 H% \( F: e
- _setImplementation(_newImplementation);
- } ^+ H( ^4 e7 _% s3 O
- /**# ~9 c: y8 M8 O; I
- * @dev Sets the address of the owner/ B2 k3 w+ b0 w+ x8 ]
- */1 U* o, l. p0 C( b! t0 d
- function _setUpgradeabilityOwner(address _newProxyOwner)2 x* O/ z9 v3 U
- internal! y: d' s7 F4 X
- {- R3 m- r3 W9 K5 H- X3 p9 V0 t# m5 Y9 l
- bytes32 position = proxyOwnerPosition;/ l1 O$ o! ?4 } U- S& B5 ^( d( E
- assembly {1 O1 {! X4 @3 K/ ~* J
- sstore(position, _newProxyOwner)
- }+ V+ N# o; ^' B4 w5 o3 m8 o
- }2 \2 w$ S) q7 T8 v+ U* H
- }
- contract ImplementationV1 {9 P3 V$ k3 i$ @' Z
- address public owner;
- mapping (address => uint) internal points;# U! _4 Q" W# \6 J! v# V0 N
- % W: @7 F6 \2 H$ Q- g( l* v
- modifier onlyOwner() {3 r3 U* L, K+ ]! [
- require (msg.sender == owner);! g% ~: o/ j6 t" h6 y6 J% X
- _;% P3 @, w- a0 a) U7 L# o& r
- }
- function initOwner() external {
- require (owner == address(0));
- owner = msg.sender;
- }
- function addPlayer(address _player, uint _points)
- public onlyOwner% c/ P7 N6 }2 P
- {
- require (points[_player] == 0);
- points[_player] = _points;% ]- W) t! I2 M( Q% ]
- }
- : R* d" s! P4 D( W
- function setPoints(address _player, uint _points)
- public onlyOwner) U3 S$ a5 }/ s" H0 S9 S+ o8 p4 l
- {% N% L1 `# u: H1 t( T+ g/ Z
- require (points[_player] != 0);
- points[_player] = _points;
- }
- }
- contract ImplementationV2 is ImplementationV1 {( m4 t: u. U* H+ | Y7 ]; j4 j
- uint public totalPlayers;7 s* Z# X# w2 i# R% {" @& z5 e2 U
- + |9 Q9 ]" o0 R3 M
- function addPlayer(address _player, uint _points)
- public onlyOwner: L3 A2 ^ ~9 ?" m+ m. \' e' H
- {
- require (points[_player] == 0);/ v- \) e A7 F; @$ R
- points[_player] = _points;
- totalPlayers++;
- }9 R, m2 F7 ], p' f7 ?
- }