split options & add helper

pull/4827/head
yann300 6 months ago
parent c0791ac74e
commit 0e2b49d560
  1. 37
      libs/remix-simulator/bin/ethsim
  2. 16
      libs/remix-simulator/src/server.ts

@ -23,22 +23,37 @@ program
.command('start') .command('start')
.option('-p, --port [port]', 'specify port', 8545) .option('-p, --port [port]', 'specify port', 8545)
.option('-b, --ip [host]', 'specify host', '127.0.0.1') .option('-b, --ip [host]', 'specify host', '127.0.0.1')
.option('-c, --coinbase [coinbase]', 'specify coinbase', '0x0000000000000000000000000000000000000000')
.option('--rpc', 'run rpc server only', true) .option('--rpc', 'run rpc server only', true)
.option('--details', 'display payloads for every requests and their responses', false) .option('--details', 'display payloads for every requests and their responses', false)
.action((option) => { .option('-c, --coinbase [coinbase]', 'specify coinbase', '0x0000000000000000000000000000000000000000')
console.log('coinbase: ', option.coinbase) .option('-f, --fork [fork]', 'specify fork name')
.option('-n, --nodeUrl [nodeUrl]', 'specify node url')
.option('-bn, --blockNumber [blockNumber]', 'specify block Number')
.option('-s, --stateDb [stateDb]', 'specify state database')
.option('-bs, --blocks [blocks]', 'specify blocks')
.action((option, env) => {
env.outputHelp()
console.log('\n')
console.log('Usage:')
console.log('remix-simulator start')
console.log('remix-simulator start -n <node url> -f cancun -bn latest')
console.log('\n')
console.log('Command line options:')
console.log('port: ', option.port)
console.log('host: ', option.ip)
console.log('rpc: ', option.rpc) console.log('rpc: ', option.rpc)
console.log('details: ', option.details) console.log('details: ', option.details)
console.log('host: ', option.ip) console.log('\n')
console.log('port: ', option.port) console.log('Provider options:')
console.log('coinbase: ', option.coinbase)
console.log('fork: ', option.fork)
console.log('nodeUrl: ', option.nodeUrl)
console.log('blockNumber: ', option.blockNumber)
console.log('stateDb: ', option.stateDb)
console.log('blocks: ', option.blocks)
const { Server } = require('../src/server') const { Server } = require('../src/server')
const server = new Server({ const server = new Server(option)
coinbase: option.coinbase, server.start(option)
rpc: option.rpc,
details: option.details
})
server.start(option.ip, option.port)
}) })
program.parse(process.argv) program.parse(process.argv)

@ -8,19 +8,17 @@ const app = express()
export class Server { export class Server {
provider provider
rpcOnly
constructor (options?:ProviderOptions) { constructor (options?: ProviderOptions) {
this.provider = new Provider(options) this.provider = new Provider(options)
this.provider.init().then(() => { this.provider.init().then(() => {
log('Provider initiated') log('Provider initiated')
}).catch((error) => { }).catch((error) => {
log(error) log(error)
}) })
this.rpcOnly = options.rpc
} }
start (host, port) { start (cliOptions: CliOptions) {
const wsApp = expressWs(app) const wsApp = expressWs(app)
app.use(cors()) app.use(cors())
@ -31,7 +29,7 @@ export class Server {
res.send('Welcome to remix-simulator') res.send('Welcome to remix-simulator')
}) })
if (this.rpcOnly) { if (cliOptions.rpc) {
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) {
@ -57,12 +55,12 @@ export class Server {
}) })
} }
app.listen(port, host, () => { app.listen(cliOptions.port, cliOptions.ip, () => {
if (!this.rpcOnly) { if (!cliOptions.rpc) {
log('Remix Simulator listening on ws://' + host + ':' + port) log('Remix Simulator listening on ws://' + cliOptions.ip + ':' + cliOptions.port)
log('http json-rpc is deprecated and disabled by default. To enable it use --rpc') log('http json-rpc is deprecated and disabled by default. To enable it use --rpc')
} else { } else {
log('Remix Simulator listening on http://' + host + ':' + port) log('Remix Simulator listening on http://' + cliOptions.ip + ':' + cliOptions.port)
} }
}) })
} }

Loading…
Cancel
Save