Skip to content
Snippets Groups Projects
Commit 093f512c authored by Cédric Moreau's avatar Cédric Moreau
Browse files

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

parent a8022b58
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,13 @@ export interface ForksDAO { ...@@ -23,6 +23,13 @@ export interface ForksDAO {
getNextForkBlocks(number:number, hash:string): Promise<DBBlock[]> 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[]> getPotentialForkBlocks(numberStart:number, medianTimeStart:number, maxNumber:number): Promise<DBBlock[]>
removeForkBlock(number:number): Promise<void> removeForkBlock(number:number): Promise<void>
......
...@@ -21,6 +21,7 @@ import {Underscore} from "../lib/common-libs/underscore" ...@@ -21,6 +21,7 @@ import {Underscore} from "../lib/common-libs/underscore"
import {dumpWotWizard} from "./dump/wotwizard/wotwizard.dump" import {dumpWotWizard} from "./dump/wotwizard/wotwizard.dump"
import {OtherConstants} from "../lib/other_constants" import {OtherConstants} from "../lib/other_constants"
import {Querable, querablep} from "../lib/common-libs/querable" import {Querable, querablep} from "../lib/common-libs/querable"
import {dumpBlocks, dumpForks} from "./dump/blocks/dump.blocks"
const Table = require('cli-table') const Table = require('cli-table')
...@@ -71,6 +72,14 @@ module.exports = { ...@@ -71,6 +72,14 @@ module.exports = {
await dumpCurrent(server) await dumpCurrent(server)
break break
case 'blocks':
await dumpBlocks(server, name)
break
case 'forks':
await dumpForks(server, name)
break
case 'volumes': case 'volumes':
await dumpVolumes(server) await dumpVolumes(server)
break 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())
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment