-
Notifications
You must be signed in to change notification settings - Fork 1
feat: implements setRecord function and unit tests #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
c104d9b
dffc626
1913d2b
26003e7
f1fc41d
b43c43d
0e5f17f
e7efabc
12214f5
c2915f9
d8224cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,4 +47,52 @@ contract L2Resolver is IL2Resolver { | |
| REVERSE_ADMIN = _reverseAdmin; | ||
| PARENT_NODE = _parentNode; | ||
| } | ||
|
|
||
| /// @inheritdoc IL2Resolver | ||
| function setRecord(bytes32 _node, string calldata _key, bytes calldata _value) external { | ||
| if (_node == REVERSE_LOOKUP_NODE) { | ||
| if (msg.sender != REVERSE_ADMIN) revert NotAuthorized(); | ||
| } else { | ||
| address _owner = _getOwner(_node); | ||
|
0xAustrian marked this conversation as resolved.
|
||
| if (_owner != address(0)) { | ||
| if (!_isApprovedOperatorOrOwner(msg.sender, _owner)) revert NotAuthorized(); | ||
| } else { | ||
| // If the node is not owned by the ENSRegistry, then it could be a wildcard | ||
| address _parentOwner = _getOwner(PARENT_NODE); | ||
| if (_parentOwner == address(0)) revert NotAuthorized(); | ||
| if (!_isApprovedOperatorOrOwner(msg.sender, _parentOwner)) revert NotAuthorized(); | ||
| } | ||
| } | ||
|
|
||
| records[_node][_key] = _value; | ||
| emit RecordSet(_node, _key, _value); | ||
| } | ||
|
|
||
| /** | ||
| * @notice Returns the owner of a node. | ||
| * @dev If the node is the NameWrapper, then the domain is wrapped and it gets the owner from the NameWrapper. | ||
| * @dev If the owner is missing, then the domain is not registered or it could be a wildcard node. | ||
| * @param _node The node to get the owner of. | ||
| * @return _owner The owner of the node. Returns address(0) if the node is not owned by the ENSRegistry. | ||
| */ | ||
| function _getOwner(bytes32 _node) private view returns (address _owner) { | ||
| _owner = ENS_REGISTRY.owner(_node); | ||
| if (_owner == address(0)) return address(0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can safely remove this line, the behaviour will be the same.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would revert if the Maybe we should validate that none of those addresses are zero in the constructor?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, do you mind adding that to another linear task?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. I removed the validation in this PR |
||
| if (_owner == address(NAME_WRAPPER)) { | ||
| _owner = NAME_WRAPPER.ownerOf(uint256(_node)); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @notice Returns whether the caller is an owner or an approved operator for the owner | ||
| * @param _caller The address to check. | ||
| * @param _owner The owner of the node. | ||
| * @return _approved True if the _caller is an owner or an approved operator for the _owner, false otherwise. | ||
| */ | ||
| function _isApprovedOperatorOrOwner(address _caller, address _owner) private view returns (bool _approved) { | ||
| if (_owner == _caller) return true; | ||
| if (ENS_REGISTRY.isApprovedForAll(_owner, _caller)) return true; | ||
| if (address(NAME_WRAPPER) != address(0) && NAME_WRAPPER.isApprovedForAll(_owner, _caller)) return true; | ||
| return false; | ||
|
0xAustrian marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can import this repo as a package and use ENS and INameWrapper, wdyt?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it worth it when we just need a few lines of code for the interfaces? wouldn't it make the contract bigger by importing all those additional functions?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, lets do it your way |
Uh oh!
There was an error while loading. Please reload this page.