ens resolve
This commit is contained in:
parent
0f6e84bca3
commit
f686fec74a
|
@ -133,7 +133,6 @@ class EmbarkController {
|
|||
engine.startService("deployment");
|
||||
engine.startService("storage");
|
||||
engine.startService("codeGenerator");
|
||||
engine.startService("namingSystem");
|
||||
engine.startService("console");
|
||||
engine.startService("pluginCommand");
|
||||
|
||||
|
@ -286,7 +285,6 @@ class EmbarkController {
|
|||
engine.startService("deployment");
|
||||
engine.startService("storage");
|
||||
engine.startService("codeGenerator");
|
||||
engine.startService("namingSystem");
|
||||
engine.startService("console");
|
||||
engine.startService("pluginCommand");
|
||||
engine.events.once('check:backOnline:Ethereum', () => callback());
|
||||
|
@ -478,7 +476,6 @@ class EmbarkController {
|
|||
engine.startService("deployment");
|
||||
engine.startService("storage");
|
||||
engine.startService("codeGenerator");
|
||||
engine.startService("namingSystem");
|
||||
callback();
|
||||
},
|
||||
function listLoadedPlugin(callback) {
|
||||
|
|
|
@ -193,6 +193,7 @@ class Engine {
|
|||
this.registerModule('profiler');
|
||||
this.registerModule('deploytracker', {trackContracts: options.trackContracts});
|
||||
this.registerModule('specialconfigs');
|
||||
this.registerModule('ens');
|
||||
this.registerModule('console_listener', {ipc: self.ipc});
|
||||
this.registerModule('deployment', {plugins: this.plugins, onlyCompile: options.onlyCompile});
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ let utils = require('../../utils/utils.js');
|
|||
class ContractDeployer {
|
||||
constructor(options) {
|
||||
const self = this;
|
||||
|
||||
this.logger = options.logger;
|
||||
this.events = options.events;
|
||||
this.plugins = options.plugins;
|
||||
|
@ -57,12 +56,26 @@ class ContractDeployer {
|
|||
async.map(arg, (sub_arg, nextSubEachCb) => {
|
||||
if (sub_arg[0] === "$") {
|
||||
parseArg(sub_arg, nextSubEachCb);
|
||||
} else if(typeof sub_arg === 'string' && sub_arg.indexOf('.eth') === sub_arg.length - 4) {
|
||||
self.events.request("ens:resolve", sub_arg, (err, name) => {
|
||||
if(err) {
|
||||
return nextSubEachCb(err);
|
||||
}
|
||||
return nextSubEachCb(err, name);
|
||||
});
|
||||
} else {
|
||||
nextSubEachCb(null, sub_arg);
|
||||
}
|
||||
}, (err, subRealArgs) => {
|
||||
nextEachCb(null, subRealArgs);
|
||||
});
|
||||
} else if(typeof arg === 'string' && arg.indexOf('.eth') === arg.length - 4) {
|
||||
self.events.request("ens:resolve", arg, (err, name) => {
|
||||
if(err) {
|
||||
return nextEachCb(err);
|
||||
}
|
||||
return nextEachCb(err, name);
|
||||
});
|
||||
} else {
|
||||
nextEachCb(null, arg);
|
||||
}
|
||||
|
|
|
@ -56,16 +56,20 @@ class ENS {
|
|||
this.logger = embark.logger;
|
||||
this.events = embark.events;
|
||||
this.namesConfig = embark.config.namesystemConfig;
|
||||
this.enabled = false;
|
||||
this.registration = this.namesConfig.register || {};
|
||||
this.embark = embark;
|
||||
this.ensConfig = require('./ensContractConfigs');
|
||||
this.configured = false;
|
||||
|
||||
this.events.setCommandHandler("ens:resolve", this.ensResolve.bind(this));
|
||||
|
||||
if (this.namesConfig === {} ||
|
||||
this.namesConfig.enabled !== true ||
|
||||
this.namesConfig.available_providers.indexOf('ens') < 0) {
|
||||
return;
|
||||
}
|
||||
this.enabled = true;
|
||||
this.doSetENSProvider = this.namesConfig.provider === 'ens';
|
||||
|
||||
this.addENSToEmbarkJS();
|
||||
|
@ -102,7 +106,6 @@ class ENS {
|
|||
|
||||
registerEvents() {
|
||||
this.embark.registerActionForEvent("deploy:beforeAll", this.configureContractsAndRegister.bind(this));
|
||||
|
||||
this.events.setCommandHandler("storage:ens:associate", this.associateStorageToEns.bind(this));
|
||||
}
|
||||
|
||||
|
@ -150,7 +153,6 @@ class ENS {
|
|||
} catch (e) {
|
||||
return cb('Invalid IPFS hash');
|
||||
}
|
||||
|
||||
// Set content
|
||||
async.waterfall([
|
||||
function getRegistryABI(next) {
|
||||
|
@ -361,6 +363,40 @@ class ENS {
|
|||
this.embark.addProviderInit('names', code, shouldInit);
|
||||
this.embark.addConsoleProviderInit('names', code, shouldInit);
|
||||
}
|
||||
|
||||
ensResolve(name, cb) {
|
||||
const self = this;
|
||||
if (!self.enabled) {
|
||||
return cb('ENS not enabled');
|
||||
}
|
||||
if(!self.configured) {
|
||||
return cb('ENS not configured');
|
||||
}
|
||||
const hashedName = namehash.hash(name);
|
||||
async.waterfall([
|
||||
function getResolverAddress(next) {
|
||||
self.ensContract.methods.resolver(hashedName).call((err, resolverAddress) => {
|
||||
if (err) {
|
||||
next(err);
|
||||
} else if(resolverAddress === '0x0000000000000000000000000000000000000000') {
|
||||
next('Name not yet registered');
|
||||
} else {
|
||||
next(null, resolverAddress);
|
||||
}
|
||||
});
|
||||
},
|
||||
function createResolverContract(resolverAddress, next) {
|
||||
self.events.request("blockchain:contract:create",
|
||||
{abi: self.ensConfig.Resolver.abiDefinition, address: resolverAddress},
|
||||
(resolver) => {
|
||||
next(null, resolver);
|
||||
});
|
||||
},
|
||||
function resolveName(resolverContract, next) {
|
||||
resolverContract.methods.addr(hashedName).call(next);
|
||||
}
|
||||
], cb);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ENS;
|
||||
|
|
|
@ -15,8 +15,28 @@ class SpecialConfigs {
|
|||
this.registerDeployIfAction();
|
||||
}
|
||||
|
||||
replaceWithENSAddress(cmd, cb) {
|
||||
const self = this;
|
||||
let regex = /\'[a-zA-Z0-9.]+\.eth\'/g;
|
||||
return stringReplaceAsync.seq(cmd, regex, (ensDomain) => {
|
||||
ensDomain = ensDomain.slice(1, ensDomain.length - 1);
|
||||
return (new Promise((resolve, reject) => {
|
||||
self.events.request("ens:resolve", ensDomain, (err, address) => {
|
||||
if(err) {
|
||||
return reject(new Error(err));
|
||||
}
|
||||
address = `'${address}'`;
|
||||
return resolve(address);
|
||||
});
|
||||
}));
|
||||
}).then((address) => {
|
||||
cb(null, address);
|
||||
}).catch(cb);
|
||||
}
|
||||
|
||||
replaceWithAddresses(cmd, cb) {
|
||||
const self = this;
|
||||
|
||||
let regex = /\$\w+/g;
|
||||
stringReplaceAsync.seq(cmd, regex, (match) => {
|
||||
return (new Promise((resolve, reject) => {
|
||||
|
@ -40,8 +60,8 @@ class SpecialConfigs {
|
|||
return resolve(referedContract.deployedAddress);
|
||||
});
|
||||
}));
|
||||
}).then((result) => {
|
||||
cb(null, result);
|
||||
}).then((address) => {
|
||||
cb(null, address);
|
||||
}).catch(cb);
|
||||
}
|
||||
|
||||
|
@ -50,9 +70,13 @@ class SpecialConfigs {
|
|||
|
||||
this.embark.registerActionForEvent("contracts:deploy:afterAll", (cb) => {
|
||||
let afterDeployCmds = self.contractsConfig.afterDeploy || [];
|
||||
|
||||
async.mapLimit(afterDeployCmds, 1, (cmd, nextMapCb) => {
|
||||
self.replaceWithAddresses(cmd, nextMapCb);
|
||||
async.waterfall([
|
||||
function replaceWithAddresses(next) {
|
||||
self.replaceWithAddresses(cmd, next);
|
||||
},
|
||||
self.replaceWithENSAddress.bind(self)
|
||||
], nextMapCb);
|
||||
}, (err, onDeployCode) => {
|
||||
if (err) {
|
||||
self.logger.trace(err);
|
||||
|
@ -87,14 +111,19 @@ class SpecialConfigs {
|
|||
if (!contract.onDeploy || contract.deploy === false) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
if (!contract.silent) {
|
||||
self.logger.info(__('executing onDeploy commands'));
|
||||
}
|
||||
|
||||
let onDeployCmds = contract.onDeploy;
|
||||
|
||||
async.mapLimit(onDeployCmds, 1, (cmd, nextMapCb) => {
|
||||
self.replaceWithAddresses(cmd, nextMapCb);
|
||||
async.waterfall([
|
||||
function replaceWithAddresses(next) {
|
||||
self.replaceWithAddresses(cmd, next);
|
||||
},
|
||||
self.replaceWithENSAddress.bind(self)
|
||||
], nextMapCb);
|
||||
}, (err, onDeployCode) => {
|
||||
if (err) {
|
||||
return cb(new Error("error running onDeploy for " + contract.className.cyan));
|
||||
|
|
|
@ -2,9 +2,11 @@ pragma solidity ^0.4.24;
|
|||
contract AnotherStorage {
|
||||
address public simpleStorageAddress;
|
||||
address simpleStorageAddress2;
|
||||
address ens;
|
||||
|
||||
constructor(address addr) public {
|
||||
constructor(address addr, address _ens) public {
|
||||
simpleStorageAddress = addr;
|
||||
ens = _ens;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,4 +19,8 @@ contract Test {
|
|||
addr = _addr;
|
||||
}
|
||||
|
||||
function changeAddress2(address _addr) public {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
"contracts": "contracts.json",
|
||||
"storage": false,
|
||||
"communication": false,
|
||||
"webserver": false
|
||||
"webserver": false,
|
||||
"namesystem": "ens.json"
|
||||
},
|
||||
"versions": {
|
||||
"web3": "1.0.0-beta",
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"default" : {
|
||||
"enabled": true,
|
||||
"available_providers": "ens",
|
||||
"register": {
|
||||
"rootDomain": "embark.eth"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ config({
|
|||
args: [100]
|
||||
},
|
||||
"AnotherStorage": {
|
||||
args: ["$SimpleStorage"]
|
||||
args: ["$SimpleStorage", "embark.eth"]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@ config({
|
|||
args: [100]
|
||||
},
|
||||
AnotherStorage: {
|
||||
args: ["$SimpleStorage"]
|
||||
args: ["$SimpleStorage", "0xCAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE"]
|
||||
},
|
||||
Token: {
|
||||
deploy: false,
|
||||
|
|
|
@ -10,6 +10,7 @@ library ZAMyLib {
|
|||
|
||||
contract Test {
|
||||
address public addr;
|
||||
address public ens;
|
||||
|
||||
function testAdd() public pure returns (uint _result) {
|
||||
return ZAMyLib.add(1, 2);
|
||||
|
@ -19,4 +20,8 @@ contract Test {
|
|||
addr = _addr;
|
||||
}
|
||||
|
||||
function changeENS(address _ens) public {
|
||||
ens = _ens;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ module.exports = {
|
|||
args: [1000]
|
||||
},
|
||||
Test: {
|
||||
onDeploy: ["Test.methods.changeAddress('$MyToken')"]
|
||||
onDeploy: ["Test.methods.changeAddress('$MyToken')", "Test.methods.changeENS('embark.eth')"]
|
||||
},
|
||||
MyToken: {
|
||||
instanceOf: "Token"
|
||||
|
|
|
@ -32,7 +32,7 @@ config({
|
|||
instanceOf: "Token"
|
||||
},
|
||||
Test: {
|
||||
onDeploy: ["Test.methods.changeAddress('$MyToken').send()"]
|
||||
onDeploy: ["Test.methods.changeAddress('$MyToken').send()", "Test.methods.changeENS('embark.eth').send()"]
|
||||
},
|
||||
ContractArgs: {
|
||||
args: {
|
||||
|
|
Loading…
Reference in New Issue