Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
Allow rsk registrars to claim
Browse files Browse the repository at this point in the history
  • Loading branch information
ilanolkies committed Jan 3, 2020
1 parent ec7b0a8 commit d2fa377
Show file tree
Hide file tree
Showing 4 changed files with 349 additions and 8 deletions.
76 changes: 68 additions & 8 deletions contracts/ReverseRegistrar.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
pragma solidity ^0.5.3;

import "@rsksmart/rns-registry/contracts/AbstractRNS.sol";
import "@openzeppelin/contracts/ownership/Ownable.sol";
import "@openzeppelin/contracts/access/Roles.sol";
import "./NameResolver.sol";

contract ReverseRegistrar {
contract ReverseRegistrar is Ownable {
using Roles for Roles.Role;

// namehash('addr.reverse')
bytes32 public constant ADDR_REVERSE_NODE = 0x91d1777781884d03a6757a803996e38de2a42967fb37eeaca72729271025a9e2;

AbstractRNS public rns;

modifier onlyRskRegistrar {
require(isRskRegistrar(msg.sender), "Not rsk registrar.");
_;
}

/// @dev Constructor
/// @param rnsAddr The address of the RNS registry.
constructor(AbstractRNS rnsAddr) public {
Expand All @@ -27,20 +36,20 @@ contract ReverseRegistrar {
/// @notice Transfer ownership of the name hex(msg.sender).addr.reverse
/// @dev Allows the caller to specify an owner other than themselves.
/// The resulting account has `name()` resolver.
/// @param owner The address to set as the owner of the reverse record in RNS.
/// @param recordOwner The address to set as the owner of the reverse record in RNS.
/// @return The RNS node hash of the reverse record.
function claim(address owner) public returns (bytes32) {
function claim(address recordOwner) public returns (bytes32) {
bytes32 label = sha3HexAddress(msg.sender);
rns.setSubnodeOwner(ADDR_REVERSE_NODE, label, owner);
rns.setSubnodeOwner(ADDR_REVERSE_NODE, label, recordOwner);
return keccak256(abi.encodePacked(ADDR_REVERSE_NODE, label));
}

/// @notice Sets the resolver of the name hex(msg.sender).addr.reverse to the specified resolver
/// @dev Transfer ownership of the name to the provided address.
/// @param owner The address to set as the owner of the reverse record in RNS.
/// @param recordOwner The address to set as the owner of the reverse record in RNS.
/// @param resolver The address of the resolver to set; 0 to leave default.
/// @return The RNS node hash of the reverse record.
function claimWithResolver(address owner, address resolver) external returns (bytes32 _node) {
function claimWithResolver(address recordOwner, address resolver) external returns (bytes32 _node) {
bytes32 label = sha3HexAddress(msg.sender);
_node = keccak256(abi.encodePacked(ADDR_REVERSE_NODE, label));

Expand All @@ -52,8 +61,8 @@ contract ReverseRegistrar {
rns.setResolver(_node, resolver);
// node has default resolver for 0x00 or resolver value

if (owner != address(this))
rns.setOwner(_node, owner);
if (recordOwner != address(this))
rns.setOwner(_node, recordOwner);
// owner owns node
}

Expand Down Expand Up @@ -87,4 +96,55 @@ contract ReverseRegistrar {
ret := keccak256(0, 40)
}
}

/**********************/
/* .rsk registrations */
/**********************/

// Allow different contracts to register reverse records for .rsk domains.
// It is assumed that these contracts register rsk names and send to this contract
// an address that is appropriate by the registrant

/// @notice Allows .rsk registrars to create reverse records.
/// @param addr The addr to register
/// @param label The label to prepend to .rsk and set as name.
function rskClaim(address addr, string calldata label) external onlyRskRegistrar {
bytes32 _label = sha3HexAddress(addr);
rns.setSubnodeOwner(ADDR_REVERSE_NODE, _label, address(this));
bytes32 _node = keccak256(abi.encodePacked(ADDR_REVERSE_NODE, _label));
NameResolver(
rns.resolver(_node)
).setName(
_node,
string(
abi.encodePacked(
bytes(label),
bytes(".rsk")
)
)
);
}

Roles.Role rskRegistrars;

/// @notice Give an account access to registrar role.
/// @dev Only owner.
/// @param registrar new registrar.
function addRskRegistrar(address registrar) external onlyOwner {
rskRegistrars.add(registrar);
}

/// @notice Check if an account has registrar role.
/// @param registrar to query if has registrar role.
/// @return true if it has registrar role.
function isRskRegistrar(address registrar) public view returns (bool) {
return rskRegistrars.has(registrar);
}

/// @notice Remove an account's access to registrar role.
/// @dev Only owner
/// @param registrar registrar to remove from registrar role.
function removeRskRegistrar(address registrar) external onlyOwner {
rskRegistrars.remove(registrar);
}
}
198 changes: 198 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d2fa377

Please sign in to comment.