fix small oopsies and make it work

This commit is contained in:
Jonathan Rainville 2018-07-30 11:57:00 -04:00 committed by Iuri Matias
parent dd510ff6a1
commit 212eb79754
6 changed files with 39 additions and 16 deletions

View File

@ -394,6 +394,7 @@ class Embark {
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) {
@ -417,8 +418,21 @@ class Embark {
engine.logger.info(__('Deployment Done')); 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) { if (err) {
engine.logger.error(err.message); engine.logger.error(err.message);
engine.logger.debug(err.stack); engine.logger.debug(err.stack);

View File

@ -234,7 +234,7 @@ __embarkENS.registerSubDomain = function (name, address, callback) {
toSend.estimateGas().then(gasEstimated => { toSend.estimateGas().then(gasEstimated => {
return toSend.send({gas: gasEstimated + 1000}).then(transaction => { 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); console.warn('Failed transaction', transaction);
return callback('Failed to register. Check gas cost.'); return callback('Failed to register. Check gas cost.');
} }

View File

@ -65,19 +65,20 @@ class ENS {
} }
associateStorageToEns(options, cb) { associateStorageToEns(options, cb) {
const self =this;
// Code inspired by https://github.com/monkybrain/ipfs-to-ens // Code inspired by https://github.com/monkybrain/ipfs-to-ens
const {name, ipfsHash} = options; const {name, storageHash} = options;
if (!ENS.isValidDomain(name)) { if (!ENS.isValidDomain(name)) {
return cb('Invalid domain name ' + 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 // Convert IPFS multihash to 32 byte hex string
let contentHash; let contentHash;
try { try {
contentHash = ENS.hashTo32ByteHexString(ipfsHash); contentHash = ENS.hashTo32ByteHexString(storageHash);
} catch(e) { } catch(e) {
return cb('Invalid IPFS hash'); return cb('Invalid IPFS hash');
} }
@ -97,7 +98,7 @@ class ENS {
}); });
}, },
function getResolverForName(registry, next) { function getResolverForName(registry, next) {
this.ens.methods.resolver(namehash).call((err, resolverAddress) => { registry.methods.resolver(hashedName).call((err, resolverAddress) => {
if (err) { if (err) {
return cb(err); return cb(err);
} }
@ -125,7 +126,15 @@ class ENS {
}); });
}, },
function setContent(resolver, defaultAccount, next) { 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); ], cb);
} }
@ -139,9 +148,9 @@ class ENS {
} }
} }
static hashTo32ByteHexString(ipfsHash) { static hashTo32ByteHexString(storageHash) {
const multihash = require('multihashes'); const multihash = require('multihashes');
let buf = multihash.fromB58String(ipfsHash); let buf = multihash.fromB58String(storageHash);
let digest = multihash.decode(buf).digest; let digest = multihash.decode(buf).digest;
return '0x' + multihash.toHexString(digest); return '0x' + multihash.toHexString(digest);
} }

View File

@ -45,15 +45,15 @@ class IPFS {
console.log(("=== " + __("DApp available at") + " http://localhost:8080/ipfs/" + dir_hash + "/").green); 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); 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) { if (err) {
console.log(__("error uploading to ipfs").red); console.log(__("error uploading to ipfs").red);
console.log(err); console.log(err);
cb(err); cb(err);
} }
else cb(null, __('successfully uploaded to ipfs')); else cb(null, dir_hash);
}); });
} }
} }

View File

@ -33,15 +33,15 @@ class Swarm {
console.log(("=== " + __("DApp available at") + ` ${self.getUrl}${dir_hash}/`).green); console.log(("=== " + __("DApp available at") + ` ${self.getUrl}${dir_hash}/`).green);
console.log(("=== " + __("DApp available at") + ` http://swarm-gateways.net/bzz:/${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) { if (err) {
console.log(__("error uploading to swarm").red); console.log(__("error uploading to swarm").red);
console.log(err); console.log(err);
return cb(err); return cb(err);
} }
cb(null, __('successfully uploaded to swarm')); cb(null, dir_hash);
}); });
} }
} }

View File

@ -38,7 +38,7 @@ contract("ENS", function () {
} }
clearInterval(wait); clearInterval(wait);
done(); done();
}); }, 50);
}); });
it("should have registered embark.eth", async function () { it("should have registered embark.eth", async function () {