-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResolverClient.sol
90 lines (77 loc) · 2.5 KB
/
ResolverClient.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
pragma solidity ^0.4.25;
import "./ContractResolver.sol";
import "./ACOwned.sol";
/// @title Contract Resolver Interface
/// @author DigixGlobal
contract ResolverClient {
/// The address of the resolver contract for this project
address public resolver;
bytes32 public key;
/// Make our own address available to us as a constant
address public CONTRACT_ADDRESS;
/// Function modifier to check if msg.sender corresponds to the resolved address of a given key
/// @param _contract The resolver key
modifier if_sender_is(bytes32 _contract) {
require(sender_is(_contract));
_;
}
function sender_is(bytes32 _contract) internal view returns (bool _isFrom) {
_isFrom = msg.sender == ContractResolver(resolver).get_contract(_contract);
}
modifier if_sender_is_from(bytes32[3] _contracts) {
require(sender_is_from(_contracts));
_;
}
function sender_is_from(bytes32[3] _contracts) internal view returns (bool _isFrom) {
uint256 _n = _contracts.length;
for (uint256 i = 0; i < _n; i++) {
if (_contracts[i] == bytes32(0x0)) continue;
if (msg.sender == ContractResolver(resolver).get_contract(_contracts[i])) {
_isFrom = true;
break;
}
}
}
/// Function modifier to check resolver's locking status.
modifier unless_resolver_is_locked() {
require(is_locked() == false);
_;
}
/// @dev Initialize new contract
/// @param _key the resolver key for this contract
/// @return _success if the initialization is successful
function init(bytes32 _key, address _resolver)
internal
returns (bool _success)
{
bool _is_locked = ContractResolver(_resolver).locked_forever();
if (_is_locked == false) {
CONTRACT_ADDRESS = address(this);
resolver = _resolver;
key = _key;
require(ContractResolver(resolver).init_register_contract(key, CONTRACT_ADDRESS));
_success = true;
} else {
_success = false;
}
}
/// @dev Check if resolver is locked
/// @return _locked if the resolver is currently locked
function is_locked()
private
view
returns (bool _locked)
{
_locked = ContractResolver(resolver).locked_forever();
}
/// @dev Get the address of a contract
/// @param _key the resolver key to look up
/// @return _contract the address of the contract
function get_contract(bytes32 _key)
public
view
returns (address _contract)
{
_contract = ContractResolver(resolver).get_contract(_key);
}
}