mirror of https://github.com/embarklabs/embark.git
fix using only_owner
This commit is contained in:
parent
89421771ef
commit
4f2d984081
|
@ -54,7 +54,7 @@ contract ENSRegistry is ENS {
|
|||
* @param node The node to update.
|
||||
* @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);
|
||||
records[node].resolver = resolver;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import './Resolver.sol';
|
|||
contract FIFSRegistrar {
|
||||
ENS ens;
|
||||
bytes32 rootNode;
|
||||
Resolver resolver;
|
||||
|
||||
modifier only_owner(bytes32 subnode) {
|
||||
bytes32 node = sha3(rootNode, subnode);
|
||||
|
@ -23,10 +22,9 @@ contract FIFSRegistrar {
|
|||
* @param ensAddr The address of the ENS registry.
|
||||
* @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;
|
||||
rootNode = node;
|
||||
resolver = resolverAddr;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,13 +32,7 @@ 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, address nodeAddress) public only_owner(subnode) {
|
||||
bytes32 subdomainHash = sha3(rootNode, subnode);
|
||||
function register(bytes32 subnode, address owner) public only_owner(subnode) {
|
||||
ens.setSubnodeOwner(rootNode, subnode, owner);
|
||||
ens.setResolver(subdomainHash, resolver); //default resolver
|
||||
bool resolveAccount = nodeAddress != address(0);
|
||||
if (resolveAccount) {
|
||||
resolver.setAddr(subdomainHash, nodeAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@ contract Resolver {
|
|||
mapping (bytes32 => Record) records;
|
||||
|
||||
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 addr The address to set.
|
||||
*/
|
||||
// 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 {
|
||||
function setAddr(bytes32 node, address addr) public only_owner(node) {
|
||||
records[node].addr = addr;
|
||||
emit AddrChanged(node, addr);
|
||||
}
|
||||
|
@ -79,11 +76,7 @@ contract Resolver {
|
|||
* @param node The node to update.
|
||||
* @param name The name to set.
|
||||
*/
|
||||
// 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 {
|
||||
function setName(bytes32 node, string name) public only_owner(node) {
|
||||
records[node].name = name;
|
||||
emit NameChanged(node, name);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ class ENS {
|
|||
this.registration = this.namesConfig.register;
|
||||
this.embark = embark;
|
||||
|
||||
// TODO add checks to see if config is ok
|
||||
this.addENSToEmbarkJS();
|
||||
this.configureContracts();
|
||||
this.registerEvents();
|
||||
|
@ -38,6 +39,7 @@ class ENS {
|
|||
], (err, results) => {
|
||||
// result[0] => ENSRegistry; result[1] => FIFSRegistrar; result[2] => FIFSRegistrar
|
||||
let config = {
|
||||
registration: self.registration,
|
||||
registryAbi: results[0].abiDefinition,
|
||||
registryAddress: results[0].deployedAddress,
|
||||
registrarAbi: results[1].abiDefinition,
|
||||
|
@ -62,8 +64,7 @@ class ENS {
|
|||
{abi: config.registrarAbi, address: config.registrarAddress},
|
||||
(registrar) => {
|
||||
async.each(Object.keys(self.registration.domains), (subDomainName, eachCb) => {
|
||||
const toSend = registrar.methods.register(utils.sha3(subDomainName),
|
||||
defaultAccount, self.registration.domains[subDomainName]);
|
||||
const toSend = registrar.methods.register(utils.soliditySha3(subDomainName), defaultAccount);
|
||||
|
||||
toSend.estimateGas().then(gasEstimated => {
|
||||
return toSend.send({gas: gasEstimated + 1000, from: defaultAccount}).then(transaction => {
|
||||
|
@ -127,11 +128,11 @@ class ENS {
|
|||
},
|
||||
"FIFSRegistrar": {
|
||||
"deploy": true,
|
||||
"args": ["$ENSRegistry", rootNode, "$Resolver"],
|
||||
"args": ["$ENSRegistry", rootNode],
|
||||
"onDeploy": [
|
||||
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => {
|
||||
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();
|
||||
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send();
|
||||
Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send();
|
||||
|
|
|
@ -270,6 +270,11 @@ function sha3(arg) {
|
|||
return Web3.utils.sha3(arg);
|
||||
}
|
||||
|
||||
function soliditySha3(arg) {
|
||||
const Web3 = require('web3');
|
||||
return Web3.utils.soliditySha3(arg);
|
||||
}
|
||||
|
||||
function normalizeInput(input) {
|
||||
let args = Object.values(input);
|
||||
if (args.length === 0) {
|
||||
|
@ -405,6 +410,7 @@ module.exports = {
|
|||
getExternalContractUrl,
|
||||
toChecksumAddress,
|
||||
sha3,
|
||||
soliditySha3,
|
||||
normalizeInput,
|
||||
buildUrl,
|
||||
buildUrlFromConfig,
|
||||
|
|
Loading…
Reference in New Issue