Commit 093f512c authored by Cédric Moreau's avatar Cédric Moreau

[enh] add `dump blocks [pattern]` and `dump forks [pattern]` commands

parent a8022b58
......@@ -23,6 +23,13 @@ export interface ForksDAO {
getNextForkBlocks(number:number, hash:string): Promise<DBBlock[]>
/**
* Find any fork block whose number is between `numberStart` and `maxNumber`, both included, and whose medianTime is
* >= `medianTimeStart`.
* @param numberStart
* @param medianTimeStart
* @param maxNumber
*/
getPotentialForkBlocks(numberStart:number, medianTimeStart:number, maxNumber:number): Promise<DBBlock[]>
removeForkBlock(number:number): Promise<void>
......
......@@ -21,6 +21,7 @@ import {Underscore} from "../lib/common-libs/underscore"
import {dumpWotWizard} from "./dump/wotwizard/wotwizard.dump"
import {OtherConstants} from "../lib/other_constants"
import {Querable, querablep} from "../lib/common-libs/querable"
import {dumpBlocks, dumpForks} from "./dump/blocks/dump.blocks"
const Table = require('cli-table')
......@@ -71,6 +72,14 @@ module.exports = {
await dumpCurrent(server)
break
case 'blocks':
await dumpBlocks(server, name)
break
case 'forks':
await dumpForks(server, name)
break
case 'volumes':
await dumpVolumes(server)
break
......
import {Server} from "../../../../server"
import {BlockDTO} from "../../../lib/dto/BlockDTO"
import {DBBlock} from "../../../lib/db/DBBlock"
export async function dumpForks(server: Server, blocks: string) {
return dumpBlocks(server, blocks, false)
}
export async function dumpBlocks(server: Server, blocks: string, showMainBcOnly = true) {
const patterns = blocks.split(',')
for (const p of patterns) {
// Single block to dump
if (p.match(/^\d+$/)) {
const bNumber = parseInt(p)
if (showMainBcOnly) {
dumpBlockIfDefined(await server.dal.getBlock(bNumber))
} else {
(await server.dal.getPotentialForkBlocks(bNumber, 0, bNumber)).forEach(dumpBlockIfDefined)
}
}
}
}
export function dumpBlockIfDefined(b: DBBlock|undefined|null) {
console.log(BlockDTO.fromJSONObject(b).getRawSigned())
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment