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
|
// resolve resolves a name into an identifier of some kind
|
||||||
EmbarkJS.Names.resolve = function (name) {
|
EmbarkJS.Names.resolve = function (name, callback) {
|
||||||
if (!this.currentNameSystems) {
|
if (!this.currentNameSystems) {
|
||||||
throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")');
|
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
|
// 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) {
|
if (!this.currentNameSystems) {
|
||||||
throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")');
|
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
|
// 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")');
|
throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")');
|
||||||
}
|
}
|
||||||
return this.currentNameSystems.register(name, options);
|
return this.currentNameSystems.register(name, options);
|
||||||
}
|
};
|
||||||
|
|
||||||
EmbarkJS.Utils = {
|
EmbarkJS.Utils = {
|
||||||
fromAscii: function (str) {
|
fromAscii: function (str) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ class GethCommands {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.syncMode || config.syncmode) {
|
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) {
|
if (config.account && config.account.password) {
|
||||||
|
|
|
@ -162,6 +162,10 @@ __embarkENS.registryAddresses = {
|
||||||
"4": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A"
|
"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 () {
|
__embarkENS.setProvider = function () {
|
||||||
const self = this;
|
const self = this;
|
||||||
// get network id and then assign ENS contract based on that
|
// get network id and then assign ENS contract based on that
|
||||||
|
@ -183,42 +187,61 @@ __embarkENS.setProvider = function () {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
__embarkENS.resolve = function (name) {
|
__embarkENS.resolve = function (name, callback) {
|
||||||
const self = this;
|
if (!this.ens) {
|
||||||
|
return callback(providerNotSetError);
|
||||||
if (self.ens === undefined) return;
|
}
|
||||||
|
|
||||||
let node = namehash.hash(name);
|
let node = namehash.hash(name);
|
||||||
|
|
||||||
return self.ens.methods.resolver(node).call().then((resolverAddress) => {
|
console.log('Name to check', name);
|
||||||
let resolverContract = new EmbarkJS.Contract({abi: self.resolverInterface, address: resolverAddress});
|
console.log('Node', node);
|
||||||
return resolverContract.methods.addr(node).call();
|
console.log(this.ens);
|
||||||
}).then((addr) => {
|
return this.ens.methods.resolver(node).call().then((resolverAddress) => {
|
||||||
return addr;
|
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) => {
|
}).catch((err) => {
|
||||||
if (err === NoDecodeAddrError) {
|
if (err === NoDecodeAddrError) {
|
||||||
console.log(name + " is not registered");
|
return callback(name + " is not registered", "0x");
|
||||||
return "0x";
|
|
||||||
}
|
}
|
||||||
return err;
|
console.log('oldekwe^pfke');
|
||||||
|
callback(err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
__embarkENS.lookup = function (address) {
|
__embarkENS.lookup = function (address, callback) {
|
||||||
const self = this;
|
if (!this.ens) {
|
||||||
|
return callback(providerNotSetError);
|
||||||
if (!self.ens) {
|
|
||||||
console.log("ENS provider not set. Exiting.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
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");
|
let node = namehash.hash(address.toLowerCase() + ".addr.reverse");
|
||||||
|
console.log('Node', node);
|
||||||
|
|
||||||
return self.ens.methods.resolver(node).call().then((resolverAddress) => {
|
return this.ens.methods.resolver(node).call().then((resolverAddress) => {
|
||||||
let resolverContract = new EmbarkJS.Contract({abi: self.resolverInterface, address: resolverAddress});
|
console.log('Resolver address', resolverAddress);
|
||||||
return resolverContract.methods.name(node).call();
|
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) => {
|
}).catch((err) => {
|
||||||
|
console.log('Got error', err);
|
||||||
if (err === NoDecodeStringError || err === NoDecodeAddrError) {
|
if (err === NoDecodeStringError || err === NoDecodeAddrError) {
|
||||||
console.log('Address does not resolve to name. Try syncing chain.');
|
console.log('Address does not resolve to name. Try syncing chain.');
|
||||||
return "";
|
return "";
|
||||||
|
|
Loading…
Reference in New Issue