bring free wheeling vars into the ensEmbark namespace

Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
VoR0220 2018-05-25 12:25:28 -05:00
parent f5a29c7f4d
commit 9cb10c7ce7
1 changed files with 7 additions and 9 deletions

View File

@ -3,7 +3,7 @@ const namehash = require('eth-ens-namehash');
let __embarkENS = {}; let __embarkENS = {};
// registry interface for later // registry interface for later
var registryInterface = [ __embarkENS.registryInterface = [
{ {
"constant": true, "constant": true,
"inputs": [ "inputs": [
@ -92,7 +92,7 @@ var registryInterface = [
} }
]; ];
var resolverInterface = [ __embarkENS.resolverInterface = [
{ {
"constant": true, "constant": true,
"inputs": [ "inputs": [
@ -241,7 +241,7 @@ var resolverInterface = [
} }
]; ];
var registryAddresses = { __embarkENS.registryAddresses = {
// Mainnet // Mainnet
"1": "0x314159265dd8dbb310642f98f50c066173c1259b", "1": "0x314159265dd8dbb310642f98f50c066173c1259b",
// Ropsten // Ropsten
@ -251,12 +251,10 @@ var registryAddresses = {
}; };
__embarkENS.setProvider = function () { __embarkENS.setProvider = function () {
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
self.ens = web3.eth.net.getId().then(id => { this.ens = web3.eth.net.getId().then(id => {
if (registryAddresses[id] !== undefined) { 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 // todo: deploy at this point
return undefined; return undefined;
@ -271,7 +269,7 @@ __embarkENS.resolve = function(name) {
let node = namehash(name); let node = namehash(name);
self.ens.methods.resolver(node).call().then((resolverAddress) => { 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(); return resolverContract.methods.addr(node).call();
}).then((addr) => { }).then((addr) => {
return addr; return addr;
@ -288,7 +286,7 @@ __embarkENS.lookup = function(address) {
let node = namehash(address.toLowerCase() + ".addr.reverse"); let node = namehash(address.toLowerCase() + ".addr.reverse");
self.ens.methods.resolver(node).call().then((resolverAddress) => { 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(); return resolverContract.methods.name(node).call();
}).then((name) => { }).then((name) => {
if (name === "" || name === undefined) throw Error("ENS name not found"); if (name === "" || name === undefined) throw Error("ENS name not found");