fix using only_owner

This commit is contained in:
Jonathan Rainville 2018-07-25 11:05:27 -04:00 committed by Iuri Matias
parent 89421771ef
commit 4f2d984081
5 changed files with 18 additions and 26 deletions

View File

@ -54,7 +54,7 @@ contract ENSRegistry is ENS {
* @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 { function setResolver(bytes32 node, address resolver) public only_owner(node, 0x0) {
NewResolver(node, resolver); NewResolver(node, resolver);
records[node].resolver = resolver; records[node].resolver = resolver;
} }

View File

@ -9,7 +9,6 @@ import './Resolver.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);
@ -23,10 +22,9 @@ 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, Resolver resolverAddr) public { function FIFSRegistrar(ENS ensAddr, bytes32 node) public {
ens = ensAddr; ens = ensAddr;
rootNode = node; rootNode = node;
resolver = resolverAddr;
} }
/** /**
@ -34,13 +32,7 @@ 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 nodeAddress) 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 = nodeAddress != address(0);
if (resolveAccount) {
resolver.setAddr(subdomainHash, nodeAddress);
}
} }
} }

View File

@ -33,7 +33,8 @@ contract Resolver {
mapping (bytes32 => Record) records; mapping (bytes32 => Record) records;
modifier only_owner(bytes32 node) { modifier only_owner(bytes32 node) {
require(ens.owner(node) == msg.sender); address currentOwner = ens.owner(node);
require(currentOwner == 0 || currentOwner == msg.sender);
_; _;
} }
@ -51,11 +52,7 @@ contract Resolver {
* @param node The node to update. * @param node The node to update.
* @param addr The address to set. * @param addr The address to set.
*/ */
// function setAddr(bytes32 node, address addr) public only_owner(node) { function setAddr(bytes32 node, address addr) public only_owner(node) {
// records[node].addr = addr;
// emit AddrChanged(node, addr);
// }
function setAddr(bytes32 node, address addr) public {
records[node].addr = addr; records[node].addr = addr;
emit AddrChanged(node, addr); emit AddrChanged(node, addr);
} }
@ -79,11 +76,7 @@ contract Resolver {
* @param node The node to update. * @param node The node to update.
* @param name The name to set. * @param name The name to set.
*/ */
// function setName(bytes32 node, string name) public only_owner(node) { function setName(bytes32 node, string name) public only_owner(node) {
// records[node].name = name;
// emit NameChanged(node, name);
// }
function setName(bytes32 node, string name) public {
records[node].name = name; records[node].name = name;
emit NameChanged(node, name); emit NameChanged(node, name);
} }

View File

@ -11,6 +11,7 @@ class ENS {
this.registration = this.namesConfig.register; this.registration = this.namesConfig.register;
this.embark = embark; this.embark = embark;
// TODO add checks to see if config is ok
this.addENSToEmbarkJS(); this.addENSToEmbarkJS();
this.configureContracts(); this.configureContracts();
this.registerEvents(); this.registerEvents();
@ -38,6 +39,7 @@ class ENS {
], (err, results) => { ], (err, results) => {
// result[0] => ENSRegistry; result[1] => FIFSRegistrar; result[2] => FIFSRegistrar // result[0] => ENSRegistry; result[1] => FIFSRegistrar; result[2] => FIFSRegistrar
let config = { let config = {
registration: self.registration,
registryAbi: results[0].abiDefinition, registryAbi: results[0].abiDefinition,
registryAddress: results[0].deployedAddress, registryAddress: results[0].deployedAddress,
registrarAbi: results[1].abiDefinition, registrarAbi: results[1].abiDefinition,
@ -62,8 +64,7 @@ class ENS {
{abi: config.registrarAbi, address: config.registrarAddress}, {abi: config.registrarAbi, address: config.registrarAddress},
(registrar) => { (registrar) => {
async.each(Object.keys(self.registration.domains), (subDomainName, eachCb) => { async.each(Object.keys(self.registration.domains), (subDomainName, eachCb) => {
const toSend = registrar.methods.register(utils.sha3(subDomainName), const toSend = registrar.methods.register(utils.soliditySha3(subDomainName), defaultAccount);
defaultAccount, self.registration.domains[subDomainName]);
toSend.estimateGas().then(gasEstimated => { toSend.estimateGas().then(gasEstimated => {
return toSend.send({gas: gasEstimated + 1000, from: defaultAccount}).then(transaction => { return toSend.send({gas: gasEstimated + 1000, from: defaultAccount}).then(transaction => {
@ -127,11 +128,11 @@ class ENS {
}, },
"FIFSRegistrar": { "FIFSRegistrar": {
"deploy": true, "deploy": true,
"args": ["$ENSRegistry", rootNode, "$Resolver"], "args": ["$ENSRegistry", rootNode],
"onDeploy": [ "onDeploy": [
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => { `ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => {
ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send(); ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send();
var reverseNode = web3.utils.sha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '.addr.reverse'); var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '.addr.reverse');
ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send(); ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send();
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send(); Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send();
Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send(); Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send();

View File

@ -270,6 +270,11 @@ function sha3(arg) {
return Web3.utils.sha3(arg); return Web3.utils.sha3(arg);
} }
function soliditySha3(arg) {
const Web3 = require('web3');
return Web3.utils.soliditySha3(arg);
}
function normalizeInput(input) { function normalizeInput(input) {
let args = Object.values(input); let args = Object.values(input);
if (args.length === 0) { if (args.length === 0) {
@ -405,6 +410,7 @@ module.exports = {
getExternalContractUrl, getExternalContractUrl,
toChecksumAddress, toChecksumAddress,
sha3, sha3,
soliditySha3,
normalizeInput, normalizeInput,
buildUrl, buildUrl,
buildUrlFromConfig, buildUrlFromConfig,