-
Notifications
You must be signed in to change notification settings - Fork 4
/
PublicResolver.sol
122 lines (111 loc) · 3.29 KB
/
PublicResolver.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
import "../registry/ENS.sol";
import "./profiles/ABIResolver.sol";
import "./profiles/AddrResolver.sol";
import "./profiles/ContentHashResolver.sol";
import "./profiles/DNSResolver.sol";
import "./profiles/InterfaceResolver.sol";
import "./profiles/NameResolver.sol";
import "./profiles/PubkeyResolver.sol";
import "./profiles/TextResolver.sol";
import "./Multicallable.sol";
interface INameWrapper {
function ownerOf(uint256 id) external view returns (address);
}
/**
* A simple resolver anyone can use; only allows the owner of a node to set its
* address.
*/
contract PublicResolver is
Multicallable,
ABIResolver,
AddrResolver,
ContentHashResolver,
DNSResolver,
InterfaceResolver,
NameResolver,
PubkeyResolver,
TextResolver
{
ENS immutable ens;
INameWrapper immutable nameWrapper;
address immutable trustedETHController;
address immutable trustedReverseRegistrar;
/**
* A mapping of operators. An address that is authorised for an address
* may make any changes to the name that the owner could, but may not update
* the set of authorisations.
* (owner, operator) => approved
*/
mapping(address => mapping(address => bool)) private _operatorApprovals;
// Logged when an operator is added or removed.
event ApprovalForAll(
address indexed owner,
address indexed operator,
bool approved
);
constructor(
ENS _ens,
INameWrapper wrapperAddress,
address _trustedETHController,
address _trustedReverseRegistrar
) {
ens = _ens;
nameWrapper = wrapperAddress;
trustedETHController = _trustedETHController;
trustedReverseRegistrar = _trustedReverseRegistrar;
}
/**
* @dev See {IERC1155-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) external {
require(
msg.sender != operator,
"ERC1155: setting approval status for self"
);
_operatorApprovals[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender, operator, approved);
}
/**
* @dev See {IERC1155-isApprovedForAll}.
*/
function isApprovedForAll(address account, address operator)
public
view
returns (bool)
{
return _operatorApprovals[account][operator];
}
function isAuthorised(bytes32 node) internal view override returns (bool) {
if (
msg.sender == trustedETHController ||
msg.sender == trustedReverseRegistrar
) {
return true;
}
address owner = ens.owner(node);
if (owner == address(nameWrapper)) {
owner = nameWrapper.ownerOf(uint256(node));
}
return owner == msg.sender || isApprovedForAll(owner, msg.sender);
}
function supportsInterface(bytes4 interfaceID)
public
view
override(
Multicallable,
ABIResolver,
AddrResolver,
ContentHashResolver,
DNSResolver,
InterfaceResolver,
NameResolver,
PubkeyResolver,
TextResolver
)
returns (bool)
{
return super.supportsInterface(interfaceID);
}
}