Skip to content

Commit

Permalink
Showing 3 changed files with 13 additions and 11 deletions.
3 changes: 3 additions & 0 deletions packages/chopsticks/src/cli-options.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@ export const defaultOptions = {
desc: 'Runtime maximum log level [off = 0; error = 1; warn = 2; info = 3; debug = 4; trace = 5]',
number: true,
},
'registered-types': {
desc: 'Registered types',
},
'offchain-worker': {
desc: 'Enable offchain worker',
boolean: true,
1 change: 1 addition & 0 deletions packages/chopsticks/src/cli.ts
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ const commands = yargs(hideBin(process.argv))
'Dev mode, fork off a chain',
(yargs) =>
yargs.options({
// TODO: find a way to extract this from configSchema
...defaultOptions,
...mockOptions,
port: {
20 changes: 9 additions & 11 deletions packages/chopsticks/src/context.ts
Original file line number Diff line number Diff line change
@@ -52,18 +52,16 @@ export const setupContext = async (argv: Config, overrideParent = false) => {
if (chain.db) {
if (argv.resume) {
let blockData: BlockEntry | null = null

switch (typeof argv.resume) {
case 'string':
blockData = await chain.db.queryBlock(argv.resume as HexString)
break
case 'number':
blockData = await chain.db.queryBlockByNumber(argv.resume)
break
default:
blockData = await chain.db.queryHighestBlock()
break
if (typeof argv.resume === 'string' && argv.resume.startsWith('0x')) {
blockData = await chain.db.queryBlock(argv.resume as HexString)
} else if (typeof argv.resume === 'boolean' || argv.resume === 'true') {
blockData = await chain.db.queryHighestBlock()
} else if (Number.isInteger(+argv.resume)) {
blockData = await chain.db.queryBlockByNumber(+argv.resume)
} else {
throw new Error(`Resume failed. Invalid resume option ${argv.resume}`)
}

if (blockData) {
const block = await chain.loadBlockFromDB(blockData.number)
block && (await chain.setHead(block))

0 comments on commit b8c2fac

Please sign in to comment.