Newer
Older
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
Luke Schoen
committed
// This file is part of Parity.
//
// SPDX-License-Identifier: BSD-3-Clause
import { runParity } from '@parity/electron';
Luke Schoen
committed
import { bundledParityPath, BUNDLED_IPC_PATH } from '../utils/paths';
Luke Schoen
committed
import handleError from '../utils/handleError';
import cli from '../cli';
import ipcChannel from '../ipcChannel';
Luke Schoen
committed
import Pino from '../utils/pino';
Luke Schoen
committed
const pino = Pino();
function wait (milliseconds) {
return new Promise(resolve => setTimeout(resolve, milliseconds));
}
Luke Schoen
committed
class ParityEthereum {
constructor () {
if (cli.ipcPath) {
pino.info('--ipc-path provided; connecting to', cli.ipcPath);
return ipcChannel.init(cli.ipcPath).catch(handleError);
}
pino.info('Running Parity Ethereum');
// Run the bundled Parity Ethereum
return this.run()
.then(async _ => {
// wait for the ipc socket file to be set up
do {
await wait(200);
} while (!fs.existsSync(BUNDLED_IPC_PATH));
})
.then(() => ipcChannel.init(BUNDLED_IPC_PATH))
.catch(handleError);
Luke Schoen
committed
Luke Schoen
committed
run = async () => {
return runParity({
flags: [
'--light',
'--no-jsonrpc',
'--no-ws',
'--ipc-path',
BUNDLED_IPC_PATH,
'--ipc-apis',
'all', // we need to enable personal to use personal_signTransaction
'--chain',
cli.chain
],
Luke Schoen
committed
onParityError: err =>
handleError(err, 'An error occured with Parity Ethereum.')
});
};
}
export default ParityEthereum;