add optioan to specify rpc server option

pull/7/head
Iuri Matias 6 years ago
parent dc0865fc8c
commit 45e865d542
  1. 4
      remix-simulator/bin/ethsim
  2. 12
      remix-simulator/src/server.js

@ -23,11 +23,13 @@ program
.option('-p, --port [port]', 'specify port') .option('-p, --port [port]', 'specify port')
.option('-b, --ip [host]', 'specify host') .option('-b, --ip [host]', 'specify host')
.option('-c, --coinbase [coinbase]', 'specify host') .option('-c, --coinbase [coinbase]', 'specify host')
.option('--rpc', 'run rpc server only')
.parse(process.argv) .parse(process.argv)
const Server = require('../src/server') const Server = require('../src/server')
const server = new Server({ const server = new Server({
coinbase: program.coinbase || "0x0000000000000000000000000000000000000000" coinbase: program.coinbase || "0x0000000000000000000000000000000000000000",
rpc: program.rpc
}) })
server.start(program.host || '127.0.0.1', program.port || 8545) server.start(program.host || '127.0.0.1', program.port || 8545)

@ -14,6 +14,7 @@ class Server {
}).catch((error) => { }).catch((error) => {
log(error) log(error)
}) })
this.rpcOnly = options.rpc;
} }
start (host, port) { start (host, port) {
@ -24,28 +25,31 @@ class Server {
app.use(bodyParser.json()) app.use(bodyParser.json())
app.get('/', (req, res) => { app.get('/', (req, res) => {
console.dir("/ request")
res.send('Welcome to remix-simulator') res.send('Welcome to remix-simulator')
}) })
if (this.rpcOnly) {
app.use((req, res) => { app.use((req, res) => {
this.provider.sendAsync(req.body, (err, jsonResponse) => { this.provider.sendAsync(req.body, (err, jsonResponse) => {
if (err) { if (err) {
return res.send(JSON.stringify({error: err})) return res.send(JSON.stringify({ error: err }))
} }
res.send(jsonResponse) res.send(jsonResponse)
}) })
}) })
} else {
app.ws('/', (ws, req) => { app.ws('/', (ws, req) => {
ws.on('message', function (msg) { ws.on('message', (msg) => {
this.provider.sendAsync(JSON.parse(msg), (err, jsonResponse) => { this.provider.sendAsync(JSON.parse(msg), (err, jsonResponse) => {
if (err) { if (err) {
return ws.send(JSON.stringify({error: err})) return ws.send(JSON.stringify({ error: err }))
} }
ws.send(JSON.stringify(jsonResponse)) ws.send(JSON.stringify(jsonResponse))
}) })
}) })
}) })
}
app.listen(port, host, () => log('Remix Simulator listening on port ' + host + ':' + port)) app.listen(port, host, () => log('Remix Simulator listening on port ' + host + ':' + port))
} }

Loading…
Cancel
Save