From a25330ddecaef066c10679bd868871dac0212fda Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 28 May 2018 11:09:48 -0400 Subject: [PATCH 1/8] set namesystem enable to true by default --- lib/core/config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/core/config.js b/lib/core/config.js index f857a43c8..26e04a482 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -235,7 +235,8 @@ Config.prototype.loadNameSystemConfigFile = function() { var configObject = { "default": { "available_providers": ["ens"], - "provider": "ens" + "provider": "ens", + "enabled": true } }; From 3750fc297bbfeca6b43a522e9689ede4ff39898d Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 28 May 2018 11:10:09 -0400 Subject: [PATCH 2/8] add missing module init --- lib/core/engine.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/core/engine.js b/lib/core/engine.js index 1c90f6933..041dcc109 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -147,6 +147,15 @@ class Engine { }); } + namingSystem(_options) { + this.registerModule('ens', { + logger: this.logger, + events: this.events, + web3: this.blockchain.web3, + namesConfig: this.config.namesystemConfig + }); + } + codeRunnerService(_options) { this.codeRunner = new CodeRunner({ plugins: this.plugins, From e988bd6b4a61a8e063c6fc3a4c75a5a9c5a183e6 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 28 May 2018 11:10:20 -0400 Subject: [PATCH 3/8] use import instead of require --- lib/modules/ens/embarkjs.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/modules/ens/embarkjs.js b/lib/modules/ens/embarkjs.js index 0c6b08be0..7034fbac3 100644 --- a/lib/modules/ens/embarkjs.js +++ b/lib/modules/ens/embarkjs.js @@ -1,4 +1,5 @@ -const namehash = require('eth-ens-namehash'); +import namehash from 'eth-ens-namehash'; + /*global web3*/ let __embarkENS = {}; From 32a9b25fe3a58b21f6013ab6a8eca15a865012ca Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 28 May 2018 11:21:52 -0400 Subject: [PATCH 4/8] fix reference to ens object --- lib/modules/ens/embarkjs.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/modules/ens/embarkjs.js b/lib/modules/ens/embarkjs.js index 7034fbac3..9ac7d3d8d 100644 --- a/lib/modules/ens/embarkjs.js +++ b/lib/modules/ens/embarkjs.js @@ -252,11 +252,13 @@ __embarkENS.registryAddresses = { }; __embarkENS.setProvider = function () { + const self = this; // get network id and then assign ENS contract based on that let registryAddresses = this.registryAddresses; - this.ens = web3.eth.net.getId().then(id => { + this.ens = null + web3.eth.net.getId().then(id => { if (registryAddresses[id] !== undefined) { - return new web3.eth.Contract(this.registryInterface, registryAddresses[id]); + self.ens = new web3.eth.Contract(self.registryInterface, registryAddresses[id]); } // todo: deploy at this point return undefined; @@ -268,7 +270,7 @@ __embarkENS.resolve = function(name) { if (self.ens === undefined) return undefined; - let node = namehash(name); + let node = namehash.hash(name); self.ens.methods.resolver(node).call().then((resolverAddress) => { let resolverContract = new web3.eth.Contract(self.resolverInterface, resolverAddress); @@ -285,7 +287,7 @@ __embarkENS.lookup = function(address) { if (address.startsWith("0x")) address = address.slice(2); - let node = namehash(address.toLowerCase() + ".addr.reverse"); + let node = namehash.hash(address.toLowerCase() + ".addr.reverse"); self.ens.methods.resolver(node).call().then((resolverAddress) => { let resolverContract = new web3.eth.Contract(self.resolverInterface, resolverAddress); From ee460e3309309f0de20fb103397258796dfd82f1 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 28 May 2018 11:42:01 -0400 Subject: [PATCH 5/8] add missing promise returns --- lib/modules/ens/embarkjs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/modules/ens/embarkjs.js b/lib/modules/ens/embarkjs.js index 9ac7d3d8d..78543c35e 100644 --- a/lib/modules/ens/embarkjs.js +++ b/lib/modules/ens/embarkjs.js @@ -272,7 +272,7 @@ __embarkENS.resolve = function(name) { let node = namehash.hash(name); - self.ens.methods.resolver(node).call().then((resolverAddress) => { + return self.ens.methods.resolver(node).call().then((resolverAddress) => { let resolverContract = new web3.eth.Contract(self.resolverInterface, resolverAddress); return resolverContract.methods.addr(node).call(); }).then((addr) => { @@ -289,7 +289,7 @@ __embarkENS.lookup = function(address) { let node = namehash.hash(address.toLowerCase() + ".addr.reverse"); - self.ens.methods.resolver(node).call().then((resolverAddress) => { + return self.ens.methods.resolver(node).call().then((resolverAddress) => { let resolverContract = new web3.eth.Contract(self.resolverInterface, resolverAddress); return resolverContract.methods.name(node).call(); }).then((name) => { From ef3bde1053169b427d8d5078c7e1e1339af813aa Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 28 May 2018 11:42:22 -0400 Subject: [PATCH 6/8] add missing code init --- lib/contracts/code_generator.js | 14 ++++++++++++++ lib/core/engine.js | 1 + 2 files changed, 15 insertions(+) diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index e7e8064d5..7fba4b5be 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -26,6 +26,7 @@ class CodeGenerator { this.contractsConfig = options.contractsConfig || {}; this.storageConfig = options.storageConfig || {}; this.communicationConfig = options.communicationConfig || {}; + this.namesystemConfig = options.namesystemConfig || {}; // TODO: this should also be removed and use events instead this.contractsManager = options.contractsManager; this.plugins = options.plugins; @@ -224,6 +225,17 @@ class CodeGenerator { return block; } + generateNamesInitialization(useEmbarkJS) { + if (!useEmbarkJS || this.namesystemConfig === {}) return ""; + + let result = "\n"; + result += Templates.define_when_env_loaded(); + result += this._getInitCode('names', this.namesystemConfig); + + return result; + } + + generateStorageInitialization(useEmbarkJS) { if (!useEmbarkJS || this.storageConfig === {}) return ""; @@ -266,6 +278,7 @@ class CodeGenerator { result += this.generateContracts(options.useEmbarkJS, options.deployment, true); result += this.generateStorageInitialization(options.useEmbarkJS); result += this.generateCommunicationInitialization(options.useEmbarkJS); + result += this.generateNamesInitialization(options.useEmbarkJS); return result; } @@ -331,6 +344,7 @@ class CodeGenerator { code += self.generateCommunicationInitialization(true); code += self.generateStorageInitialization(true); + code += self.generateNamesInitialization(true); next(); }, function writeFile(next) { diff --git a/lib/core/engine.js b/lib/core/engine.js index 041dcc109..4a84b234d 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -173,6 +173,7 @@ class Engine { contractsManager: this.contractsManager, plugins: self.plugins, storageConfig: self.config.storageConfig, + namesystemConfig: self.config.namesystemConfig, communicationConfig: self.config.communicationConfig, events: self.events }); From 5b58c9f1b87048aae26ed9efb1092387e57aa763 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 28 May 2018 12:20:04 -0400 Subject: [PATCH 7/8] fix variable name being passed to name provider implementation --- js/embark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/embark.js b/js/embark.js index 05357039d..57a9d6c5a 100644 --- a/js/embark.js +++ b/js/embark.js @@ -305,7 +305,7 @@ EmbarkJS.Names.lookup = function(identifier) { if (!this.currentNameSystems) { throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")'); } - return this.currentNameSystems.lookup(name); + return this.currentNameSystems.lookup(identifier); } // To Implement From 033613d7f6eb32a462354f6e3e89ec8667d4367c Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 28 May 2018 12:29:47 -0400 Subject: [PATCH 8/8] lint is king --- lib/modules/ens/embarkjs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/ens/embarkjs.js b/lib/modules/ens/embarkjs.js index 78543c35e..4b3ac9488 100644 --- a/lib/modules/ens/embarkjs.js +++ b/lib/modules/ens/embarkjs.js @@ -255,7 +255,7 @@ __embarkENS.setProvider = function () { const self = this; // get network id and then assign ENS contract based on that let registryAddresses = this.registryAddresses; - this.ens = null + this.ens = null; web3.eth.net.getId().then(id => { if (registryAddresses[id] !== undefined) { self.ens = new web3.eth.Contract(self.registryInterface, registryAddresses[id]);