fix small oopsies and make it work
This commit is contained in:
parent
dd510ff6a1
commit
212eb79754
16
lib/index.js
16
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);
|
||||
|
|
|
@ -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.');
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ contract("ENS", function () {
|
|||
}
|
||||
clearInterval(wait);
|
||||
done();
|
||||
});
|
||||
}, 50);
|
||||
});
|
||||
|
||||
it("should have registered embark.eth", async function () {
|
||||
|
|
Loading…
Reference in New Issue