- <b>contract StorageStructure {8 e7 \3 W1 [( V3 U; p5 ?! j9 D5 Z
- address public implementation;( l# f) `: o. `
- address public owner;
- mapping (address => uint) internal points;
- uint internal totalPlayers;
- }</b>
- contract ImplementationV1 is StorageStructure {
- modifier onlyOwner() {
- require (msg.sender == owner);6 u; v$ I) r# o1 ?
- _;
- }( x8 g; z( m" E; W; ^
- function addPlayer(address _player, uint _points)
- public onlyOwner
- {. G( t; P2 S9 @1 _
- require (points[_player] == 0);2 j4 S5 Q( P5 {
- points[_player] = _points;
- }
- function setPoints(address _player, uint _points)
- public onlyOwner; I$ z8 a3 \! e# B, L8 {+ x+ _
- {
- require (points[_player] != 0);0 F. I9 _8 F; w8 L$ @6 J# D
- points[_player] = _points;4 ]6 L8 b; |8 s) }4 R) N, h% p
- }( {: I5 k7 A* M$ p! x: M& B
- }
- contract Proxy is StorageStructure {
- e( a/ ]2 y) f4 ^; ^& j" e& k
- modifier onlyOwner() {
- require (msg.sender == owner);! P4 j+ ~3 E, J
- _;
- }
- /**
- * @dev constructor that sets the owner address! B+ |8 o, ]- |% g& l
- */" v* J) v7 D7 q# Q
- constructor() public {
- owner = msg.sender;& }! @' ^3 K/ A2 T
- }8 x7 ^0 C2 m+ {7 X# }2 A
- /**7 G9 U) z8 A: ], k$ I
- * @dev Upgrades the implementation address
- * @param _newImplementation address of the new implementation# D9 P6 X6 a h+ P: n" f
- */. \) G% P! Y2 d- A" x( s
- function upgradeTo(address _newImplementation)% O2 J* S/ n- A* n
- external onlyOwner
- {
- require(implementation != _newImplementation);
- _setImplementation(_newImplementation);
- }0 g( @9 P6 S* V( X/ U- @: b- ]5 e
- /**
- * @dev Fallback function allowing to perform a delegatecall
- * to the given implementation. This function will return3 l# D' E& e3 R! f8 w0 g1 D
- * whatever the implementation call returns. v6 ?; a. g/ r \! u
- */6 R. m7 R$ ], t2 F% e
- function () payable public {2 O, v m* Y5 v4 j" H5 X/ S" `
- address impl = implementation;
- require(impl != address(0));
- assembly { R# B7 v- I* g5 i! [- U! Y- ~2 r* Y* l
- let ptr := mload(0x40)
- calldatacopy(ptr, 0, calldatasize)0 ?8 r8 Z2 G! R
- let result := delegatecall(gas, impl, ptr, calldatasize, 0, 0)# @. [ ^: K/ v, q3 ?* m
- let size := returndatasize/ c% a2 Z- O) _5 d; @ T* H+ ~
- returndatacopy(ptr, 0, size)
- switch result/ h1 S/ N9 T: f9 k' I
- case 0 { revert(ptr, size) }) e$ r& V) x2 g2 t5 M0 E
- default { return(ptr, size) }5 u& `( K& `4 A0 l% f
- }
- }
- /**
- * @dev Sets the address of the current implementation
- * @param _newImp address of the new implementation4 h3 c" c! \: i
- */
- function _setImplementation(address _newImp) internal {
- implementation = _newImp;
- }
- }
- contract ImplementationV2 is ImplementationV1 {9 s$ E% v: Y7 k7 k+ i! b
- % W9 n X& W' Z& Q, K
- # r/ j" S* q- E' v5 O( J3 ^
- function addPlayer(address _player, uint _points)$ Q7 d0 T9 s: c: E. d6 x
- public onlyOwner9 Z# I- K* Q F
- {* ?' m& c- S( n) @
- require (points[_player] == 0);5 `1 y5 f; Y" j3 F6 B
- points[_player] = _points;( b. o: \4 [' j' t
- totalPlayers++;
- }8 L* E6 K+ ?& U
- }
- contract UnstructuredProxy {
- $ n7 n7 @1 V- d) J5 C
- // Storage position of the address of the current implementation1 {+ z$ {& o' k3 \ ?% y |$ D
- bytes32 private constant implementationPosition =% `$ _4 K( ?, ^: C& l
- keccak256("org.govblocks.implementation.address"); |) w& Q. w4 @- o& ^7 y
- // Storage position of the owner of the contract5 u: j' k( W0 R
- bytes32 private constant proxyOwnerPosition =
- keccak256("org.govblocks.proxy.owner");
- /**
- * @dev Throws if called by any account other than the owner.8 L7 S: C% Y, M
- */
- modifier onlyProxyOwner() {9 p9 J. I) V$ r- l
- require (msg.sender == proxyOwner());
- _;2 Z4 j; i0 B$ W9 z. J1 a6 O
- }9 d; b) f8 o9 C9 ?
- /**2 W' S2 F |' p
- * @dev the constructor sets owner
- */# i. b" b, R* I
- constructor() public {
- _setUpgradeabilityOwner(msg.sender);" C5 P3 g; A9 Y6 @: W1 K; L) A# j
- }6 F2 N" \+ o' [, S
- /**
- * @dev Allows the current owner to transfer ownership
- * @param _newOwner The address to transfer ownership to8 Z- e1 j* r( V4 G
- */
- function transferProxyOwnership(address _newOwner): Z: [: V! Y$ c" l8 Y! S. { Z
- public onlyProxyOwner
- {# c5 O$ e; _& T6 ]9 I
- require(_newOwner != address(0));7 V9 i- c) L1 V
- _setUpgradeabilityOwner(_newOwner);7 A4 Y2 P3 ]4 `: C8 w
- }, B7 I5 e' T; E3 {, m- i$ Q
- /**
- * @dev Allows the proxy owner to upgrade the implementation
- * @param _implementation address of the new implementation) k2 M, \' q u, ]2 _4 D8 d) H
- */9 c0 t3 K4 U* U- q
- function upgradeTo(address _implementation)
- public onlyProxyOwner
- {7 Y( {2 b( K d6 F* U0 ]
- _upgradeTo(_implementation);
- }$ Q4 n2 N! ~8 J4 {7 c
- /**) [* ]* x1 d# J$ D3 r
- * @dev Tells the address of the current implementation
- * @return address of the current implementation
- */% `2 N- Q7 M& f% D, _2 h0 }. S( ?- g/ m: j
- function implementation() public view returns (address impl) {% ~0 u. {% K& m O1 K# q4 w
- bytes32 position = implementationPosition;
- assembly {+ g$ `: U9 `/ R, N, O8 ]7 \+ n+ p+ j
- impl := sload(position)% a. {. H) H- {
- }1 E# u6 f/ Q1 ^4 `- x" ]
- }
- /**
- * @dev Tells the address of the owner1 H3 h8 l0 e$ a: b" o0 n* L
- * @return the address of the owner' `& m" }& h ]. f1 n# X0 l) y
- */
- function proxyOwner() public view returns (address owner) {4 D# o( ]5 `/ q6 \
- bytes32 position = proxyOwnerPosition;: I1 J; N/ V8 o" W' f5 [" |
- assembly {
- owner := sload(position)+ H3 Q1 @9 M5 E9 L7 P( i
- }9 h$ J6 S) _ b( u
- }
- /**
- * @dev Sets the address of the current implementation6 W9 ]" u" z9 v& R
- * @param _newImplementation address of the new implementation- V; r0 G% l9 |5 |' u1 L; r
- */: ~9 x* y V+ ]* {; [, b
- function _setImplementation(address _newImplementation)
- internal+ v" i; b! i5 O
- {
- bytes32 position = implementationPosition;
- assembly {
- sstore(position, _newImplementation)1 o$ G1 D% \ Q" I% G& a
- }8 k7 K4 G: c' x8 I
- }
- /**. ]) F8 r- h, u; _; [6 e8 q
- * @dev Upgrades the implementation address
- * @param _newImplementation address of the new implementation
- */
- function _upgradeTo(address _newImplementation) internal {* @/ Z" B6 P* w( y8 O! P
- address currentImplementation = implementation();1 C7 p1 J- X+ T) n; T
- require(currentImplementation != _newImplementation);6 M; |( Y& {) n6 u( J* r
- _setImplementation(_newImplementation);- t4 p5 _9 M! w& z% a! y1 Q; o) W
- }. N) w- }7 S* N% O) y/ u+ v7 i
- 7 H, M9 w d7 s5 T2 w
- /**! k, t+ q+ F# [5 S4 s
- * @dev Sets the address of the owner
- */
- function _setUpgradeabilityOwner(address _newProxyOwner)4 w; j/ L; R) K6 n
- internal7 T& m$ y' I9 u- f2 C* g
- {8 a' \$ J) \0 o9 p) A
- bytes32 position = proxyOwnerPosition;& ^- C. Q% Z0 G
- assembly {! \4 I d8 d( e+ w$ \+ Y
- sstore(position, _newProxyOwner)
- }
- }
- }
- contract ImplementationV1 {
- address public owner;' K( k8 N h5 ?: r% c* @' b; k# y
- mapping (address => uint) internal points; W& N. d2 O5 _1 f1 I( x6 y3 g/ K
- modifier onlyOwner() {2 ^+ u3 l0 w9 G$ x/ F& `
- require (msg.sender == owner);
- _;! e3 `, o0 S( E% O6 L/ ]" @
- }
- function initOwner() external { [5 l) z; t+ X5 k% x7 q& h3 k
- require (owner == address(0));9 l% m$ _$ W& ?+ o: D: Z, n9 s4 B
- owner = msg.sender;9 X. V+ b5 e+ O+ Q+ l" T& m6 A
- }9 V8 m. N0 L% A8 |- I5 J% S
- function addPlayer(address _player, uint _points)- u2 w& s# f! W D
- public onlyOwner
- {$ j5 R) N2 m4 y2 i; I B0 C
- require (points[_player] == 0);
- points[_player] = _points;
- }5 I) O2 z# L* B h! _: @' i
- + |; E7 S. W. W/ u# B2 }, T$ P
- function setPoints(address _player, uint _points)
- public onlyOwner0 y, a2 N% \5 |3 f
- {
- require (points[_player] != 0);
- points[_player] = _points;& D( e8 |8 ]+ M- _8 s9 [
- } Y2 n; J# |& ^" t- N
- }
- contract ImplementationV2 is ImplementationV1 {
- uint public totalPlayers;. Z1 g- Q. U; h2 Q1 F; P
- 7 w0 Z5 Y+ J! X
- function addPlayer(address _player, uint _points)0 @* n5 { T, l
- public onlyOwner
- {# j: ~3 ^. ~8 b8 r3 A1 |
- require (points[_player] == 0);0 X" s/ v5 l4 U! ?
- points[_player] = _points;( Y( s& H# W4 S1 B, t% H2 s
- totalPlayers++;
- }
- }