Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option for output file #11

Merged
merged 1 commit into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Make sure you have setup Rust environment (>= 1.64).

- `yarn start run-block --endpoint=wss://acala-rpc-2.aca-api.network/ws`
- This will replay the last block and print out the changed storages
- Use option `--output-path=<file_path>` to print out JSON file

- Run a test node
- `yarn start dev --endpoint=wss://acala-rpc-2.aca-api.network/ws`
Expand Down
13 changes: 12 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { TaskManager } from './task'
import { createServer } from './server'
import { defaultLogger } from './logger'
import { handler } from './rpc'
import { writeFileSync } from 'fs'

const setup = async (argv: any) => {
const port = argv.port || process.env.PORT || 8000
Expand Down Expand Up @@ -67,7 +68,13 @@ const runBlock = async (argv: any) => {
wasm,
calls,
},
console.log
(output) => {
if (argv['output-path']) {
writeFileSync(argv['output-path'], JSON.stringify(output, null, 2))
} else {
console.dir(output, { depth: null, colors: false })
}
}
)

setTimeout(() => process.exit(0), 50)
Expand Down Expand Up @@ -96,6 +103,10 @@ yargs(hideBin(process.argv))
desc: 'Command to execute the executor',
string: true,
},
'output-path': {
desc: 'File path to print output',
string: true,
},
}),
(argv) => {
runBlock(argv).catch((err) => {
Expand Down