- <b>contract StorageStructure {
- address public implementation;
- address public owner;1 q& q* {4 T3 M, c: A
- mapping (address => uint) internal points;4 s" g+ |0 b* \# ~: r
- uint internal totalPlayers;
- }</b>
- contract ImplementationV1 is StorageStructure {9 W5 r5 _+ |/ t6 @/ R9 N
- modifier onlyOwner() {
- require (msg.sender == owner);
- _;
- }
- function addPlayer(address _player, uint _points)8 [: P& `1 K: |$ r
- public onlyOwner. |, G3 y# {. E- f; U
- {7 J2 Q8 ]" h, i+ X3 G
- require (points[_player] == 0);
- points[_player] = _points;
- }6 n" s* d+ a7 m& L- A( y8 Y
- function setPoints(address _player, uint _points): T2 W/ T/ F4 r: k7 j" D! g# g
- public onlyOwner0 X& |- K# Z- G" B. I( `/ i
- {
- require (points[_player] != 0);
- points[_player] = _points;
- }0 x3 ?/ |4 L' y, l4 B
- }
- contract Proxy is StorageStructure {
- modifier onlyOwner() {
- require (msg.sender == owner);
- _;
- }, S, w# M+ G/ H# }7 s
- /**
- * @dev constructor that sets the owner address
- */2 R" _5 Q% ~) M: l9 I; ?; s$ J9 N9 ]$ s
- constructor() public {4 H. J+ J+ B& L* u. y
- owner = msg.sender;4 O; {) @; B) \$ ~
- }
- /**( U) l$ ^" J5 a) X+ ]7 S
- * @dev Upgrades the implementation address
- * @param _newImplementation address of the new implementation" S0 a( A1 F( C% [8 @1 f1 X
- */, y, u/ p. I2 I: G4 U7 ^2 z- O: L
- function upgradeTo(address _newImplementation)$ T) \* I5 t. d6 M
- external onlyOwner
- {4 n+ \! }8 M, g6 D0 ^2 \
- require(implementation != _newImplementation);
- _setImplementation(_newImplementation);
- }) d1 L* B( r/ `$ r
- /**
- * @dev Fallback function allowing to perform a delegatecall
- * to the given implementation. This function will return
- * whatever the implementation call returns A+ q6 R9 l: a, p* C- t% a
- */
- function () payable public {
- address impl = implementation;
- require(impl != address(0)); L5 ?; r. D' n+ n
- assembly {! H4 ?3 x2 c6 |' w7 k' c9 ]$ V
- let ptr := mload(0x40)- B5 r+ m2 o& z# m, u. m
- calldatacopy(ptr, 0, calldatasize)
- let result := delegatecall(gas, impl, ptr, calldatasize, 0, 0)
- let size := returndatasize
- returndatacopy(ptr, 0, size)
- switch result9 @- v' O' V, {2 ^
- case 0 { revert(ptr, size) }$ e2 m* U6 K* v6 m
- default { return(ptr, size) }/ P7 d7 U1 R' d7 [: W" ?
- }
- }/ i! j C2 G" O4 y L7 `/ `
- 8 f. ^- e/ Z. ]; g( f" S. r/ D
- /**& O T! H+ c6 W
- * @dev Sets the address of the current implementation
- * @param _newImp address of the new implementation
- */
- function _setImplementation(address _newImp) internal {. x! i9 |7 e1 B/ y1 T! X0 [
- implementation = _newImp;
- }
- }
- contract ImplementationV2 is ImplementationV1 {
- ( y6 ?! d' w7 ?$ ~, h: T) q$ h
- function addPlayer(address _player, uint _points)9 V d8 W6 r7 { f
- public onlyOwner8 O0 M& ?( R$ Y" E* t
- {# \3 x- }2 R G
- require (points[_player] == 0);' p( z O8 l4 Y9 f% Q9 M
- points[_player] = _points;
- totalPlayers++;) ? x' z- i4 b6 t# ~! e
- }$ |/ S# |2 f6 d/ w8 c k# J
- }
- contract UnstructuredProxy {
- // Storage position of the address of the current implementation6 J8 n" I& X: k j
- bytes32 private constant implementationPosition =
- keccak256("org.govblocks.implementation.address");0 |1 C7 w: e9 j8 |: `" _
- // Storage position of the owner of the contract
- bytes32 private constant proxyOwnerPosition =
- keccak256("org.govblocks.proxy.owner");
- /** a2 x7 w# X5 |7 w+ R
- * @dev Throws if called by any account other than the owner.
- */) I$ J4 t' U$ w. a) C2 l" m
- modifier onlyProxyOwner() {
- require (msg.sender == proxyOwner());- P. E/ {' T7 O) ^0 H8 n O
- _;
- }1 F; \7 g7 i4 W+ Y- N
- /**
- * @dev the constructor sets owner5 \7 a( h5 ~! j. s- z! t, U0 J
- */
- constructor() public {
- _setUpgradeabilityOwner(msg.sender);
- }
- /**; R4 h3 T8 v% ?
- * @dev Allows the current owner to transfer ownership
- * @param _newOwner The address to transfer ownership to
- */
- function transferProxyOwnership(address _newOwner)
- public onlyProxyOwner$ D5 `* _; w3 e
- {* M5 ]3 ^1 W3 A+ r! |
- require(_newOwner != address(0));
- _setUpgradeabilityOwner(_newOwner);% R3 x6 c/ c7 A% H7 @
- }- q' @5 F& A! L4 C2 s- O+ H
- /**# N6 I) l& m- d0 I" h
- * @dev Allows the proxy owner to upgrade the implementation5 a) }9 o7 @% {5 _: X6 c3 r
- * @param _implementation address of the new implementation
- */6 e6 q" ?* |2 s
- function upgradeTo(address _implementation)& ^* Y# U6 W/ C4 \9 Y/ e
- public onlyProxyOwner
- {
- _upgradeTo(_implementation);* \* s; |) f5 a/ f& O
- }
- /**
- * @dev Tells the address of the current implementation
- * @return address of the current implementation
- */) M; N4 D- n K7 `0 n" a
- function implementation() public view returns (address impl) {# v/ o. d6 v* f1 a2 a1 s8 w6 U( ~
- bytes32 position = implementationPosition;
- assembly {
- impl := sload(position)
- }# X, Y1 f# J# |- S' N0 |
- }
- /**
- * @dev Tells the address of the owner
- * @return the address of the owner
- */
- function proxyOwner() public view returns (address owner) {
- bytes32 position = proxyOwnerPosition;
- assembly {# y8 @9 I! Y# p$ {) O h
- owner := sload(position). E, \9 e6 Q g$ M: \
- }
- }7 S8 N2 t0 ?6 ?$ j+ c
- /**
- * @dev Sets the address of the current implementation+ J) i' ~) K2 H$ U' j' l: k0 _4 N
- * @param _newImplementation address of the new implementation
- */. t2 G1 t4 B5 j2 v# w0 X
- function _setImplementation(address _newImplementation)
- internal( i' U$ K' @; R: e
- {
- bytes32 position = implementationPosition;
- assembly {4 D. g3 y9 c/ }4 V" n; G4 ^' x% i
- sstore(position, _newImplementation)1 y+ V* G) `* ~$ {9 n
- }. `- E7 s8 |4 [4 w; Q
- }
- /**3 ~* R8 t; a; b( y4 E
- * @dev Upgrades the implementation address
- * @param _newImplementation address of the new implementation5 ~6 e, ^; C' B5 E1 _* p7 K
- */4 G. e2 Q D( K* E" N; e' z/ g
- function _upgradeTo(address _newImplementation) internal {
- address currentImplementation = implementation();
- require(currentImplementation != _newImplementation);
- _setImplementation(_newImplementation);
- }
- ; @( a( {2 I% q8 v, t2 m# M
- /**
- * @dev Sets the address of the owner+ a$ E u' m8 a- D% k ?$ L. T& h- X' [
- */
- function _setUpgradeabilityOwner(address _newProxyOwner)
- internal+ R; H6 L# x X& I% L
- {
- bytes32 position = proxyOwnerPosition;
- assembly {3 n+ X; X4 H9 u* j8 P& u- K( \
- sstore(position, _newProxyOwner)& w+ i" ~. o0 R# E
- }
- }
- }
- contract ImplementationV1 {
- address public owner;
- mapping (address => uint) internal points;
- modifier onlyOwner() {
- require (msg.sender == owner);) Q7 Z; c! E8 m: {
- _;
- }
- function initOwner() external {
- require (owner == address(0));
- owner = msg.sender;
- }3 t9 R% t" ]; s, N! H
- function addPlayer(address _player, uint _points)- G: G* G1 |# C" q7 t: ?8 i$ w! r
- public onlyOwner/ _7 o7 Z6 s0 H0 M n5 U: Y
- {8 f2 P4 Y, a. |+ G: c5 P
- require (points[_player] == 0);
- points[_player] = _points;2 G9 f5 f/ t1 Q g5 q
- }
- function setPoints(address _player, uint _points)6 P( F$ K+ B5 u e' e! e/ v
- public onlyOwner
- {* O. H& H- M( Q$ G2 X" r" t( J
- require (points[_player] != 0);- u7 _7 ~2 t: v' }; h3 ?1 u7 h P
- points[_player] = _points;( T; Q, c9 e* D, ?4 A6 ~% q
- } `3 ] ~3 z; W
- }
- contract ImplementationV2 is ImplementationV1 {
- uint public totalPlayers;
- 9 y# U6 V3 h+ b# U1 B: @& b4 `( I
- 2 X1 {4 B9 _, H8 K% [7 H
- function addPlayer(address _player, uint _points)
- public onlyOwner
- {
- require (points[_player] == 0);
- points[_player] = _points; G& x1 H! d6 {6 b+ n, ?4 S4 X
- totalPlayers++;- w# R; d) t4 _- D$ @
- }
- }