wip changes
This commit is contained in:
parent
a3d612f8ba
commit
054215ce21
10
js/embark.js
10
js/embark.js
|
@ -393,19 +393,19 @@ EmbarkJS.Names.setProvider = function (provider, options) {
|
|||
};
|
||||
|
||||
// resolve resolves a name into an identifier of some kind
|
||||
EmbarkJS.Names.resolve = function (name) {
|
||||
EmbarkJS.Names.resolve = function (name, callback) {
|
||||
if (!this.currentNameSystems) {
|
||||
throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")');
|
||||
}
|
||||
return this.currentNameSystems.resolve(name);
|
||||
return this.currentNameSystems.resolve(name, callback);
|
||||
};
|
||||
|
||||
// the reverse of resolve, resolves using an identifier to get to a name
|
||||
EmbarkJS.Names.lookup = function (identifier) {
|
||||
EmbarkJS.Names.lookup = function (identifier, callback) {
|
||||
if (!this.currentNameSystems) {
|
||||
throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")');
|
||||
}
|
||||
return this.currentNameSystems.lookup(identifier);
|
||||
return this.currentNameSystems.lookup(identifier, callback);
|
||||
};
|
||||
|
||||
// To Implement
|
||||
|
@ -417,7 +417,7 @@ EmbarkJS.Names.register = function(name, options) {
|
|||
throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")');
|
||||
}
|
||||
return this.currentNameSystems.register(name, options);
|
||||
}
|
||||
};
|
||||
|
||||
EmbarkJS.Utils = {
|
||||
fromAscii: function (str) {
|
||||
|
|
|
@ -21,7 +21,7 @@ class GethCommands {
|
|||
}
|
||||
|
||||
if (config.syncMode || config.syncmode) {
|
||||
cmd.push("--syncmode=" + config.syncmode || config.syncMode);
|
||||
cmd.push("--syncmode=" + (config.syncmode || config.syncMode));
|
||||
}
|
||||
|
||||
if (config.account && config.account.password) {
|
||||
|
|
|
@ -162,6 +162,10 @@ __embarkENS.registryAddresses = {
|
|||
"4": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A"
|
||||
};
|
||||
|
||||
const providerNotSetError = 'ENS provider not set';
|
||||
const NoDecodeAddrError = 'Error: Couldn\'t decode address from ABI: 0x';
|
||||
const NoDecodeStringError = 'ERROR: The returned value is not a convertible string: 0x0';
|
||||
|
||||
__embarkENS.setProvider = function () {
|
||||
const self = this;
|
||||
// get network id and then assign ENS contract based on that
|
||||
|
@ -183,42 +187,61 @@ __embarkENS.setProvider = function () {
|
|||
});
|
||||
};
|
||||
|
||||
__embarkENS.resolve = function (name) {
|
||||
const self = this;
|
||||
|
||||
if (self.ens === undefined) return;
|
||||
__embarkENS.resolve = function (name, callback) {
|
||||
if (!this.ens) {
|
||||
return callback(providerNotSetError);
|
||||
}
|
||||
|
||||
let node = namehash.hash(name);
|
||||
|
||||
return self.ens.methods.resolver(node).call().then((resolverAddress) => {
|
||||
let resolverContract = new EmbarkJS.Contract({abi: self.resolverInterface, address: resolverAddress});
|
||||
return resolverContract.methods.addr(node).call();
|
||||
}).then((addr) => {
|
||||
return addr;
|
||||
|
||||
console.log('Name to check', name);
|
||||
console.log('Node', node);
|
||||
console.log(this.ens);
|
||||
return this.ens.methods.resolver(node).call().then((resolverAddress) => {
|
||||
console.log('address', resolverAddress);
|
||||
let resolverContract = new EmbarkJS.Contract({abi: this.resolverInterface, address: resolverAddress});
|
||||
return resolverContract.methods.addr(node).call()
|
||||
.then((addr) => {
|
||||
console.log('ADRESSS', addr);
|
||||
callback(null, addr);
|
||||
})
|
||||
.catch(err => {
|
||||
if (err === NoDecodeAddrError) {
|
||||
return callback(name + " is not registered", "0x");
|
||||
}
|
||||
callback(err);
|
||||
});
|
||||
}).catch((err) => {
|
||||
if (err === NoDecodeAddrError) {
|
||||
console.log(name + " is not registered");
|
||||
return "0x";
|
||||
return callback(name + " is not registered", "0x");
|
||||
}
|
||||
return err;
|
||||
console.log('oldekwe^pfke');
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
__embarkENS.lookup = function (address) {
|
||||
const self = this;
|
||||
|
||||
if (!self.ens) {
|
||||
console.log("ENS provider not set. Exiting.");
|
||||
return;
|
||||
__embarkENS.lookup = function (address, callback) {
|
||||
if (!this.ens) {
|
||||
return callback(providerNotSetError);
|
||||
}
|
||||
if (address.startsWith("0x")) address = address.slice(2);
|
||||
|
||||
if (address.startsWith("0x")) {
|
||||
address = address.slice(2);
|
||||
}
|
||||
console.log('Address', address);
|
||||
let node = namehash.hash(address.toLowerCase() + ".addr.reverse");
|
||||
console.log('Node', node);
|
||||
|
||||
return self.ens.methods.resolver(node).call().then((resolverAddress) => {
|
||||
let resolverContract = new EmbarkJS.Contract({abi: self.resolverInterface, address: resolverAddress});
|
||||
return resolverContract.methods.name(node).call();
|
||||
return this.ens.methods.resolver(node).call().then((resolverAddress) => {
|
||||
console.log('Resolver address', resolverAddress);
|
||||
let resolverContract = new EmbarkJS.Contract({abi: this.resolverInterface, address: resolverAddress});
|
||||
resolverContract.methods.name(node).call()
|
||||
.then(name => {
|
||||
console.log('Name');
|
||||
callback(null, name);
|
||||
})
|
||||
.catch(callback);
|
||||
}).catch((err) => {
|
||||
console.log('Got error', err);
|
||||
if (err === NoDecodeStringError || err === NoDecodeAddrError) {
|
||||
console.log('Address does not resolve to name. Try syncing chain.');
|
||||
return "";
|
||||
|
|
Loading…
Reference in New Issue