commit
8719ce8667
@ -1,19 +1,62 @@ |
||||
#!/usr/bin/env node
|
||||
var Router = require('./router') |
||||
var program = require('commander') |
||||
var startmistGeth = require('./services/startMistGeth') |
||||
var startFrontend = require('./services/startFrontend') |
||||
var fs = require('fs-extra') |
||||
|
||||
program |
||||
.usage('-S <shared folder>') |
||||
.description('Provide a two ways connection between the local computer and Remix IDE') |
||||
.option('-S, --shared-folder <path>', 'Folder to share with Remix IDE') |
||||
.option('-s, --shared-folder <path>', 'Folder to share with Remix IDE') |
||||
.option('-m, --mist', 'start mist') |
||||
.option('-g, --geth', 'start geth') |
||||
.option('-p, --dev-path <dev-path>', 'Folder used by mist/geth to start the development instance') |
||||
.option('-f, --frontend <front-end>', 'Folder that should be served by remixd') |
||||
.option('-p, --frontend-port <front-end-port>', 'Http port used by the frontend (default 8082)') |
||||
.option('-a, --auto-mine', 'mine pending transactions') |
||||
.option('-r, --rpc <cors-domains>', 'start rpc server. Values are CORS domain') |
||||
.option('-rp, --rpc-port', 'rpc server port (default 8545)') |
||||
.parse(process.argv) |
||||
console.log('example: --dev-path /home/devchains/chain1 --mist --geth --frontend /home/frontend --frontend-port 8084 --auto-mine') |
||||
program.outputHelp() |
||||
|
||||
var killCallBack = [] |
||||
|
||||
if (program.devPath) { |
||||
if (fs.existsSync(program.devPath)) { |
||||
killCallBack.push(startmistGeth(program.devPath, program.mist, program.geth, program.autoMine, program.rpc, program.rpcPort)) |
||||
} else { |
||||
console.log('\x1b[31m%s\x1b[0m', '[ERR] can\'t start mist/geth. ' + program.devPath + ' does not exist') |
||||
} |
||||
} |
||||
|
||||
if (!program.sharedFolder) { |
||||
program.outputHelp() |
||||
process.exit(1) |
||||
} else { |
||||
if (program.frontend) { |
||||
if (!program.frontendPort) program.frontendPort = 8082 |
||||
if (fs.existsSync(program.frontend)) { |
||||
killCallBack.push(startFrontend(program.frontend, program.frontendPort)) |
||||
} else { |
||||
console.log('\x1b[31m%s\x1b[0m', '[ERR] can\'t start frontend. ' + program.frontend + ' does not exist') |
||||
} |
||||
} |
||||
|
||||
if (program.sharedFolder) { |
||||
console.log('\x1b[33m%s\x1b[0m', '[WARN] Any application that runs on your computer can potentially read from and write to all files in the directory.') |
||||
console.log('\x1b[33m%s\x1b[0m', '[WARN] Symbolinc links are not forwarded to Remix IDE\n') |
||||
var router = new Router() |
||||
killCallBack.push(router.start(program.sharedFolder)) |
||||
} |
||||
|
||||
var router = new Router() |
||||
router.start(program.sharedFolder) |
||||
// kill
|
||||
function kill () { |
||||
for (var k in killCallBack) { |
||||
try { |
||||
killCallBack[k]() |
||||
} catch (e) { |
||||
console.log(e) |
||||
} |
||||
} |
||||
} |
||||
process.on('SIGINT', kill) // catch ctrl-c
|
||||
process.on('SIGTERM', kill) // catch kill
|
||||
process.on('exit', kill) |
||||
|
@ -0,0 +1,37 @@ |
||||
module.exports = function (web3) { |
||||
console.log('auto mine transactions') |
||||
|
||||
var methods = [] |
||||
methods.push({ |
||||
name: 'start', |
||||
call: 'miner_start', |
||||
inputFormatter: [null], |
||||
params: 1 |
||||
}) |
||||
methods.push({ |
||||
name: 'stop', |
||||
call: 'miner_stop', |
||||
inputFormatter: [], |
||||
params: 0 |
||||
}) |
||||
web3.extend({ |
||||
property: 'miner', |
||||
methods: methods, |
||||
properties: [] |
||||
}) |
||||
|
||||
var timeOutId |
||||
web3.eth.subscribe('pendingTransactions', (error, result) => { |
||||
if (error) { |
||||
console.log(error) |
||||
} else { |
||||
console.log('start or continue mining') |
||||
web3.miner.start() |
||||
if (timeOutId) clearTimeout(timeOutId) |
||||
timeOutId = setTimeout(() => { |
||||
console.log('stop mining') |
||||
web3.miner.stop() |
||||
}, 30000) |
||||
} |
||||
}) |
||||
} |
@ -0,0 +1,13 @@ |
||||
const serve = require('serve') |
||||
|
||||
module.exports = function (path, port) { |
||||
var server = serve(path, { |
||||
port: port |
||||
}) |
||||
|
||||
function kill () { |
||||
console.log('stopping frontend') |
||||
server.stop() |
||||
} |
||||
return kill |
||||
} |
@ -0,0 +1,99 @@ |
||||
var spawn = require('child_process').spawn |
||||
var stdout = require('stdout') |
||||
var autoMine = require('./autoMine') |
||||
var Web3 = require('web3') |
||||
var net = require('net') |
||||
|
||||
var connectTimeout |
||||
module.exports = function (dataDir, mist, geth, mine, rpc, rpcPort) { |
||||
console.log('opening dev env at ' + dataDir) |
||||
// geth --vmdebug --dev --ipcpath /home/yann/Ethereum/testchains/test2/geth.ipc --datadir /home/yann/Ethereum/testchains/test2
|
||||
var gethprocess |
||||
if (geth) { |
||||
var ipcPath = dataDir + '/geth.ipc' |
||||
var gethArgs = [ |
||||
'--vmdebug', |
||||
'--dev', |
||||
'--ipcpath', ipcPath, |
||||
'--datadir', dataDir |
||||
] |
||||
if (rpc) { |
||||
gethArgs.push('--rpc') |
||||
gethArgs.push('--rpccorsdomain') |
||||
gethArgs.push(rpc) |
||||
gethArgs.push('--rpcapi') |
||||
gethArgs.push('web3,eth,debug,net') |
||||
if (!rpcPort) { |
||||
rpcPort = 8545 |
||||
} |
||||
gethArgs.push('--rpcport') |
||||
gethArgs.push(rpcPort) |
||||
} |
||||
console.log(gethArgs) |
||||
console.log('starting geth ... ') |
||||
gethprocess = run('geth', gethArgs) |
||||
|
||||
connectTimeout = setInterval(() => { |
||||
connectWeb3(ipcPath, (web3) => { |
||||
clearInterval(connectTimeout) |
||||
if (mine) { |
||||
autoMine(web3) |
||||
} |
||||
}) |
||||
}, 1000) |
||||
} |
||||
|
||||
// mist --rpc /home/yann/Ethereum/testchains/test2/geth.ipc
|
||||
var mistprocess |
||||
if (mist) { |
||||
const mistArgs = [ |
||||
'--rpc', ipcPath |
||||
] |
||||
console.log('starting mist ...') |
||||
mistprocess = run('mist', mistArgs) |
||||
} |
||||
|
||||
function kill () { |
||||
if (connectTimeout) { |
||||
clearInterval(connectTimeout) |
||||
} |
||||
if (mistprocess) { |
||||
console.log('stopping mist') |
||||
mistprocess.kill() |
||||
} |
||||
if (gethprocess) { |
||||
console.log('stopping geth') |
||||
gethprocess.kill() |
||||
} |
||||
} |
||||
|
||||
return kill |
||||
} |
||||
|
||||
function connectWeb3 (ipcpath, cb) { |
||||
try { |
||||
console.log('connect to ' + ipcpath) |
||||
var web3 = new Web3(new Web3.providers.IpcProvider(ipcpath, net)) |
||||
web3.eth.getBlockNumber(function (error) { |
||||
if (error) { |
||||
console.log('still trying to connect to node... ' + error) |
||||
} else { |
||||
cb(web3) |
||||
} |
||||
}) |
||||
} catch (e) {} |
||||
} |
||||
|
||||
function run (app, args) { |
||||
var proc |
||||
try { |
||||
proc = spawn(app, args) |
||||
proc.on('error', (err) => { |
||||
console.log('\x1b[31m%s\x1b[0m', '[ERR] can\'t start ' + app + '. seems not installed') |
||||
console.log(err) |
||||
}) |
||||
proc.stdout.pipe(stdout()) |
||||
} catch (e) { |
||||
} |
||||
return proc |
||||
} |
Loading…
Reference in new issue