-
Notifications
You must be signed in to change notification settings - Fork 413
/
PublicResolver.sol
163 lines (148 loc) · 4.67 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.17 <0.9.0;
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";
import {ReverseClaimer} from "../reverseRegistrar/ReverseClaimer.sol";
import {INameWrapper} from "../wrapper/INameWrapper.sol";
/**
* 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,
ReverseClaimer
{
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;
/**
* A mapping of delegates. A delegate that is authorised by an owner
* for a name may make changes to the name's resolver, but may not update
* the set of token approvals.
* (owner, name, delegate) => approved
*/
mapping(address => mapping(bytes32 => mapping(address => bool)))
private _tokenApprovals;
// Logged when an operator is added or removed.
event ApprovalForAll(
address indexed owner,
address indexed operator,
bool approved
);
// Logged when a delegate is approved or an approval is revoked.
event Approved(
address owner,
bytes32 indexed node,
address indexed delegate,
bool indexed approved
);
constructor(
ENS _ens,
INameWrapper wrapperAddress,
address _trustedETHController,
address _trustedReverseRegistrar
) ReverseClaimer(_ens, msg.sender) {
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];
}
/**
* @dev Approve a delegate to be able to updated records on a node.
*/
function approve(bytes32 node, address delegate, bool approved) external {
require(msg.sender != delegate, "Setting delegate status for self");
_tokenApprovals[msg.sender][node][delegate] = approved;
emit Approved(msg.sender, node, delegate, approved);
}
/**
* @dev Check to see if the delegate has been approved by the owner for the node.
*/
function isApprovedFor(
address owner,
bytes32 node,
address delegate
) public view returns (bool) {
return _tokenApprovals[owner][node][delegate];
}
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) ||
isApprovedFor(owner, node, msg.sender);
}
function supportsInterface(
bytes4 interfaceID
)
public
view
override(
Multicallable,
ABIResolver,
AddrResolver,
ContentHashResolver,
DNSResolver,
InterfaceResolver,
NameResolver,
PubkeyResolver,
TextResolver
)
returns (bool)
{
return super.supportsInterface(interfaceID);
}
}