- <b>contract StorageStructure {! O8 |2 G0 o( c2 X, i1 ~
- address public implementation;
- address public owner;
- mapping (address => uint) internal points;
- uint internal totalPlayers; P! f2 l* i$ J+ \0 y T# d
- }</b>
- contract ImplementationV1 is StorageStructure {6 {1 ~# X9 k. A) h( B, Q
- modifier onlyOwner() {
- require (msg.sender == owner);
- _;% m6 I; t( g/ p: D
- }
- function addPlayer(address _player, uint _points)2 }( ^0 [; S* n* q0 G
- public onlyOwner, d3 U0 C- n1 q l( [( m5 o# y
- {/ \* m- E3 ]- R5 @, V5 d: i
- require (points[_player] == 0);) |7 q( \: K: a
- points[_player] = _points;1 E* g7 k/ v; g, i
- }
- function setPoints(address _player, uint _points)
- public onlyOwner
- {
- require (points[_player] != 0);
- points[_player] = _points;
- }- x: S- ^9 f" ]: [7 m/ ~3 z
- }
- contract Proxy is StorageStructure {; V3 L9 h; Q" i7 H/ }
- modifier onlyOwner() {" B4 {, ^$ ]- g9 q2 W) A# n2 d" k
- require (msg.sender == owner);$ r/ g$ |9 E1 |/ |' }! x
- _;8 ~1 ]. m! d% v2 u$ h5 X
- }. c+ U) H8 E+ ~$ r+ c( r" Q/ b
- /**
- * @dev constructor that sets the owner address
- */
- constructor() public {- X+ D5 U6 ]; S
- owner = msg.sender;
- }+ B, s8 j9 ]- R0 z+ Q8 ^' }- H* Z2 y
- /**' b1 U! B+ n' N" {
- * @dev Upgrades the implementation address9 \2 w% F* Q9 S- c
- * @param _newImplementation address of the new implementation
- */8 y: I9 v! p c5 @; @
- function upgradeTo(address _newImplementation)
- external onlyOwner8 P- p j3 x7 e2 R% ^% M9 }5 t
- {
- require(implementation != _newImplementation);8 k4 \ Y1 F* o+ `1 M; k
- _setImplementation(_newImplementation);& i: I9 r8 M$ P% ?
- }2 h& C' C) w. x4 }# U% \) G" o
- /**
- * @dev Fallback function allowing to perform a delegatecall
- * to the given implementation. This function will return1 s' A: r" c; I9 z! o. q7 W- Y
- * whatever the implementation call returns D" [; X/ }3 x2 i/ m
- */
- function () payable public {* H8 v2 w( b' B, V0 H- U5 ^
- address impl = implementation;# [7 Q# L& T' {; t% j
- require(impl != address(0));! [6 {; e0 |& w3 \) J# q
- assembly {5 t' ] f1 T- u+ Q: `& e
- let ptr := mload(0x40): z$ ~& M0 _: v% n% \
- calldatacopy(ptr, 0, calldatasize)8 v C/ b$ p/ O1 K
- let result := delegatecall(gas, impl, ptr, calldatasize, 0, 0)
- let size := returndatasize
- returndatacopy(ptr, 0, size)
- switch result$ L: I4 n% ]" P$ W) K5 a, l/ Y
- case 0 { revert(ptr, size) }- c1 j& t" a/ n0 D1 z/ i: s
- default { return(ptr, size) }/ O2 p0 F0 K3 B
- }3 X, }- q8 D5 e1 O7 e: V0 O. v
- }9 E7 c7 W8 l6 t. F) u: ~
- : ~" Z/ r0 X; i. A7 J. I
- /**4 D# @2 p _* j0 T% h7 r- t
- * @dev Sets the address of the current implementation
- * @param _newImp address of the new implementation/ c' p7 T. d7 [6 L6 T( h
- */7 u: _+ p$ X% q3 d8 G7 y# w- [
- function _setImplementation(address _newImp) internal {
- implementation = _newImp;- W+ R0 @3 E4 Y8 f
- }1 K% K" v1 h. L: I0 ?1 Y
- }
- contract ImplementationV2 is ImplementationV1 {
- 8 b8 E9 ~! i% y( O: q$ ]- K5 L0 l3 G
- function addPlayer(address _player, uint _points)
- public onlyOwner9 f' x* C! U. Q1 G: {$ o8 ~
- {6 k% F1 h: C8 I8 Y$ D
- require (points[_player] == 0);
- points[_player] = _points;
- totalPlayers++;' y8 X# ~. X$ ?/ s9 Z8 G
- }
- }
- contract UnstructuredProxy {
- // Storage position of the address of the current implementation8 |* D: A* Y6 ^6 t |5 q
- bytes32 private constant implementationPosition =
- keccak256("org.govblocks.implementation.address");# f9 L0 s% Y' u7 _" e9 j) y
- // Storage position of the owner of the contract: q! R6 m9 `* N$ { y& A
- bytes32 private constant proxyOwnerPosition =% K: U2 w2 z9 Q! l( T- g: s
- keccak256("org.govblocks.proxy.owner");9 h2 _2 L; l+ B
- /**/ M5 B6 {* _6 E
- * @dev Throws if called by any account other than the owner.
- */; [3 A( c- g3 `) b
- modifier onlyProxyOwner() {, s" ^. }6 _. _
- require (msg.sender == proxyOwner());
- _;3 N* {0 E$ ?/ i$ m( Z" P
- }
- /**7 b; K8 M. C; B, A
- * @dev the constructor sets owner
- */6 [& p8 G; u+ }* z5 {0 n5 ~; F: ~* K
- constructor() public {
- _setUpgradeabilityOwner(msg.sender);
- }9 n% B# ^; K, v, \
- /**
- * @dev Allows the current owner to transfer ownership" z% L( ], ?* T& y( a$ M
- * @param _newOwner The address to transfer ownership to, b5 q2 h Q4 C5 R1 v7 N! z( n
- */
- function transferProxyOwnership(address _newOwner)
- public onlyProxyOwner
- {$ D- T+ L; m8 f# {5 W
- require(_newOwner != address(0));
- _setUpgradeabilityOwner(_newOwner);/ G$ j: |% R+ Y& [, a+ a
- }
- /**1 g3 `4 M7 n. S/ ?) f' ^# [
- * @dev Allows the proxy owner to upgrade the implementation
- * @param _implementation address of the new implementation' E4 i/ B! X8 L$ h7 t5 @8 M! t
- */
- function upgradeTo(address _implementation), {3 z/ H7 V' M) w
- public onlyProxyOwner0 T/ Q- b: _- c. \* S
- {
- _upgradeTo(_implementation);& Y* X3 T l+ Q$ i
- }/ u3 K6 V P9 u# o3 ?( C
- /**3 c/ Y, u, h/ J! U' ?
- * @dev Tells the address of the current implementation
- * @return address of the current implementation
- */
- function implementation() public view returns (address impl) {6 k5 i8 n/ P+ O4 ^/ B9 v
- bytes32 position = implementationPosition;" X0 B! s. b @, k4 t) p: Z: g
- assembly {6 E$ [' B, Z( X$ r; d
- impl := sload(position)0 y2 e( Z5 T0 A9 l" X7 q
- }
- }% D; D8 [( f3 V
- /**2 _" [' t6 ]# X! l( c& b
- * @dev Tells the address of the owner
- * @return the address of the owner; E- d* k! y6 `9 Z* L
- */
- function proxyOwner() public view returns (address owner) {( E: N; ?8 \: G( M/ V. F4 G" b
- bytes32 position = proxyOwnerPosition;
- assembly {* |; c1 H6 v. E
- owner := sload(position)
- }
- }! M% ]' | N9 s, c9 {
- /**- Z5 d: w8 J1 }. K% Z& e1 a
- * @dev Sets the address of the current implementation! @# R( a! Q* E% J5 E+ b
- * @param _newImplementation address of the new implementation# N( e6 B5 y3 n; | Y) K u
- */3 B9 o \1 c: u( b, g; x
- function _setImplementation(address _newImplementation)
- internal
- {3 ]6 A' A" [0 c0 j
- bytes32 position = implementationPosition;
- assembly {+ J2 ^1 h( M4 m" I5 O6 T
- sstore(position, _newImplementation)
- }5 g L* L: a, |8 D
- }) M$ m% _6 ~& d
- /**
- * @dev Upgrades the implementation address
- * @param _newImplementation address of the new implementation" m/ n2 P1 T' w" {2 m. o( s9 R0 P" ~
- */) H2 m) B- G. b# C. g# ]
- function _upgradeTo(address _newImplementation) internal {1 U0 u1 b4 {3 O
- address currentImplementation = implementation();
- require(currentImplementation != _newImplementation);0 U1 T P) f+ X
- _setImplementation(_newImplementation);
- }
- 0 W2 o+ i: j2 a/ ]; y: y+ E
- /**& s4 j8 E# q$ L. G1 Z0 ~$ y) B
- * @dev Sets the address of the owner W+ x0 W& `3 s. f T
- */' A; B$ l; X& A
- function _setUpgradeabilityOwner(address _newProxyOwner)
- internal
- {. l( {1 R1 L0 f1 ]
- bytes32 position = proxyOwnerPosition;9 |3 q @! k Y/ G8 A$ B( {
- assembly {* g7 T" K, d, f7 A! h, d
- sstore(position, _newProxyOwner)
- }
- }0 r. m- y4 r: V3 E" [: x6 C5 ^1 G
- }
- contract ImplementationV1 {
- address public owner;9 J+ Q7 ] U' q* m h
- mapping (address => uint) internal points;
- V1 q0 T L; j) ]7 @0 n5 z
- modifier onlyOwner() {: f j# R) v3 T4 {+ k/ [1 z( P
- require (msg.sender == owner);4 J( c: q! C8 y1 W
- _;& o' }" T. G2 E3 f
- }' ]7 \- F6 Z6 R4 V( d; h
- function initOwner() external {
- require (owner == address(0));$ T. h+ O! b4 ^) u
- owner = msg.sender;
- }* w! m8 U: x Y' d( Y+ k
- function addPlayer(address _player, uint _points)
- public onlyOwner; v% e# N1 p" ?. j; Z) K& J4 B5 A
- {
- require (points[_player] == 0);
- points[_player] = _points;
- }9 a3 I I" _8 c" `5 ]" j8 }
- function setPoints(address _player, uint _points)
- public onlyOwner
- {( ^3 m& A/ k: R4 F
- require (points[_player] != 0);
- points[_player] = _points;4 g3 i' Y0 J0 t' s- I* j4 x
- }' H5 D# L2 Q' w1 |- n* @* a. f# B
- }
- contract ImplementationV2 is ImplementationV1 {
- uint public totalPlayers;
- function addPlayer(address _player, uint _points)1 }' A0 K4 f+ @% z% h, }+ l
- public onlyOwner: Y- `5 r7 x5 H( w3 `' |3 P
- {
- require (points[_player] == 0);3 K; c7 w* C# U& M0 c4 c; P$ \
- points[_player] = _points;: A V" n2 _6 R- p8 i+ C
- totalPlayers++;
- }
- }