From 212eb79754464b54c369a78300980a89752438dd Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 30 Jul 2018 11:57:00 -0400 Subject: [PATCH] fix small oopsies and make it work --- lib/index.js | 16 +++++++++++++++- lib/modules/ens/embarkjs.js | 2 +- lib/modules/ens/index.js | 23 ++++++++++++++++------- lib/modules/ipfs/upload.js | 6 +++--- lib/modules/swarm/upload.js | 6 +++--- test_apps/test_app/test/ens_spec.js | 2 +- 6 files changed, 39 insertions(+), 16 deletions(-) diff --git a/lib/index.js b/lib/index.js index affc1c02..4f426b0d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -394,6 +394,7 @@ class Embark { engine.startService("deployment"); engine.startService("storage"); engine.startService("codeGenerator"); + engine.startService("namingSystem"); callback(); }, function listLoadedPlugin(callback) { @@ -417,8 +418,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 340cf843..92d16f93 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 42cf4c3a..01492f69 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 39452da5..d5e493d7 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 02259add..6ca16253 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 0b2d3cab..7c564734 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 () {