mirror of https://github.com/embarklabs/embark.git
resolve appears to be done, now I just need some help wiring the module together
Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
parent
3aa4c9fd1f
commit
4de830ca29
|
@ -1,7 +1,8 @@
|
||||||
|
const namehash = require('eth-ens-namehash');
|
||||||
|
|
||||||
/*global web3*/
|
/*global web3*/
|
||||||
let __embarkENS = {};
|
let __embarkENS = {};
|
||||||
|
|
||||||
/*
|
|
||||||
// registry interface for later
|
// registry interface for later
|
||||||
var registryInterface = [
|
var registryInterface = [
|
||||||
{
|
{
|
||||||
|
@ -91,7 +92,6 @@ var registryInterface = [
|
||||||
"type": "function"
|
"type": "function"
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
*/
|
|
||||||
|
|
||||||
var resolverInterface = [
|
var resolverInterface = [
|
||||||
{
|
{
|
||||||
|
@ -260,12 +260,12 @@ __embarkENS.setProvider = function (options) {
|
||||||
provider = options.server + ':' + options.port;
|
provider = options.server + ':' + options.port;
|
||||||
}
|
}
|
||||||
// TODO: take into account type
|
// TODO: take into account type
|
||||||
var web3 = new Web3(new Web3.providers.WebsocketProvider("ws://" + provider));
|
let web3 = new Web3(new Web3.providers.WebsocketProvider("ws://" + provider));
|
||||||
|
self.web3 = web3;
|
||||||
// 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 => {
|
self.ens = web3.eth.net.getId().then(id => {
|
||||||
if (registryAddresses[id] !== undefined) {
|
if (registryAddresses[id] !== undefined) {
|
||||||
return new web3.eth.Contract(resolverInterface, registryAddresses[id]);
|
return new web3.eth.Contract(registryInterface, registryAddresses[id]);
|
||||||
}
|
}
|
||||||
// todo: deploy at this point
|
// todo: deploy at this point
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -273,6 +273,15 @@ __embarkENS.setProvider = function (options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
__embarkENS.resolve = function(name) {
|
__embarkENS.resolve = function(name) {
|
||||||
|
const self = this;
|
||||||
|
const web3 = this.web3;
|
||||||
if (this.ens === undefined)
|
if (this.ens === undefined)
|
||||||
return undefined;
|
return undefined;
|
||||||
|
let node = namehash(name)
|
||||||
|
this.ens.methods.resolver(node).call().then((resolverAddress) => {
|
||||||
|
let resolverContract = new web3.eth.Contract(resolverInterface, resolverAddress);
|
||||||
|
return resolverContract.methods.addr(node).call()
|
||||||
|
}).then((addr) => {
|
||||||
|
return addr
|
||||||
|
}).catch(err => err);
|
||||||
}
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
const fs = require('../../core/fs.js');
|
||||||
|
|
||||||
|
class ENS {
|
||||||
|
constructor(embark, options) {
|
||||||
|
this.logger = embark.logger;
|
||||||
|
this.events = embark.events;
|
||||||
|
this.web3 = options.web3;
|
||||||
|
this.embark = embark;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue