From e2efbbd846def8ede7eebadf415b111f75e718d6 Mon Sep 17 00:00:00 2001 From: Eric Mastro Date: Wed, 16 Oct 2019 22:35:26 +0900 Subject: [PATCH] refactor(@embark/parity): move module into own package (#1951) Contains bug fixes to get parity to work as a blockchain client. **NOTE:** Please merge https://github.com/embark-framework/embark/pull/1950 first before merging this PR, as this PR contains removal of dependencies from `packages/embark` that are needed for geth. So if this is merged first, and the geth PR (https://github.com/embark-framework/embark/pull/1950) is not merged, then geth will not have some of the dependencies it needs. --- packages/core/utils/package.json | 3 +- packages/embark/package.json | 3 +- packages/embark/src/lib/core/engine.js | 2 +- packages/embark/tsconfig.json | 4 -- packages/embark/tslint.json | 3 - packages/plugins/parity/.npmrc | 4 ++ packages/plugins/parity/README.md | 6 ++ packages/plugins/parity/package.json | 71 +++++++++++++++++++ .../parity/src}/blockchain.js | 8 --- .../parity/src}/blockchainProcess.js | 0 .../parity/src}/blockchainProcessLauncher.js | 0 .../parity => plugins/parity/src}/check.js | 0 .../parity => plugins/parity/src}/index.js | 16 +++-- .../parity => plugins/parity/src}/miner.js | 0 .../parity/src}/parityClient.js | 0 packages/plugins/parity/tsconfig.json | 5 ++ packages/plugins/parity/tslint.json | 3 + 17 files changed, 104 insertions(+), 24 deletions(-) delete mode 100644 packages/embark/tsconfig.json delete mode 100644 packages/embark/tslint.json create mode 100644 packages/plugins/parity/.npmrc create mode 100644 packages/plugins/parity/README.md create mode 100644 packages/plugins/parity/package.json rename packages/{embark/src/lib/modules/parity => plugins/parity/src}/blockchain.js (98%) rename packages/{embark/src/lib/modules/parity => plugins/parity/src}/blockchainProcess.js (100%) rename packages/{embark/src/lib/modules/parity => plugins/parity/src}/blockchainProcessLauncher.js (100%) rename packages/{embark/src/lib/modules/parity => plugins/parity/src}/check.js (100%) rename packages/{embark/src/lib/modules/parity => plugins/parity/src}/index.js (89%) rename packages/{embark/src/lib/modules/parity => plugins/parity/src}/miner.js (100%) rename packages/{embark/src/lib/modules/parity => plugins/parity/src}/parityClient.js (100%) create mode 100644 packages/plugins/parity/tsconfig.json create mode 100644 packages/plugins/parity/tslint.json diff --git a/packages/core/utils/package.json b/packages/core/utils/package.json index 48ccd2fe4..cd478280b 100644 --- a/packages/core/utils/package.json +++ b/packages/core/utils/package.json @@ -65,7 +65,8 @@ "shelljs": "0.8.3", "web3": "1.2.1", "web3-eth": "1.2.1", - "web3-eth-abi": "1.2.1" + "web3-eth-abi": "1.2.1", + "ws": "7.1.2" }, "devDependencies": { "@types/follow-redirects": "1.5.0", diff --git a/packages/embark/package.json b/packages/embark/package.json index 48abf6b99..a337753ba 100644 --- a/packages/embark/package.json +++ b/packages/embark/package.json @@ -116,6 +116,7 @@ "embark-logger": "^4.1.1", "embark-mocha-tests": "^4.1.1", "embark-namesystem": "^4.1.1", + "embark-parity": "^4.1.1", "embark-pipeline": "^4.1.1", "embark-plugin-cmd": "^4.1.1", "embark-process-logs-api-manager": "^4.1.1", @@ -162,7 +163,6 @@ "lodash.clonedeep": "4.5.0", "mocha": "6.2.0", "neo-blessed": "0.2.0", - "netcat": "1.3.5", "node-http-proxy-json": "0.1.6", "node-ipc": "9.1.1", "node-sass": "4.9.3", @@ -211,7 +211,6 @@ "web3-shh": "1.2.1", "web3-utils": "1.2.1", "window-size": "1.1.1", - "ws": "7.1.2", "yo-yoify": "4.3.0" }, "devDependencies": { diff --git a/packages/embark/src/lib/core/engine.js b/packages/embark/src/lib/core/engine.js index 1ab2c37af..d398bcfb8 100644 --- a/packages/embark/src/lib/core/engine.js +++ b/packages/embark/src/lib/core/engine.js @@ -191,7 +191,7 @@ class Engine { plugins: this.plugins, ipc: this.ipc }); - this.registerModule('parity', { + this.registerModulePackage('embark-parity', { client: this.client, locale: this.locale, isDev: this.isDev, diff --git a/packages/embark/tsconfig.json b/packages/embark/tsconfig.json deleted file mode 100644 index 52d43eaaa..000000000 --- a/packages/embark/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "include": ["src/**/*"] -} diff --git a/packages/embark/tslint.json b/packages/embark/tslint.json deleted file mode 100644 index 0946f2096..000000000 --- a/packages/embark/tslint.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "../../tslint.json" -} diff --git a/packages/plugins/parity/.npmrc b/packages/plugins/parity/.npmrc new file mode 100644 index 000000000..e031d3432 --- /dev/null +++ b/packages/plugins/parity/.npmrc @@ -0,0 +1,4 @@ +engine-strict = true +package-lock = false +save-exact = true +scripts-prepend-node-path = true diff --git a/packages/plugins/parity/README.md b/packages/plugins/parity/README.md new file mode 100644 index 000000000..4fe7c7c4b --- /dev/null +++ b/packages/plugins/parity/README.md @@ -0,0 +1,6 @@ +# `embark-parity` + +> Implementation of the Parity blockchain for Embark + +Visit [embark.status.im](https://embark.status.im/) to get started with +[Embark](https://github.com/embark-framework/embark). diff --git a/packages/plugins/parity/package.json b/packages/plugins/parity/package.json new file mode 100644 index 000000000..d75347086 --- /dev/null +++ b/packages/plugins/parity/package.json @@ -0,0 +1,71 @@ +{ + "name": "embark-parity", + "version": "4.1.1", + "author": "Iuri Matias ", + "contributors": [], + "description": "Implementation of the Parity blockchain for Embark", + "homepage": "https://github.com/embark-framework/embark/tree/master/packages/plugins/parity#readme", + "bugs": "https://github.com/embark-framework/embark/issues", + "keywords": [ + "blockchain", + "dapps", + "ethereum", + "ipfs", + "serverless", + "solc", + "solidity" + ], + "files": [ + "dist" + ], + "license": "MIT", + "repository": { + "directory": "packages/plugins/parity", + "type": "git", + "url": "https://github.com/embark-framework/embark.git" + }, + "main": "./dist/index.js", + "embark-collective": { + "build:node": true + }, + "scripts": { + "_build": "npm run solo -- build", + "ci": "npm run qa", + "clean": "npm run reset", + "lint": "npm-run-all lint:*", + "lint:ts": "tslint -c tslint.json \"src/**/*.ts\"", + "qa": "npm-run-all lint typecheck _build", + "reset": "npx rimraf dist embark-*.tgz package", + "solo": "embark-solo", + "typecheck": "tsc", + "watch": "run-p watch:*", + "watch:typecheck": "npm run typecheck -- --preserveWatchOutput --watch" + }, + "eslintConfig": { + "extends": "../../../.eslintrc.json" + }, + "dependencies": { + "@babel/runtime-corejs2": "7.6.2", + "async": "2.6.1", + "embark-core": "^4.1.1", + "embark-i18n": "^4.1.1", + "embark-utils": "^4.1.1", + "fs-extra": "8.1.0", + "netcat": "1.3.5", + "semver": "5.6.0", + "ws": "7.1.2" + }, + "devDependencies": { + "embark-solo": "^4.1.1", + "eslint": "5.7.0", + "npm-run-all": "4.1.5", + "rimraf": "3.0.0", + "tslint": "5.16.0", + "typescript": "3.6.3" + }, + "engines": { + "node": ">=8.12.0 <12.0.0", + "npm": ">=6.4.1", + "yarn": ">=1.12.3" + } +} diff --git a/packages/embark/src/lib/modules/parity/blockchain.js b/packages/plugins/parity/src/blockchain.js similarity index 98% rename from packages/embark/src/lib/modules/parity/blockchain.js rename to packages/plugins/parity/src/blockchain.js index 840bd9c3e..cdf69b6a8 100644 --- a/packages/embark/src/lib/modules/parity/blockchain.js +++ b/packages/plugins/parity/src/blockchain.js @@ -104,7 +104,6 @@ var Blockchain = function (userConfig, clientClass) { this.logger.error(__(spaceMessage, 'genesisBlock')); process.exit(1); } - this.initProxy(); this.client = new clientClass({config: this.config, env: this.env, isDev: this.isDev}); this.initStandaloneProcess(); @@ -154,13 +153,6 @@ Blockchain.prototype.initStandaloneProcess = function () { } }; -Blockchain.prototype.initProxy = function () { - if (this.config.proxy) { - this.config.rpcPort += constants.blockchain.servicePortOnProxy; - this.config.wsPort += constants.blockchain.servicePortOnProxy; - } -}; - Blockchain.prototype.setupProxy = async function () { // if (!this.proxyIpc) this.proxyIpc = new IPC({ipcRole: 'client'}); diff --git a/packages/embark/src/lib/modules/parity/blockchainProcess.js b/packages/plugins/parity/src/blockchainProcess.js similarity index 100% rename from packages/embark/src/lib/modules/parity/blockchainProcess.js rename to packages/plugins/parity/src/blockchainProcess.js diff --git a/packages/embark/src/lib/modules/parity/blockchainProcessLauncher.js b/packages/plugins/parity/src/blockchainProcessLauncher.js similarity index 100% rename from packages/embark/src/lib/modules/parity/blockchainProcessLauncher.js rename to packages/plugins/parity/src/blockchainProcessLauncher.js diff --git a/packages/embark/src/lib/modules/parity/check.js b/packages/plugins/parity/src/check.js similarity index 100% rename from packages/embark/src/lib/modules/parity/check.js rename to packages/plugins/parity/src/check.js diff --git a/packages/embark/src/lib/modules/parity/index.js b/packages/plugins/parity/src/index.js similarity index 89% rename from packages/embark/src/lib/modules/parity/index.js rename to packages/plugins/parity/src/index.js index de99834c0..fa02c1eef 100644 --- a/packages/embark/src/lib/modules/parity/index.js +++ b/packages/plugins/parity/src/index.js @@ -23,7 +23,8 @@ class Parity { return; } - this.events.request("blockchain:node:register", constants.blockchain.clients.parity, (readyCb) => { + this.events.request("blockchain:node:register", constants.blockchain.clients.parity, { + launchFn: (readyCb) => { this.events.request('processes:register', 'blockchain', { launchFn: (cb) => { // this.startBlockchainNode(readyCb); @@ -40,12 +41,17 @@ class Parity { readyCb(); }); this.registerServiceCheck(); - }); + }, + stopFn: async (cb) => { + await this.events.request("processes:stop", "blockchain"); + cb(); + } + }); } shouldInit() { return ( - this.blockchainConfig.client === constants.blockchain.clients.geth && + this.blockchainConfig.client === constants.blockchain.clients.parity && this.blockchainConfig.enabled ); } @@ -64,9 +70,9 @@ class Parity { this.events.request("services:register", 'Ethereum', (cb) => { const {rpcHost, rpcPort, wsRPC, wsHost, wsPort} = this.blockchainConfig; if (wsRPC) { - return ws(wsHost, wsPort + 10, (err, version) => this._getNodeState(err, version, cb)); + return ws(wsHost, wsPort, (err, version) => this._getNodeState(err, version, cb)); } - rpc(rpcHost, rpcPort + 10, (err, version) => this._getNodeState(err, version, cb)); + rpc(rpcHost, rpcPort, (err, version) => this._getNodeState(err, version, cb)); }, 5000, 'off'); } diff --git a/packages/embark/src/lib/modules/parity/miner.js b/packages/plugins/parity/src/miner.js similarity index 100% rename from packages/embark/src/lib/modules/parity/miner.js rename to packages/plugins/parity/src/miner.js diff --git a/packages/embark/src/lib/modules/parity/parityClient.js b/packages/plugins/parity/src/parityClient.js similarity index 100% rename from packages/embark/src/lib/modules/parity/parityClient.js rename to packages/plugins/parity/src/parityClient.js diff --git a/packages/plugins/parity/tsconfig.json b/packages/plugins/parity/tsconfig.json new file mode 100644 index 000000000..1ffac409c --- /dev/null +++ b/packages/plugins/parity/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { "baseUrl": ".", "paths": { "*": ["types/*"] } }, + "extends": "../../../tsconfig.json", + "include": ["src/**/*"] +} diff --git a/packages/plugins/parity/tslint.json b/packages/plugins/parity/tslint.json new file mode 100644 index 000000000..1f63906f0 --- /dev/null +++ b/packages/plugins/parity/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../../../tslint.json" +}