diff --git a/lib/index.js b/lib/index.js index 8d0d75ba7..a8b586ec7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -397,6 +397,7 @@ class Embark { engine.startService("deployment"); engine.startService("storage"); engine.startService("codeGenerator"); + engine.startService("namingSystem"); callback(); }, function listLoadedPlugin(callback) { @@ -420,8 +421,21 @@ class Embark { engine.logger.info(__('Deployment Done')); }); }); + }, + function associateToENS(hash, callback) { + if(!options.ensDomain) { + return callback(null, hash); + } + engine.plugins.emitAndRunActionsForEvent("storage:ens:associate", + {name: options.ensDomain, storageHash: hash}, (err) => { + if (err) { + return callback(err); + } + engine.logger.info(__('ENS association completed for {{hash}} at {{domain}}', {hash, domain: options.ensDomain})); + callback(); + }); } - ], function (err, _result) { + ], function (err) { if (err) { engine.logger.error(err.message); engine.logger.debug(err.stack); diff --git a/lib/modules/ens/embarkjs.js b/lib/modules/ens/embarkjs.js index 0934cc143..c835d7549 100644 --- a/lib/modules/ens/embarkjs.js +++ b/lib/modules/ens/embarkjs.js @@ -234,7 +234,7 @@ __embarkENS.registerSubDomain = function (name, address, callback) { toSend.estimateGas().then(gasEstimated => { return toSend.send({gas: gasEstimated + 1000}).then(transaction => { - if (transaction.status !== "0x1" && transaction.status !== "0x01") { + if (transaction.status !== "0x1" && transaction.status !== "0x01" && transaction.status !== true) { console.warn('Failed transaction', transaction); return callback('Failed to register. Check gas cost.'); } diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index 42cf4c3a0..01492f697 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -65,19 +65,20 @@ class ENS { } associateStorageToEns(options, cb) { + const self =this; // Code inspired by https://github.com/monkybrain/ipfs-to-ens - const {name, ipfsHash} = options; + const {name, storageHash} = options; if (!ENS.isValidDomain(name)) { return cb('Invalid domain name ' + name); } - let namehash = namehash.hash(name); + let hashedName = namehash.hash(name); // Convert IPFS multihash to 32 byte hex string let contentHash; try { - contentHash = ENS.hashTo32ByteHexString(ipfsHash); + contentHash = ENS.hashTo32ByteHexString(storageHash); } catch(e) { return cb('Invalid IPFS hash'); } @@ -97,7 +98,7 @@ class ENS { }); }, function getResolverForName(registry, next) { - this.ens.methods.resolver(namehash).call((err, resolverAddress) => { + registry.methods.resolver(hashedName).call((err, resolverAddress) => { if (err) { return cb(err); } @@ -125,7 +126,15 @@ class ENS { }); }, function setContent(resolver, defaultAccount, next) { - resolver.methods.setContent(namehash, contentHash).send({from: defaultAccount}).then(next); + resolver.methods.setContent(hashedName, contentHash).send({from: defaultAccount}).then((err, transaction) => { + if (err) { + return next(err); + } + if (transaction.status !== "0x1" && transaction.status !== "0x01" && transaction.status !== true) { + return next('Association failed. Status: ' + transaction.status); + } + next(); + }); } ], cb); } @@ -139,9 +148,9 @@ class ENS { } } - static hashTo32ByteHexString(ipfsHash) { + static hashTo32ByteHexString(storageHash) { const multihash = require('multihashes'); - let buf = multihash.fromB58String(ipfsHash); + let buf = multihash.fromB58String(storageHash); let digest = multihash.decode(buf).digest; return '0x' + multihash.toHexString(digest); } diff --git a/lib/modules/ipfs/upload.js b/lib/modules/ipfs/upload.js index 39452da50..d5e493d70 100644 --- a/lib/modules/ipfs/upload.js +++ b/lib/modules/ipfs/upload.js @@ -45,15 +45,15 @@ class IPFS { console.log(("=== " + __("DApp available at") + " http://localhost:8080/ipfs/" + dir_hash + "/").green); console.log(("=== " + __("DApp available at") + " http://ipfs.infura.io/ipfs/" + dir_hash + "/").green); - callback(); + callback(null, dir_hash); } - ], function (err, _result) { + ], function (err, dir_hash) { if (err) { console.log(__("error uploading to ipfs").red); console.log(err); cb(err); } - else cb(null, __('successfully uploaded to ipfs')); + else cb(null, dir_hash); }); } } diff --git a/lib/modules/swarm/upload.js b/lib/modules/swarm/upload.js index 02259adde..6ca162536 100644 --- a/lib/modules/swarm/upload.js +++ b/lib/modules/swarm/upload.js @@ -33,15 +33,15 @@ class Swarm { console.log(("=== " + __("DApp available at") + ` ${self.getUrl}${dir_hash}/`).green); console.log(("=== " + __("DApp available at") + ` http://swarm-gateways.net/bzz:/${dir_hash}`).green); - callback(); + callback(null, dir_hash); } - ], function (err, _result) { + ], function (err, dir_hash) { if (err) { console.log(__("error uploading to swarm").red); console.log(err); return cb(err); } - cb(null, __('successfully uploaded to swarm')); + cb(null, dir_hash); }); } } diff --git a/test_apps/test_app/test/ens_spec.js b/test_apps/test_app/test/ens_spec.js index 0b2d3cab7..7c564734f 100644 --- a/test_apps/test_app/test/ens_spec.js +++ b/test_apps/test_app/test/ens_spec.js @@ -38,7 +38,7 @@ contract("ENS", function () { } clearInterval(wait); done(); - }); + }, 50); }); it("should have registered embark.eth", async function () {