From fc92b6921186f8135f48fb10490caeea88779cf2 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 28 May 2018 18:03:33 -0400 Subject: [PATCH 01/28] use self --- lib/contracts/code_generator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index e7adc4c9..9b45318a 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -115,7 +115,7 @@ class CodeGenerator { }); this.events.setCommandHandler('embark-building-placeholder', (cb) => { - this.buildPlaceholderPage(cb); + self.buildPlaceholderPage(cb); }); } From cf999ce99767d6280930dcf2cf8c3a6075c571ab Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 21 May 2018 18:44:36 -0400 Subject: [PATCH 02/28] refactor runcode to use events instead; remove dependencies --- lib/i18n/locales/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/i18n/locales/en.json b/lib/i18n/locales/en.json index 2ec0df1b..4b25e6ba 100644 --- a/lib/i18n/locales/en.json +++ b/lib/i18n/locales/en.json @@ -143,4 +143,4 @@ "Starting ipfs process": "Starting ipfs process", "ipfs process started": "ipfs process started", "IPFS node detected": "IPFS node detected" -} \ No newline at end of file +} From 5f64376c846d7057dfdb07b447af82439362eb9f Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 22 May 2018 14:31:21 -0400 Subject: [PATCH 03/28] refactor generateContractsJson --- lib/contracts/code_generator.js | 69 +++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index 9b45318a..a6ffaf9d 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -46,68 +46,78 @@ class CodeGenerator { // deprecated events; to remove in embark 2.7.0 this.events.setCommandHandlerOnce('abi-vanila', function(cb) { let vanillaABI = self.generateABI({useEmbarkJS: false}); - let contractsJSON = self.generateContractsJSON(); - cb(vanillaABI, contractsJSON); + this.events.request("contracts:list", (contractsList) => { + let contractsJSON = self.generateContractsJSON(contractsList); + cb(vanillaABI, contractsJSON); + }); }); this.events.setCommandHandlerOnce('abi', function(cb) { let embarkJSABI = self.generateABI({useEmbarkJS: true}); - let contractsJSON = self.generateContractsJSON(); - - cb(embarkJSABI, contractsJSON); + this.events.request("contracts:list", (contractsList) => { + let contractsJSON = self.generateContractsJSON(contractsList); + cb(embarkJSABI, contractsJSON); + }); }); this.events.setCommandHandlerOnce('abi-contracts-vanila', function(cb) { let vanillaContractsABI = self.generateContracts(false, true, false); - let contractsJSON = self.generateContractsJSON(); - - cb(vanillaContractsABI, contractsJSON); + self.events.request("contracts:list", (contractsList) => { + let contractsJSON = self.generateContractsJSON(contractsList); + cb(vanillaContractsABI, contractsJSON); + }); }); this.events.setCommandHandlerOnce('abi-vanila-deployment', function(cb) { let vanillaABI = self.generateABI({useEmbarkJS: false, deployment: true}); - let contractsJSON = self.generateContractsJSON(); - - cb(vanillaABI, contractsJSON); + self.events.request("contracts:list", (contractsList) => { + let contractsJSON = self.generateContractsJSON(contractsList); + cb(vanillaABI, contractsJSON); + }); }); // new events this.events.setCommandHandlerOnce('code-vanila', function(cb) { let vanillaABI = self.generateABI({useEmbarkJS: false}); - let contractsJSON = self.generateContractsJSON(); - - cb(vanillaABI, contractsJSON); + self.events.request("contracts:list", (contractsList) => { + let contractsJSON = self.generateContractsJSON(contractsList); + cb(vanillaABI, contractsJSON); + }); }); this.events.setCommandHandlerOnce('code', function(cb) { let embarkJSABI = self.generateABI({useEmbarkJS: true}); - let contractsJSON = self.generateContractsJSON(); - - cb(embarkJSABI, contractsJSON); + self.events.request("contracts:list", (contractsList) => { + let contractsJSON = self.generateContractsJSON(contractsList); + cb(embarkJSABI, contractsJSON); + }); }); this.events.setCommandHandlerOnce('code-contracts-vanila', function(cb) { let vanillaContractsABI = self.generateContracts(false, true, false); - let contractsJSON = self.generateContractsJSON(); - - cb(vanillaContractsABI, contractsJSON); + self.events.request("contracts:list", (contractsList) => { + let contractsJSON = self.generateContractsJSON(contractsList); + cb(vanillaContractsABI, contractsJSON); + }); }); this.events.setCommandHandlerOnce('code-vanila-deployment', function(cb) { let vanillaABI = self.generateABI({useEmbarkJS: false, deployment: true}); - let contractsJSON = self.generateContractsJSON(); - - cb(vanillaABI, contractsJSON); + self.events.request("contracts:list", (contractsList) => { + let contractsJSON = self.generateContractsJSON(contractsList); + cb(vanillaABI, contractsJSON); + }); }); this.events.setCommandHandlerOnce('code-generator:web3js', function(cb) { self.buildWeb3JS(cb); }); - this.events.setCommandHandler('code-generator:contract', (contractName, cb) => { - let contract = self.contractsManager.contracts[contractName]; - self.buildContractJS(contractName, self.generateContractJSON(contractName, contract), cb); + self.events.setCommandHandler('code-generator:contract', (contractName, cb) => { + self.events.setCommandHandler('contracts:contract', contractName, (contract) => { + self.buildContractJS(contractName, self.generateContractJSON(contract, contract), cb); + }); }); self.events.setCommandHandler('code-generator:contract:vanilla', (contract, gasLimit, cb) => { @@ -304,12 +314,11 @@ class CodeGenerator { return contractJSON; } - generateContractsJSON() { + generateContractsJSON(contractsList) { let contracts = {}; - for (let className in this.contractsManager.contracts) { - let contract = this.contractsManager.contracts[className]; - contracts[className] = this.generateContractJSON(className, contract); + for (let contract of contractsList) { + contracts[contract.className] = this.generateContractJSON(contract.className, contract); } return contracts; From 3f9c55131b65c661f683f616a3a1e4a50b105cae Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 22 May 2018 14:49:25 -0400 Subject: [PATCH 04/28] use requests instead of contractsManager directly --- lib/contracts/code_generator.js | 38 +++++++++++++--------------- test/code_generator.js | 35 +++++++++++++++---------- test_apps/test_app/package-lock.json | 14 +++++----- 3 files changed, 45 insertions(+), 42 deletions(-) diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index a6ffaf9d..971ba0c0 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -45,33 +45,32 @@ class CodeGenerator { // deprecated events; to remove in embark 2.7.0 this.events.setCommandHandlerOnce('abi-vanila', function(cb) { - let vanillaABI = self.generateABI({useEmbarkJS: false}); - this.events.request("contracts:list", (contractsList) => { + let vanillaABI = self.generateABI(contractsList, {useEmbarkJS: false}); let contractsJSON = self.generateContractsJSON(contractsList); cb(vanillaABI, contractsJSON); }); }); this.events.setCommandHandlerOnce('abi', function(cb) { - let embarkJSABI = self.generateABI({useEmbarkJS: true}); this.events.request("contracts:list", (contractsList) => { + let embarkJSABI = self.generateABI(contractsList, {useEmbarkJS: true}); let contractsJSON = self.generateContractsJSON(contractsList); cb(embarkJSABI, contractsJSON); }); }); this.events.setCommandHandlerOnce('abi-contracts-vanila', function(cb) { - let vanillaContractsABI = self.generateContracts(false, true, false); self.events.request("contracts:list", (contractsList) => { + let vanillaContractsABI = self.generateContracts(contractsList, false, true, false); let contractsJSON = self.generateContractsJSON(contractsList); cb(vanillaContractsABI, contractsJSON); }); }); this.events.setCommandHandlerOnce('abi-vanila-deployment', function(cb) { - let vanillaABI = self.generateABI({useEmbarkJS: false, deployment: true}); self.events.request("contracts:list", (contractsList) => { + let vanillaABI = self.generateABI(contractsList, {useEmbarkJS: false, deployment: true}); let contractsJSON = self.generateContractsJSON(contractsList); cb(vanillaABI, contractsJSON); }); @@ -79,32 +78,32 @@ class CodeGenerator { // new events this.events.setCommandHandlerOnce('code-vanila', function(cb) { - let vanillaABI = self.generateABI({useEmbarkJS: false}); self.events.request("contracts:list", (contractsList) => { + let vanillaABI = self.generateABI(contractsList, {useEmbarkJS: false}); let contractsJSON = self.generateContractsJSON(contractsList); cb(vanillaABI, contractsJSON); }); }); this.events.setCommandHandlerOnce('code', function(cb) { - let embarkJSABI = self.generateABI({useEmbarkJS: true}); self.events.request("contracts:list", (contractsList) => { + let embarkJSABI = self.generateABI(contractsList, {useEmbarkJS: true}); let contractsJSON = self.generateContractsJSON(contractsList); cb(embarkJSABI, contractsJSON); }); }); this.events.setCommandHandlerOnce('code-contracts-vanila', function(cb) { - let vanillaContractsABI = self.generateContracts(false, true, false); self.events.request("contracts:list", (contractsList) => { + let vanillaContractsABI = self.generateContracts(contractsList, false, true, false); let contractsJSON = self.generateContractsJSON(contractsList); cb(vanillaContractsABI, contractsJSON); }); }); this.events.setCommandHandlerOnce('code-vanila-deployment', function(cb) { - let vanillaABI = self.generateABI({useEmbarkJS: false, deployment: true}); self.events.request("contracts:list", (contractsList) => { + let vanillaABI = self.generateABI(contractsList, {useEmbarkJS: false, deployment: true}); let contractsJSON = self.generateContractsJSON(contractsList); cb(vanillaABI, contractsJSON); }); @@ -183,16 +182,15 @@ class CodeGenerator { return result; } - generateContracts(useEmbarkJS, isDeployment, useLoader) { + generateContracts(contractsList, useEmbarkJS, isDeployment, useLoader) { let self = this; let result = "\n"; let contractsPlugins; if (useLoader === false) { - for (let className in this.contractsManager.contracts) { - let contract = this.contractsManager.contracts[className]; + for (let contract of contractsList) { let abi = JSON.stringify(contract.abiDefinition); - result += Templates.vanilla_contract({className: className, abi: abi, contract: contract, gasLimit: 6000000}); + result += Templates.vanilla_contract({className: contract.className, abi: abi, contract: contract, gasLimit: 6000000}); } return result; } @@ -207,12 +205,10 @@ class CodeGenerator { if (this.plugins && contractsPlugins.length > 0) { contractsPlugins.forEach(function (plugin) { - result += plugin.generateContracts({contracts: self.contractsManager.contracts}); + result += plugin.generateContracts({contracts: contractsList}); }); } else { - for (let className in this.contractsManager.contracts) { - let contract = this.contractsManager.contracts[className]; - + for (let contract of contractsList) { let abi = JSON.stringify(contract.abiDefinition); let gasEstimates = JSON.stringify(contract.gasEstimates); @@ -220,9 +216,9 @@ class CodeGenerator { if (useEmbarkJS) { let contractAddress = contract.deployedAddress ? ("'" + contract.deployedAddress + "'") : "undefined"; - block += Templates.embarkjs_contract({className: className, abi: abi, contract: contract, contractAddress: contractAddress, gasEstimates: gasEstimates}); + block += Templates.embarkjs_contract({className: contract.className, abi: abi, contract: contract, contractAddress: contractAddress, gasEstimates: gasEstimates}); } else { - block += Templates.vanilla_contract({className: className, abi: abi, contract: contract, gasLimit: (isDeployment ? 6000000 : false)}); + block += Templates.vanilla_contract({className: contract.className, abi: abi, contract: contract, gasLimit: (isDeployment ? 6000000 : false)}); } result += Templates.exec_when_ready({block: block}); @@ -286,11 +282,11 @@ class CodeGenerator { return result; } - generateABI(options) { + generateABI(contractsList, options) { let result = ""; result += this.generateProvider(options.deployment); - result += this.generateContracts(options.useEmbarkJS, options.deployment, true); + result += this.generateContracts(contractsList, options.useEmbarkJS, options.deployment, true); result += this.generateStorageInitialization(options.useEmbarkJS); result += this.generateCommunicationInitialization(options.useEmbarkJS); result += this.generateNamesInitialization(options.useEmbarkJS); diff --git a/test/code_generator.js b/test/code_generator.js index c74149c2..3d030e92 100644 --- a/test/code_generator.js +++ b/test/code_generator.js @@ -12,20 +12,27 @@ describe('embark.CodeGenerator', function() { this.timeout(0); describe('#generateContracts', function() { + let contracts = [ + { + className: 'SimpleStorage', + abiDefinition: [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"type":"constructor"}], + gasEstimates: 12000, + deployedAddress: "0x123", + code: '12345' + }, + { + className: 'Foo', + abiDefinition: [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"type":"constructor"}], + gasEstimates: 12000, + deployedAddress: "0x124", + code: '123456' + } + ] + let generator = new CodeGenerator({blockchainConfig: {}, contractsManager: { contracts: { - SimpleStorage: { - abiDefinition: [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"type":"constructor"}], - gasEstimates: 12000, - deployedAddress: "0x123", - code: '12345' - }, - Foo: { - abiDefinition: [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"type":"constructor"}], - gasEstimates: 12000, - deployedAddress: "0x124", - code: '123456' - } + SimpleStorage: contracts[0], + Foo: contracts[1] } }}); @@ -34,7 +41,7 @@ describe('embark.CodeGenerator', function() { it('should generate contract code', function() { var contractCode = "\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n __mainContext.SimpleStorage = new EmbarkJS.Contract({abi: [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}], address: '0x123', code: '12345', gasEstimates: 12000});\n\n});\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n __mainContext.Foo = new EmbarkJS.Contract({abi: [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}], address: '0x124', code: '123456', gasEstimates: 12000});\n\n});\n"; - assert.strictEqual(replaceCRLF(generator.generateContracts(withEmbarkJS)), contractCode); + assert.strictEqual(replaceCRLF(generator.generateContracts(contracts, withEmbarkJS)), contractCode); }); }); @@ -43,7 +50,7 @@ describe('embark.CodeGenerator', function() { it('should generate contract code', function() { var contractCode = "\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n SimpleStorageAbi = [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}];\nSimpleStorage = new web3.eth.Contract(SimpleStorageAbi);\nSimpleStorage.options.address = '0x123';\nSimpleStorage.address = '0x123';\nSimpleStorage.options.from = web3.eth.defaultAccount;\n\n\n});\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n FooAbi = [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}];\nFoo = new web3.eth.Contract(FooAbi);\nFoo.options.address = '0x124';\nFoo.address = '0x124';\nFoo.options.from = web3.eth.defaultAccount;\n\n\n});\n"; - assert.strictEqual(replaceCRLF(generator.generateContracts(withEmbarkJS)), contractCode); + assert.strictEqual(replaceCRLF(generator.generateContracts(contracts, withEmbarkJS)), contractCode); }); }); diff --git a/test_apps/test_app/package-lock.json b/test_apps/test_app/package-lock.json index 6a0c2c66..3dba6607 100644 --- a/test_apps/test_app/package-lock.json +++ b/test_apps/test_app/package-lock.json @@ -89,7 +89,7 @@ "dom-helpers": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/dom-helpers/-/dom-helpers-3.3.1.tgz", - "integrity": "sha1-/BpOFf/fYN3eA6SAqcD+zoId1KY=" + "integrity": "sha512-2Sm+JaYn74OiTM2wHvxJOo3roiq/h25Yi69Fqk269cNUwIXsCvATB6CRSFC9Am/20G2b28hGv/+7NiWydIrPvg==" }, "dotenv": { "version": "4.0.0", @@ -229,7 +229,7 @@ "node-fetch": { "version": "1.7.3", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", - "integrity": "sha1-mA9vcthSEaU0fGsrwYxbhMPrR+8=", + "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", "requires": { "encoding": "0.1.12", "is-stream": "1.1.0" @@ -252,7 +252,7 @@ "promise": { "version": "7.3.1", "resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz", - "integrity": "sha1-BktyYCsY+Q8pGSuLG8QY/9Hr078=", + "integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==", "requires": { "asap": "2.0.6" } @@ -289,7 +289,7 @@ "react-bootstrap": { "version": "0.32.1", "resolved": "https://registry.npmjs.org/react-bootstrap/-/react-bootstrap-0.32.1.tgz", - "integrity": "sha1-YGJMG0ijnXc+9szmQhpPM+zBZrs=", + "integrity": "sha512-RbfzKUbsukWsToWqGHfCCyMFq9QQI0TznutdyxyJw6dih2NvIne25Mrssg8LZsprqtPpyQi8bN0L0Fx3fUsL8Q==", "requires": { "babel-runtime": "6.26.0", "classnames": "2.2.5", @@ -319,7 +319,7 @@ "react-overlays": { "version": "0.8.3", "resolved": "https://registry.npmjs.org/react-overlays/-/react-overlays-0.8.3.tgz", - "integrity": "sha1-+tZe6lskMBzKGSoWn13dsLINOsU=", + "integrity": "sha512-h6GT3jgy90PgctleP39Yu3eK1v9vaJAW73GOA/UbN9dJ7aAN4BTZD6793eI1D5U+ukMk17qiqN/wl3diK1Z5LA==", "requires": { "classnames": "2.2.5", "dom-helpers": "3.3.1", @@ -353,7 +353,7 @@ "regenerator-runtime": { "version": "0.11.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", - "integrity": "sha1-vgWtf5v30i4Fb5cmzuUBf78Z4uk=" + "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" }, "setimmediate": { "version": "1.0.5", @@ -412,7 +412,7 @@ "zeppelin-solidity": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/zeppelin-solidity/-/zeppelin-solidity-1.8.0.tgz", - "integrity": "sha1-BJ/N59rqn8hSEPjG25+M0auKhTo=", + "integrity": "sha512-7Mxq6Y7EES0PSLrRF6v0EVYqBVRRo8hFrr7m3jEs69VbbQ5kpANzizeEdbP1/PWKSOmBOg208qP2vSA0FlzFLA==", "requires": { "dotenv": "4.0.0", "ethjs-abi": "0.2.1" From 742632eccf678037f41c89eeb127f35812cf67d3 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 22 May 2018 14:56:51 -0400 Subject: [PATCH 05/28] remove contractsManager dependency --- lib/core/engine.js | 1 - test/code_generator.js | 7 +------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/core/engine.js b/lib/core/engine.js index 440dc695..82b7aa26 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -170,7 +170,6 @@ class Engine { this.codeGenerator = new CodeGenerator({ blockchainConfig: self.config.blockchainConfig, contractsConfig: self.config.contractsConfig, - contractsManager: this.contractsManager, plugins: self.plugins, storageConfig: self.config.storageConfig, namesystemConfig: self.config.namesystemConfig, diff --git a/test/code_generator.js b/test/code_generator.js index 3d030e92..b8d7c6dd 100644 --- a/test/code_generator.js +++ b/test/code_generator.js @@ -29,12 +29,7 @@ describe('embark.CodeGenerator', function() { } ] - let generator = new CodeGenerator({blockchainConfig: {}, contractsManager: { - contracts: { - SimpleStorage: contracts[0], - Foo: contracts[1] - } - }}); + let generator = new CodeGenerator({blockchainConfig: {}}); describe('with EmbarkJS', function() { let withEmbarkJS = true; From 8cc86e0b0fd3fe26ce9123153e53908e00f07f97 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 22 May 2018 15:00:46 -0400 Subject: [PATCH 06/28] remove legacy events --- lib/contracts/code_generator.js | 33 --------------------------------- lib/core/events.js | 2 +- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index 971ba0c0..b30807de 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -43,39 +43,6 @@ class CodeGenerator { cb(providerCode); }); - // deprecated events; to remove in embark 2.7.0 - this.events.setCommandHandlerOnce('abi-vanila', function(cb) { - this.events.request("contracts:list", (contractsList) => { - let vanillaABI = self.generateABI(contractsList, {useEmbarkJS: false}); - let contractsJSON = self.generateContractsJSON(contractsList); - cb(vanillaABI, contractsJSON); - }); - }); - - this.events.setCommandHandlerOnce('abi', function(cb) { - this.events.request("contracts:list", (contractsList) => { - let embarkJSABI = self.generateABI(contractsList, {useEmbarkJS: true}); - let contractsJSON = self.generateContractsJSON(contractsList); - cb(embarkJSABI, contractsJSON); - }); - }); - - this.events.setCommandHandlerOnce('abi-contracts-vanila', function(cb) { - self.events.request("contracts:list", (contractsList) => { - let vanillaContractsABI = self.generateContracts(contractsList, false, true, false); - let contractsJSON = self.generateContractsJSON(contractsList); - cb(vanillaContractsABI, contractsJSON); - }); - }); - - this.events.setCommandHandlerOnce('abi-vanila-deployment', function(cb) { - self.events.request("contracts:list", (contractsList) => { - let vanillaABI = self.generateABI(contractsList, {useEmbarkJS: false, deployment: true}); - let contractsJSON = self.generateContractsJSON(contractsList); - cb(vanillaABI, contractsJSON); - }); - }); - // new events this.events.setCommandHandlerOnce('code-vanila', function(cb) { self.events.request("contracts:list", (contractsList) => { diff --git a/lib/core/events.js b/lib/core/events.js index 2111e221..f68d736a 100644 --- a/lib/core/events.js +++ b/lib/core/events.js @@ -1,7 +1,7 @@ var EventEmitter = require('events'); function warnIfLegacy(eventName) { - const legacyEvents = ['abi-vanila', 'abi', 'abi-contracts-vanila', 'abi-vanila-deployment']; + const legacyEvents = []; if (legacyEvents.indexOf(eventName) >= 0) { console.info(__("this event is deprecated and will be removed in future versions %s", eventName)); } From f4010bd66ec03808ca2dde71f342fa079bc7a27a Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 22 May 2018 15:13:20 -0400 Subject: [PATCH 07/28] remove unnecessary determin params call --- lib/contracts/deploy.js | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index 462d7a81..959971b1 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -134,32 +134,27 @@ class Deploy { contractToDeploy(contract, params, callback) { const self = this; - // TODO: refactor to async - self.determineArguments(params || contract.args, contract, (realArgs) => { - contract.realArgs = realArgs; + // TODO: this whole callback is almost pointless and should be moved to deployContract + this.deployContract(contract, contract.realArgs, function (err, address) { + if (err) { + self.events.emit("deploy:contract:error", contract); + return callback(new Error(err)); + } + contract.address = address; + self.events.emit("deploy:contract:deployed", contract); - this.deployContract(contract, contract.realArgs, function (err, address) { - if (err) { - self.events.emit("deploy:contract:error", contract); - return callback(new Error(err)); - } - contract.address = address; - self.events.emit("deploy:contract:deployed", contract); + // TODO: can be moved into a afterDeploy event + // just need to figure out the gasLimit coupling issue + self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => { + self.events.request('runcode:eval', contractCode); - // TODO: can be moved into a afterDeploy event - // just need to figure out the gasLimit coupling issue - self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => { - self.events.request('runcode:eval', contractCode); + let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions'); - let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions'); - - async.eachLimit(onDeployPlugins, 1, function(plugin, nextEach) { - plugin.call(plugin, contract, nextEach); - }, () => { - callback(); - }); + async.eachLimit(onDeployPlugins, 1, function(plugin, nextEach) { + plugin.call(plugin, contract, nextEach); + }, () => { + callback(); }); - }); }); } From cf13f098ac12691ded7006ee7802d69879a8d978 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 22 May 2018 15:37:04 -0400 Subject: [PATCH 08/28] refactor deploy method --- lib/contracts/deploy.js | 55 +++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index 959971b1..695103a8 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -102,14 +102,14 @@ class Deploy { // TODO: this should be a plugin API instead, if not existing, it should by default deploy the contract self.events.request("deploy:contract:shouldDeploy", contract, function(trackedContract) { if (!trackedContract) { - return self.contractToDeploy(contract, params, next); + return self.deployContract(contract, next); } self.blockchain.getCode(trackedContract.address, function(_getCodeErr, codeInChain) { if (codeInChain !== "0x") { self.contractAlreadyDeployed(contract, trackedContract, next); } else { - self.contractToDeploy(contract, params, next); + self.deployContract(contract, next); } }); }); @@ -131,38 +131,10 @@ class Deploy { }); } - contractToDeploy(contract, params, callback) { - const self = this; - - // TODO: this whole callback is almost pointless and should be moved to deployContract - this.deployContract(contract, contract.realArgs, function (err, address) { - if (err) { - self.events.emit("deploy:contract:error", contract); - return callback(new Error(err)); - } - contract.address = address; - self.events.emit("deploy:contract:deployed", contract); - - // TODO: can be moved into a afterDeploy event - // just need to figure out the gasLimit coupling issue - self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => { - self.events.request('runcode:eval', contractCode); - - let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions'); - - async.eachLimit(onDeployPlugins, 1, function(plugin, nextEach) { - plugin.call(plugin, contract, nextEach); - }, () => { - callback(); - }); - }); - }); - } - - deployContract(contract, params, callback) { + deployContract(contract, callback) { let self = this; let accounts = []; - let contractParams = (params || contract.args).slice(); + let contractParams = (contract.realArgs || contract.args).slice(); let contractCode = contract.code; let deploymentAccount = self.blockchain.defaultAccount(); let deployObject; @@ -284,12 +256,29 @@ class Deploy { gasPrice: contract.gasPrice }, function(error, receipt) { if (error) { + contract.error = error.message; + self.events.emit("deploy:contract:error", contract); return next(new Error("error deploying =" + contract.className + "= due to error: " + error.message)); } self.logger.info(contract.className.bold.cyan + " " + __("deployed at").green + " " + receipt.contractAddress.bold.cyan); contract.deployedAddress = receipt.contractAddress; contract.transactionHash = receipt.transactionHash; - return next(null, receipt.contractAddress); + self.events.emit("deploy:contract:receipt", receipt); + self.events.emit("deploy:contract:deployed", contract); + + // TODO: can be moved into a afterDeploy event + // just need to figure out the gasLimit coupling issue + self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => { + self.events.request('runcode:eval', contractCode); + + let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions'); + + async.eachLimit(onDeployPlugins, 1, function(plugin, nextEach) { + plugin.call(plugin, contract, nextEach); + }, () => { + return next(null, receipt); + }); + }); }); } ], callback); From f08bb563370511e84bc2cead88345573d815f673 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 22 May 2018 16:16:52 -0400 Subject: [PATCH 09/28] simplify determine args method --- lib/contracts/deploy.js | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index 695103a8..da20f957 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -30,38 +30,30 @@ class Deploy { } } - let realArgs = []; - async.eachLimit(args, 1, (arg, nextEachCb) => { + async.map(args, (arg, nextEachCb) => { if (arg[0] === "$") { let contractName = arg.substr(1); self.events.request('contracts:contract', contractName, (referedContract) => { - realArgs.push(referedContract.deployedAddress); - nextEachCb(); + nextEachCb(null, referedContract.deployedAddress); }); } else if (Array.isArray(arg)) { - let subRealArgs = []; - - async.eachLimit(arg, 1, (sub_arg, nextSubEachCb) => { + async.map(arg, (sub_arg, nextSubEachCb) => { if (sub_arg[0] === "$") { let contractName = sub_arg.substr(1); self.events.request('contracts:contract', contractName, (referedContract) => { - subRealArgs.push(referedContract.deployedAddress); - nextSubEachCb(); + nextSubEachCb(null, referedContract.deployedAddress); }); } else { - subRealArgs.push(sub_arg); - nextSubEachCb(); + nextSubEachCb(null, sub_arg); } - }, () => { - realArgs.push(subRealArgs); - nextEachCb(); + }, (err, subRealArgs) => { + nextEachCb(null, subRealArgs); }); } else { - realArgs.push(arg); - nextEachCb(); + nextEachCb(null, arg); } - }, () => { + }, (err, realArgs) => { callback(realArgs); }); } From 4f45b4fa1399067d603d9258fbbd73aeeba4fef5 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 28 May 2018 18:49:18 -0400 Subject: [PATCH 10/28] add new plugin method for generalized event actions --- lib/contracts/deploy_manager.js | 13 +++++++------ lib/core/plugin.js | 9 +++++++++ lib/core/plugins.js | 18 ++++++++++++++++-- lib/modules/specialconfigs/index.js | 3 ++- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index e5954138..d436a4e9 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -84,13 +84,14 @@ class DeployManager { }); }, function runAfterDeploy(callback) { - let afterDeployPlugins = self.plugins.getPluginsProperty('afterContractsDeployActions', 'afterContractsDeployActions'); + self.plugins.runActionsForEvent('contracts:deploy:afterAll', callback); + //let afterDeployPlugins = self.plugins.getPluginsProperty('afterContractsDeployActions', 'afterContractsDeployActions'); - async.eachLimit(afterDeployPlugins, 1, function(plugin, nextEach) { - plugin.call(plugin, nextEach); - }, () => { - callback(); - }); + //async.eachLimit(afterDeployPlugins, 1, function(plugin, nextEach) { + // plugin.call(plugin, nextEach); + //}, () => { + // callback(); + //}); } ], function (err, _result) { done(err); diff --git a/lib/core/plugin.js b/lib/core/plugin.js index 17feb99a..f2320bb2 100644 --- a/lib/core/plugin.js +++ b/lib/core/plugin.js @@ -27,6 +27,7 @@ var Plugin = function(options) { this.embarkjs_init_code = {}; this.afterContractsDeployActions = []; this.onDeployActions = []; + this.eventActions = {}; this.logger = options.logger; this.events = options.events; this.config = options.config; @@ -215,6 +216,14 @@ Plugin.prototype.registerOnDeployContracts = function(cb) { this.pluginTypes.push('onDeployActions'); }; +Plugin.prototype.registerActionForEvent = function(eventName, cb) { + if (!this.eventActions[eventName]) { + this.eventActions[eventName] = []; + } + this.eventActions[eventName].push(cb); + this.pluginTypes.push('eventActions'); +} + Plugin.prototype.runFilePipeline = function() { var self = this; diff --git a/lib/core/plugins.js b/lib/core/plugins.js index 78a21975..8efa8442 100644 --- a/lib/core/plugins.js +++ b/lib/core/plugins.js @@ -1,3 +1,4 @@ +const async = require('async'); var Plugin = require('./plugin.js'); var utils = require('../utils/utils.js'); @@ -98,18 +99,31 @@ Plugins.prototype.getPluginsFor = function(pluginType) { }); }; -Plugins.prototype.getPluginsProperty = function(pluginType, property) { +Plugins.prototype.getPluginsProperty = function(pluginType, property, sub_property) { let matchingPlugins = this.plugins.filter(function(plugin) { return plugin.has(pluginType); }); let matchingProperties = matchingPlugins.map((plugin) => { + if (sub_property) { + return plugin[property][sub_property]; + } return plugin[property]; }); //return flattened list if (matchingProperties.length === 0) return []; - return matchingProperties.reduce((a,b) => { return a.concat(b); }); + return matchingProperties.reduce((a,b) => { return a.concat(b); }) || []; +}; + +//Plugins.prototype.runActionsForEvent = function(eventName, args, cb) { +Plugins.prototype.runActionsForEvent = function(eventName, cb) { + let actionPlugins = this.getPluginsProperty('eventActions', 'eventActions', eventName); + + async.eachLimit(actionPlugins, 1, function(plugin, nextEach) { + //plugin.call(plugin, ...args, nextEach); + plugin.call(plugin, nextEach); + }, cb); }; module.exports = Plugins; diff --git a/lib/modules/specialconfigs/index.js b/lib/modules/specialconfigs/index.js index 94b8328e..0ffe15e1 100644 --- a/lib/modules/specialconfigs/index.js +++ b/lib/modules/specialconfigs/index.js @@ -48,7 +48,8 @@ class SpecialConfigs { registerAfterDeployAction() { const self = this; - this.embark.registerAfterAllContractsDeploy((cb) => { + //this.embark.registerAfterAllContractsDeploy((cb) => { + this.embark.registerActionForEvent("contracts:deploy:afterAll", (cb) => { let afterDeployCmds = self.contractsConfig.afterDeploy || []; async.mapLimit(afterDeployCmds, 1, (cmd, nextMapCb) => { From 93e5003c64e797a0e9c31558e6deffaf942f0be3 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 28 May 2018 18:59:12 -0400 Subject: [PATCH 11/28] cleanup --- lib/contracts/deploy_manager.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index d436a4e9..afdb91b5 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -85,13 +85,6 @@ class DeployManager { }, function runAfterDeploy(callback) { self.plugins.runActionsForEvent('contracts:deploy:afterAll', callback); - //let afterDeployPlugins = self.plugins.getPluginsProperty('afterContractsDeployActions', 'afterContractsDeployActions'); - - //async.eachLimit(afterDeployPlugins, 1, function(plugin, nextEach) { - // plugin.call(plugin, nextEach); - //}, () => { - // callback(); - //}); } ], function (err, _result) { done(err); From 16653d491b392f9c99b712e4dd7ba344c4289ff7 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 28 May 2018 19:40:55 -0400 Subject: [PATCH 12/28] move onDeploy to new api --- lib/contracts/deploy.js | 7 +------ lib/core/plugins.js | 18 ++++++++++++++---- lib/modules/specialconfigs/index.js | 4 +++- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index da20f957..25b95c9e 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -262,12 +262,7 @@ class Deploy { // just need to figure out the gasLimit coupling issue self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => { self.events.request('runcode:eval', contractCode); - - let onDeployPlugins = self.plugins.getPluginsProperty('onDeployActions', 'onDeployActions'); - - async.eachLimit(onDeployPlugins, 1, function(plugin, nextEach) { - plugin.call(plugin, contract, nextEach); - }, () => { + self.plugins.runActionsForEvent('deploy:contract:deployed', {contract: contract}, () => { return next(null, receipt); }); }); diff --git a/lib/core/plugins.js b/lib/core/plugins.js index 8efa8442..d3479f58 100644 --- a/lib/core/plugins.js +++ b/lib/core/plugins.js @@ -116,13 +116,23 @@ Plugins.prototype.getPluginsProperty = function(pluginType, property, sub_proper return matchingProperties.reduce((a,b) => { return a.concat(b); }) || []; }; -//Plugins.prototype.runActionsForEvent = function(eventName, args, cb) { -Plugins.prototype.runActionsForEvent = function(eventName, cb) { +Plugins.prototype.runActionsForEvent = function(eventName, args, cb) { + if (typeof(args) === 'function') { + cb = args; + } let actionPlugins = this.getPluginsProperty('eventActions', 'eventActions', eventName); + if (actionPlugins.length === 0) { + return cb(); + } + async.eachLimit(actionPlugins, 1, function(plugin, nextEach) { - //plugin.call(plugin, ...args, nextEach); - plugin.call(plugin, nextEach); + if (typeof(args) === 'function') { + plugin.call(plugin, nextEach); + } else { + //plugin.call(plugin, ...args, nextEach); + plugin.call(plugin, args, nextEach); + } }, cb); }; diff --git a/lib/modules/specialconfigs/index.js b/lib/modules/specialconfigs/index.js index 0ffe15e1..bd8dca71 100644 --- a/lib/modules/specialconfigs/index.js +++ b/lib/modules/specialconfigs/index.js @@ -80,7 +80,9 @@ class SpecialConfigs { registerOnDeployAction() { const self = this; - this.embark.registerOnDeployContracts((contract, cb) => { + this.embark.registerActionForEvent("deploy:contract:deployed", (params, cb) => { + let contract = params.contract; + if (!contract.onDeploy) { return cb(); } From 71cd523f30550730745b00526d3a364ce8977700 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 28 May 2018 19:42:32 -0400 Subject: [PATCH 13/28] remove old methods --- lib/core/plugin.js | 10 ---------- lib/modules/specialconfigs/index.js | 1 - 2 files changed, 11 deletions(-) diff --git a/lib/core/plugin.js b/lib/core/plugin.js index f2320bb2..44345487 100644 --- a/lib/core/plugin.js +++ b/lib/core/plugin.js @@ -206,16 +206,6 @@ Plugin.prototype.registerImportFile = function(importName, importLocation) { this.pluginTypes.push('imports'); }; -Plugin.prototype.registerAfterAllContractsDeploy = function(cb) { - this.afterContractsDeployActions.push(cb); - this.pluginTypes.push('afterContractsDeployActions'); -}; - -Plugin.prototype.registerOnDeployContracts = function(cb) { - this.onDeployActions.push(cb); - this.pluginTypes.push('onDeployActions'); -}; - Plugin.prototype.registerActionForEvent = function(eventName, cb) { if (!this.eventActions[eventName]) { this.eventActions[eventName] = []; diff --git a/lib/modules/specialconfigs/index.js b/lib/modules/specialconfigs/index.js index bd8dca71..25b299df 100644 --- a/lib/modules/specialconfigs/index.js +++ b/lib/modules/specialconfigs/index.js @@ -48,7 +48,6 @@ class SpecialConfigs { registerAfterDeployAction() { const self = this; - //this.embark.registerAfterAllContractsDeploy((cb) => { this.embark.registerActionForEvent("contracts:deploy:afterAll", (cb) => { let afterDeployCmds = self.contractsConfig.afterDeploy || []; From 3f20f400ddc406004f4d0291bd685a3caf815712 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 29 May 2018 09:35:55 -0400 Subject: [PATCH 14/28] certify pluginTypes are uniques, to avoid issue with a plugin call being called twice or more --- lib/core/plugin.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/core/plugin.js b/lib/core/plugin.js index 44345487..f5ad6624 100644 --- a/lib/core/plugin.js +++ b/lib/core/plugin.js @@ -1,6 +1,7 @@ const fs = require('./fs.js'); const utils = require('../utils/utils.js'); const constants = require('../constants'); +const _ = require('underscore') // TODO: pass other params like blockchainConfig, contract files, etc.. var Plugin = function(options) { @@ -120,43 +121,45 @@ Plugin.prototype.interceptLogs = function(context) { Plugin.prototype.registerClientWeb3Provider = function(cb) { this.clientWeb3Providers.push(cb); this.pluginTypes.push('clientWeb3Provider'); -}; - -Plugin.prototype.registerBeforeDeploy = function(cb) { - this.beforeDeploy.push(cb); - this.pluginTypes.push('beforeDeploy'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.registerContractsGeneration = function(cb) { this.contractsGenerators.push(cb); this.pluginTypes.push('contractGeneration'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.registerPipeline = function(matcthingFiles, cb) { // TODO: generate error for more than one pipeline per plugin this.pipeline.push({matcthingFiles: matcthingFiles, cb: cb}); this.pluginTypes.push('pipeline'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) { this.pipelineFiles.push({file: file, intendedPath: intendedPath, options: options}); this.pluginTypes.push('pipelineFiles'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.addContractFile = function(file) { this.contractsFiles.push(file); this.pluginTypes.push('contractFiles'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.registerConsoleCommand = function(cb) { this.console.push(cb); this.pluginTypes.push('console'); + this.pluginTypes = _.uniq(this.pluginTypes); }; // TODO: this only works for services done on startup Plugin.prototype.registerServiceCheck = function(checkName, checkFn, time) { this.serviceChecks.push({checkName: checkName, checkFn: checkFn, time: time}); this.pluginTypes.push('serviceChecks'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.has = function(pluginType) { @@ -178,32 +181,38 @@ Plugin.prototype.generateContracts = function(args) { Plugin.prototype.registerContractConfiguration = function(config) { this.contractsConfigs.push(config); this.pluginTypes.push('contractsConfig'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.registerCompiler = function(extension, cb) { this.compilers.push({extension: extension, cb: cb}); this.pluginTypes.push('compilers'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.registerUploadCommand = function(cmd, cb) { this.uploadCmds.push({cmd: cmd, cb: cb}); this.pluginTypes.push('uploadCmds'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.addCodeToEmbarkJS = function(code) { this.embarkjs_code.push(code); this.pluginTypes.push('embarkjsCode'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.addProviderInit = function(providerType, code, initCondition) { this.embarkjs_init_code[providerType] = this.embarkjs_init_code[providerType] || []; this.embarkjs_init_code[providerType].push([code, initCondition]); this.pluginTypes.push('initCode'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.registerImportFile = function(importName, importLocation) { this.imports.push([importName, importLocation]); this.pluginTypes.push('imports'); + this.pluginTypes = _.uniq(this.pluginTypes); }; Plugin.prototype.registerActionForEvent = function(eventName, cb) { @@ -212,6 +221,7 @@ Plugin.prototype.registerActionForEvent = function(eventName, cb) { } this.eventActions[eventName].push(cb); this.pluginTypes.push('eventActions'); + this.pluginTypes = _.uniq(this.pluginTypes); } Plugin.prototype.runFilePipeline = function() { From 8458acd207dc6483344b3e90fe7069a58c52b22c Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 29 May 2018 09:36:27 -0400 Subject: [PATCH 15/28] filter for plugins that have defined properties --- lib/core/plugins.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/core/plugins.js b/lib/core/plugins.js index d3479f58..cad5f71e 100644 --- a/lib/core/plugins.js +++ b/lib/core/plugins.js @@ -111,6 +111,8 @@ Plugins.prototype.getPluginsProperty = function(pluginType, property, sub_proper return plugin[property]; }); + matchingProperties = matchingProperties.filter((property) => property); + //return flattened list if (matchingProperties.length === 0) return []; return matchingProperties.reduce((a,b) => { return a.concat(b); }) || []; From 69e5af230873d8c9995bdd7c8538821c1a127159 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 29 May 2018 09:37:16 -0400 Subject: [PATCH 16/28] replace beforeAction plugin api with event action api --- lib/contracts/deploy.js | 29 +------------------ .../extensions/embark-service/index.js | 9 ++++-- 2 files changed, 7 insertions(+), 31 deletions(-) diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index 25b95c9e..20aac7d3 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -186,34 +186,7 @@ class Deploy { }); }, function applyBeforeDeploy(next) { - let beforeDeployPlugins = self.plugins.getPluginsFor('beforeDeploy'); - - //self.logger.info("applying beforeDeploy plugins...", beforeDeployPlugins.length); - async.eachSeries(beforeDeployPlugins, (plugin, eachPluginCb) => { - self.logger.info(__("running beforeDeploy plugin %s .", plugin.name)); - - // calling each beforeDeploy handler declared by the plugin - async.eachSeries(plugin.beforeDeploy, (beforeDeployFn, eachCb) => { - function beforeDeployCb(resObj){ - contract.code = resObj.contractCode; - eachCb(); - } - beforeDeployFn({ - embarkDeploy: self, - pluginConfig: plugin.pluginConfig, - deploymentAccount: deploymentAccount, - contract: contract, - callback: beforeDeployCb - }, beforeDeployCb); - }, () => { - //self.logger.info('All beforeDeploy handlers of the plugin has processed.'); - eachPluginCb(); - }); - }, () => { - //self.logger.info('All beforeDeploy plugins has been processed.'); - contractCode = contract.code; - next(); - }); + self.plugins.runActionsForEvent('deploy:contract:beforeDeploy', {contract: contract}, next); }, function createDeployObject(next) { let contractObject = self.blockchain.ContractObject({abi: contract.abiDefinition}); diff --git a/test_apps/test_app/extensions/embark-service/index.js b/test_apps/test_app/extensions/embark-service/index.js index 6783352a..7717c760 100644 --- a/test_apps/test_app/extensions/embark-service/index.js +++ b/test_apps/test_app/extensions/embark-service/index.js @@ -23,9 +23,12 @@ module.exports = function (embark) { embark.addFileToPipeline('./fileInPipeline.js'); embark.addFileToPipeline('./fileInPipeline.js', 'js/fileInPipeline.js'); - embark.registerBeforeDeploy(function (options, callback) { - // Just calling register to prove it works. We don't actually want to change the contracts - callback({contractCode: options.contract.code}); + embark.registerActionForEvent("deploy:contract:beforeDeploy", (params, cb) => { + embark.logger.info("applying beforeDeploy plugin..."); + //console.dir(params); + //console.dir(cb); + //console.dir('------------------'); + cb(); }); // NOTE: uncommenting this will make dappConnection stop working From f1cb7d118745fcbfab0bd8a3fb6aaf1e5b4998b8 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 29 May 2018 09:58:19 -0400 Subject: [PATCH 17/28] lint is king --- lib/core/plugin.js | 4 ++-- lib/core/plugins.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/core/plugin.js b/lib/core/plugin.js index f5ad6624..fa8c8650 100644 --- a/lib/core/plugin.js +++ b/lib/core/plugin.js @@ -1,7 +1,7 @@ const fs = require('./fs.js'); const utils = require('../utils/utils.js'); const constants = require('../constants'); -const _ = require('underscore') +const _ = require('underscore'); // TODO: pass other params like blockchainConfig, contract files, etc.. var Plugin = function(options) { @@ -222,7 +222,7 @@ Plugin.prototype.registerActionForEvent = function(eventName, cb) { this.eventActions[eventName].push(cb); this.pluginTypes.push('eventActions'); this.pluginTypes = _.uniq(this.pluginTypes); -} +}; Plugin.prototype.runFilePipeline = function() { var self = this; diff --git a/lib/core/plugins.js b/lib/core/plugins.js index cad5f71e..782113d0 100644 --- a/lib/core/plugins.js +++ b/lib/core/plugins.js @@ -119,7 +119,7 @@ Plugins.prototype.getPluginsProperty = function(pluginType, property, sub_proper }; Plugins.prototype.runActionsForEvent = function(eventName, args, cb) { - if (typeof(args) === 'function') { + if (typeof (args) === 'function') { cb = args; } let actionPlugins = this.getPluginsProperty('eventActions', 'eventActions', eventName); @@ -129,7 +129,7 @@ Plugins.prototype.runActionsForEvent = function(eventName, args, cb) { } async.eachLimit(actionPlugins, 1, function(plugin, nextEach) { - if (typeof(args) === 'function') { + if (typeof (args) === 'function') { plugin.call(plugin, nextEach); } else { //plugin.call(plugin, ...args, nextEach); From 70f38d863eb959ad54eb5c9c653e4a1b521d8cf5 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 29 May 2018 17:23:07 -0400 Subject: [PATCH 18/28] fix code generator event --- lib/contracts/code_generator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index b30807de..a00e6112 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -81,7 +81,7 @@ class CodeGenerator { }); self.events.setCommandHandler('code-generator:contract', (contractName, cb) => { - self.events.setCommandHandler('contracts:contract', contractName, (contract) => { + self.events.request('contracts:contract', contractName, (contract) => { self.buildContractJS(contractName, self.generateContractJSON(contract, contract), cb); }); }); From 1912981d7d7fed41ad85506fe1ec3cf3fdb8079e Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 29 May 2018 17:23:29 -0400 Subject: [PATCH 19/28] move contract deploy code to contract deployer; move it to events --- .../{deploy.js => contract_deployer.js} | 44 ++++------------ lib/contracts/deploy_manager.js | 52 ++++++++++++++----- lib/core/engine.js | 13 ++++- lib/index.js | 11 ++-- lib/tests/test.js | 2 +- 5 files changed, 66 insertions(+), 56 deletions(-) rename lib/contracts/{deploy.js => contract_deployer.js} (90%) diff --git a/lib/contracts/deploy.js b/lib/contracts/contract_deployer.js similarity index 90% rename from lib/contracts/deploy.js rename to lib/contracts/contract_deployer.js index 20aac7d3..6d48d51b 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/contract_deployer.js @@ -2,13 +2,19 @@ let async = require('async'); //require("../utils/debug_util.js")(__filename, async); let utils = require('../utils/utils.js'); -class Deploy { +class ContractDeployer { constructor(options) { + const self = this; + this.blockchain = options.blockchain; this.logger = options.logger; this.events = options.events; this.plugins = options.plugins; this.gasLimit = options.gasLimit; + + self.events.setCommandHandler('deploy:contract', (contract, cb) => { + self.checkAndDeployContract(contract, null, cb); + }); } // TODO: determining the arguments could also be in a module since it's not @@ -117,7 +123,7 @@ class Deploy { // TODO: can be moved into a afterDeploy event // just need to figure out the gasLimit coupling issue - self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => { + self.events.request('code-generator:contract:vanilla', contract, contract._gasLimit, (contractCode) => { self.events.request('runcode:eval', contractCode); return callback(); }); @@ -186,6 +192,7 @@ class Deploy { }); }, function applyBeforeDeploy(next) { + self.events.emit('deploy:contract:beforeDeploy', {contract: contract}); self.plugins.runActionsForEvent('deploy:contract:beforeDeploy', {contract: contract}, next); }, function createDeployObject(next) { @@ -233,7 +240,7 @@ class Deploy { // TODO: can be moved into a afterDeploy event // just need to figure out the gasLimit coupling issue - self.events.request('code-generator:contract:vanilla', contract, self.gasLimit, (contractCode) => { + self.events.request('code-generator:contract:vanilla', contract, contract._gasLimit, (contractCode) => { self.events.request('runcode:eval', contractCode); self.plugins.runActionsForEvent('deploy:contract:deployed', {contract: contract}, () => { return next(null, receipt); @@ -244,35 +251,6 @@ class Deploy { ], callback); } - deployAll(done) { - let self = this; - this.logger.info(__("deploying contracts")); - this.events.emit("deploy:beforeAll"); - - self.events.request('contracts:list', (contracts) => { - async.eachOfSeries(contracts, - function (contract, key, callback) { - self.logger.trace(arguments); - self.checkAndDeployContract(contract, null, 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")); - self.logger.trace(arguments); - done(err); - } - ); - }); - - } } -module.exports = Deploy; +module.exports = ContractDeployer; diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index afdb91b5..fe986673 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -1,9 +1,8 @@ let async = require('async'); -//require("../utils/debug_util.js")(__filename, async); -let Deploy = require('./deploy.js'); class DeployManager { constructor(options) { + const self = this; this.config = options.config; this.logger = options.logger; this.blockchainConfig = this.config.blockchainConfig; @@ -17,6 +16,41 @@ class DeployManager { this.fatalErrors = false; this.deployOnlyOnConfig = false; this.onlyCompile = options.onlyCompile !== undefined ? options.onlyCompile : false; + + this.events.setCommandHandler('deploy:contracts', (cb) => { + self.deployContracts(cb); + }); + } + + deployAll(done) { + let self = this; + this.logger.info(__("deploying contracts")); + this.events.emit("deploy:beforeAll"); + + self.events.request('contracts:list', (contracts) => { + async.eachOfSeries(contracts, + function (contract, key, callback) { + contract._gasLimit = self.gasLimit; + self.events.request('deploy:contract', contract, () => { + 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")); + self.logger.trace(arguments); + done(err); + } + ); + }); } deployContracts(done) { @@ -62,18 +96,7 @@ class DeployManager { }, function deployAllContracts(callback) { - let deploy = new Deploy({ - blockchain: self.blockchain, - contractsManager: self.contractsManager, - logger: self.logger, - events: self.events, - chainConfig: self.chainConfig, - env: self.config.env, - plugins: self.plugins, - gasLimit: self.gasLimit - }); - - deploy.deployAll(function (err) { + self.deployAll(function (err) { if (!err) { self.events.emit('contractsDeployed', self.contractsManager); } @@ -84,6 +107,7 @@ class DeployManager { }); }, function runAfterDeploy(callback) { + self.events.emit('contracts:deploy:afterAll'); self.plugins.runActionsForEvent('contracts:deploy:afterAll', callback); } ], function (err, _result) { diff --git a/lib/core/engine.js b/lib/core/engine.js index 82b7aa26..71383aac 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -6,6 +6,7 @@ const Config = require('./config.js'); const Blockchain = require('../contracts/blockchain.js'); const Compiler = require('../contracts/compiler.js'); const ContractsManager = require('../contracts/contracts.js'); +const ContractDeployer = require('../contracts/contract_deployer.js'); const DeployManager = require('../contracts/deploy_manager.js'); const CodeGenerator = require('../contracts/code_generator.js'); const ServicesMonitor = require('./services_monitor.js'); @@ -242,6 +243,14 @@ class Engine { onlyCompile: options.onlyCompile }); + this.contractDeployer = new ContractDeployer({ + blockchain: this.blockchain, + logger: this.logger, + events: this.events, + plugins: this.plugins + //gasLimit: options.gasLimit + }); + this.events.on('file-event', function (fileType) { clearTimeout(self.fileTimeout); self.fileTimeout = setTimeout(() => { @@ -255,8 +264,8 @@ class Engine { // because the contractsManager config is corrupted after a deploy if (fileType === 'contract' || fileType === 'config') { self.config.reloadConfig(); - self.deployManager.deployContracts(function () { - }); + + self.events.request('deploy:contracts', () => {}); } }, 50); }); diff --git a/lib/index.js b/lib/index.js index 82802615..f8a0f645 100644 --- a/lib/index.js +++ b/lib/index.js @@ -167,7 +167,7 @@ class Embark { engine.events.on('check:backOnline:Ethereum', function () { engine.logger.info(__('Ethereum node detected') + '..'); engine.config.reloadConfig(); - engine.deployManager.deployContracts(function () { + engine.events.request('deploy:contracts', function() { engine.logger.info(__('Deployment Done')); }); }); @@ -191,6 +191,7 @@ class Embark { engine.logger.info(__("Ready").underline); engine.events.emit("status", __("Ready").green); }); + if (options.runWebserver) { engine.startService("webServer", { host: options.serverHost, @@ -255,7 +256,7 @@ class Embark { callback(); }, function deploy(callback) { - engine.deployManager.deployContracts(function (err) { + engine.events.request('deploy:contracts', function(err) { callback(err); }); } @@ -306,7 +307,7 @@ class Embark { engine.startService("deployment", {onlyCompile: true}); engine.startService("codeGenerator"); - engine.deployManager.deployContracts(function (err) { + engine.events.request('deploy:contracts', function(err) { callback(err); }); } @@ -418,7 +419,6 @@ class Embark { callback(); }, function deploy(callback) { - // 2. upload to storage (outputDone event triggered after webpack finished) engine.events.on('outputDone', function () { cmdPlugin.uploadCmds[0].cb() .then((success) => { @@ -427,8 +427,7 @@ class Embark { .catch(callback); }); - // 1. build the contracts and dapp webpack - engine.deployManager.deployContracts(function (err) { + engine.events.request('deploy:contracts', function(err) { engine.logger.info(__("finished deploying").underline); if(err){ callback(err); diff --git a/lib/tests/test.js b/lib/tests/test.js index 956f4ac2..a17a5d03 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -88,7 +88,7 @@ Test.prototype.deployAll = function(contractsConfig, cb) { self.engine.contractsManager.gasLimit = 6000000; self.engine.deployManager.fatalErrors = true; self.engine.deployManager.deployOnlyOnConfig = true; - self.engine.deployManager.deployContracts(function(err, _result) { + self.engine.events.request('deploy:contracts', function(err) { if (err) { callback(err); } From 9b368bc1b39efcc8c3d7d3d70e8d7052ab9f795a Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 29 May 2018 17:25:45 -0400 Subject: [PATCH 20/28] remove unneeded assignment --- lib/contracts/code_generator.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index a00e6112..90231e8c 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -28,8 +28,6 @@ class CodeGenerator { this.communicationConfig = options.communicationConfig || {}; this.namesystemConfig = options.namesystemConfig || {}; this.env = options.env || 'development'; - // TODO: this should also be removed and use events instead - this.contractsManager = options.contractsManager; this.plugins = options.plugins; this.events = options.events; } From 68e6782f49227e4f5eb475e53486ee6b6dbdc880 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 30 May 2018 06:38:35 -0400 Subject: [PATCH 21/28] remove unneded assignment --- lib/contracts/deploy_manager.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index fe986673..d9055e87 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -1,5 +1,9 @@ let async = require('async'); +// TODO: remove contractsManager dependency +// * use events +// * in the engine use the instance instead + class DeployManager { constructor(options) { const self = this; @@ -10,7 +14,6 @@ class DeployManager { this.events = options.events; this.plugins = options.plugins; this.blockchain = options.blockchain; - this.chainConfig = (options.trackContracts !== false) ? this.config.chainTracker : false; this.contractsManager = options.contractsManager; this.gasLimit = false; this.fatalErrors = false; From 1d782c0e53b39565094b36061c30b7c784619dac Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 30 May 2018 06:56:51 -0400 Subject: [PATCH 22/28] emit contractsDeployed event only --- lib/contracts/deploy_manager.js | 8 ++------ lib/core/engine.js | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index d9055e87..d4eb4830 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -1,9 +1,5 @@ let async = require('async'); -// TODO: remove contractsManager dependency -// * use events -// * in the engine use the instance instead - class DeployManager { constructor(options) { const self = this; @@ -76,7 +72,7 @@ class DeployManager { // TODO: shouldn't be necessary function checkCompileOnly(callback){ if(self.onlyCompile){ - self.events.emit('contractsDeployed', self.contractsManager); + self.events.emit('contractsDeployed'); return done(); } return callback(); @@ -101,7 +97,7 @@ class DeployManager { function deployAllContracts(callback) { self.deployAll(function (err) { if (!err) { - self.events.emit('contractsDeployed', self.contractsManager); + self.events.emit('contractsDeployed'); } if (err && self.fatalErrors) { return callback(err); diff --git a/lib/core/engine.js b/lib/core/engine.js index 71383aac..012bfcf1 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -189,8 +189,8 @@ class Engine { generateCode(tasks[tasks.length - 1].contractsManager); self.events.once('outputDone', callback); }); - const addToCargo = function (contractsManager) { - cargo.push({contractsManager}); + const addToCargo = function () { + cargo.push({contractsManager: self.contractsManager}); }; this.events.on('contractsDeployed', addToCargo); From 45f776731378536ba8e64eef49c60ec436c4c338 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 30 May 2018 07:01:22 -0400 Subject: [PATCH 23/28] remove contracts manager dependency from deploy manager --- lib/contracts/contracts.js | 8 ++++++++ lib/contracts/deploy_manager.js | 4 +--- lib/core/engine.js | 2 -- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/contracts/contracts.js b/lib/contracts/contracts.js index 6f9fbd81..b09945b6 100644 --- a/lib/contracts/contracts.js +++ b/lib/contracts/contracts.js @@ -34,6 +34,13 @@ class ContractsManager { cb(self.getContract(contractName)); }); + self.events.setCommandHandler("contracts:build", (configOnly, cb) => { + self.deployOnlyOnConfig = configOnly; // temporary, should refactor + self.build(() => { + cb(); + }); + }); + self.events.on("deploy:contract:error", (_contract) => { self.events.emit('contractsState', self.contractsState()); }); @@ -45,6 +52,7 @@ class ContractsManager { self.events.on("deploy:contract:undeployed", (_contract) => { self.events.emit('contractsState', self.contractsState()); }); + } build(done) { diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index d4eb4830..91d9f5b3 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -10,7 +10,6 @@ class DeployManager { this.events = options.events; this.plugins = options.plugins; this.blockchain = options.blockchain; - this.contractsManager = options.contractsManager; this.gasLimit = false; this.fatalErrors = false; this.deployOnlyOnConfig = false; @@ -63,8 +62,7 @@ class DeployManager { async.waterfall([ function buildContracts(callback) { - self.contractsManager.deployOnlyOnConfig = self.deployOnlyOnConfig; // temporary, should refactor - self.contractsManager.build(() => { + self.events.request("contracts:build", self.deployOnlyOnConfig, (cb) => { callback(); }); }, diff --git a/lib/core/engine.js b/lib/core/engine.js index 012bfcf1..e135a434 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -234,12 +234,10 @@ class Engine { this.deployManager = new DeployManager({ blockchain: this.blockchain, - trackContracts: options.trackContracts, config: this.config, logger: this.logger, plugins: this.plugins, events: this.events, - contractsManager: this.contractsManager, onlyCompile: options.onlyCompile }); From 4f20d31b4cd30b6daafb4de40fe6a9a19876e444 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 30 May 2018 08:00:31 -0400 Subject: [PATCH 24/28] add emitAndRunActionsForEvent --- lib/contracts/contract_deployer.js | 3 +-- lib/contracts/deploy_manager.js | 3 +-- lib/core/plugins.js | 5 +++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/contracts/contract_deployer.js b/lib/contracts/contract_deployer.js index 6d48d51b..921f9f2a 100644 --- a/lib/contracts/contract_deployer.js +++ b/lib/contracts/contract_deployer.js @@ -192,8 +192,7 @@ class ContractDeployer { }); }, function applyBeforeDeploy(next) { - self.events.emit('deploy:contract:beforeDeploy', {contract: contract}); - self.plugins.runActionsForEvent('deploy:contract:beforeDeploy', {contract: contract}, next); + self.plugins.emitAndRunActionsForEvent('deploy:contract:beforeDeploy', {contract: contract}, next); }, function createDeployObject(next) { let contractObject = self.blockchain.ContractObject({abi: contract.abiDefinition}); diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index 91d9f5b3..f39aaeb2 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -104,8 +104,7 @@ class DeployManager { }); }, function runAfterDeploy(callback) { - self.events.emit('contracts:deploy:afterAll'); - self.plugins.runActionsForEvent('contracts:deploy:afterAll', callback); + self.plugins.emitAndRunActionsForEvent('contracts:deploy:afterAll', callback); } ], function (err, _result) { done(err); diff --git a/lib/core/plugins.js b/lib/core/plugins.js index 782113d0..d98305e8 100644 --- a/lib/core/plugins.js +++ b/lib/core/plugins.js @@ -138,4 +138,9 @@ Plugins.prototype.runActionsForEvent = function(eventName, args, cb) { }, cb); }; +Plugins.prototype.emitAndRunActionsForEvent = function(eventName, args, cb) { + this.events.emit(eventName); + return this.runActionsForEvent(eventName, args, cb); +}; + module.exports = Plugins; From 7d795fa180ba75dbe7699ce0409946c9a2a2b11b Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 30 May 2018 08:06:23 -0400 Subject: [PATCH 25/28] remove unused var --- lib/contracts/deploy_manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index f39aaeb2..815847d3 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -62,7 +62,7 @@ class DeployManager { async.waterfall([ function buildContracts(callback) { - self.events.request("contracts:build", self.deployOnlyOnConfig, (cb) => { + self.events.request("contracts:build", self.deployOnlyOnConfig, () => { callback(); }); }, From b43a766de73e913172e287123b8ffb866be7350e Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 30 May 2018 12:26:49 -0400 Subject: [PATCH 26/28] cleanup module call --- lib/core/engine.js | 33 +++++++-------------------------- lib/core/plugins.js | 2 +- lib/modules/ens/index.js | 5 ++--- lib/modules/ipfs/index.js | 2 +- lib/modules/profiler/index.js | 1 - lib/modules/solidity/index.js | 4 ++-- lib/modules/swarm/index.js | 2 +- lib/modules/vyper/index.js | 4 ++-- lib/modules/whisper/index.js | 2 +- test/compiler.js | 10 ++++++---- test/contracts.js | 14 ++++++++++---- 11 files changed, 33 insertions(+), 46 deletions(-) diff --git a/lib/core/engine.js b/lib/core/engine.js index e135a434..671b7cd0 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -93,7 +93,7 @@ class Engine { } registerModule(moduleName, options) { - this.plugins.loadInternalPlugin(moduleName, options); + this.plugins.loadInternalPlugin(moduleName, options || {}); } startService(serviceName, _options) { @@ -149,12 +149,7 @@ class Engine { } namingSystem(_options) { - this.registerModule('ens', { - logger: this.logger, - events: this.events, - web3: this.blockchain.web3, - namesConfig: this.config.namesystemConfig - }); + this.registerModule('ens'); } codeRunnerService(_options) { @@ -206,22 +201,11 @@ class Engine { compiler.compile_contracts(contractFiles, cb); }); - this.registerModule('solidity', { - contractDirectories: self.config.contractDirectories - }); - this.registerModule('vyper', { - contractDirectories: self.config.contractDirectories - }); - this.registerModule('profiler', { - events: this.events, - logger: this.logger - }); - - this.registerModule('deploytracker', { - }); - - this.registerModule('specialconfigs', { - }); + this.registerModule('solidity'); + this.registerModule('vyper'); + this.registerModule('profiler'); + this.registerModule('deploytracker'); + this.registerModule('specialconfigs'); this.contractsManager = new ContractsManager({ contractFiles: this.config.contractsFiles, @@ -284,7 +268,6 @@ class Engine { ipfsService(_options) { this.registerModule('ipfs', { addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor), - storageConfig: this.config.storageConfig, host: _options.host, port: _options.port }); @@ -293,7 +276,6 @@ class Engine { swarmService(_options) { this.registerModule('swarm', { addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor), - storageConfig: this.config.storageConfig, // TODO: this should not be needed and should be deducted from the config instead // the eth provider is not necessary the same as the swarm one bzz: this.blockchain.web3.bzz @@ -314,7 +296,6 @@ class Engine { this.registerModule('whisper', { addCheck: this.servicesMonitor.addCheck.bind(this.servicesMonitor), - communicationConfig: this.config.communicationConfig, // TODO: this should not be needed and should be deducted from the config instead // the eth provider is not necessary the same as the whisper one web3: this.blockchain.web3 diff --git a/lib/core/plugins.js b/lib/core/plugins.js index d98305e8..096ce43f 100644 --- a/lib/core/plugins.js +++ b/lib/core/plugins.js @@ -59,7 +59,7 @@ Plugins.prototype.loadInternalPlugin = function(pluginName, pluginConfig) { var pluginWrapper = new Plugin({ name: pluginName, pluginModule: plugin, - pluginConfig: pluginConfig, + pluginConfig: pluginConfig || {}, logger: this.logger, pluginPath: pluginPath, interceptLogs: this.interceptLogs, diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index e6ba7295..0b0c6656 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -2,11 +2,10 @@ const fs = require('../../core/fs.js'); const utils = require('../../utils/utils.js'); class ENS { - constructor(embark, options) { + constructor(embark, _options) { this.logger = embark.logger; this.events = embark.events; - this.web3 = options.web3; - this.namesConfig = options.namesConfig; + this.namesConfig = embark.config.namesystemConfig; this.embark = embark; this.addENSToEmbarkJS(); diff --git a/lib/modules/ipfs/index.js b/lib/modules/ipfs/index.js index bccd839c..a2f01d9e 100644 --- a/lib/modules/ipfs/index.js +++ b/lib/modules/ipfs/index.js @@ -10,7 +10,7 @@ class IPFS { this.logger = embark.logger; this.events = embark.events; this.buildDir = options.buildDir; - this.storageConfig = options.storageConfig; + this.storageConfig = embark.config.storageConfig; this.host = options.host || this.storageConfig.host; this.port = options.port || this.storageConfig.port; this.addCheck = options.addCheck; diff --git a/lib/modules/profiler/index.js b/lib/modules/profiler/index.js index e78c2dcf..f86ad995 100644 --- a/lib/modules/profiler/index.js +++ b/lib/modules/profiler/index.js @@ -5,7 +5,6 @@ class Profiler { this.embark = embark; this.logger = embark.logger; this.events = embark.events; - this.plugins = embark.plugins; this.registerConsoleCommand(); } diff --git a/lib/modules/solidity/index.js b/lib/modules/solidity/index.js index b28fb039..c0d77188 100644 --- a/lib/modules/solidity/index.js +++ b/lib/modules/solidity/index.js @@ -3,10 +3,10 @@ let SolcW = require('./solcW.js'); class Solidity { - constructor(embark, options) { + constructor(embark, _options) { this.logger = embark.logger; this.events = embark.events; - this.contractDirectories = options.contractDirectories; + this.contractDirectories = embark.config.contractDirectories; this.solcAlreadyLoaded = false; this.solcW = null; diff --git a/lib/modules/swarm/index.js b/lib/modules/swarm/index.js index a8901cc1..b6479b94 100644 --- a/lib/modules/swarm/index.js +++ b/lib/modules/swarm/index.js @@ -8,7 +8,7 @@ class Swarm { this.logger = embark.logger; this.events = embark.events; this.buildDir = options.buildDir; - this.storageConfig = options.storageConfig; + this.storageConfig = embark.config.storageConfig; this.host = options.host || this.storageConfig.host; this.port = options.port || this.storageConfig.port; this.addCheck = options.addCheck; diff --git a/lib/modules/vyper/index.js b/lib/modules/vyper/index.js index 10a603de..6e11d0b3 100644 --- a/lib/modules/vyper/index.js +++ b/lib/modules/vyper/index.js @@ -4,10 +4,10 @@ const path = require('path'); class Vyper { - constructor(embark, options) { + constructor(embark, _options) { this.logger = embark.logger; this.events = embark.events; - this.contractDirectories = options.contractDirectories; + this.contractDirectories = embark.config.contractDirectories; // FIXME: Use array of extensions instead of duplicatiing embark.registerCompiler(".py", this.compile_vyper.bind(this)); diff --git a/lib/modules/whisper/index.js b/lib/modules/whisper/index.js index 624fb63e..f2d961f1 100644 --- a/lib/modules/whisper/index.js +++ b/lib/modules/whisper/index.js @@ -6,7 +6,7 @@ class Whisper { constructor(embark, options) { this.logger = embark.logger; this.events = embark.events; - this.communicationConfig = options.communicationConfig; + this.communicationConfig = embark.config.communicationConfig; this.addCheck = options.addCheck; // TODO: this should not be needed and should be deducted from the config instead this.web3 = options.web3; diff --git a/test/compiler.js b/test/compiler.js index 1fffdc55..e79fcd52 100644 --- a/test/compiler.js +++ b/test/compiler.js @@ -19,20 +19,22 @@ var TestEvents = { var apiObject = { registerCompiler: function() {}, logger: new TestLogger({}), - events: TestEvents + events: TestEvents, + config: { + contractDirectories: ['app/contracts/'] + } }; describe('embark.Compiler', function() { //let compiler = new Compiler({logger: new TestLogger({})}); - let compiler = new SolidityCompiler(apiObject, {contractDirectories: ['app/contracts/']}); + let compiler = new SolidityCompiler(apiObject); describe('#compile_solidity', function() { this.timeout(0); let expectedObject = {}; - //expectedObject["SimpleStorage"] = {"code":"608060405234801561001057600080fd5b50604051602080610114833981016040525160005560e1806100336000396000f30060806040526004361060525763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114605757806360fe47b114607b5780636d4ce63c146092575b600080fd5b348015606257600080fd5b50606960a4565b60408051918252519081900360200190f35b348015608657600080fd5b50609060043560aa565b005b348015609d57600080fd5b50606960af565b60005481565b600055565b600054905600a165627a7a72305820194e9895d54b0b5d8b469e794926ef9115b42631ab9a06ce726f9fea067633850029","runtimeBytecode":"60806040526004361060525763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114605757806360fe47b114607b5780636d4ce63c146092575b600080fd5b348015606257600080fd5b50606960a4565b60408051918252519081900360200190f35b348015608657600080fd5b50609060043560aa565b005b348015609d57600080fd5b50606960af565b60005481565b600055565b600054905600a165627a7a72305820194e9895d54b0b5d8b469e794926ef9115b42631ab9a06ce726f9fea067633850029","realRuntimeBytecode":"60806040526004361060525763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114605757806360fe47b114607b5780636d4ce63c146092575b600080fd5b348015606257600080fd5b50606960a4565b60408051918252519081900360200190f35b348015608657600080fd5b50609060043560aa565b005b348015609d57600080fd5b50606960af565b60005481565b600055565b600054905600a165627a7a72305820","swarmHash":"194e9895d54b0b5d8b469e794926ef9115b42631ab9a06ce726f9fea06763385","gasEstimates":{"creation":{"codeDepositCost":"45000","executionCost":"20141","totalCost":"65141"},"external":{"get()":"428","set(uint256)":"20161","storedData()":"384"}},"functionHashes":{"get()":"6d4ce63c","set(uint256)":"60fe47b1","storedData()":"2a1afcd9"},"abiDefinition":[{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}],"filename":"test/contracts/simple_storage.sol"}; - expectedObject["SimpleStorage"] = expectedObject["SimpleStorage"] = {"code":"608060405234801561001057600080fd5b50604051602080610114833981016040525160005560e1806100336000396000f30060806040526004361060525763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114605757806360fe47b114607b5780636d4ce63c146092575b600080fd5b348015606257600080fd5b50606960a4565b60408051918252519081900360200190f35b348015608657600080fd5b50609060043560aa565b005b348015609d57600080fd5b50606960af565b60005481565b600055565b600054905600a165627a7a72305820194e9895d54b0b5d8b469e794926ef9115b42631ab9a06ce726f9fea067633850029","runtimeBytecode":"60806040526004361060525763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114605757806360fe47b114607b5780636d4ce63c146092575b600080fd5b348015606257600080fd5b50606960a4565b60408051918252519081900360200190f35b348015608657600080fd5b50609060043560aa565b005b348015609d57600080fd5b50606960af565b60005481565b600055565b600054905600a165627a7a72305820194e9895d54b0b5d8b469e794926ef9115b42631ab9a06ce726f9fea067633850029","realRuntimeBytecode":"60806040526004361060525763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114605757806360fe47b114607b5780636d4ce63c146092575b600080fd5b348015606257600080fd5b50606960a4565b60408051918252519081900360200190f35b348015608657600080fd5b50609060043560aa565b005b348015609d57600080fd5b50606960af565b60005481565b600055565b600054905600a165627a7a72305820","swarmHash":"194e9895d54b0b5d8b469e794926ef9115b42631ab9a06ce726f9fea06763385","gasEstimates":{"creation":{"codeDepositCost":"45000","executionCost":"20141","totalCost":"65141"},"external":{"get()":"428","set(uint256)":"20161","storedData()":"384"}},"functionHashes":{"get()":"6d4ce63c","set(uint256)":"60fe47b1","storedData()":"2a1afcd9"},"abiDefinition":[{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}],"filename":"test/contracts/simple_storage.sol"}; + expectedObject["SimpleStorage"] = {"code":"608060405234801561001057600080fd5b50604051602080610114833981016040525160005560e1806100336000396000f30060806040526004361060525763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114605757806360fe47b114607b5780636d4ce63c146092575b600080fd5b348015606257600080fd5b50606960a4565b60408051918252519081900360200190f35b348015608657600080fd5b50609060043560aa565b005b348015609d57600080fd5b50606960af565b60005481565b600055565b600054905600a165627a7a72305820194e9895d54b0b5d8b469e794926ef9115b42631ab9a06ce726f9fea067633850029","runtimeBytecode":"60806040526004361060525763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114605757806360fe47b114607b5780636d4ce63c146092575b600080fd5b348015606257600080fd5b50606960a4565b60408051918252519081900360200190f35b348015608657600080fd5b50609060043560aa565b005b348015609d57600080fd5b50606960af565b60005481565b600055565b600054905600a165627a7a72305820194e9895d54b0b5d8b469e794926ef9115b42631ab9a06ce726f9fea067633850029","realRuntimeBytecode":"60806040526004361060525763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114605757806360fe47b114607b5780636d4ce63c146092575b600080fd5b348015606257600080fd5b50606960a4565b60408051918252519081900360200190f35b348015608657600080fd5b50609060043560aa565b005b348015609d57600080fd5b50606960af565b60005481565b600055565b600054905600a165627a7a72305820","swarmHash":"194e9895d54b0b5d8b469e794926ef9115b42631ab9a06ce726f9fea06763385","gasEstimates":{"creation":{"codeDepositCost":"45000","executionCost":"20141","totalCost":"65141"},"external":{"get()":"428","set(uint256)":"20161","storedData()":"384"}},"functionHashes":{"get()":"6d4ce63c","set(uint256)":"60fe47b1","storedData()":"2a1afcd9"},"abiDefinition":[{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}],"filename":"test/contracts/simple_storage.sol"}; expectedObject["Token"] = {"code":"608060405234801561001057600080fd5b5060405160208061047e8339810160409081529051600160a060020a033316600090815260208190529190912081905560025561042c806100526000396000f3006080604052600436106100775763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007c57806318160ddd146100b457806323b872dd146100db57806370a0823114610105578063a9059cbb14610126578063dd62ed3e1461014a575b600080fd5b34801561008857600080fd5b506100a0600160a060020a0360043516602435610171565b604080519115158252519081900360200190f35b3480156100c057600080fd5b506100c96101db565b60408051918252519081900360200190f35b3480156100e757600080fd5b506100a0600160a060020a03600435811690602435166044356101e1565b34801561011157600080fd5b506100c9600160a060020a03600435166102f2565b34801561013257600080fd5b506100a0600160a060020a036004351660243561030d565b34801561015657600080fd5b506100c9600160a060020a03600435811690602435166103ce565b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a350600192915050565b60025490565b600160a060020a03831660009081526020819052604081205482111561020657600080fd5b600160a060020a038085166000908152600160209081526040808320339094168352929052205482111561023957600080fd5b600160a060020a03831660009081526020819052604090205461025c90836103f9565b151561026757600080fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b600160a060020a031660009081526020819052604090205490565b600160a060020a03331660009081526020819052604081205482111561033257600080fd5b600160a060020a03831660009081526020819052604090205461035590836103f9565b151561036057600080fd5b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a350600192915050565b600160a060020a03918216600090815260016020908152604080832093909416825291909152205490565b81011015905600a165627a7a72305820c34209c42f57b08f62d29e65db6744b4c8991eee33c4c83e0d81674550945da80029","runtimeBytecode":"6080604052600436106100775763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007c57806318160ddd146100b457806323b872dd146100db57806370a0823114610105578063a9059cbb14610126578063dd62ed3e1461014a575b600080fd5b34801561008857600080fd5b506100a0600160a060020a0360043516602435610171565b604080519115158252519081900360200190f35b3480156100c057600080fd5b506100c96101db565b60408051918252519081900360200190f35b3480156100e757600080fd5b506100a0600160a060020a03600435811690602435166044356101e1565b34801561011157600080fd5b506100c9600160a060020a03600435166102f2565b34801561013257600080fd5b506100a0600160a060020a036004351660243561030d565b34801561015657600080fd5b506100c9600160a060020a03600435811690602435166103ce565b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a350600192915050565b60025490565b600160a060020a03831660009081526020819052604081205482111561020657600080fd5b600160a060020a038085166000908152600160209081526040808320339094168352929052205482111561023957600080fd5b600160a060020a03831660009081526020819052604090205461025c90836103f9565b151561026757600080fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b600160a060020a031660009081526020819052604090205490565b600160a060020a03331660009081526020819052604081205482111561033257600080fd5b600160a060020a03831660009081526020819052604090205461035590836103f9565b151561036057600080fd5b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a350600192915050565b600160a060020a03918216600090815260016020908152604080832093909416825291909152205490565b81011015905600a165627a7a72305820c34209c42f57b08f62d29e65db6744b4c8991eee33c4c83e0d81674550945da80029","realRuntimeBytecode":"6080604052600436106100775763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007c57806318160ddd146100b457806323b872dd146100db57806370a0823114610105578063a9059cbb14610126578063dd62ed3e1461014a575b600080fd5b34801561008857600080fd5b506100a0600160a060020a0360043516602435610171565b604080519115158252519081900360200190f35b3480156100c057600080fd5b506100c96101db565b60408051918252519081900360200190f35b3480156100e757600080fd5b506100a0600160a060020a03600435811690602435166044356101e1565b34801561011157600080fd5b506100c9600160a060020a03600435166102f2565b34801561013257600080fd5b506100a0600160a060020a036004351660243561030d565b34801561015657600080fd5b506100c9600160a060020a03600435811690602435166103ce565b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a350600192915050565b60025490565b600160a060020a03831660009081526020819052604081205482111561020657600080fd5b600160a060020a038085166000908152600160209081526040808320339094168352929052205482111561023957600080fd5b600160a060020a03831660009081526020819052604090205461025c90836103f9565b151561026757600080fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b600160a060020a031660009081526020819052604090205490565b600160a060020a03331660009081526020819052604081205482111561033257600080fd5b600160a060020a03831660009081526020819052604090205461035590836103f9565b151561036057600080fd5b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a350600192915050565b600160a060020a03918216600090815260016020908152604080832093909416825291909152205490565b81011015905600a165627a7a72305820","swarmHash":"c34209c42f57b08f62d29e65db6744b4c8991eee33c4c83e0d81674550945da8","gasEstimates":{"creation":{"codeDepositCost":"213600","executionCost":"40466","totalCost":"254066"},"external":{"allowance(address,address)":"818","approve(address,uint256)":"22344","balanceOf(address)":"675","totalSupply()":"406","transfer(address,uint256)":"43625","transferFrom(address,address,uint256)":"64402"},"internal":{"safeToAdd(uint256,uint256)":"24"}},"functionHashes":{"allowance(address,address)":"dd62ed3e","approve(address,uint256)":"095ea7b3","balanceOf(address)":"70a08231","totalSupply()":"18160ddd","transfer(address,uint256)":"a9059cbb","transferFrom(address,address,uint256)":"23b872dd"},"abiDefinition":[{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"value","type":"uint256"}],"name":"approve","outputs":[{"name":"ok","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"supply","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"ok","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"who","type":"address"}],"name":"balanceOf","outputs":[{"name":"value","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"ok","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"_allowance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"initial_balance","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}],"filename":"test/contracts/token.sol"}; diff --git a/test/contracts.js b/test/contracts.js index bb695dc7..b8452b80 100644 --- a/test/contracts.js +++ b/test/contracts.js @@ -26,9 +26,12 @@ describe('embark.Contracts', function() { describe('simple', function() { let plugins = new Plugins({ logger: new TestLogger({}), - events: TestEvents + events: TestEvents, + config: { + contractDirectories: ['app/contracts/'] + } }); - plugins.loadInternalPlugin('solidity', {solcVersion: '0.4.17', contractDirectories: ['app/contracts/']}); + plugins.loadInternalPlugin('solidity'); let compiler = new Compiler({plugins: plugins, logger: plugins.logger}); let events = new Events(); @@ -115,9 +118,12 @@ describe('embark.Contracts', function() { describe('config with contract instances', function() { let plugins = new Plugins({ logger: new TestLogger({}), - events: TestEvents + events: TestEvents, + config: { + contractDirectories: ['app/contracts/'] + } }); - plugins.loadInternalPlugin('solidity', {solcVersion: '0.4.17', contractDirectories: ['app/contracts/']}); + plugins.loadInternalPlugin('solidity'); let compiler = new Compiler({plugins: plugins, logger: plugins.logger}); let events = new Events(); From 20d7496980e7724632196026e7158c6d7e2e43fa Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 31 May 2018 10:02:57 -0400 Subject: [PATCH 27/28] take into account errors when determining arguments --- lib/contracts/contract_deployer.js | 9 +++++---- lib/contracts/deploy_manager.js | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/contracts/contract_deployer.js b/lib/contracts/contract_deployer.js index 921f9f2a..23476954 100644 --- a/lib/contracts/contract_deployer.js +++ b/lib/contracts/contract_deployer.js @@ -59,9 +59,7 @@ class ContractDeployer { } else { nextEachCb(null, arg); } - }, (err, realArgs) => { - callback(realArgs); - }); + }, callback); } checkAndDeployContract(contract, params, callback) { @@ -75,7 +73,10 @@ class ContractDeployer { async.waterfall([ function _determineArguments(next) { - self.determineArguments(params || contract.args, contract, (realArgs) => { + self.determineArguments(params || contract.args, contract, (err, realArgs) => { + if (err) { + return next(err); + } contract.realArgs = realArgs; next(); }); diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index 815847d3..ff87adf4 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -44,7 +44,6 @@ class DeployManager { return done(); } self.logger.info(__("finished deploying contracts")); - self.logger.trace(arguments); done(err); } ); From 9929415da888507764df4a69228d68cc621c1917 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 31 May 2018 10:09:26 -0400 Subject: [PATCH 28/28] remove unneded passing of contracts manager --- lib/core/engine.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/core/engine.js b/lib/core/engine.js index 671b7cd0..cf7336e2 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -180,12 +180,12 @@ class Engine { self.events.emit('code-generator-ready'); }); }; - const cargo = async.cargo((tasks, callback) => { - generateCode(tasks[tasks.length - 1].contractsManager); + const cargo = async.cargo((_tasks, callback) => { + generateCode(); self.events.once('outputDone', callback); }); const addToCargo = function () { - cargo.push({contractsManager: self.contractsManager}); + cargo.push({}); }; this.events.on('contractsDeployed', addToCargo); @@ -230,7 +230,6 @@ class Engine { logger: this.logger, events: this.events, plugins: this.plugins - //gasLimit: options.gasLimit }); this.events.on('file-event', function (fileType) {