mirror of https://github.com/embarklabs/embark.git
commit
0858092306
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -235,7 +235,8 @@ Config.prototype.loadNameSystemConfigFile = function() {
|
|||
var configObject = {
|
||||
"default": {
|
||||
"available_providers": ["ens"],
|
||||
"provider": "ens"
|
||||
"provider": "ens",
|
||||
"enabled": true
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
@ -164,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
|
||||
});
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const namehash = require('eth-ens-namehash');
|
||||
import namehash from 'eth-ens-namehash';
|
||||
|
||||
/*global web3*/
|
||||
let __embarkENS = {};
|
||||
|
||||
|
@ -251,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;
|
||||
|
@ -267,9 +270,9 @@ __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) => {
|
||||
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) => {
|
||||
|
@ -284,9 +287,9 @@ __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) => {
|
||||
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) => {
|
||||
|
|
Loading…
Reference in New Issue