This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
M-Picco
committed
Nov 14, 2018
0 parents
commit 5745acb
Showing
35 changed files
with
4,325 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
node_modules | ||
_build | ||
_static | ||
_templates | ||
|
||
.DS_Store | ||
|
||
# Compiled contract ABIs and binaries | ||
build/contracts/* | ||
# Keep the RNS lll artifact | ||
!build/contracts/RNS.lll.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# RSK Name Service | ||
|
||
Implementation for Registry, Registrar, Deed and Resolver for the RSK Name Service | ||
|
||
For more information see the [documentation](https://docs.rns.rsk.co). | ||
|
||
## Install Truffle | ||
|
||
``` | ||
sudo npm install -g truffle | ||
npm install | ||
``` | ||
|
||
For details see [Truffle Docs](https://truffleframework.com/) | ||
|
||
## Install Package | ||
|
||
If Truffle is already installed run: | ||
|
||
``` | ||
npm install | ||
``` | ||
|
||
## Deploy | ||
|
||
Deploy to local ganache-cli: | ||
|
||
``` | ||
truffle deploy --network dev | ||
``` | ||
|
||
Deploy to local RSK node | ||
|
||
``` | ||
truffle deploy --network rsk | ||
``` | ||
|
||
## Test | ||
|
||
Test on local ganache-cli: | ||
|
||
``` | ||
truffle test --network dev | ||
``` | ||
|
||
Test on local RSK node: | ||
|
||
``` | ||
truffle test --network rsk | ||
``` | ||
|
||
## Contracts | ||
|
||
### RNS.sol | ||
|
||
Implementation of the Registry contract, it provides a simple mapping between a domain and its Resolver. Everything related to a domain ownership is managed in this contract, including ownership transfer and sub-domain creation. | ||
|
||
### TokenRegistrar.sol | ||
|
||
Implementation of the Registrar, it handles the auction process for each subnode of the node it owns. | ||
|
||
### TokenDeed.sol | ||
|
||
Implementation of the Deed, it holds RIF tokens in exchange for ownership of a node. | ||
|
||
### PublicResolver.sol | ||
|
||
Implementation of a simple resolver anyone can use; only allows the owner of a node to set its address. | ||
|
||
|
||
## Documentation | ||
|
||
For more information see [RNS Docs](https://docs.rns.rsk.co) | ||
|
||
# Contributors | ||
|
||
- [@m-picco](https://github.com/m-picco) | ||
- [@ajlopez](https://github.com/ajlopez) | ||
- [@julianlen](https://github.com/julianlen) | ||
- [@ilanolkies](https://github.com/ilanolkies) | ||
- [@alebanzas](https://github.com/alebanzas) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
/** | ||
* Truffle migration helper contract | ||
*/ | ||
contract Migrations { | ||
address public owner; | ||
uint public last_completed_migration; | ||
|
||
modifier restricted() { | ||
if (msg.sender == owner) _; | ||
} | ||
|
||
constructor() public { | ||
owner = msg.sender; | ||
} | ||
|
||
function setCompleted(uint completed) public restricted { | ||
last_completed_migration = completed; | ||
} | ||
|
||
function upgrade(address new_address) public restricted { | ||
Migrations upgraded = Migrations(new_address); | ||
upgraded.setCompleted(last_completed_migration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
contract AbstractRNS { | ||
function owner(bytes32 node) public view returns(address); | ||
function resolver(bytes32 node) public view returns(address); | ||
function ttl(bytes32 node) public view returns(uint64); | ||
function setOwner(bytes32 node, address ownerAddress) public; | ||
function setSubnodeOwner(bytes32 node, bytes32 label, address ownerAddress) public; | ||
function setResolver(bytes32 node, address resolverAddress) public; | ||
function setTTL(bytes32 node, uint64 ttlValue) public; | ||
|
||
// Logged when the owner of a node assigns a new owner to a subnode. | ||
event NewOwner(bytes32 indexed node, bytes32 indexed label, address ownerAddress); | ||
|
||
// Logged when the owner of a node transfers ownership to a new account. | ||
event Transfer(bytes32 indexed node, address ownerAddress); | ||
|
||
// Logged when the resolver for a node changes. | ||
event NewResolver(bytes32 indexed node, address resolverAddress); | ||
|
||
// Logged when the TTL of a node changes | ||
event NewTTL(bytes32 indexed node, uint64 ttlValue); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
import './AbstractRNS.sol'; | ||
|
||
/** | ||
* A simple resolver anyone can use; only allows the owner of a node to set its | ||
* address. | ||
*/ | ||
contract PublicResolver { | ||
AbstractRNS rns; | ||
mapping(bytes32=>address) addresses; | ||
mapping(bytes32=>bytes32) hashes; | ||
|
||
modifier only_owner(bytes32 node) { | ||
require(rns.owner(node) == msg.sender); | ||
_; | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* @param rnsAddr The RNS registrar contract. | ||
*/ | ||
constructor(AbstractRNS rnsAddr) public { | ||
rns = rnsAddr; | ||
} | ||
|
||
/** | ||
* Fallback function. | ||
*/ | ||
function() public { | ||
revert(); | ||
} | ||
|
||
/** | ||
* Returns true if the specified node has the specified record type. | ||
* @param node The RNS node to query. | ||
* @param kind The record type name, as specified in EIP137. | ||
* @return True if this resolver has a record of the provided type on the | ||
* provided node. | ||
*/ | ||
function has(bytes32 node, bytes32 kind) public view returns (bool) { | ||
return (kind == "addr" && addresses[node] != 0) || | ||
(kind == "hash" && hashes[node] != 0); | ||
} | ||
|
||
/** | ||
* Returns true if the resolver implements the interface specified by the provided hash. | ||
* @param interfaceID The ID of the interface to check for. | ||
* @return True if the contract implements the requested interface. | ||
*/ | ||
function supportsInterface(bytes4 interfaceID) public pure returns (bool) { | ||
return interfaceID == 0x3b3b57de || interfaceID == 0xd8389dc5; | ||
} | ||
|
||
/** | ||
* Returns the address associated with an RNS node. | ||
* @param node The RNS node to query. | ||
* @return The associated address. | ||
*/ | ||
function addr(bytes32 node) public view returns (address) { | ||
return addresses[node]; | ||
} | ||
|
||
/** | ||
* Sets the address associated with an RNS node. | ||
* May only be called by the owner of that node in the RNS registry. | ||
* @param node The node to update. | ||
* @param addrValue The address to set. | ||
*/ | ||
function setAddr(bytes32 node, address addrValue) public only_owner(node) { | ||
addresses[node] = addrValue; | ||
} | ||
|
||
/** | ||
* Returns the content hash associated with an RNS node. | ||
* Note that this resource type is not standardized, and will likely change | ||
* in future to a resource type based on multihash. | ||
* @param node The RNS node to query. | ||
* @return The associated content hash. | ||
*/ | ||
function content(bytes32 node) public view returns (bytes32) { | ||
return hashes[node]; | ||
} | ||
|
||
/** | ||
* Sets the content hash associated with an RNS node. | ||
* May only be called by the owner of that node in the RNS registry. | ||
* Note that this resource type is not standardized, and will likely change | ||
* in future to a resource type based on multihash. | ||
* @param node The node to update. | ||
* @param hash The content hash to set | ||
*/ | ||
function setContent(bytes32 node, bytes32 hash) public only_owner(node) { | ||
hashes[node] = hash; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
import './AbstractRNS.sol'; | ||
|
||
/** | ||
* The RNS registry contract. | ||
*/ | ||
contract RNS is AbstractRNS { | ||
struct Record { | ||
address owner; | ||
address resolver; | ||
uint64 ttl; | ||
} | ||
|
||
mapping(bytes32=>Record) records; | ||
|
||
// Permits modifications only by the owner of the specified node. | ||
modifier only_owner(bytes32 node) { | ||
require(records[node].owner == msg.sender); | ||
_; | ||
} | ||
|
||
/** | ||
* Constructs a new RNS registrar. | ||
*/ | ||
constructor() public { | ||
records[bytes32(0)].owner = msg.sender; | ||
} | ||
|
||
/** | ||
* Returns the address that owns the specified node. | ||
*/ | ||
function owner(bytes32 node) public view returns (address) { | ||
return records[node].owner; | ||
} | ||
|
||
/** | ||
* Returns the address of the resolver for the specified node. | ||
*/ | ||
function resolver(bytes32 node) public view returns (address) { | ||
return records[node].resolver; | ||
} | ||
|
||
/** | ||
* Returns the TTL of a node, and any records associated with it. | ||
*/ | ||
function ttl(bytes32 node) public view returns (uint64) { | ||
return records[node].ttl; | ||
} | ||
|
||
/** | ||
* Transfers ownership of a node to a new address. May only be called by the current | ||
* owner of the node. | ||
* @param node The node to transfer ownership of. | ||
* @param ownerAddress The address of the new owner. | ||
*/ | ||
function setOwner(bytes32 node, address ownerAddress) public only_owner(node) { | ||
emit Transfer(node, ownerAddress); | ||
records[node].owner = ownerAddress; | ||
} | ||
|
||
/** | ||
* Transfers ownership of a subnode keccak256(node, label) to a new address. May only be | ||
* called by the owner of the parent node. | ||
* @param node The parent node. | ||
* @param label The hash of the label specifying the subnode. | ||
* @param ownerAddress The address of the new owner. | ||
*/ | ||
function setSubnodeOwner(bytes32 node, bytes32 label, address ownerAddress) public only_owner(node) { | ||
bytes32 subnode = keccak256(abi.encodePacked(node, label)); | ||
emit NewOwner(node, label, ownerAddress); | ||
records[subnode].owner = ownerAddress; | ||
|
||
emit NewResolver(subnode, records[node].resolver); | ||
records[subnode].resolver = records[node].resolver; | ||
} | ||
|
||
/** | ||
* Sets the resolver address for the specified node. | ||
* @param node The node to update. | ||
* @param resolverAddress The address of the resolver. | ||
*/ | ||
function setResolver(bytes32 node, address resolverAddress) public only_owner(node) { | ||
emit NewResolver(node, resolverAddress); | ||
records[node].resolver = resolverAddress; | ||
} | ||
|
||
/** | ||
* Sets the TTL for the specified node. | ||
* @param node The node to update. | ||
* @param ttlValue The TTL in seconds. | ||
*/ | ||
function setTTL(bytes32 node, uint64 ttlValue) public only_owner(node) { | ||
emit NewTTL(node, ttlValue); | ||
records[node].ttl = ttlValue; | ||
} | ||
|
||
/** | ||
* Sets the default resolver for new nodes | ||
* @param resolver The address of the new defaultResolver | ||
*/ | ||
function setDefaultResolver(address resolver) public only_owner(0) { | ||
records[bytes32(0)].resolver = resolver; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
contract AbstractPublicResolver { | ||
function PublicResolver(address rnsAddr) public; | ||
function supportsInterface(bytes4 interfaceID) public pure returns (bool); | ||
function addr(bytes32 node) public view returns (address ret); | ||
function setAddr(bytes32 node, address addrValue) public; | ||
function content(bytes32 node) public view returns (bytes32 ret); | ||
function setContent(bytes32 node, bytes32 hashValue) public; | ||
function has(bytes32 node, bytes32 kind) public view returns (bool); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
import '../../common/AbstractRNS.sol'; | ||
|
||
/** | ||
* A registrar that allocates subdomains to the first person to claim them, but | ||
* expires registrations a fixed period after they're initially claimed. | ||
*/ | ||
contract TestRegistrar { | ||
uint constant registrationPeriod = 4 weeks; | ||
|
||
AbstractRNS public rns; | ||
bytes32 public rootNode; | ||
mapping(bytes32=>uint) public expiryTimes; | ||
|
||
/** | ||
* Constructor. | ||
* @param rnsAddr The address of the RNS registry. | ||
* @param node The node that this registrar administers. | ||
*/ | ||
constructor(AbstractRNS rnsAddr, bytes32 node) public { | ||
rns = rnsAddr; | ||
rootNode = node; | ||
} | ||
|
||
/** | ||
* Register a name that's not currently registered | ||
* @param subnode The hash of the label to register. | ||
* @param owner The address of the new owner. | ||
*/ | ||
function register(bytes32 subnode, address owner) public { | ||
require(expiryTimes[subnode] < now); | ||
|
||
expiryTimes[subnode] = now + registrationPeriod; | ||
rns.setSubnodeOwner(rootNode, subnode, owner); | ||
} | ||
} |
Oops, something went wrong.