- <b>contract StorageStructure {4 d' g- V; K9 }; T
- address public implementation;
- address public owner;
- mapping (address => uint) internal points;
- uint internal totalPlayers;$ w$ J* H" L- {. B/ v
- }</b>
- contract ImplementationV1 is StorageStructure {
- modifier onlyOwner() {
- require (msg.sender == owner);4 H4 I( ^5 x8 x9 s. y+ j N. ?9 Z
- _;+ d- j$ e: l- ?) e2 Q4 D
- }, P$ P3 m8 X0 D, ^! `' \" R, I
- function addPlayer(address _player, uint _points): _7 I) j+ o+ q- K0 X5 e
- public onlyOwner
- {
- require (points[_player] == 0);
- points[_player] = _points;
- } o; h6 K( W: p& A9 U6 W
- function setPoints(address _player, uint _points)
- public onlyOwner
- {( C5 P+ |& _3 A6 y& |
- require (points[_player] != 0);& O8 V* k8 p% [
- points[_player] = _points;8 F K {1 ?2 Q" V6 Y3 W& n7 q5 b) U
- }
- }
- contract Proxy is StorageStructure {0 n2 l+ T& Z( P/ E
- modifier onlyOwner() {# ]1 T1 t! x' J( Y+ B0 k; R* w* W
- require (msg.sender == owner);
- _;
- }* I9 Y% ~8 Z$ N8 o# {; b1 s0 c
- /**
- * @dev constructor that sets the owner address
- */, _9 t! O' z# X, ~3 V
- constructor() public {1 g" F4 i" V9 @7 m4 P
- owner = msg.sender;. N% o: d6 f& w/ x+ D* s
- }
- /**
- * @dev Upgrades the implementation address
- * @param _newImplementation address of the new implementation
- */6 \' h: X* D% a0 G% J
- function upgradeTo(address _newImplementation)
- external onlyOwner
- {; I9 L6 H! V3 r- }8 z5 K: L! p
- require(implementation != _newImplementation);% D0 G t, U8 O& ?% }4 P, X% o. [
- _setImplementation(_newImplementation);
- }; I# N$ h+ t' \5 g1 H& [
- /**
- * @dev Fallback function allowing to perform a delegatecall
- * to the given implementation. This function will return
- * whatever the implementation call returns. ?, g& X+ R8 t5 Q/ O
- */9 q2 \. B% i7 @" E4 ]7 }
- function () payable public {
- address impl = implementation;
- require(impl != address(0));
- assembly {# z& S/ A( v) K% o9 W# z9 U. ?8 P2 w' h
- let ptr := mload(0x40)# a9 B( x: W2 |" T
- calldatacopy(ptr, 0, calldatasize)8 p! L( g+ `0 s! O) s0 W+ _
- let result := delegatecall(gas, impl, ptr, calldatasize, 0, 0)
- let size := returndatasize
- returndatacopy(ptr, 0, size)6 L3 g3 ?/ M) J" ?4 i" y+ R0 O4 o
- switch result" w" K8 O( O0 M, s
- case 0 { revert(ptr, size) }
- default { return(ptr, size) }
- }
- }" z; F3 K" r3 d8 t: U- h8 b
- ( C' ]2 n# S$ ~( G- X7 Y7 \
- /**
- * @dev Sets the address of the current implementation) g3 {6 t, j: ?9 r2 Y
- * @param _newImp address of the new implementation
- */
- function _setImplementation(address _newImp) internal { X( Z2 p6 I; B' f7 f* k# `( {
- implementation = _newImp;8 n3 y) g. c3 f6 K5 q1 ?
- }
- }
- contract ImplementationV2 is ImplementationV1 { Y' J& E& L& {: q, E
- function addPlayer(address _player, uint _points)
- public onlyOwner
- {0 `# [% b) U7 A
- require (points[_player] == 0);
- points[_player] = _points;
- totalPlayers++;
- }
- }
- contract UnstructuredProxy {
- , L- L' [, ^1 F9 D' g
- // Storage position of the address of the current implementation
- bytes32 private constant implementationPosition =4 @1 P+ E# z a% A9 }% D
- keccak256("org.govblocks.implementation.address");
- // Storage position of the owner of the contract
- bytes32 private constant proxyOwnerPosition =- }$ _5 m' E, E" i9 w4 D, ~6 F) Y* `
- keccak256("org.govblocks.proxy.owner");" g& ^4 U3 M) K/ F4 t
- /**5 j* I6 x2 \/ t- l
- * @dev Throws if called by any account other than the owner.
- */% L) {" k! C3 [
- modifier onlyProxyOwner() {
- require (msg.sender == proxyOwner());4 s8 x1 Y, R4 R7 h$ G3 r5 U) E* j
- _;4 x3 E4 @+ i+ V7 Y
- }/ p5 g& C7 w9 z/ L5 I$ E
- /**
- * @dev the constructor sets owner8 l1 U V. x1 ~- V% S
- */
- constructor() public {
- _setUpgradeabilityOwner(msg.sender);" V8 X& t4 \2 ] G. x& v
- }* t7 U0 V# P& q
- /**
- * @dev Allows the current owner to transfer ownership
- * @param _newOwner The address to transfer ownership to
- */! n% p" E% r) ^8 K# r5 K1 I
- function transferProxyOwnership(address _newOwner)
- public onlyProxyOwner: o+ p* j- [# D4 T$ Q
- {
- require(_newOwner != address(0));
- _setUpgradeabilityOwner(_newOwner);; p) r6 }7 V% W. G
- }
- /**
- * @dev Allows the proxy owner to upgrade the implementation& t" N0 \0 _6 \* l/ ]# i8 M& W" a
- * @param _implementation address of the new implementation
- */
- function upgradeTo(address _implementation); s( d* N/ K4 G3 f9 v: C
- public onlyProxyOwner
- {
- _upgradeTo(_implementation);
- }
- /**- B& y% |$ I2 A- w2 O
- * @dev Tells the address of the current implementation L- k. v8 _. r* m2 v( ?. y3 [
- * @return address of the current implementation) M# E9 B; p' w# t; O
- */
- function implementation() public view returns (address impl) {4 b7 F/ }( b: J& v
- bytes32 position = implementationPosition;
- assembly {
- impl := sload(position)! d+ ]+ W( p% T( p
- }
- }! _! P1 Y" _ b
- /**: M$ z5 t7 J$ D! G
- * @dev Tells the address of the owner
- * @return the address of the owner
- */6 o- _' n; Z7 h9 E w
- function proxyOwner() public view returns (address owner) {
- bytes32 position = proxyOwnerPosition;
- assembly {3 ?. u- Q6 t/ B# F2 d% T0 X
- owner := sload(position)
- }) d W( y4 |" R5 g7 G! F
- }$ R% g6 V b! `
- /**
- * @dev Sets the address of the current implementation
- * @param _newImplementation address of the new implementation
- */
- function _setImplementation(address _newImplementation)+ ?! j' M. n- [) R
- internal
- {
- bytes32 position = implementationPosition;1 H5 M" I( I$ K v
- assembly {
- sstore(position, _newImplementation)
- }
- }
- /**
- * @dev Upgrades the implementation address
- * @param _newImplementation address of the new implementation9 X! j2 s) j7 K8 R6 s% n
- */% k8 }# d: d. k8 T- y7 D
- function _upgradeTo(address _newImplementation) internal {
- address currentImplementation = implementation();4 T" v8 ]8 D+ d9 x
- require(currentImplementation != _newImplementation);8 W7 W" }$ Q" ]7 w& n
- _setImplementation(_newImplementation);
- }
- /**
- * @dev Sets the address of the owner
- */1 K% d8 ^* y, h; d* W8 Q# z5 h# @
- function _setUpgradeabilityOwner(address _newProxyOwner)$ N/ i, s7 p9 u6 w
- internal
- {
- bytes32 position = proxyOwnerPosition;
- assembly {
- sstore(position, _newProxyOwner)
- }, `; G7 d* C7 t) k+ {8 T
- }
- }
- contract ImplementationV1 {
- address public owner;
- mapping (address => uint) internal points;
- + y6 t) i' W" Q) V
- modifier onlyOwner() {
- require (msg.sender == owner);3 Z8 ^) n+ t3 Q5 r0 V; d, A3 o) i% {
- _;
- }
- function initOwner() external {
- require (owner == address(0));) \, A) E' n0 X6 v9 Y
- owner = msg.sender;7 M9 j4 t$ r, Y/ K- g4 ~4 x
- }
- function addPlayer(address _player, uint _points)
- public onlyOwner' l+ ^$ G; Q7 r3 W) G
- {
- require (points[_player] == 0);
- points[_player] = _points;
- }
- " q& k, z' i, v" d! ~, X
- function setPoints(address _player, uint _points)
- public onlyOwner
- {# ~. [. }. O; v
- require (points[_player] != 0);) N5 c; p- ]7 Q4 S9 t
- points[_player] = _points;
- }
- }
- contract ImplementationV2 is ImplementationV1 {
- uint public totalPlayers;& n3 z& c! o# E4 w- t/ i+ U9 J
- $ _2 F- t9 K$ E% w
- 7 Y$ ~2 e7 x" h O+ n" @- g
- function addPlayer(address _player, uint _points)5 O( Z4 m6 u& t7 O: q
- public onlyOwner
- {
- require (points[_player] == 0);( k2 l% m4 V) [6 x f. |! H' t0 v+ s: `
- points[_player] = _points;/ x% C: H) X& @( {6 x. i" Z0 u/ \
- totalPlayers++;! q$ M" h$ ]3 G# g$ i* G" K
- }
- }