forked from monetha/verifiable-data-layer-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassport.sol
70 lines (59 loc) · 2.14 KB
/
Passport.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
pragma solidity ^0.4.24;
import "./ownership/ClaimableProxy.sol";
import "./lifecycle/DestructibleProxy.sol";
import "./IPassportLogicRegistry.sol";
import "./upgradeability/Proxy.sol";
/**
* @title Passport
*/
contract Passport is Proxy, ClaimableProxy, DestructibleProxy {
event PassportLogicRegistryChanged(
address indexed previousRegistry,
address indexed newRegistry
);
/**
* @dev Storage slot with the address of the current registry of the passport implementations.
* This is the keccak-256 hash of "org.monetha.passport.proxy.registry", and is
* validated in the constructor.
*/
bytes32 private constant REGISTRY_SLOT = 0xa04bab69e45aeb4c94a78ba5bc1be67ef28977c4fdf815a30b829a794eb67a4a;
/**
* @dev Contract constructor.
* @param _registry Address of the passport implementations registry.
*/
constructor(IPassportLogicRegistry _registry) public {
assert(REGISTRY_SLOT == keccak256("org.monetha.passport.proxy.registry"));
_setRegistry(_registry);
}
/**
* @return the address of passport logic registry.
*/
function getPassportLogicRegistry() public view returns (address) {
return _getRegistry();
}
/**
* @dev Returns the current passport logic implementation (used in Proxy fallback function to delegate call
* to passport logic implementation).
* @return Address of the current passport implementation
*/
function _implementation() internal view returns (address) {
return _getRegistry().getCurrentPassportLogic();
}
/**
* @dev Returns the current passport implementations registry.
* @return Address of the current implementation
*/
function _getRegistry() internal view returns (IPassportLogicRegistry reg) {
bytes32 slot = REGISTRY_SLOT;
assembly {
reg := sload(slot)
}
}
function _setRegistry(IPassportLogicRegistry _registry) internal {
require(address(_registry) != 0x0, "Cannot set registry to a zero address");
bytes32 slot = REGISTRY_SLOT;
assembly {
sstore(slot, _registry)
}
}
}