- <b>contract StorageStructure {
- address public implementation;% f9 Y% f' I% p: V& L
- address public owner;2 o- ^. q' h9 {
- mapping (address => uint) internal points;
- uint internal totalPlayers;
- }</b>
- contract ImplementationV1 is StorageStructure {3 z+ M3 p/ G0 i& s
- modifier onlyOwner() {
- require (msg.sender == owner);: }0 e8 v _) Y2 F9 e
- _;7 A: }" F2 b' d6 f: d3 e
- }
- function addPlayer(address _player, uint _points)% m& G9 J) u4 E. k- s8 ^& I
- public onlyOwner8 |! W8 V* v0 y5 [
- {
- require (points[_player] == 0);. K4 \7 D* {$ \8 I* ?/ h
- points[_player] = _points;
- }
- function setPoints(address _player, uint _points)
- public onlyOwner
- {+ P2 }: h8 D& d0 N; v, E
- require (points[_player] != 0);3 p' H+ ~3 _2 P x
- points[_player] = _points;- X% m( O. q, Q" v' A/ d8 Y
- }, I4 j$ x% T5 c
- }
- contract Proxy is StorageStructure {
- modifier onlyOwner() {3 P6 m$ W- U9 N' M: u/ o% ~& u
- require (msg.sender == owner);6 d E( |: C8 n$ _1 W
- _;
- }2 E g! m6 [" G) i. i w
- /**" |* ~; q% [, }& m) o0 o* K
- * @dev constructor that sets the owner address3 D. |- `; h( Q# k j- f
- */4 _# r% e( k* y% {: E4 m2 P
- constructor() public {
- owner = msg.sender;
- }. ~( F( W5 N3 @6 i ?9 m
- /**
- * @dev Upgrades the implementation address3 G# T# u' q' \
- * @param _newImplementation address of the new implementation
- */9 i& t; t; D+ k2 ~) Q- i) I
- function upgradeTo(address _newImplementation)
- external onlyOwner5 _5 e) c) d$ a, @9 i7 V% Z5 r
- {
- require(implementation != _newImplementation);
- _setImplementation(_newImplementation);
- }) i& t# M8 n' z) E3 P
- /**
- * @dev Fallback function allowing to perform a delegatecall
- * to the given implementation. This function will return* C$ h$ Q; A5 D
- * whatever the implementation call returns5 o+ p# T! k# p2 a0 B
- */) V% L0 I; f! n3 G! ~: X9 _/ i
- function () payable public {5 X7 |" i" e& d: k1 D V# w
- address impl = implementation;& a& B8 \$ t' a+ \; }
- require(impl != address(0));
- assembly {
- let ptr := mload(0x40)
- calldatacopy(ptr, 0, calldatasize)
- let result := delegatecall(gas, impl, ptr, calldatasize, 0, 0)6 k9 u, B9 u3 G7 b) J
- let size := returndatasize* R r/ X8 w$ z! s9 L" b; [2 I! m% y
- returndatacopy(ptr, 0, size)
- switch result
- case 0 { revert(ptr, size) }$ u. z) h( @! ]1 u# k
- default { return(ptr, size) }& R9 ^* O& K/ V5 p2 t' q
- }
- }- I5 m2 B& D s
- ! f) J, @- \! {1 z) H% `0 K# S
- /**! c3 x3 k& E) N5 O/ W5 T- c( _" ?% B# \
- * @dev Sets the address of the current implementation6 I- \$ c6 }+ Q4 C# d s- h
- * @param _newImp address of the new implementation( P& I* i, j7 _0 @2 A
- */
- function _setImplementation(address _newImp) internal {
- implementation = _newImp;
- }% Y. a8 l4 m' ~ Z0 x7 \' c
- }
- contract ImplementationV2 is ImplementationV1 {
- # D# I) e5 z, B! j
- function addPlayer(address _player, uint _points)
- public onlyOwner
- {2 D7 s, `. \# @# N' c! j
- require (points[_player] == 0);7 _# B$ h; ?" S, Y5 y0 x& l6 {/ N6 B
- points[_player] = _points;6 A( b0 X+ u$ N5 G; q; [
- totalPlayers++;
- }( r) x) u5 ^: U/ W0 G P4 Y% ]
- }
- contract UnstructuredProxy {
- // Storage position of the address of the current implementation8 L7 ?% H" I9 H# }) c6 L/ K6 _! I
- bytes32 private constant implementationPosition =$ c J5 h4 [5 f! c. D
- keccak256("org.govblocks.implementation.address");
- // Storage position of the owner of the contract
- bytes32 private constant proxyOwnerPosition =
- keccak256("org.govblocks.proxy.owner");
- /**7 A" ?, u4 ?1 Q' c6 h
- * @dev Throws if called by any account other than the owner.! b4 Y2 x1 k% w: b; i9 z
- */
- modifier onlyProxyOwner() {
- require (msg.sender == proxyOwner());. }) R' p6 K. d
- _;+ n& \2 z2 X' O9 I$ d1 G2 ~/ ~ p
- }
- /**
- * @dev the constructor sets owner+ z- I* B, ] W. L
- */% _# o" d P) j, R
- constructor() public {
- _setUpgradeabilityOwner(msg.sender);) @2 a( W1 u9 D7 ~
- }4 _3 \. N+ W% a# A @ i5 P( l
- /**$ Y+ q5 s9 D H4 ^, a( \4 y4 ~
- * @dev Allows the current owner to transfer ownership0 A- Q. i, _, r0 K. {, C
- * @param _newOwner The address to transfer ownership to: H$ w+ l* O: n% ^9 G
- */7 K; x f' H% K& @/ T* a
- function transferProxyOwnership(address _newOwner)* i# T& W) I0 `$ K1 ]/ l
- public onlyProxyOwner# ?4 d1 B- s. d+ Q3 N6 Z
- {
- require(_newOwner != address(0));/ l: n7 r; O$ T% {
- _setUpgradeabilityOwner(_newOwner);" \- c8 d1 b& l9 s: c2 E- f( O( C
- }# `1 \0 p; ^1 [
- /**1 O9 O4 s* ]9 r& {- _% |& S5 p i
- * @dev Allows the proxy owner to upgrade the implementation
- * @param _implementation address of the new implementation1 x6 D/ g) M# [1 e3 s$ M
- */
- function upgradeTo(address _implementation)
- public onlyProxyOwner
- {
- _upgradeTo(_implementation);
- }
- /**
- * @dev Tells the address of the current implementation/ d$ e y3 `% }: M' Q2 {
- * @return address of the current implementation
- */8 u* S0 ] {8 G3 k3 T8 X0 F5 Q
- function implementation() public view returns (address impl) {
- bytes32 position = implementationPosition; p1 A+ y$ K: l, [* w6 v
- assembly {
- impl := sload(position)
- }% s& d9 y% L/ b
- }& Q3 m* ?3 Q p( Q- `
- /**
- * @dev Tells the address of the owner5 X6 v4 p+ h0 X# n! H5 m D/ r/ Q
- * @return the address of the owner' v5 f* _( N8 P8 b! p6 v
- */( C$ M6 s- L- W+ j3 \7 P+ r* [
- function proxyOwner() public view returns (address owner) {
- bytes32 position = proxyOwnerPosition;
- assembly {( ^' w- V/ X! p8 T) f
- owner := sload(position)9 S; }9 f: Q0 M" C
- }
- }
- /**6 }- ^) X. I! t: w' P* h$ o0 r
- * @dev Sets the address of the current implementation
- * @param _newImplementation address of the new implementation
- */ ^( h- u: M/ c, k: G
- function _setImplementation(address _newImplementation)
- internal
- {1 U& z$ V; n* g$ x/ I
- bytes32 position = implementationPosition;3 m+ w3 f7 \% \# h( u1 [
- assembly {
- sstore(position, _newImplementation) L& g% Z; I! g1 w7 z: k
- }' t9 k, f. j3 G+ w+ O4 _
- }
- /**
- * @dev Upgrades the implementation address' G" B! P9 o' w L9 G) k+ G
- * @param _newImplementation address of the new implementation6 F# ?* x2 j" U( I" C; `& C: T8 L" D
- */& T, _6 |/ I6 ?2 G/ e j$ q
- function _upgradeTo(address _newImplementation) internal {) c! A" I j9 }5 [$ ?& _/ K
- address currentImplementation = implementation();: k6 R) g2 k% E% i
- require(currentImplementation != _newImplementation);
- _setImplementation(_newImplementation);" \0 D' l4 I3 Z: J! I
- }
- 9 S- K$ t( s9 T/ P7 b7 @7 o! ~
- /**
- * @dev Sets the address of the owner/ C3 |: g1 E* Q% Z1 w2 `
- */' [5 g' H4 }, z/ i
- function _setUpgradeabilityOwner(address _newProxyOwner)
- internal
- {
- bytes32 position = proxyOwnerPosition;
- assembly {% ~8 q/ `/ e$ g
- sstore(position, _newProxyOwner)9 C' l# I3 O2 n2 h# ~: E9 a9 L
- }+ U% i4 u) @3 u; Z7 p
- }
- }
- contract ImplementationV1 {6 c% ]- }6 s& @; T1 `$ n
- address public owner;# F6 Y! N' F/ w- } `3 j
- mapping (address => uint) internal points;
- modifier onlyOwner() {! k( p1 \. K ^% ~" z' k$ U
- require (msg.sender == owner);- { ], A/ J, O: V& d0 H" M* n% J L
- _;+ w j$ m4 v) d9 B
- }& W m- a7 [; h& ^ l/ p
- function initOwner() external {
- require (owner == address(0));
- owner = msg.sender;! @) E" W( n y8 {. u
- }4 i( i5 Y* o8 Z# y
- function addPlayer(address _player, uint _points)+ i3 z9 k: S' t6 T# G8 {. J% M/ {3 y
- public onlyOwner
- {- q1 j( @$ K! l1 W! z6 o
- require (points[_player] == 0);
- points[_player] = _points;% }6 T% f w0 \7 D3 Y8 j! b6 C
- }$ V% L @7 a: z
- function setPoints(address _player, uint _points)
- public onlyOwner
- {
- require (points[_player] != 0);
- points[_player] = _points;; q# E9 s6 L8 X9 [. m0 [
- }
- }
- contract ImplementationV2 is ImplementationV1 {
- uint public totalPlayers;
- 6 \, a/ a _* T8 l: h/ b" Z
- function addPlayer(address _player, uint _points)" F( f" X9 C# D
- public onlyOwner- b9 E5 G* `% z1 y P7 N) w& D
- {
- require (points[_player] == 0);5 w9 ?" n! a. F
- points[_player] = _points;
- totalPlayers++;
- }& u, ~+ X1 m7 P
- }