mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-18 08:36:51 +00:00
ENS config use the actual network ID
Instead of relying on the name of network. Fetch the real network id and configure ENS based on that value
This commit is contained in:
parent
2e5f794820
commit
c6b0c34d8c
@ -291,9 +291,11 @@ class EmbarkController {
|
|||||||
engine.startService("namingSystem");
|
engine.startService("namingSystem");
|
||||||
engine.startService("console");
|
engine.startService("console");
|
||||||
engine.startService("pluginCommand");
|
engine.startService("pluginCommand");
|
||||||
|
engine.events.on('check:backOnline:Ethereum', function () {
|
||||||
callback();
|
callback();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
function web3IPC(callback) {
|
function ipcConnect(callback) {
|
||||||
// Do specific work in case we are connected to a socket:
|
// Do specific work in case we are connected to a socket:
|
||||||
// - Setup Web3
|
// - Setup Web3
|
||||||
// - Apply history
|
// - Apply history
|
||||||
|
@ -76,7 +76,7 @@ class BlockchainConnector {
|
|||||||
|
|
||||||
self.events.request("processes:launch", "blockchain", () => {
|
self.events.request("processes:launch", "blockchain", () => {
|
||||||
self.provider.startWeb3Provider(() => {
|
self.provider.startWeb3Provider(() => {
|
||||||
this.web3.eth.net.getId()
|
this.getNetworkId()
|
||||||
.then(id => {
|
.then(id => {
|
||||||
let networkId = self.blockchainConfig.networkId;
|
let networkId = self.blockchainConfig.networkId;
|
||||||
if (!networkId && constants.blockchain.networkIds[self.blockchainConfig.networkType]) {
|
if (!networkId && constants.blockchain.networkIds[self.blockchainConfig.networkType]) {
|
||||||
@ -185,6 +185,10 @@ class BlockchainConnector {
|
|||||||
self.getGasPrice(cb);
|
self.getGasPrice(cb);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.events.setCommandHandler("blockchain:networkId", function(cb) {
|
||||||
|
self.getNetworkId().then(cb);
|
||||||
|
});
|
||||||
|
|
||||||
this.events.setCommandHandler("blockchain:contract:create", function(params, cb) {
|
this.events.setCommandHandler("blockchain:contract:create", function(params, cb) {
|
||||||
cb(self.ContractObject(params));
|
cb(self.ContractObject(params));
|
||||||
});
|
});
|
||||||
@ -217,6 +221,10 @@ class BlockchainConnector {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getNetworkId() {
|
||||||
|
return this.web3.eth.net.getId();
|
||||||
|
}
|
||||||
|
|
||||||
ContractObject(params) {
|
ContractObject(params) {
|
||||||
return new this.web3.eth.Contract(params.abi, params.address);
|
return new this.web3.eth.Contract(params.abi, params.address);
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,78 @@ const async = require('async');
|
|||||||
const embarkJsUtils = require('embarkjs').Utils;
|
const embarkJsUtils = require('embarkjs').Utils;
|
||||||
const reverseAddrSuffix = '.addr.reverse';
|
const reverseAddrSuffix = '.addr.reverse';
|
||||||
|
|
||||||
|
const DEFAULT_ENS_CONTRACTS_CONFIG = {
|
||||||
|
"default": {
|
||||||
|
"contracts": {
|
||||||
|
"ENS": {
|
||||||
|
"deploy": false,
|
||||||
|
"silent": true
|
||||||
|
},
|
||||||
|
"ENSRegistry": {
|
||||||
|
"deploy": true,
|
||||||
|
"silent": true,
|
||||||
|
"args": []
|
||||||
|
},
|
||||||
|
"Resolver": {
|
||||||
|
"deploy": true,
|
||||||
|
"silent": true,
|
||||||
|
"args": ["$ENSRegistry"]
|
||||||
|
},
|
||||||
|
"FIFSRegistrar": {
|
||||||
|
"deploy": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const ENS_CONTRACTS_CONFIG = {
|
||||||
|
"1": {
|
||||||
|
"contracts": {
|
||||||
|
"ENSRegistry": {
|
||||||
|
"address": "0x314159265dd8dbb310642f98f50c066173c1259b",
|
||||||
|
"silent": true
|
||||||
|
},
|
||||||
|
"Resolver": {
|
||||||
|
"deploy": false
|
||||||
|
},
|
||||||
|
"FIFSRegistrar": {
|
||||||
|
"deploy": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"3": {
|
||||||
|
"contracts": {
|
||||||
|
"ENSRegistry": {
|
||||||
|
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
||||||
|
"silent": true
|
||||||
|
},
|
||||||
|
"Resolver": {
|
||||||
|
"deploy": false
|
||||||
|
},
|
||||||
|
"FIFSRegistrar": {
|
||||||
|
"deploy": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"4": {
|
||||||
|
"contracts": {
|
||||||
|
"ENSRegistry": {
|
||||||
|
"address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A",
|
||||||
|
"silent": true
|
||||||
|
},
|
||||||
|
"Resolver": {
|
||||||
|
"deploy": false
|
||||||
|
},
|
||||||
|
"FIFSRegistrar": {
|
||||||
|
"deploy": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class ENS {
|
class ENS {
|
||||||
constructor(embark, _options) {
|
constructor(embark, _options) {
|
||||||
this.env = embark.env;
|
this.env = embark.env;
|
||||||
this.isDev = embark.config.blockchainConfig.isDev;
|
|
||||||
this.logger = embark.logger;
|
this.logger = embark.logger;
|
||||||
this.events = embark.events;
|
this.events = embark.events;
|
||||||
this.namesConfig = embark.config.namesystemConfig;
|
this.namesConfig = embark.config.namesystemConfig;
|
||||||
@ -23,12 +91,12 @@ class ENS {
|
|||||||
this.doSetENSProvider = this.namesConfig.provider === 'ens';
|
this.doSetENSProvider = this.namesConfig.provider === 'ens';
|
||||||
|
|
||||||
this.addENSToEmbarkJS();
|
this.addENSToEmbarkJS();
|
||||||
this.configureContracts();
|
|
||||||
this.registerEvents();
|
this.registerEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
registerEvents() {
|
registerEvents() {
|
||||||
this.events.once("contracts:deploy:afterAll", this.setProviderAndRegisterDomains.bind(this));
|
this.events.once("contracts:deploy:afterAll", this.setProviderAndRegisterDomains.bind(this));
|
||||||
|
this.events.once("web3Ready", this.configureContracts.bind(this));
|
||||||
|
|
||||||
this.events.setCommandHandler("storage:ens:associate", this.associateStorageToEns.bind(this));
|
this.events.setCommandHandler("storage:ens:associate", this.associateStorageToEns.bind(this));
|
||||||
}
|
}
|
||||||
@ -74,11 +142,15 @@ class ENS {
|
|||||||
self.addSetProvider(config);
|
self.addSetProvider(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!self.isDev && self.env !== 'privatenet') || !self.registration || !self.registration.subdomains || !Object.keys(self.registration.subdomains).length) {
|
self.events.request('blockchain:networkId', (networkId) => {
|
||||||
|
const isKnownNetworks = Object.keys(ENS_CONTRACTS_CONFIG).includes(networkId);
|
||||||
|
const shouldRegisterSubdomain = self.registration && self.registration.subdomains && Object.keys(self.registration.subdomains).length;
|
||||||
|
if (isKnownNetworks || !shouldRegisterSubdomain) {
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
self.registerConfigDomains(config, cb);
|
self.registerConfigDomains(config, cb);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
associateStorageToEns(options, cb) {
|
associateStorageToEns(options, cb) {
|
||||||
@ -216,73 +288,8 @@ class ENS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configureContracts() {
|
configureContracts() {
|
||||||
const config = {
|
this.events.request('blockchain:networkId', (networkId) => {
|
||||||
"default": {
|
const config = Object.assign({}, DEFAULT_ENS_CONTRACTS_CONFIG, {[this.env]: ENS_CONTRACTS_CONFIG[networkId]});
|
||||||
"gas": "auto",
|
|
||||||
"contracts": {
|
|
||||||
"ENS": {
|
|
||||||
"deploy": false,
|
|
||||||
"silent": true
|
|
||||||
},
|
|
||||||
"ENSRegistry": {
|
|
||||||
"deploy": true,
|
|
||||||
"silent": true,
|
|
||||||
"args": []
|
|
||||||
},
|
|
||||||
"Resolver": {
|
|
||||||
"deploy": true,
|
|
||||||
"silent": true,
|
|
||||||
"args": ["$ENSRegistry"]
|
|
||||||
},
|
|
||||||
"FIFSRegistrar": {
|
|
||||||
"deploy": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ropsten": {
|
|
||||||
"contracts": {
|
|
||||||
"ENSRegistry": {
|
|
||||||
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
|
||||||
"silent": true
|
|
||||||
},
|
|
||||||
"Resolver": {
|
|
||||||
"deploy": false
|
|
||||||
},
|
|
||||||
"FIFSRegistrar": {
|
|
||||||
"deploy": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"rinkeby": {
|
|
||||||
"contracts": {
|
|
||||||
"ENSRegistry": {
|
|
||||||
"address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A",
|
|
||||||
"silent": true
|
|
||||||
},
|
|
||||||
"Resolver": {
|
|
||||||
"deploy": false
|
|
||||||
},
|
|
||||||
"FIFSRegistrar": {
|
|
||||||
"deploy": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"livenet": {
|
|
||||||
"contracts": {
|
|
||||||
"ENSRegistry": {
|
|
||||||
"address": "0x314159265dd8dbb310642f98f50c066173c1259b",
|
|
||||||
"silent": true
|
|
||||||
},
|
|
||||||
"Resolver": {
|
|
||||||
"deploy": false
|
|
||||||
},
|
|
||||||
"FIFSRegistrar": {
|
|
||||||
"deploy": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
config.testnet = config.ropsten;
|
|
||||||
|
|
||||||
if (this.registration && this.registration.rootDomain) {
|
if (this.registration && this.registration.rootDomain) {
|
||||||
// Register root domain if it is defined
|
// Register root domain if it is defined
|
||||||
@ -302,14 +309,12 @@ class ENS {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
config.privatenet = config.development;
|
|
||||||
this.embark.registerContractConfiguration(config);
|
this.embark.registerContractConfiguration(config);
|
||||||
|
|
||||||
//if (this.isDev || this.env === 'privatenet') {
|
|
||||||
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/ENSRegistry.sol'));
|
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/ENSRegistry.sol'));
|
||||||
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/FIFSRegistrar.sol'));
|
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/FIFSRegistrar.sol'));
|
||||||
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/Resolver.sol'));
|
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/Resolver.sol'));
|
||||||
//}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addSetProvider(config) {
|
addSetProvider(config) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user