mirror of https://github.com/embarklabs/embark.git
bring free wheeling vars into the ensEmbark namespace
Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
parent
f5a29c7f4d
commit
9cb10c7ce7
|
@ -3,7 +3,7 @@ const namehash = require('eth-ens-namehash');
|
|||
let __embarkENS = {};
|
||||
|
||||
// registry interface for later
|
||||
var registryInterface = [
|
||||
__embarkENS.registryInterface = [
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
|
@ -92,7 +92,7 @@ var registryInterface = [
|
|||
}
|
||||
];
|
||||
|
||||
var resolverInterface = [
|
||||
__embarkENS.resolverInterface = [
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
|
@ -241,7 +241,7 @@ var resolverInterface = [
|
|||
}
|
||||
];
|
||||
|
||||
var registryAddresses = {
|
||||
__embarkENS.registryAddresses = {
|
||||
// Mainnet
|
||||
"1": "0x314159265dd8dbb310642f98f50c066173c1259b",
|
||||
// Ropsten
|
||||
|
@ -251,12 +251,10 @@ var registryAddresses = {
|
|||
};
|
||||
|
||||
__embarkENS.setProvider = function () {
|
||||
const self = this;
|
||||
|
||||
// get network id and then assign ENS contract based on that
|
||||
self.ens = web3.eth.net.getId().then(id => {
|
||||
this.ens = web3.eth.net.getId().then(id => {
|
||||
if (registryAddresses[id] !== undefined) {
|
||||
return new web3.eth.Contract(registryInterface, registryAddresses[id]);
|
||||
return new web3.eth.Contract(this.registryInterface, this.registryAddresses[id]);
|
||||
}
|
||||
// todo: deploy at this point
|
||||
return undefined;
|
||||
|
@ -271,7 +269,7 @@ __embarkENS.resolve = function(name) {
|
|||
let node = namehash(name);
|
||||
|
||||
self.ens.methods.resolver(node).call().then((resolverAddress) => {
|
||||
let resolverContract = new web3.eth.Contract(resolverInterface, resolverAddress);
|
||||
let resolverContract = new web3.eth.Contract(self.resolverInterface, resolverAddress);
|
||||
return resolverContract.methods.addr(node).call();
|
||||
}).then((addr) => {
|
||||
return addr;
|
||||
|
@ -288,7 +286,7 @@ __embarkENS.lookup = function(address) {
|
|||
let node = namehash(address.toLowerCase() + ".addr.reverse");
|
||||
|
||||
self.ens.methods.resolver(node).call().then((resolverAddress) => {
|
||||
let resolverContract = new web3.eth.Contract(resolverInterface, resolverAddress);
|
||||
let resolverContract = new web3.eth.Contract(self.resolverInterface, resolverAddress);
|
||||
return resolverContract.methods.name(node).call();
|
||||
}).then((name) => {
|
||||
if (name === "" || name === undefined) throw Error("ENS name not found");
|
||||
|
|
Loading…
Reference in New Issue