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. // Permits modifications only by the owner of the specified node.
modifier only_owner(bytes32 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 node The parent node.
* @param label The hash of the label specifying the subnode. * @param label The hash of the label specifying the subnode.
* @param owner The address of the new owner. * @param owner The address of the new owner.
*/ */
/*
function setSubnodeOwner(bytes32 node, bytes32 label, address owner) public only_owner(node) { function setSubnodeOwner(bytes32 node, bytes32 label, address owner) public only_owner(node) {
var subnode = keccak256(node, label); var subnode = keccak256(node, label);
NewOwner(node, label, owner); NewOwner(node, label, owner);
records[subnode].owner = 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. * @dev Sets the resolver address for the specified node.
* @param node The node to update. * @param node The node to update.
* @param resolver The address of the resolver. * @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); NewResolver(node, resolver);
records[node].resolver = resolver; records[node].resolver = resolver;
} }

View File

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

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.embark = embark;
this.addENSToEmbarkJS(); this.addENSToEmbarkJS();
this.configureENSRegistry(); this.configureContracts();
this.configureRootRegistrar();
self.embark.registerActionForEvent("contracts:deploy:afterAll", (cb) => { self.embark.registerActionForEvent("contracts:deploy:afterAll", (cb) => {
self.events.request('contracts:contract', "ENSRegistry", (contract) => { self.events.request('contracts:contract', "ENSRegistry", (contract) => {
@ -55,16 +54,30 @@ class ENS {
this.embark.addCodeToEmbarkJS(code); this.embark.addCodeToEmbarkJS(code);
} }
configureENSRegistry() { configureContracts() {
const self = this; let rootNode = namehash.hash(this.registration.rootDomain);
self.embark.registerContractConfiguration({ this.embark.registerContractConfiguration({
"default": { "default": {
"gas": "auto", "gas": "auto",
"contracts": { "contracts": {
"ENSRegistry": { "ENSRegistry": {
"deploy": true, "deploy": true,
"args": [] "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": { "contracts": {
"ENSRegistry": { "ENSRegistry": {
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010" "address": "0x112234455c3a32fd11230c42e7bccd4a84e02010"
},
"FIFSRegistrar": {
"deploy": false
} }
} }
}, },
@ -79,6 +95,9 @@ class ENS {
"contracts": { "contracts": {
"ENSRegistry": { "ENSRegistry": {
"address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A" "address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A"
},
"FIFSRegistrar": {
"deploy": false
} }
} }
}, },
@ -86,51 +105,17 @@ class ENS {
"contracts": { "contracts": {
"ENSRegistry": { "ENSRegistry": {
"address": "0x314159265dd8dbb310642f98f50c066173c1259b" "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": { "FIFSRegistrar": {
"deploy": false "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) { addSetProvider(config) {