chore(@embark/blockchain-listeener): remove blockchain-listener package (#1887)

This commit is contained in:
Iuri Matias 2019-09-11 12:32:16 -04:00 committed by GitHub
parent ee634c8403
commit 8849aca264
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 0 additions and 393 deletions

View File

@ -1,4 +0,0 @@
engine-strict = true
package-lock = false
save-exact = true
scripts-prepend-node-path = true

View File

@ -1,64 +0,0 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [4.1.1](https://github.com/embark-framework/embark/compare/v4.1.0...v4.1.1) (2019-08-28)
**Note:** Version bump only for package embark-blockchain-listener
# [4.1.0](https://github.com/embark-framework/embark/compare/v4.1.0-beta.6...v4.1.0) (2019-08-12)
**Note:** Version bump only for package embark-blockchain-listener
# [4.1.0-beta.6](https://github.com/embark-framework/embark/compare/v4.1.0-beta.5...v4.1.0-beta.6) (2019-08-09)
**Note:** Version bump only for package embark-blockchain-listener
# [4.1.0-beta.5](https://github.com/embark-framework/embark/compare/v4.1.0-beta.4...v4.1.0-beta.5) (2019-07-10)
**Note:** Version bump only for package embark-blockchain-listener
# [4.1.0-beta.4](https://github.com/embark-framework/embark/compare/v4.1.0-beta.3...v4.1.0-beta.4) (2019-06-27)
**Note:** Version bump only for package embark-blockchain-listener
# [4.1.0-beta.3](https://github.com/embark-framework/embark/compare/v4.1.0-beta.2...v4.1.0-beta.3) (2019-06-07)
**Note:** Version bump only for package embark-blockchain-listener
# [4.1.0-beta.2](https://github.com/embark-framework/embark/compare/v4.1.0-beta.1...v4.1.0-beta.2) (2019-05-22)
**Note:** Version bump only for package embark-blockchain-listener
# [4.1.0-beta.1](https://github.com/embark-framework/embark/compare/v4.1.0-beta.0...v4.1.0-beta.1) (2019-05-15)
**Note:** Version bump only for package embark-blockchain-listener

View File

@ -1,6 +0,0 @@
# `embark-blockchain-listener`
> Blockchain Listener APIs for Embark
Visit [embark.status.im](https://embark.status.im/) to get started with
[Embark](https://github.com/embark-framework/embark).

View File

@ -1,70 +0,0 @@
{
"name": "embark-blockchain-listener",
"version": "4.1.1",
"author": "Iuri Matias <iuri.matias@gmail.com>",
"contributors": [],
"description": "Blockchain Listener APIs for Embark",
"homepage": "https://github.com/embark-framework/embark/tree/master/packages/embark-blockchain-listener#readme",
"bugs": "https://github.com/embark-framework/embark/issues",
"keywords": [
"blockchain",
"dapps",
"ethereum",
"ipfs",
"serverless",
"solc",
"solidity"
],
"files": [
"dist"
],
"license": "MIT",
"repository": {
"directory": "packages/embark-blockchain-listener",
"type": "git",
"url": "https://github.com/embark-framework/embark.git"
},
"main": "./dist/index.js",
"scripts": {
"build": "cross-env BABEL_ENV=node babel src --extensions \".js\" --out-dir dist --root-mode upward --source-maps",
"ci": "npm run qa",
"clean": "npm run reset",
"lint": "npm-run-all lint:*",
"lint:js": "eslint src/",
"// lint:ts": "tslint -c tslint.json \"src/**/*.ts\"",
"package": "npm pack",
"// qa": "npm-run-all lint typecheck build package",
"qa": "npm-run-all lint build package",
"reset": "npx rimraf dist embark-*.tgz package",
"start": "npm run watch",
"// typecheck": "tsc",
"watch": "run-p watch:*",
"watch:build": "npm run build -- --verbose --watch",
"// watch:typecheck": "npm run typecheck -- --preserveWatchOutput --watch"
},
"eslintConfig": {
"extends": "../../.eslintrc.json"
},
"dependencies": {
"@babel/runtime-corejs2": "7.3.1",
"async": "2.6.1",
"embark-core": "^4.1.1",
"embark-utils": "^4.1.1",
"web3": "1.2.1"
},
"devDependencies": {
"@babel/cli": "7.2.3",
"@babel/core": "7.2.2",
"cross-env": "5.2.0",
"eslint": "5.7.0",
"npm-run-all": "4.1.5",
"rimraf": "3.0.0",
"tslint": "5.16.0",
"typescript": "3.4.5"
},
"engines": {
"node": ">=8.12.0 <12.0.0",
"npm": ">=6.4.1",
"yarn": ">=1.12.3"
}
}

View File

@ -1,74 +0,0 @@
import { buildUrl, defaultHost, dockerHostSwap } from 'embark-utils';
const Web3 = require('web3');
const constants = require('embark-core/constants');
class DevTxs {
constructor(options) {
this.blockchainConfig = options.blockchainConfig;
this.networkId = null;
if (options.provider) {
this.provider = options.provider;
} else if (this.blockchainConfig.wsRPC !== false) {
this.provider = new Web3.providers.WebsocketProvider(
buildUrl(
'ws',
dockerHostSwap(this.blockchainConfig.wsHost) || defaultHost,
this.blockchainConfig.wsPort || constants.blockchain.defaults.wsPort
),
{headers: {Origin: constants.embarkResourceOrigin}});
} else {
this.provider = new Web3.providers.HttpProvider(
buildUrl(
'http',
dockerHostSwap(this.blockchainConfig.rpcHost) || defaultHost,
this.blockchainConfig.rpcPort || constants.blockchain.defaults.rpcPort
)
);
}
this.web3 = new Web3(this.provider);
this.logger = options.logger || console;
}
static async new(options) {
const dt = new DevTxs(options);
await dt._init();
return dt;
}
async _init() {
const accounts = await this.web3.eth.getAccounts();
this.web3.eth.defaultAccount = accounts[0];
}
sendTx(cb) {
// Send TXs only in dev networks
if (this.networkId !== constants.blockchain.networkIds.development && this.networkId !== constants.blockchain.networkIds.development_parity) {
return;
}
this.web3.eth.sendTransaction({value: "0", to: this.web3.eth.defaultAccount, from: this.web3.eth.defaultAccount}).then(cb);
}
startRegularTxs(cb) {
const self = this;
self.web3.eth.net.getId().then((networkId) => {
self.networkId = networkId;
if (self.networkId !== constants.blockchain.networkIds.development && this.networkId !== constants.blockchain.networkIds.development_parity) {
return;
}
this.regularTxsInt = setInterval(function() { self.sendTx(() => {}); }, 1500);
if (cb) {
cb();
}
});
}
stopRegularTxs(cb) {
if(!this.regularTxsInt) {
return cb('Regular txs not enabled.');
}
clearInterval(this.regularTxsInt);
cb();
}
}
module.exports = DevTxs;

View File

@ -1,167 +0,0 @@
import { dappPath } from 'embark-utils';
import { __ } from 'embark-i18n';
const async = require('async');
const DevTxs = require('./dev_txs');
const constants = require('embark-core/constants');
const PROCESS_NAME = 'blockchain';
/**
* BlockchainListener has two functions:
* 1. Register API endpoints (HTTP GET and WS) to retrieve blockchain logs
* when in standalone mode (ie `embark blockchain`).
* 2. Listen to log events from the IPC connection (to `embark blockchain`)
* and ensure they are processed through the LogHandler.
*/
class BlockchainListener {
/**
* @param {Plugin} embark Embark module plugin object
* @param {Object} options Options object containing:
* - {Ipc} ipc IPC started by embark (in server role) used for communication
* with the standalone blockchain process.
*/
constructor(embark, {ipc}) {
this.embark = embark;
this.events = embark.events;
this.logger = embark.logger;
this.ipc = ipc;
this.isDev = this.embark.config.env === constants.environments.development;
this.devTxs = null;
this.fs = this.embark.fs;
this.proxyLogFile = dappPath(".embark", "proxyLogs.json");
this.writeProxyLogFile = async.cargo((tasks, callback) => {
const data = this._readProxyLogs();
tasks.forEach(task => {
data[new Date().getTime()] = task;
});
this.fs.writeJson(this.proxyLogFile, data, err => {
if (err) {
console.error(err);
}
callback();
});
});
this.ipc.server.once('connect', () => {
this.events.request('process:logs:register', {processName: PROCESS_NAME, eventName: "blockchain:log", silent: true});
this._listenToBlockchainLogs();
});
if (this.ipc.isServer() && this.isDev) {
this.events.request('blockchain:ready', () => {
DevTxs.new({blockchainConfig: this.embark.config.blockchainConfig}).then(devTxs => {
this.devTxs = devTxs;
this.events.emit('blockchain:devtxs:ready');
});
});
this._registerConsoleCommands();
this._listenToIpcCommands();
}
}
/**
* Listens to log events emitted by the standalone blockchain and ensures
* they are processed through the LogHandler.
*
* @return {void}
*/
_listenToBlockchainLogs() {
this.ipc.on('blockchain:log', ({logLevel, message}) => {
this.events.emit('blockchain:log', logLevel, message);
});
}
_listenToIpcCommands() {
this.ipc.on('blockchain:proxy:log', (log) => {
this.logger.trace(log);
});
this.ipc.on('blockchain:proxy:logtofile', (log) => {
this._saveProxyLog(log);
});
this.ipc.on('blockchain:devtxs:sendtx', () => {
this._sendTx(() => {});
});
}
_registerConsoleCommands() {
this.embark.registerConsoleCommand({
description: __('Toggles regular transactions used to prevent transactions from getting stuck when using Geth and Metamask'),
matches: ['devtxs on', 'devtxs off', 'regularTxs on', 'regularTxs off'],
usage: "devtxs on/off",
process: (cmd, callback) => {
if (cmd.startsWith('regularTxs')) {
this.logger.info(__("Deprecation notice: The command 'regularTxs on/off' is now deprecated in favor of 'devtxs on/off' and will be removed in future versions."));
}
const enable = cmd.trim().endsWith('on');
this.logger.info(`${enable ? 'Enabling' : 'Disabling'} regular transactions...`);
if(enable) {
return this._startRegularTxs(() => {
const message = __('Regular transactions have been enabled');
this.logger.info(message);
callback(null, message);
});
}
this._stopRegularTxs(() => {
const message = __('Regular transactions have been disabled');
this.logger.info(message);
callback(null, message);
});
}
});
this.embark.registerConsoleCommand({
description: __('Sends a transaction from default --dev account (generally used if txs are getting stuck in geth in development)'),
matches: ['senddevtx'],
process: (cmd, callback) => {
this.logger.info(__('Sending a tx from the dev account...'));
return this._sendTx((receipt) => {
const message = __('Transaction sent. Receipt:') + `\n${JSON.stringify(receipt)}`;
this.logger.debug(message);
callback(null, message);
});
}
});
}
_startRegularTxs(cb) {
if(this.devTxs) {
return this.devTxs.startRegularTxs(cb);
}
this.events.once('blockchain:devtxs:ready', () => { this.devTxs.startRegularTxs(cb); });
}
_stopRegularTxs(cb) {
if(this.devTxs) {
return this.devTxs.stopRegularTxs(cb);
}
this.events.once('blockchain:devtxs:ready', () => { this.devTxs.stopRegularTxs(cb); });
}
_sendTx(cb) {
if(this.devTxs) {
return this.devTxs.sendTx(cb);
}
this.events.once('blockchain:devtxs:ready', () => { this.devTxs.sendTx(cb); });
}
_saveProxyLog(log) {
this.writeProxyLogFile.push(log);
}
_readProxyLogs() {
this.fs.ensureFileSync(this.proxyLogFile);
try {
return JSON.parse(this.fs.readFileSync(this.proxyLogFile));
} catch (_error) {
return {};
}
}
}
module.exports = BlockchainListener;

View File

@ -1,4 +0,0 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*"]
}

View File

@ -1,3 +0,0 @@
{
"extends": "../../tslint.json"
}

View File

@ -93,7 +93,6 @@
"embark-accounts-manager": "^4.1.1",
"embark-api": "^4.1.1",
"embark-authenticator": "^4.1.1",
"embark-blockchain-listener": "^4.1.1",
"embark-code-runner": "^4.1.1",
"embark-compiler": "^4.1.1",
"embark-console": "^4.1.1",