mirror of https://github.com/embarklabs/embark.git
remove direct reference to contracts manager, use a request instead
This commit is contained in:
parent
98c5b2dd06
commit
3fb2b6fa60
|
@ -8,6 +8,7 @@ const constants = require('../constants');
|
||||||
|
|
||||||
class ContractsManager {
|
class ContractsManager {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
const self = this;
|
||||||
this.contractFiles = options.contractFiles;
|
this.contractFiles = options.contractFiles;
|
||||||
this.contractsConfig = options.contractsConfig;
|
this.contractsConfig = options.contractsConfig;
|
||||||
this.contracts = {};
|
this.contracts = {};
|
||||||
|
@ -18,14 +19,13 @@ class ContractsManager {
|
||||||
this.deployOnlyOnConfig = false;
|
this.deployOnlyOnConfig = false;
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
|
|
||||||
this.events.on(constants.events.contractFilesChanged, (newContractFiles) => {
|
self.events.on(constants.events.contractFilesChanged, (newContractFiles) => {
|
||||||
this.contractFiles = newContractFiles;
|
self.contractFiles = newContractFiles;
|
||||||
});
|
});
|
||||||
this.events.on(constants.events.contractConfigChanged, (newContracts) => {
|
self.events.on(constants.events.contractConfigChanged, (newContracts) => {
|
||||||
this.contractsConfig = newContracts;
|
self.contractsConfig = newContracts;
|
||||||
});
|
});
|
||||||
|
|
||||||
const self = this;
|
|
||||||
self.events.setCommandHandler('contracts:list', (cb) => {
|
self.events.setCommandHandler('contracts:list', (cb) => {
|
||||||
cb(self.listContracts());
|
cb(self.listContracts());
|
||||||
});
|
});
|
||||||
|
|
|
@ -181,31 +181,31 @@ class Deploy {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function doLinking(next) {
|
function doLinking(next) {
|
||||||
// Applying linked contracts
|
self.events.request('contracts:list', (contracts) => {
|
||||||
let contractsList = self.contractsManager.listContracts();
|
for (let contractObj of contracts) {
|
||||||
for (let contractObj of contractsList) {
|
let filename = contractObj.filename;
|
||||||
let filename = contractObj.filename;
|
let deployedAddress = contractObj.deployedAddress;
|
||||||
let deployedAddress = contractObj.deployedAddress;
|
if (deployedAddress) {
|
||||||
if (deployedAddress) {
|
deployedAddress = deployedAddress.substr(2);
|
||||||
deployedAddress = deployedAddress.substr(2);
|
}
|
||||||
|
let linkReference = '__' + filename + ":" + contractObj.className;
|
||||||
|
if (contractCode.indexOf(linkReference) < 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (linkReference.length > 40) {
|
||||||
|
return next(new Error(__("{{linkReference}} is too long, try reducing the path of the contract ({{filename}}) and/or its name {{contractName}}", {linkReference: linkReference, filename: filename, contractName: contractObj.className})));
|
||||||
|
}
|
||||||
|
let toReplace = linkReference + "_".repeat(40 - linkReference.length);
|
||||||
|
if (deployedAddress === undefined) {
|
||||||
|
let libraryName = contractObj.className;
|
||||||
|
return next(new Error(__("{{contractName}} needs {{libraryName}} but an address was not found, did you deploy it or configured an address?", {contractName: contract.className, libraryName: libraryName})));
|
||||||
|
}
|
||||||
|
contractCode = contractCode.replace(new RegExp(toReplace, "g"), deployedAddress);
|
||||||
}
|
}
|
||||||
let linkReference = '__' + filename + ":" + contractObj.className;
|
// saving code changes back to contract object
|
||||||
if (contractCode.indexOf(linkReference) < 0) {
|
contract.code = contractCode;
|
||||||
continue;
|
next();
|
||||||
}
|
});
|
||||||
if (linkReference.length > 40) {
|
|
||||||
return next(new Error(__("{{linkReference}} is too long, try reducing the path of the contract ({{filename}}) and/or its name {{contractName}}", {linkReference: linkReference, filename: filename, contractName: contractObj.className})));
|
|
||||||
}
|
|
||||||
let toReplace = linkReference + "_".repeat(40 - linkReference.length);
|
|
||||||
if (deployedAddress === undefined) {
|
|
||||||
let libraryName = contractObj.className;
|
|
||||||
return next(new Error(__("{{contractName}} needs {{libraryName}} but an address was not found, did you deploy it or configured an address?", {contractName: contract.className, libraryName: libraryName})));
|
|
||||||
}
|
|
||||||
contractCode = contractCode.replace(new RegExp(toReplace, "g"), deployedAddress);
|
|
||||||
}
|
|
||||||
// saving code changes back to contract object
|
|
||||||
contract.code = contractCode;
|
|
||||||
next();
|
|
||||||
},
|
},
|
||||||
function applyBeforeDeploy(next) {
|
function applyBeforeDeploy(next) {
|
||||||
let beforeDeployPlugins = self.plugins.getPluginsFor('beforeDeploy');
|
let beforeDeployPlugins = self.plugins.getPluginsFor('beforeDeploy');
|
||||||
|
@ -284,29 +284,30 @@ class Deploy {
|
||||||
deployAll(done) {
|
deployAll(done) {
|
||||||
let self = this;
|
let self = this;
|
||||||
this.logger.info(__("deploying contracts"));
|
this.logger.info(__("deploying contracts"));
|
||||||
let contracts = this.contractsManager.listContracts();
|
|
||||||
this.events.emit("deploy:beforeAll");
|
this.events.emit("deploy:beforeAll");
|
||||||
|
|
||||||
async.eachOfSeries(contracts,
|
self.events.request('contracts:list', (contracts) => {
|
||||||
function (contract, key, callback) {
|
async.eachOfSeries(contracts,
|
||||||
self.logger.trace(arguments);
|
function (contract, key, callback) {
|
||||||
self.checkAndDeployContract(contract, null, callback);
|
self.logger.trace(arguments);
|
||||||
},
|
self.checkAndDeployContract(contract, null, callback);
|
||||||
function (err, _results) {
|
},
|
||||||
if (err) {
|
function (err, _results) {
|
||||||
self.logger.error(__("error deploying contracts"));
|
if (err) {
|
||||||
self.logger.error(err.message);
|
self.logger.error(__("error deploying contracts"));
|
||||||
self.logger.debug(err.stack);
|
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"));
|
||||||
|
self.logger.trace(arguments);
|
||||||
|
done(err);
|
||||||
}
|
}
|
||||||
if (contracts.length === 0) {
|
);
|
||||||
self.logger.info(__("no contracts found"));
|
});
|
||||||
return done();
|
|
||||||
}
|
|
||||||
self.logger.info(__("finished deploying contracts"));
|
|
||||||
self.logger.trace(arguments);
|
|
||||||
done(err);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue