- <b>contract StorageStructure {
- address public implementation;
- address public owner;
- mapping (address => uint) internal points;
- uint internal totalPlayers;
- }</b>
- contract ImplementationV1 is StorageStructure {! { _+ k ~7 `' E) \: j) Z
- modifier onlyOwner() {- ?3 o% J# s1 w
- require (msg.sender == owner);
- _;% P2 u, z# I0 e. m! F% u
- }
- function addPlayer(address _player, uint _points)! ~# X" {3 c; B, U3 g+ W
- public onlyOwner( j1 a* y# I, \ |" C+ Q9 J7 C4 d6 x
- {
- require (points[_player] == 0);
- points[_player] = _points;
- }
- function setPoints(address _player, uint _points)8 \3 M. i G* z4 N5 ~, _3 R
- public onlyOwner2 j2 O* `/ |# Y9 }4 k9 F' ]( {
- {% Q: o# F7 ?8 i, `
- require (points[_player] != 0);
- points[_player] = _points;
- }% X8 n9 H( ]$ @* c
- }
- contract Proxy is StorageStructure {
- & c! n7 Y! l' `2 _$ B" k
- modifier onlyOwner() {
- require (msg.sender == owner);
- _;
- }/ }0 w% \/ y, ~ r d u& M
- /**
- * @dev constructor that sets the owner address
- */
- constructor() public {
- owner = msg.sender;
- }2 ]" Y& v0 t8 r, ^5 f4 h. N
- /**; P- l* c$ Q/ f
- * @dev Upgrades the implementation address: l9 d+ ^& q; Z& p G3 B9 V
- * @param _newImplementation address of the new implementation
- */! d, K: m2 ~! x# z# Z! K
- function upgradeTo(address _newImplementation)
- external onlyOwner. ~* U( C" [+ V! Q" G1 |; c) T# G
- {# ^4 X9 U4 s( h5 O$ q* x. b4 }
- require(implementation != _newImplementation);' x0 R) |8 [- W! `! a5 a
- _setImplementation(_newImplementation);
- }+ A. m% Y/ d7 F. P
- /**
- * @dev Fallback function allowing to perform a delegatecall1 h' }; t' Y/ h; Z/ N! Z$ e
- * to the given implementation. This function will return
- * whatever the implementation call returns w+ G" ~5 Y( a% ~2 t( _: P
- *// L3 v9 G9 N9 h% z. U/ E2 O) Q8 o
- function () payable public {0 [: ^( ]* t. N4 Y6 ^, U N4 A
- address impl = implementation;1 B3 E- {; Q, n; N
- require(impl != address(0));$ L; m% S7 i7 T1 j
- assembly {5 v/ R! N( z4 T, u/ L8 Z
- let ptr := mload(0x40)
- calldatacopy(ptr, 0, calldatasize)
- let result := delegatecall(gas, impl, ptr, calldatasize, 0, 0); [" M n1 f G% D: w
- let size := returndatasize
- returndatacopy(ptr, 0, size)$ s6 ^# v& J: ]- Z
- switch result9 c& r6 b9 p' M( ~
- case 0 { revert(ptr, size) }
- default { return(ptr, size) }- \' O# M+ K( _8 [9 P# B
- }& G& S) P B( z+ |/ y! Z: m
- }
- : F, D# N% ?. o _, l) b' Y
- /**" n9 S! d- |, w, F z7 Q
- * @dev Sets the address of the current implementation$ \5 v, I$ F$ A% T, d% Q$ y1 B' @
- * @param _newImp address of the new implementation
- */9 f2 b# x6 G- p# t
- function _setImplementation(address _newImp) internal {( K7 f, x! o ?8 k* H+ `
- implementation = _newImp;" W0 ^' }1 c" [6 z; u
- }
- }
- contract ImplementationV2 is ImplementationV1 {( V! ^# y7 M9 Y
- , H2 @, q) T: B8 R" B; C
- function addPlayer(address _player, uint _points)
- public onlyOwner/ r; b( l- N l% b, ^9 q& z
- {
- require (points[_player] == 0);
- points[_player] = _points;) B8 j1 S% z5 {7 P6 \
- totalPlayers++;
- }) ^: E3 [& g# j+ e- c; a
- }
- contract UnstructuredProxy {
- // 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 contract
- bytes32 private constant proxyOwnerPosition =' d; l, n6 L% G
- keccak256("org.govblocks.proxy.owner");
- /**0 t) k2 Z; `9 l5 e
- * @dev Throws if called by any account other than the owner.
- *// k+ d6 i* Z* t: j) i, k- l
- modifier onlyProxyOwner() {
- require (msg.sender == proxyOwner());
- _;
- }1 [9 Y, B& ~+ T$ l! t7 R8 H. r& b
- /**7 \8 @. t1 _# S8 [9 m
- * @dev the constructor sets owner' n& q& H) F' R" p# t& H, w- O6 Q4 J
- */3 h: f |7 Y8 \2 |3 E7 B3 H
- constructor() public {/ @3 w4 ?/ c* P; H8 B2 [. R# B& l
- _setUpgradeabilityOwner(msg.sender);( y. b% O& E- }& W* |
- }
- /**- U: f9 g8 s2 N6 `; ^
- * @dev Allows the current owner to transfer ownership: [4 Z! Q3 ~0 P3 Z
- * @param _newOwner The address to transfer ownership to x. t( }7 X1 p" i% w$ q e
- */
- function transferProxyOwnership(address _newOwner)/ Z& Z9 {# G2 _
- public onlyProxyOwner
- {3 \" P& D3 m7 ^. j
- require(_newOwner != address(0));
- _setUpgradeabilityOwner(_newOwner);
- }
- /**
- * @dev Allows the proxy owner to upgrade the implementation* a$ ?" H( J/ S$ g
- * @param _implementation address of the new implementation
- */% P% o8 C; K/ t: Y/ [0 l" }9 F
- function upgradeTo(address _implementation)
- public onlyProxyOwner
- {
- _upgradeTo(_implementation);
- }! P0 e% e8 V2 I G- E9 j' q4 [
- /**
- * @dev Tells the address of the current implementation
- * @return address of the current implementation
- */
- function implementation() public view returns (address impl) {) {1 C( X9 a. M/ ^( Q" I8 X
- bytes32 position = implementationPosition;+ S8 z. W4 `* g8 R
- assembly {
- impl := sload(position)( W J0 g& Y# M+ @1 T$ W2 o
- }$ c$ E o" }" g, v# l
- }5 ^* u6 D; Y/ Q# d4 q0 \3 h
- /**8 ~ h `( l% d7 k
- * @dev Tells the address of the owner" \5 S0 z7 I0 ]! c; u/ e
- * @return the address of the owner6 z8 U/ b& C! z1 u4 b3 P; M: P" p
- */
- function proxyOwner() public view returns (address owner) {
- bytes32 position = proxyOwnerPosition;$ @/ Z7 s- W" J& D5 ]8 g
- assembly {6 r7 ~1 Z" X) V6 T
- owner := sload(position)1 X1 J* }& m# s- p5 n% E+ _
- }- ?8 s' W; ]* W: m+ q9 a: I
- }& Q9 B1 Z4 `& t5 _' E) h" p& u
- /**
- * @dev Sets the address of the current implementation6 V" L& d9 h j
- * @param _newImplementation address of the new implementation9 H. C+ p9 t5 e* Q5 U6 A
- */
- function _setImplementation(address _newImplementation); }/ `/ l( X' F! l* t
- internal/ k7 u1 B3 o) C- j J
- {$ R! l1 }) s, U" v8 ]
- bytes32 position = implementationPosition;
- assembly {
- sstore(position, _newImplementation)5 {' s/ O& D) R. D* M1 V. E
- }; F. A4 {# j) S
- }+ }, ]# k: A/ [$ _4 x1 o
- /*** G2 e# }2 p+ w% K5 y& }- V* x
- * @dev Upgrades the implementation address5 k) x9 p. _. d( l, ~
- * @param _newImplementation address of the new implementation( v0 e- |8 `+ r; A. |
- */! J$ }7 E4 @! V" N$ a* A. N
- function _upgradeTo(address _newImplementation) internal {. \; F# c+ F: e1 N
- address currentImplementation = implementation();6 s$ a9 e& ~' w/ l- k
- require(currentImplementation != _newImplementation);
- _setImplementation(_newImplementation);
- }# u7 r" \& h6 g( a/ C' @* V Z
- 8 v- n; b A7 p* `+ ~) [
- /**
- * @dev Sets the address of the owner
- */
- function _setUpgradeabilityOwner(address _newProxyOwner)
- internal/ W8 z$ Y4 h% m5 T8 k
- {
- bytes32 position = proxyOwnerPosition;
- assembly {
- sstore(position, _newProxyOwner)! Z: u4 C1 _9 D
- }
- }
- }
- contract ImplementationV1 {
- address public owner;2 o/ [. N& B+ ` r1 Q
- mapping (address => uint) internal points;
- modifier onlyOwner() {
- require (msg.sender == owner);/ u4 b& r: @, `9 F
- _;* N3 u6 k% o9 N- Y' y
- }$ p) ?& }. e& n0 c! |% Z
- function initOwner() external {! Y: t9 z* k0 x, [$ f9 ~3 p
- require (owner == address(0));
- owner = msg.sender;
- }
- function addPlayer(address _player, uint _points)& n. W& R9 g. p! C7 o% r
- public onlyOwner
- {0 g, a" `# v$ M' ~% B
- require (points[_player] == 0);
- points[_player] = _points;
- }8 w9 }6 f I) ~. y5 z; [9 S' Q) [) o
- 1 }% j. f2 |3 |: f3 M" O
- function setPoints(address _player, uint _points)
- public onlyOwner2 u5 |1 S6 M8 o3 w/ n( r) C
- {
- require (points[_player] != 0);
- points[_player] = _points;" B/ _6 w# Z# v2 ^4 J+ ? X7 \& P
- }
- }
- contract ImplementationV2 is ImplementationV1 {$ I+ \3 E' d: ~- r b P
- uint public totalPlayers;
- h2 w* q# t! M' ?
- function addPlayer(address _player, uint _points)
- public onlyOwner
- {+ I& a! _" E4 `% D
- require (points[_player] == 0);
- points[_player] = _points;& F5 i" ^' x2 Y* y$ C. J
- totalPlayers++;
- }% L# w: y. ?0 G
- }