- <b>contract StorageStructure {& x2 L, x. u3 V7 Z3 o% a5 A6 S
- address public implementation;% b/ f! _* J( ^
- address public owner;" x9 `( [$ i9 t# G+ |7 o) O T4 h
- mapping (address => uint) internal points;
- uint internal totalPlayers;
- }</b>
- contract ImplementationV1 is StorageStructure {
- modifier onlyOwner() {6 V' c& s' ?% n- ]+ L8 b: F- g
- require (msg.sender == owner);! p0 h4 `) g, z! y* Y' d3 Q. ^! Z& a& L
- _;
- }
- function addPlayer(address _player, uint _points)/ k' x% j. B6 V& A$ P3 w
- public onlyOwner8 x0 ~$ d1 ?6 o# o9 I
- {/ S1 B/ v! M$ D9 `' J
- require (points[_player] == 0);3 n! E; j6 ]. k* a' v/ j
- points[_player] = _points;$ G3 F. _6 `3 D p" A" L
- }
- function setPoints(address _player, uint _points)* a' r- D# p6 y
- public onlyOwner
- {. d* A) d. C, E7 g2 i( }
- require (points[_player] != 0);
- points[_player] = _points; S% \1 q0 U8 T- M% n, M1 U
- }
- }
- contract Proxy is StorageStructure {4 x2 ^4 s& e) D9 f; [+ z0 {
- # `) y5 _ a+ i* a0 A' t" I
- modifier onlyOwner() {4 n& n% N! h' R! w" Z1 M
- require (msg.sender == owner); i+ ]: Y3 p0 t5 |: ^8 D, Q3 }
- _;
- }
- /** o' A {- \8 _1 r6 ^; d7 B( [
- * @dev constructor that sets the owner address
- */- _: k# s% U4 d0 t4 l$ z8 F# E
- constructor() public {7 k9 ~ v% G$ i6 t0 i; [
- owner = msg.sender;
- }) j3 E, I, r; D: O6 K/ m) f2 m$ J \8 m
- /**- S3 d; ]3 Y0 z$ K. i' |
- * @dev Upgrades the implementation address
- * @param _newImplementation address of the new implementation
- */5 B( M' @- `0 T: \6 B- ^
- function upgradeTo(address _newImplementation)
- external onlyOwner
- {) x, q/ X, C( I) O" f2 U" u$ z2 f
- require(implementation != _newImplementation);
- _setImplementation(_newImplementation);& B, k+ A, o8 J' i/ T# q. g6 z5 R+ o
- }4 z; k% `4 h/ c
- /**
- * @dev Fallback function allowing to perform a delegatecall4 ]5 U$ D% X; |3 Z; U2 n- Z( S% b
- * to the given implementation. This function will return
- * whatever the implementation call returns$ M' i; ]. ^+ ?0 e! \, I- G
- */
- function () payable public {
- address impl = implementation;
- require(impl != address(0));
- assembly {
- let ptr := mload(0x40)
- calldatacopy(ptr, 0, calldatasize): b1 _) h+ |- T2 [! d ^, y: ^6 C+ n
- let result := delegatecall(gas, impl, ptr, calldatasize, 0, 0)
- let size := returndatasize
- returndatacopy(ptr, 0, size)
- switch result5 B% t* S: |1 J I' C/ s, U
- case 0 { revert(ptr, size) }" W: z* R; W. L7 k0 p3 S
- default { return(ptr, size) }
- }! Z& @/ ]7 D3 I+ O3 l
- }, D9 C' r" h/ A' y
- 6 ?' G9 @, \9 d( E' ^, H( H
- /**
- * @dev Sets the address of the current implementation5 M3 c5 o+ T% m7 U4 G G! m# @. v
- * @param _newImp address of the new implementation% q0 }4 M' B I/ g
- */6 H6 Y) O, t) T6 {8 R
- function _setImplementation(address _newImp) internal {( u& K( `! Z4 ?0 F3 m7 O% a
- implementation = _newImp;* |: G# \( D9 @3 ?( D7 n9 d$ U* e
- }; u$ W" Z3 L8 Z. M
- }
- contract ImplementationV2 is ImplementationV1 {8 l. q, y8 ~6 c1 j
- $ \( U0 T( R/ ~$ y
- function addPlayer(address _player, uint _points)& v8 O$ ^9 J- S, R4 A
- public onlyOwner! Z$ c+ e, O# N/ Z+ X. O% ^
- {
- require (points[_player] == 0);
- points[_player] = _points;/ y) ~- n% U0 E2 m# W& A
- totalPlayers++;
- }
- }
- contract UnstructuredProxy {
- " u! {8 T% w8 V( u+ q$ C5 o* i
- // Storage position of the address of the current implementation
- bytes32 private constant implementationPosition =5 A! a) f% b" e* ?0 }4 q& [
- keccak256("org.govblocks.implementation.address");
- // Storage position of the owner of the contract: u- o; P, @0 [- U" Y. H. _% z! t* g
- bytes32 private constant proxyOwnerPosition =
- keccak256("org.govblocks.proxy.owner");
- /**4 g5 A! L5 f+ o, u
- * @dev Throws if called by any account other than the owner.* m' l7 V- i$ C2 Q
- */
- modifier onlyProxyOwner() {
- require (msg.sender == proxyOwner());
- _;
- }( _- A$ [* v6 Q; W5 z& T, F5 l
- /**
- * @dev the constructor sets owner
- */ H! b" |2 e$ N9 {' r& j! d6 m
- constructor() public {+ V' T" |+ ]" ?' v1 g
- _setUpgradeabilityOwner(msg.sender);- o6 ?& x" t' \% ~& E
- }9 [/ b/ _" T, L7 R' m
- /**6 @/ g( x% z* S% k* M; n
- * @dev Allows the current owner to transfer ownership1 R0 B0 v# I. F
- * @param _newOwner The address to transfer ownership to5 w5 R+ u! [6 p3 e' V: R! `8 O1 l
- */
- function transferProxyOwnership(address _newOwner)
- public onlyProxyOwner) e1 A# Q4 J4 t G0 U* ~
- {0 }, m9 V e& s0 v, z
- require(_newOwner != address(0));
- _setUpgradeabilityOwner(_newOwner);
- }
- /**
- * @dev Allows the proxy owner to upgrade the implementation
- * @param _implementation address of the new implementation# Z5 J/ z8 {7 i0 J5 `
- */7 \$ R6 u( `' ?+ ~
- function upgradeTo(address _implementation)3 ]5 m. X i/ q$ ~* |8 K. S+ {
- public onlyProxyOwner$ U! ~3 w$ Y y4 n' K: H" Q
- {6 G: W+ a- R/ }( w
- _upgradeTo(_implementation);5 M; c7 `; C3 \" T
- }7 k }! c7 p9 b3 l" q+ y
- /**
- * @dev Tells the address of the current implementation# c, U% B Q+ g4 G; _; ~
- * @return address of the current implementation+ u( P; ?2 S5 C3 b
- */: \1 |/ f/ J0 z8 H7 |" Y
- function implementation() public view returns (address impl) {
- bytes32 position = implementationPosition;
- assembly {
- impl := sload(position)
- }4 N* f& G9 G( r; Z) P5 y/ i' z+ y
- }- L: J, S( x2 k. q
- /**( j6 z$ `9 j9 ~) E4 k& i
- * @dev Tells the address of the owner
- * @return the address of the owner1 X4 m; Q1 d3 a
- */& Q! N9 o8 \6 r% r
- function proxyOwner() public view returns (address owner) {# q- R. |3 M6 V" ~
- bytes32 position = proxyOwnerPosition;" l; Z- d- o& h, V: V8 ~
- assembly {+ Z. [) }3 U6 A2 f, _9 o# V
- owner := sload(position)) E3 a2 d: c, t$ a
- }) f4 T: k6 |* K/ X: I0 V. e% u
- } Q# ?& D" I6 { f, m u- K
- /**
- * @dev Sets the address of the current implementation7 Y1 I- [* Z6 z# c h; R. h7 b, C% l
- * @param _newImplementation address of the new implementation
- */
- function _setImplementation(address _newImplementation)
- internal( }9 t4 I1 U: q
- {
- bytes32 position = implementationPosition;
- assembly {
- sstore(position, _newImplementation)
- }
- }
- /**
- * @dev Upgrades the implementation address) [+ k8 V- N$ E7 [: L+ w
- * @param _newImplementation address of the new implementation
- */ M6 ~7 F. j! u' T
- function _upgradeTo(address _newImplementation) internal {+ K7 L. R7 b A/ f% M$ T9 y1 I
- address currentImplementation = implementation();+ B; Y$ W+ }, ^2 [
- require(currentImplementation != _newImplementation);
- _setImplementation(_newImplementation);
- }
- /**
- * @dev Sets the address of the owner' R7 c* j% x6 J& A) a0 E1 `4 x# J
- */
- function _setUpgradeabilityOwner(address _newProxyOwner)
- internal2 F3 a# @9 m7 V5 `4 _ D, g5 @. }
- {8 o2 j3 o- o6 ^, q) M
- bytes32 position = proxyOwnerPosition;4 l6 u$ F' y; q0 C: {
- assembly {3 f" T5 |1 \0 f' F1 S
- sstore(position, _newProxyOwner)" y' Z, x: C' m$ U
- }
- }" T9 r) V1 @0 _+ ]1 Z
- }
- contract ImplementationV1 {& |6 Y7 G# F3 A+ E! F) ^0 a, l3 B$ _
- address public owner;; Q9 Z9 @' P- Y: } n3 W3 G; x
- mapping (address => uint) internal points;
- % E" o3 U5 N" E# z3 u& b& V
- modifier onlyOwner() {' {2 a6 C* _9 n. T4 y
- require (msg.sender == owner);
- _;
- }
- function initOwner() external {
- require (owner == address(0));
- owner = msg.sender; G m' @7 h1 ]& x0 o- o
- }
- function addPlayer(address _player, uint _points)
- public onlyOwner
- {6 L! a) W- I$ j" b; t& E
- require (points[_player] == 0);
- points[_player] = _points;
- }
- 1 X! g& k1 V% _
- function setPoints(address _player, uint _points)2 J9 }1 S. m- a! p" \
- public onlyOwner
- {: f1 q ^* H. h* E) I
- require (points[_player] != 0);
- points[_player] = _points;4 y0 Q, ?; B% B @
- }
- }
- contract ImplementationV2 is ImplementationV1 {
- uint public totalPlayers;
- function addPlayer(address _player, uint _points)
- public onlyOwner
- {- ^: o1 V D8 B8 l: `
- require (points[_player] == 0);
- points[_player] = _points;
- totalPlayers++;- f, x5 M9 V |+ |3 v8 \0 b: C: p
- }
- }