- <b>contract StorageStructure {. G) l5 S* c# U' B1 Q
- address public implementation;
- address public owner;4 ]. Q( B3 p8 W9 w
- mapping (address => uint) internal points;7 K! G0 Y$ b, R! O$ a! |) r
- uint internal totalPlayers;
- }</b>
- contract ImplementationV1 is StorageStructure {/ C, u$ {7 H# G/ V# `) g
- modifier onlyOwner() {
- require (msg.sender == owner);
- _;" |; G( F$ s ?# Z* H
- }
- function addPlayer(address _player, uint _points)7 j3 q" k& a: y7 n
- public onlyOwner g8 z% @6 Z8 p% R7 k
- {
- require (points[_player] == 0);3 _. F2 [5 j& n
- points[_player] = _points;: |& T( O: c9 p/ X" M4 g+ Y, T8 V& G5 C
- }
- function setPoints(address _player, uint _points)
- public onlyOwner; _4 c0 H1 @' c. S* v
- {! i' |) Y1 W7 i& F) l& t6 w
- require (points[_player] != 0);
- points[_player] = _points;8 J- w, G2 l1 X+ h% _ Z( |4 {
- }6 b/ a; t( a0 E/ [$ a. V! k. `
- }
- contract Proxy is StorageStructure {
- 6 Y* e$ I/ g( T+ H* @; h$ Q7 p
- modifier onlyOwner() {
- require (msg.sender == owner);& n. ~/ q0 L" Z/ I
- _;: h: E% D* M) [0 V. p" f+ T3 ~) n
- }7 m+ k& q; `4 m
- /**
- * @dev constructor that sets the owner address& o+ t: J7 ~# V
- *// [# m: R5 z. e4 N4 J$ y
- constructor() public {* X0 ~* Z4 s' M0 L5 d3 m7 x3 t
- owner = msg.sender;. w( X; T/ j* R9 v0 S( n
- }
- /**; q- L9 H/ W/ t0 c
- * @dev Upgrades the implementation address
- * @param _newImplementation address of the new implementation
- */
- function upgradeTo(address _newImplementation)
- external onlyOwner
- {+ t9 Y+ W4 d* \( N& O
- require(implementation != _newImplementation);1 c* M, i; u1 r- q! c! g
- _setImplementation(_newImplementation);" c% e/ r0 _9 m2 j& D0 c) m1 D) ?
- }
- /**9 E5 D9 y/ o0 I; O
- * @dev Fallback function allowing to perform a delegatecall
- * to the given implementation. This function will return4 y! ]( {% r: P0 ^- h
- * whatever the implementation call returns/ Q/ p t# Q+ _" q
- */
- function () payable public { ]* h; q2 U- u3 M- ?3 j' W
- address impl = implementation;. q' Z0 F1 M' \( b" X
- require(impl != address(0));
- assembly {; A$ G; ~% Z6 |% r! d! Z5 r/ [+ A
- let ptr := mload(0x40)
- calldatacopy(ptr, 0, calldatasize)
- let result := delegatecall(gas, impl, ptr, calldatasize, 0, 0)7 S/ a- j# w6 n9 i0 X: Y2 @( f
- let size := returndatasize
- returndatacopy(ptr, 0, size)
- switch result
- case 0 { revert(ptr, size) }) M" t1 w; M4 B5 K
- default { return(ptr, size) }
- }
- }
- " X+ R% t" Y3 y
- /**
- * @dev Sets the address of the current implementation
- * @param _newImp address of the new implementation3 M) {8 {9 Z4 _. V# @5 K, w* M
- */- _ p+ g# Q7 n; n, @: d
- function _setImplementation(address _newImp) internal {# ~+ h Y0 K/ q3 @+ D6 e
- implementation = _newImp;, E: \6 o, Z0 `; W0 |9 y
- }8 x, r- D4 z/ h9 O% F+ M) |* K
- }
- contract ImplementationV2 is ImplementationV1 {$ m% ?1 P$ i/ }* z$ F2 N! }+ L. `
- - p( S( p9 ]1 h, O8 u7 a
- : G$ g s- p! r( d! T& P
- function addPlayer(address _player, uint _points)
- public onlyOwner
- {, V$ {& U& g$ z- b, E
- require (points[_player] == 0);
- points[_player] = _points;7 Z# s( X5 q C4 e- S
- totalPlayers++;( j( Q- }/ n( L% B! y. D
- }
- }
- contract UnstructuredProxy {, }6 d! j! t" y
- // Storage position of the address of the current implementation) z9 V8 _. P7 p# c) {' u4 d
- bytes32 private constant implementationPosition =
- keccak256("org.govblocks.implementation.address");& t! J+ {7 E6 f( p
- // Storage position of the owner of the contract
- bytes32 private constant proxyOwnerPosition =
- keccak256("org.govblocks.proxy.owner");
- /**
- * @dev Throws if called by any account other than the owner.
- */* o5 Y- t& s) B+ Q
- modifier onlyProxyOwner() {
- require (msg.sender == proxyOwner());
- _;
- }
- /**) z6 @9 w. o$ s9 X6 b
- * @dev the constructor sets owner4 r& R3 A/ n+ H5 s- R
- */
- constructor() public {
- _setUpgradeabilityOwner(msg.sender);! H7 S3 ]: r: X1 _2 k: |
- }+ Z- ^, g$ z/ u5 C/ a
- /**9 l& l4 w# g, o4 K T
- * @dev Allows the current owner to transfer ownership
- * @param _newOwner The address to transfer ownership to
- */* l/ a1 ]2 q5 t m0 V& K' {" Y
- function transferProxyOwnership(address _newOwner)
- public onlyProxyOwner9 R% {; _% Q4 f* L4 R
- {# f" W/ `9 Z0 H- o' n/ D# a
- require(_newOwner != address(0));
- _setUpgradeabilityOwner(_newOwner);6 ~2 g% M1 S: z# B" L% r* G
- }+ M' Z1 f' [9 b- F0 Y
- /**5 E' M2 @& ~* T3 ~
- * @dev Allows the proxy owner to upgrade the implementation
- * @param _implementation address of the new implementation
- */
- function upgradeTo(address _implementation)9 `" @% e" u0 e% c# S
- public onlyProxyOwner9 Y4 ~2 _* H# M6 i/ A
- {1 n! s2 {( M" j8 K2 r, k2 N
- _upgradeTo(_implementation);$ c2 U/ f# u' r9 c$ q _
- } r# G7 Z% A+ n
- /**
- * @dev Tells the address of the current implementation
- * @return address of the current implementation
- */ K. x9 ~8 ~* Z" A! }/ b4 j
- function implementation() public view returns (address impl) {. y0 p! d& S$ m3 m/ M; v0 r A' w
- bytes32 position = implementationPosition;
- assembly {# q$ z5 f$ n& ?8 H
- impl := sload(position)
- }# @2 T4 V7 k$ Z+ E
- }
- /**
- * @dev Tells the address of the owner
- * @return the address of the owner2 w0 Q0 o8 }5 ^
- */
- function proxyOwner() public view returns (address owner) {
- bytes32 position = proxyOwnerPosition;
- assembly {7 m- z) N4 [# {* F( y" _2 I4 @) b
- owner := sload(position)% b9 W3 v& O$ p7 m3 n& p1 g
- }! P- I( y& q! X* K# \
- }
- /**
- * @dev Sets the address of the current implementation
- * @param _newImplementation address of the new implementation0 A, R S# i R9 V( {- f
- */
- function _setImplementation(address _newImplementation)7 h E. i7 H- P( F% A6 m
- internal2 A2 U( r0 R% E
- {
- bytes32 position = implementationPosition;
- assembly {
- sstore(position, _newImplementation)
- }
- }0 _3 |1 J7 p# \7 `$ g# H. u
- /**! p9 Q3 i; {7 L4 l4 J$ d; T+ |
- * @dev Upgrades the implementation address
- * @param _newImplementation address of the new implementation
- */! b7 Q3 w4 b3 a6 l1 w% D
- function _upgradeTo(address _newImplementation) internal {
- address currentImplementation = implementation();0 I$ E9 i9 ^# X, I8 A* s0 N u: U
- require(currentImplementation != _newImplementation);( B# x- l' z e' N$ G. s
- _setImplementation(_newImplementation);" i4 A* M6 q% F# \" V" n1 J0 O
- }
- /**
- * @dev Sets the address of the owner: N/ p9 N7 _; n H% m
- */
- function _setUpgradeabilityOwner(address _newProxyOwner)/ s7 q- s) E& y( ~
- internal4 V# d, Q7 j* E( u% x r. c1 P
- {+ j2 I" ~, j7 l& q4 X H; q
- bytes32 position = proxyOwnerPosition;8 C+ o# h/ ~, ?- i" u; S
- assembly {' u9 T! x% I7 j
- sstore(position, _newProxyOwner)
- }5 h& [" y1 o. ]! k" B; ~
- }
- }
- contract ImplementationV1 {( u. R/ ^1 u$ E, j
- address public owner;
- mapping (address => uint) internal points;
- modifier onlyOwner() {
- require (msg.sender == owner);: m# P4 `; C+ v8 x7 l2 e0 `5 X
- _;
- }
- function initOwner() external {
- require (owner == address(0));3 ^& k' ~7 `* U J) i a c6 _: t
- owner = msg.sender;
- }: ?$ U8 L; [, A8 m
- function addPlayer(address _player, uint _points)% n* A' Q! B |- v* A0 [* p x
- public onlyOwner
- {
- require (points[_player] == 0);
- points[_player] = _points;
- }
- function setPoints(address _player, uint _points), Q3 x T! H, o# e0 ]$ U0 X) J
- public onlyOwner& w( ?( e$ q$ R. q ^& A
- {
- require (points[_player] != 0);
- points[_player] = _points;+ }1 U; ~, o$ }! r3 f/ j+ \
- } Z1 Q* L8 I3 e. x G. f) U3 y
- }
- contract ImplementationV2 is ImplementationV1 {
- uint public totalPlayers;* n- e, c' J, X2 A7 l! M+ I
- 5 X; z6 G' @$ N* R; B2 m
- / D" e) t* k. l( y3 U7 N
- function addPlayer(address _player, uint _points)
- public onlyOwner% U i$ g8 s& R3 w& G1 \. V
- {7 _( y/ r3 J" a7 S8 v0 G% C7 F
- require (points[_player] == 0);
- points[_player] = _points;0 g8 o: p o+ ?, [/ l3 V7 k" |6 u2 Q
- totalPlayers++;- Z8 s) e: L9 a2 w$ I
- }& N) D# K: B d. q
- }