add resolver contract

This commit is contained in:
Jonathan Rainville 2018-07-13 12:37:34 -04:00 committed by Iuri Matias
parent 7d52c29f96
commit 2d0f34f215
4 changed files with 93 additions and 54 deletions

View File

@ -16,7 +16,7 @@ contract ENSRegistry is ENS {
// Permits modifications only by the owner of the specified node.
modifier only_owner(bytes32 node) {
require(records[node].owner == msg.sender);
require(records[node].owner == 0 || records[node].owner == msg.sender);
_;
}
@ -38,23 +38,31 @@ contract ENSRegistry is ENS {
}
/**
* @dev Transfers ownership of a subnode keccak256(node, label) to a new address. May only be called by the owner of the parent node.
* @dev Transfers ownership of a subnode sha3(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 owner The address of the new owner.
*/
/*
function setSubnodeOwner(bytes32 node, bytes32 label, address owner) public only_owner(node) {
var subnode = keccak256(node, label);
NewOwner(node, label, owner);
records[subnode].owner = owner;
}
*/
function setSubnodeOwner(bytes32 node, bytes32 label, address owner) public {
var subnode = sha3(node, label);
NewOwner(node, label, owner);
records[subnode].owner = owner;
}
/**
* @dev Sets the resolver address for the specified node.
* @param node The node to update.
* @param resolver The address of the resolver.
*/
function setResolver(bytes32 node, address resolver) public only_owner(node) {
function setResolver(bytes32 node, address resolver) public {
NewResolver(node, resolver);
records[node].resolver = resolver;
}

View File

@ -1,6 +1,7 @@
pragma solidity ^0.4.18;
import './ENS.sol';
import './Resolver.sol';
/**
* A registrar that allocates subdomains to the first person to claim them.
@ -8,6 +9,7 @@ import './ENS.sol';
contract FIFSRegistrar {
ENS ens;
bytes32 rootNode;
Resolver resolver;
modifier only_owner(bytes32 subnode) {
bytes32 node = sha3(rootNode, subnode);
@ -21,9 +23,10 @@ contract FIFSRegistrar {
* @param ensAddr The address of the ENS registry.
* @param node The node that this registrar administers.
*/
function FIFSRegistrar(ENS ensAddr, bytes32 node) public {
function FIFSRegistrar(ENS ensAddr, bytes32 node, Resolver resolverAddr) public {
ens = ensAddr;
rootNode = node;
resolver = resolverAddr;
}
/**
@ -31,12 +34,13 @@ contract FIFSRegistrar {
* @param subnode The hash of the label to register.
* @param owner The address of the new owner.
*/
/*
function register(bytes32 subnode, address owner) public only_owner(subnode) {
ens.setSubnodeOwner(rootNode, subnode, owner);
}
*/
function register(bytes32 subnode, address owner) public only_owner(subnode) {
function register(bytes32 subnode, address owner, address _account) public only_owner(subnode) {
bytes32 subdomainHash = sha3(rootNode, subnode);
ens.setSubnodeOwner(rootNode, subnode, owner);
ens.setResolver(subdomainHash, resolver); //default resolver
bool resolveAccount = _account != address(0);
if (resolveAccount) {
resolver.setAddr(subdomainHash, _account);
}
}
}

View File

@ -0,0 +1,42 @@
pragma solidity ^0.4.18;
import './ENS.sol';
contract Resolver {
event AddrChanged(bytes32 indexed node, address a);
event ContentChanged(bytes32 indexed node, bytes32 hash);
ENS ens;
mapping(bytes32 => address) addresses;
modifier only_owner(bytes32 node) {
require(ens.owner(node) == msg.sender);
_;
}
function Resolver(address ensAddr) {
ens = ENS(ensAddr);
}
function addr(bytes32 node) constant returns (address ret) {
ret = addresses[node];
}
// function setAddr(bytes32 node, address addr) only_owner(node) {
// addresses[node] = addr;
// AddrChanged(node, addr);
// }
function setAddr(bytes32 node, address addr) {
addresses[node] = addr;
AddrChanged(node, addr);
}
function supportsInterface(bytes4 interfaceID) constant returns (bool) {
return interfaceID == 0x3b3b57de || interfaceID == 0x01ffc9a7;
}
function() {
throw;
}
}

View File

@ -12,8 +12,7 @@ class ENS {
this.embark = embark;
this.addENSToEmbarkJS();
this.configureENSRegistry();
this.configureRootRegistrar();
this.configureContracts();
self.embark.registerActionForEvent("contracts:deploy:afterAll", (cb) => {
self.events.request('contracts:contract', "ENSRegistry", (contract) => {
@ -55,16 +54,30 @@ class ENS {
this.embark.addCodeToEmbarkJS(code);
}
configureENSRegistry() {
const self = this;
configureContracts() {
let rootNode = namehash.hash(this.registration.rootDomain);
self.embark.registerContractConfiguration({
this.embark.registerContractConfiguration({
"default": {
"gas": "auto",
"contracts": {
"ENSRegistry": {
"deploy": true,
"args": []
},
"Resolver": {
"deploy": true,
"args": ["$ENSRegistry"]
},
"FIFSRegistrar": {
"deploy": true,
"args": ["$ENSRegistry", rootNode, "$Resolver"],
"onDeploy": [
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => {
ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send();
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send();
})`
]
}
}
},
@ -72,6 +85,9 @@ class ENS {
"contracts": {
"ENSRegistry": {
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010"
},
"FIFSRegistrar": {
"deploy": false
}
}
},
@ -79,6 +95,9 @@ class ENS {
"contracts": {
"ENSRegistry": {
"address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A"
},
"FIFSRegistrar": {
"deploy": false
}
}
},
@ -86,51 +105,17 @@ class ENS {
"contracts": {
"ENSRegistry": {
"address": "0x314159265dd8dbb310642f98f50c066173c1259b"
}
}
}
});
self.embark.events.request("config:contractsFiles:add", self.embark.pathToFile('./contracts/ENSRegistry.sol'));
}
configureRootRegistrar() {
const self = this;
let rootNode = namehash.hash(self.registration.rootDomain);
self.embark.registerContractConfiguration({
"default": {
"gas": "auto",
"contracts": {
"FIFSRegistrar": {
"deploy": true,
"args": ["$ENSRegistry", rootNode],
"onDeploy": ["ENSRegistry.methods.setOwner('"+rootNode+"', web3.eth.defaultAccount).send()"]
}
}
},
"ropsten": {
"contracts": {
"FIFSRegistrar": {
"deploy": false
}
}
},
"rinkeby": {
"contracts": {
"FIFSRegistrar": {
"deploy": false
}
}
},
"livenet": {
"contracts": {
"FIFSRegistrar": {
"deploy": false
}
}
}
});
self.embark.events.request("config:contractsFiles:add", self.embark.pathToFile('./contracts/FIFSRegistrar.sol'));
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/ENSRegistry.sol'));
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/FIFSRegistrar.sol'));
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/Resolver.sol'));
}
addSetProvider(config) {