fix rebase problems and now works
This commit is contained in:
parent
c0d32e3581
commit
eae7784a87
|
@ -5,75 +5,45 @@ const async = require('async');
|
|||
const embarkJsUtils = require('embarkjs').Utils;
|
||||
const reverseAddrSuffix = '.addr.reverse';
|
||||
|
||||
const DEFAULT_ENS_CONTRACTS_CONFIG = {
|
||||
"default": {
|
||||
"contracts": {
|
||||
"ENS": {
|
||||
"deploy": false,
|
||||
"silent": true
|
||||
},
|
||||
"ENSRegistry": {
|
||||
"deploy": true,
|
||||
"silent": true,
|
||||
"args": []
|
||||
},
|
||||
"Resolver": {
|
||||
"deploy": true,
|
||||
"silent": true,
|
||||
"args": ["$ENSRegistry"]
|
||||
},
|
||||
"FIFSRegistrar": {
|
||||
"deploy": false
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const MAINNET_ID = '1';
|
||||
const ROPSTEN_ID = '3';
|
||||
const RINKEBY_ID = '4';
|
||||
|
||||
const ENS_CONTRACTS_CONFIG = {
|
||||
[MAINNET_ID]: {
|
||||
"contracts": {
|
||||
"ENSRegistry": {
|
||||
"address": "0x314159265dd8dbb310642f98f50c066173c1259b",
|
||||
"silent": true
|
||||
},
|
||||
"Resolver": {
|
||||
"deploy": false
|
||||
},
|
||||
"FIFSRegistrar": {
|
||||
"deploy": false
|
||||
}
|
||||
"ENSRegistry": {
|
||||
"address": "0x314159265dd8dbb310642f98f50c066173c1259b",
|
||||
"silent": true
|
||||
},
|
||||
"Resolver": {
|
||||
"deploy": false
|
||||
},
|
||||
"FIFSRegistrar": {
|
||||
"deploy": false
|
||||
}
|
||||
},
|
||||
[ROPSTEN_ID]: {
|
||||
"contracts": {
|
||||
"ENSRegistry": {
|
||||
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
||||
"silent": true
|
||||
},
|
||||
"Resolver": {
|
||||
"deploy": false
|
||||
},
|
||||
"FIFSRegistrar": {
|
||||
"deploy": false
|
||||
}
|
||||
"ENSRegistry": {
|
||||
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
||||
"silent": true
|
||||
},
|
||||
"Resolver": {
|
||||
"deploy": false
|
||||
},
|
||||
"FIFSRegistrar": {
|
||||
"deploy": false
|
||||
}
|
||||
},
|
||||
[RINKEBY_ID]: {
|
||||
"contracts": {
|
||||
"ENSRegistry": {
|
||||
"address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A",
|
||||
"silent": true
|
||||
},
|
||||
"Resolver": {
|
||||
"deploy": false
|
||||
},
|
||||
"FIFSRegistrar": {
|
||||
"deploy": false
|
||||
}
|
||||
"ENSRegistry": {
|
||||
"address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A",
|
||||
"silent": true
|
||||
},
|
||||
"Resolver": {
|
||||
"deploy": false
|
||||
},
|
||||
"FIFSRegistrar": {
|
||||
"deploy": false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -130,7 +100,6 @@ class ENS {
|
|||
|
||||
registerEvents() {
|
||||
this.embark.registerActionForEvent("deploy:beforeAll", this.configureContractsAndRegister.bind(this));
|
||||
this.events.once("web3Ready", this.configureContracts.bind(this));
|
||||
|
||||
this.events.setCommandHandler("storage:ens:associate", this.associateStorageToEns.bind(this));
|
||||
}
|
||||
|
@ -152,14 +121,14 @@ class ENS {
|
|||
self.addSetProvider(config);
|
||||
}
|
||||
|
||||
self.events.request('blockchain:networkId', (networkId) => {
|
||||
const isKnownNetwork = Object.keys(ENS_CONTRACTS_CONFIG).includes(networkId);
|
||||
const shouldRegisterSubdomain = self.registration && self.registration.subdomains && Object.keys(self.registration.subdomains).length;
|
||||
if (isKnownNetwork || !shouldRegisterSubdomain) {
|
||||
return cb();
|
||||
}
|
||||
self.registerConfigDomains(config, cb);
|
||||
});
|
||||
self.events.request('blockchain:networkId', (networkId) => {
|
||||
const isKnownNetwork = Boolean(ENS_CONTRACTS_CONFIG[networkId]);
|
||||
const shouldRegisterSubdomain = self.registration && self.registration.subdomains && Object.keys(self.registration.subdomains).length;
|
||||
if (isKnownNetwork || !shouldRegisterSubdomain) {
|
||||
return cb();
|
||||
}
|
||||
process.exit();
|
||||
self.registerConfigDomains(config, cb);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -298,100 +267,60 @@ class ENS {
|
|||
}
|
||||
|
||||
configureContractsAndRegister(cb) {
|
||||
this.events.request('blockchain:networkId', (networkId) => {
|
||||
const config = Object.assign({}, DEFAULT_ENS_CONTRACTS_CONFIG, {[this.env]: ENS_CONTRACTS_CONFIG[networkId]});
|
||||
const self = this;
|
||||
if (self.configured) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
const knownConfigs = {
|
||||
"ropsten": {
|
||||
"ENSRegistry": {
|
||||
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
||||
"silent": true
|
||||
},
|
||||
"Resolver": {
|
||||
"deploy": false
|
||||
},
|
||||
"FIFSRegistrar": {
|
||||
"deploy": false
|
||||
}
|
||||
},
|
||||
"rinkeby": {
|
||||
"ENSRegistry": {
|
||||
"address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A",
|
||||
"silent": true
|
||||
},
|
||||
"Resolver": {
|
||||
"deploy": false
|
||||
},
|
||||
"FIFSRegistrar": {
|
||||
"deploy": false
|
||||
}
|
||||
},
|
||||
"livenet": {
|
||||
"ENSRegistry": {
|
||||
"address": "0x314159265dd8dbb310642f98f50c066173c1259b",
|
||||
"silent": true
|
||||
},
|
||||
"Resolver": {
|
||||
"deploy": false
|
||||
},
|
||||
"FIFSRegistrar": {
|
||||
"deploy": false
|
||||
}
|
||||
self.events.request('blockchain:networkId', (networkId) => {
|
||||
if (ENS_CONTRACTS_CONFIG[networkId]) {
|
||||
self.ensConfig = utils.recursiveMerge(self.ensConfig, ENS_CONTRACTS_CONFIG[networkId]);
|
||||
} else {
|
||||
process.exit();
|
||||
}
|
||||
};
|
||||
knownConfigs.testnet = knownConfigs.ropsten; // Synonyms
|
||||
knownConfigs.mainnet = knownConfigs.livenet; // Synonyms
|
||||
|
||||
if (knownConfigs[this.env]) {
|
||||
self.ensConfig = utils.recursiveMerge(self.ensConfig, knownConfigs[this.env]);
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function registry(next) {
|
||||
self.events.request('deploy:contract', self.ensConfig.ENSRegistry, (err, _receipt) => {
|
||||
return next(err);
|
||||
});
|
||||
},
|
||||
function resolver(next) {
|
||||
self.ensConfig.Resolver.args = [self.ensConfig.ENSRegistry.deployedAddress];
|
||||
self.events.request('deploy:contract', self.ensConfig.Resolver, (err, _receipt) => {
|
||||
return next(err);
|
||||
});
|
||||
},
|
||||
function registrar(next) {
|
||||
if (!self.registration || !self.registration.rootDomain) {
|
||||
return next();
|
||||
}
|
||||
const registryAddress = self.ensConfig.ENSRegistry.deployedAddress;
|
||||
const resolverAddress = self.ensConfig.Resolver.deployedAddress;
|
||||
const rootNode = namehash.hash(self.registration.rootDomain);
|
||||
const contract = self.ensConfig.FIFSRegistrar;
|
||||
contract.args = [registryAddress, rootNode];
|
||||
contract.onDeploy = [
|
||||
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount}).then(() => {
|
||||
async.waterfall([
|
||||
function registry(next) {
|
||||
self.events.request('deploy:contract', self.ensConfig.ENSRegistry, (err, _receipt) => {
|
||||
return next(err);
|
||||
});
|
||||
},
|
||||
function resolver(next) {
|
||||
self.ensConfig.Resolver.args = [self.ensConfig.ENSRegistry.deployedAddress];
|
||||
self.events.request('deploy:contract', self.ensConfig.Resolver, (err, _receipt) => {
|
||||
return next(err);
|
||||
});
|
||||
},
|
||||
function registrar(next) {
|
||||
if (!self.registration || !self.registration.rootDomain) {
|
||||
return next();
|
||||
}
|
||||
const registryAddress = self.ensConfig.ENSRegistry.deployedAddress;
|
||||
const resolverAddress = self.ensConfig.Resolver.deployedAddress;
|
||||
const rootNode = namehash.hash(self.registration.rootDomain);
|
||||
const contract = self.ensConfig.FIFSRegistrar;
|
||||
contract.args = [registryAddress, rootNode];
|
||||
contract.onDeploy = [
|
||||
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount}).then(() => {
|
||||
ENSRegistry.methods.setResolver('${rootNode}', "${resolverAddress}").send({from: web3.eth.defaultAccount});
|
||||
var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '${reverseAddrSuffix}');
|
||||
ENSRegistry.methods.setResolver(reverseNode, "${resolverAddress}").send({from: web3.eth.defaultAccount});
|
||||
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount});
|
||||
Resolver.methods.setName(reverseNode, '${self.registration.rootDomain}').send({from: web3.eth.defaultAccount});
|
||||
})`
|
||||
];
|
||||
self.events.request('deploy:contract', contract, (err, _receipt) => {
|
||||
return next(err);
|
||||
});
|
||||
}
|
||||
], (err) => {
|
||||
self.configured = true;
|
||||
if (err) {
|
||||
self.logger.error('Error while deploying ENS contracts');
|
||||
self.logger.error(err.message || err);
|
||||
return;
|
||||
}
|
||||
self.setProviderAndRegisterDomains(cb);
|
||||
];
|
||||
self.events.request('deploy:contract', contract, (err, _receipt) => {
|
||||
return next(err);
|
||||
});
|
||||
}
|
||||
], (err) => {
|
||||
self.configured = true;
|
||||
if (err) {
|
||||
self.logger.error('Error while deploying ENS contracts');
|
||||
self.logger.error(err.message || err);
|
||||
return;
|
||||
}
|
||||
self.setProviderAndRegisterDomains(cb);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue