mirror of https://github.com/embarklabs/embark.git
wip changes
This commit is contained in:
parent
d0525c7e5b
commit
ffbec61554
10
js/embark.js
10
js/embark.js
|
@ -359,19 +359,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
|
||||
|
@ -383,7 +383,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) {
|
||||
|
|
|
@ -153,6 +153,7 @@ __embarkENS.resolverInterface = [
|
|||
}
|
||||
];
|
||||
|
||||
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';
|
||||
|
||||
|
@ -163,42 +164,61 @@ __embarkENS.setProvider = function (config) {
|
|||
});
|
||||
};
|
||||
|
||||
__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