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
|
// 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
|
||||||
|
@ -383,7 +383,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) {
|
||||||
|
|
|
@ -153,6 +153,7 @@ __embarkENS.resolverInterface = [
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const providerNotSetError = 'ENS provider not set';
|
||||||
const NoDecodeAddrError = 'Error: Couldn\'t decode address from ABI: 0x';
|
const NoDecodeAddrError = 'Error: Couldn\'t decode address from ABI: 0x';
|
||||||
const NoDecodeStringError = 'ERROR: The returned value is not a convertible string: 0x0';
|
const NoDecodeStringError = 'ERROR: The returned value is not a convertible string: 0x0';
|
||||||
|
|
||||||
|
@ -163,42 +164,61 @@ __embarkENS.setProvider = function (config) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
__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