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