rebase fixes

This commit is contained in:
Iuri Matias 2018-09-30 12:48:44 -04:00
parent bc1c9fce51
commit 6b9ab12bca
6 changed files with 5757 additions and 302 deletions

View File

@ -1,132 +0,0 @@
const async = require('async');
const AccountParser = require('./accountParser');
const fundAccount = require('./fundAccount');
class Provider {
constructor(options) {
this.web3 = options.web3;
this.accountsConfig = options.accountsConfig;
this.blockchainConfig = options.blockchainConfig;
this.type = options.type;
this.web3Endpoint = options.web3Endpoint;
this.logger = options.logger;
this.isDev = options.isDev;
this.engine = new ProviderEngine();
this.asyncMethods = {};
}
startWeb3Provider(callback) {
const self = this;
if (this.type === 'rpc') {
self.engine.addProvider(new RpcSubprovider({
rpcUrl: self.web3Endpoint
}));
} else if (this.type === 'ws') {
//self.engine.addProvider(new WsSubprovider({
console.log('USing ws');
self.addProvider(new SubscriptionSubprovider());
self.addProvider(new WsSubprovider({
rpcUrl: self.web3Endpoint,
origin: this.blockchainConfig.wsOrigins.split(',')[0]
}));
//self.provider = new this.web3.providers.WebsocketProvider(self.web3Endpoint, {headers: {Origin: "embark"}});
} else {
return callback(__("contracts config error: unknown deployment type %s", this.type));
}
// network connectivity error
self.engine.on('error', (err) => {
// report connectivity errors
self.logger.error(err);
});
self.engine.start();
//self.on('error', (err) => {
// console.log('ERR', JSON.stringify(err));
// // report connectivity errors as trace due to polling
// self.logger.trace('web3 provider error: ', err);
// self.logger.trace('stopping web3 provider due to error');
// // prevent continuous polling errors
// self.stop();
//});
//self.web3.setProvider(self);
//self.start();
self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, self.logger);
self.addresses = [];
if (!self.accounts.length) {
return callback();
}
self.accounts.forEach(account => {
self.addresses.push(account.address);
self.web3.eth.accounts.wallet.add(account);
});
self.realAccountFunction = self.web3.eth.getAccounts;
self.web3.eth.getAccounts = function (cb) {
if (!cb) {
cb = function () {
};
}
return new Promise((resolve, reject) => {
self.realAccountFunction((err, accounts) => {
if (err) {
cb(err);
return reject(err);
}
accounts = accounts.concat(self.addresses);
// accounts = self.addresses.concat(accounts);
cb(null, accounts);
resolve(accounts);
});
});
};
callback();
}
fundAccounts(callback) {
const self = this;
if (!self.accounts.length) {
return callback();
}
if (!self.isDev) {
return callback();
}
async.each(self.accounts, (account, eachCb) => {
fundAccount(self.web3, account.address, account.hexBalance, eachCb);
}, callback);
}
stop() {
this.engine.stop();
}
eth_accounts(payload, cb) {
return cb(null, this.addresses);
}
sendAsync(payload, callback) {
let method = this.asyncMethods[payload.method];
if (method) {
return method.call(method, payload, (err, result) => {
if (err) {
return callback(err);
}
let response = {'id': payload.id, 'jsonrpc': '2.0', 'result': result};
callback(null, response);
});
}
this.engine.sendAsync.apply(this.engine, arguments);
}
send() {
return this.engine.send.apply(this.engine, arguments);
}
}
module.exports = Provider;

View File

@ -1,17 +1,16 @@
let async = require('async');
const ContractDeployer = require('./contract_deployer.js');
const utils = require('../../utils/utils.js');
//require("../utils/debug_util.js")(__filename, async);
const cloneDeep = require('clone-deep');
class DeployManager {
constructor(options) {
constructor(embark, options) {
const self = this;
this.config = options.config;
this.logger = options.logger;
this.config = embark.config;
this.logger = embark.logger;
this.blockchainConfig = this.config.blockchainConfig;
this.events = options.events;
this.events = embark.events;
this.plugins = options.plugins;
this.blockchain = options.blockchain;
this.gasLimit = false;
@ -19,47 +18,90 @@ class DeployManager {
this.deployOnlyOnConfig = false;
this.onlyCompile = options.onlyCompile !== undefined ? options.onlyCompile : false;
this.contractDeployer = new ContractDeployer({
logger: this.logger,
events: this.events,
plugins: this.plugins
});
this.events.setCommandHandler('deploy:setGasLimit', (gasLimit) => {
self.gasLimit = gasLimit;
});
this.events.setCommandHandler('deploy:contracts', (cb) => {
self.deployContracts(cb);
});
this.events.setCommandHandler('deploy:contracts:test', (cb) => {
self.fatalErrors = true;
self.deployOnlyOnConfig = true;
self.deployContracts(cb);
});
}
deployAll(done) {
let self = this;
self.events.request('contracts:list', (err, contracts) => {
if (err) {
return done(err);
}
self.logger.info(__("deploying contracts"));
self.events.emit("deploy:beforeAll");
const contractsPerDependencyCount = utils.groupBy(contracts, 'dependencyCount');
async.eachSeries(contractsPerDependencyCount,
function (parallelGroups, callback) {
async.each(parallelGroups, (contract, eachCb) => {
contract._gasLimit = self.gasLimit;
self.events.request('deploy:contract', contract, (err) => {
eachCb(err);
});
}, callback);
},
function (err, _results) {
if (err) {
self.logger.error(__("error deploying contracts"));
self.logger.error(err.message);
self.logger.debug(err.stack);
}
if (contracts.length === 0) {
self.logger.info(__("no contracts found"));
return done();
}
self.logger.info(__("finished deploying contracts"));
done(err);
self.events.request('contracts:dependencies', (err, contractDependencies) => {
self.events.request('contracts:list', (err, contracts) => {
if (err) {
return done(err);
}
);
self.logger.info(__("deploying contracts"));
async.waterfall([
function (next) {
self.plugins.emitAndRunActionsForEvent("deploy:beforeAll", next);
},
function () {
const contractDeploys = {};
const errors = [];
contracts.forEach(contract => {
function deploy(result, callback) {
if (typeof result === 'function') {
callback = result;
}
contract._gasLimit = self.gasLimit;
self.events.request('deploy:contract', contract, (err) => {
if (err) {
contract.error = err.message || err;
self.logger.error(err.message || err);
errors.push(err);
}
callback();
});
}
const className = contract.className;
if (!contractDependencies[className] || contractDependencies[className].length === 0) {
contractDeploys[className] = deploy;
return;
}
contractDeploys[className] = cloneDeep(contractDependencies[className]);
contractDeploys[className].push(deploy);
});
try {
async.auto(contractDeploys, 1, function(_err, _results) {
if (errors.length) {
_err = __("Error deploying contracts. Please fix errors to continue.");
self.logger.error(_err);
return done(_err);
}
if (contracts.length === 0) {
self.logger.info(__("no contracts found"));
return done();
}
self.logger.info(__("finished deploying contracts"));
done(err);
});
} catch (e) {
self.logger.error(e.message || e);
done(__('Error deploying'));
}
}
]);
});
});
}
@ -73,6 +115,13 @@ class DeployManager {
}
async.waterfall([
function requestBlockchainConnector(callback) {
self.events.request("blockchain:object", (blockchain) => {
self.blockchain = blockchain;
callback();
});
},
function buildContracts(callback) {
self.events.request("contracts:build", self.deployOnlyOnConfig, (err) => {
callback(err);
@ -80,22 +129,19 @@ class DeployManager {
},
// TODO: shouldn't be necessary
function checkCompileOnly(callback){
if(self.onlyCompile){
function checkCompileOnly(callback) {
if (self.onlyCompile) {
self.events.emit('contractsDeployed');
return done();
}
}
return callback();
},
// TODO: could be implemented as an event (beforeDeployAll)
function checkIsConnectedToBlockchain(callback) {
callback();
//self.blockchain.onReady(() => {
// self.blockchain.assertNodeConnection((err) => {
// callback(err);
// });
//});
self.blockchain.onReady((err) => {
callback(err);
});
},
// TODO: this can be done on the fly or as part of the initialization

View File

@ -329,17 +329,6 @@ class ENS {
configureContracts() {
const config = {
"default": {
"gas": "auto"
},
"development": {
"contracts": {
"ENS": {
"deploy": false,
"silent": true
}
}
},
"development": {
"contracts": {
"ENS": {
"deploy": false,
@ -408,29 +397,29 @@ class ENS {
if (this.registration && this.registration.rootDomain) {
// Register root domain if it is defined
const rootNode = namehash.hash(this.registration.rootDomain);
config.development.contracts['FIFSRegistrar'] = {
config.default.contracts['FIFSRegistrar'] = {
"deploy": true,
"silent": true,
"args": ["$ENSRegistry", rootNode],
"onDeploy": [
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount}).then(() => {
ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send({from: web3.eth.defaultAccount});
var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '${reverseAddrSuffix}');
ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send({from: web3.eth.defaultAccount});
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount});
Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send({from: web3.eth.defaultAccount});
})`
ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send({from: web3.eth.defaultAccount});
var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '${reverseAddrSuffix}');
ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send({from: web3.eth.defaultAccount});
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount});
Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send({from: web3.eth.defaultAccount});
})`
]
};
}
config.privatenet = config.development;
this.embark.registerContractConfiguration(config);
if (this.isDev || this.env === 'privatenet') {
//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/FIFSRegistrar.sol'));
this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/Resolver.sol'));
}
//}
}
addSetProvider(config) {

View File

@ -31,7 +31,8 @@ class IPFS {
return;
}
self.logger.info("IPFS node not found, attempting to start own node");
this.events.request("processes:launch", "ipfs", () => {});
//this.events.request("processes:launch", "ipfs", () => {});
self.startProcess(() => {})
});
}
}
@ -101,14 +102,6 @@ class IPFS {
this.embark.addCodeToEmbarkJS(code);
}
addNamesystemProviderToEmbarkJS() {
let code = "";
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs', 'name.js')).toString();
code += "\nEmbarkJS.Names.registerProvider('ipns', __embarkIPFS);";
this.embark.addCodeToEmbarkJS(code);
}
addObjectToConsole() {
let ipfs = IpfsApi(this.host, this.port);
this.events.emit("runcode:register", "ipfs", ipfs);
@ -121,8 +114,7 @@ class IPFS {
events: self.events,
storageConfig: self.storageConfig,
webServerConfig: self.webServerConfig,
blockchainConfig: self.blockchainConfig,
embark: self.embark
blockchainConfig: self.blockchainConfig
});
self.logger.trace(`Storage module: Launching ipfs process...`);
return storageProcessesLauncher.launchProcess('ipfs', callback);

View File

@ -73,7 +73,7 @@ class ScaffoldingReact {
});
}
build(contract){
async build(contract){
this._buildHTML(contract);
const filename = contract.className.toLowerCase();

5742
package-lock.json generated

File diff suppressed because it is too large Load Diff