- <b>contract StorageStructure {
- address public implementation;: Y0 g A7 r1 P0 w. ~' ]
- address public owner;
- mapping (address => uint) internal points;0 z/ e F# I% z
- uint internal totalPlayers;4 B% I4 ]# j& N
- }</b>
- contract ImplementationV1 is StorageStructure {4 N. o& R5 t' D; _) s
- modifier onlyOwner() {7 X8 K- c9 a9 m8 Y- K
- require (msg.sender == owner);
- _;7 [' t( ] h- d( l+ s
- }7 q- b K: y1 e7 n, }; @3 l
- function addPlayer(address _player, uint _points)
- public onlyOwner& |, x+ N* Z- {7 Z- F8 m
- {% z4 U9 @! }$ @# ?* }& u6 Y
- require (points[_player] == 0);4 R: y& `3 n. x4 U) u: W
- points[_player] = _points;: j. Y; D. ?2 p$ a G# F/ M* ]+ }7 [; J
- }
- function setPoints(address _player, uint _points)# k m) N) N3 e
- public onlyOwner& \, `5 M1 X3 W9 r/ u `# V
- {$ U, ?0 J. N9 M5 i- }, c
- require (points[_player] != 0);
- points[_player] = _points;
- }
- }
- contract Proxy is StorageStructure {; n1 x Y$ [" s& a3 \# E! d6 i& `# n
- # F" I7 h# |4 h* f
- modifier onlyOwner() {
- require (msg.sender == owner);8 x$ m# M, g7 g0 [- N
- _;) P% A' j: Y* E& y, S# o* m
- }
- /**
- * @dev constructor that sets the owner address+ P6 z7 O0 |1 b' z
- */+ V; m' y' R. J+ J( g& r
- constructor() public {
- owner = msg.sender;
- }" f) B% A5 B- ^; m" _& B) I/ Z! M3 B
- /**
- * @dev Upgrades the implementation address# ?6 |4 i. c5 n% B5 E7 l3 Z2 L
- * @param _newImplementation address of the new implementation
- */7 \) e" Z# ]8 \+ k
- function upgradeTo(address _newImplementation)+ u( p- J3 F, y+ p
- external onlyOwner
- {
- require(implementation != _newImplementation);
- _setImplementation(_newImplementation);
- }
- /**
- * @dev Fallback function allowing to perform a delegatecall$ a6 G& B4 J+ S& W& M2 G, D
- * to the given implementation. This function will return
- * whatever the implementation call returns
- */
- function () payable public {
- address impl = implementation;
- require(impl != address(0));
- assembly {. `7 H; B9 e: c& _& W+ n
- let ptr := mload(0x40)7 ?: j* s. ^& D' M. ?+ i9 a: r$ x
- calldatacopy(ptr, 0, calldatasize)9 V% H. H) w+ H) Z; x" Z4 J; E
- let result := delegatecall(gas, impl, ptr, calldatasize, 0, 0)0 V3 o& n4 g& p, T9 J* q8 M8 k
- let size := returndatasize* Y: J, z# V7 t1 t" h
- returndatacopy(ptr, 0, size)
- switch result
- case 0 { revert(ptr, size) }/ `% \! M% t" Z" A0 i( F9 _
- default { return(ptr, size) }
- }
- }% A% {% r0 e5 t* ~7 w3 s) `* Q
- /**
- * @dev Sets the address of the current implementation
- * @param _newImp address of the new implementation
- */2 v. s' m4 F4 z2 {4 i X
- function _setImplementation(address _newImp) internal {
- implementation = _newImp;
- }5 q6 s: S, [9 p2 e
- }
- contract ImplementationV2 is ImplementationV1 {
- + Z% n0 f0 t4 {) [! t. T% i! r- @
- 3 h, y/ d a" n
- function addPlayer(address _player, uint _points)
- public onlyOwner
- {/ n, {* H. W8 J. N/ p
- require (points[_player] == 0);
- points[_player] = _points;
- totalPlayers++;8 }( L6 e! a; W% W9 l$ p6 E
- }
- }
- contract UnstructuredProxy {- s) q2 s% c! ]* Z$ H$ J" Y
- 1 P- S4 X5 _8 u* N) {+ c: C
- // Storage position of the address of the current implementation
- bytes32 private constant implementationPosition =
- keccak256("org.govblocks.implementation.address");
- // Storage position of the owner of the contract9 n) w4 k6 [" U% T n4 O& V8 d
- bytes32 private constant proxyOwnerPosition =
- keccak256("org.govblocks.proxy.owner");6 M! `. J( K0 C' R" S% D4 y
- /**/ H0 d- H$ ^ q3 W0 R& ^" ?
- * @dev Throws if called by any account other than the owner., p- R' b, K5 z# s |/ o
- */
- modifier onlyProxyOwner() {' `5 d6 l+ O6 j/ z" ~4 q
- require (msg.sender == proxyOwner());$ o- b7 o- [+ H8 R/ y; @- v
- _;/ i S8 U! j2 i1 a4 p$ g8 G
- }; t; u0 X& Q8 \0 U( z, Z# i: \# a# ?
- /**! R+ b% {9 \: A
- * @dev the constructor sets owner
- */9 A; s& B4 p+ X- f. D2 A4 V
- constructor() public {. w2 q8 V: \# u6 K
- _setUpgradeabilityOwner(msg.sender);
- }2 d+ S5 m5 ]6 ~- D
- /**
- * @dev Allows the current owner to transfer ownership0 Y5 L* c/ o) I
- * @param _newOwner The address to transfer ownership to( ~3 U j/ j- F8 S2 A" K! {
- */
- function transferProxyOwnership(address _newOwner)" u% a" G& N x" U5 T) ?7 V
- public onlyProxyOwner& r B" ]8 N& G K' X
- {! s3 q. M8 L2 p' P; F7 [$ Z( i! k
- require(_newOwner != address(0));
- _setUpgradeabilityOwner(_newOwner);
- }
- /**$ o' O. _. ?# `( T
- * @dev Allows the proxy owner to upgrade the implementation5 d. {2 d1 q9 z+ R* ?4 U% j, o% _0 e
- * @param _implementation address of the new implementation4 y7 K6 K" h F& I+ ~$ Y! C
- */
- function upgradeTo(address _implementation)5 b+ G8 k+ R' H- u- ?& m2 t3 {
- public onlyProxyOwner
- {' h5 q* K: z; V$ q! \0 u
- _upgradeTo(_implementation);
- }9 c) r8 a( F( [
- /**
- * @dev Tells the address of the current implementation) [' [' g1 V; N3 A- y4 G1 L# r' v/ M
- * @return address of the current implementation
- */' G6 q3 b0 T2 @! o
- function implementation() public view returns (address impl) { b% z( C$ [3 t3 J. P
- bytes32 position = implementationPosition;
- assembly {8 z% g" {( s& F8 L# p9 R
- impl := sload(position)7 V. w0 m8 x0 q" Z/ G/ X7 {
- }4 x; j9 ] |, f L) o/ C
- }2 ]. z/ B- m. y7 f! U
- /**# N: a" I" y a$ l! ~
- * @dev Tells the address of the owner# a$ e( f; }" V! L, T9 a- |- h7 h; U6 M
- * @return the address of the owner
- */
- function proxyOwner() public view returns (address owner) {; D/ o4 B- V! `( o I s
- bytes32 position = proxyOwnerPosition;
- assembly {+ {2 H, E: y5 s' S0 k
- owner := sload(position)/ E& P" T4 i2 s9 \% V/ O4 t! H0 ]
- }6 w9 h5 @( o& R8 x3 I. y+ m/ }% ]
- }
- /**
- * @dev Sets the address of the current implementation
- * @param _newImplementation address of the new implementation; y' G M9 z! B8 z# f
- */
- function _setImplementation(address _newImplementation)
- internal
- {
- bytes32 position = implementationPosition;
- assembly {
- sstore(position, _newImplementation)2 h9 C. ^! Z0 {9 B5 b. r9 N. P- h/ m) ^
- }; y* z. O( Y3 v0 Y' U# O
- }* D5 T# a7 Q( j* F9 |1 V
- /**+ ^5 j0 [% n/ Z6 r8 A1 z$ ]2 ?
- * @dev Upgrades the implementation address
- * @param _newImplementation address of the new implementation1 t/ W5 m) l* U
- */( E7 m, }8 `2 t9 Y
- function _upgradeTo(address _newImplementation) internal {
- address currentImplementation = implementation();9 e' O' Y' o4 i# w Y4 k
- require(currentImplementation != _newImplementation);
- _setImplementation(_newImplementation);
- }
- /**
- * @dev Sets the address of the owner
- */4 G' r T9 k' W6 Q' G
- function _setUpgradeabilityOwner(address _newProxyOwner)! R& Y, m9 w& j2 `3 M
- internal
- {
- bytes32 position = proxyOwnerPosition;
- assembly {' e, T- e: w2 o* _+ y; v. f' F
- sstore(position, _newProxyOwner)2 O8 z6 M8 m7 _" i3 U' s" t9 w
- }* @6 Z# ^8 q4 n" d/ x, n
- }
- }
- contract ImplementationV1 {
- address public owner;3 ^6 W' C8 E5 }! W2 S% h7 B" p
- mapping (address => uint) internal points;$ ]8 k. M9 W5 e, s( D9 E6 K
- - X0 X, n6 S* U- }6 H- R: z+ x
- modifier onlyOwner() {
- require (msg.sender == owner);
- _;
- }
- function initOwner() external {) }# t9 m8 e7 t, v' o: Y
- require (owner == address(0));4 ~; Y" v2 Z* v) }! u: \- P
- owner = msg.sender;7 Z6 D* I0 N: o/ a. U& b
- }8 C$ g6 A% S5 W/ Y2 ?' X
- function addPlayer(address _player, uint _points)
- public onlyOwner
- {
- require (points[_player] == 0);
- points[_player] = _points;' t* S5 }2 B! l# N. w
- }) M# N2 B2 Z" S( v+ W3 A9 _
- function setPoints(address _player, uint _points)# B/ C- j6 L* R- R1 p' m
- public onlyOwner$ T+ F5 P& f1 Z( [$ |" P! v
- {) O N4 C- v: h) [
- require (points[_player] != 0); z: Z; O. V- r1 o) ~
- points[_player] = _points;
- }
- }
- contract ImplementationV2 is ImplementationV1 {$ u9 U& E/ z" i" d3 t
- uint public totalPlayers;7 J* Q- |; T7 `4 ^5 `+ G
- / `* a9 Y$ f8 p$ }5 s
- function addPlayer(address _player, uint _points)) ~, e5 E8 j$ `
- public onlyOwner
- {; X; d0 B/ X( C; Q8 ` L3 @0 }& ]1 k
- require (points[_player] == 0);
- points[_player] = _points;4 Z2 M( ? k H H$ G2 E
- totalPlayers++;# [/ u1 T, j( R a' `3 ]
- }
- }