Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
0652c09
commit d77b15a
Showing
15 changed files
with
443 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env node | ||
|
||
require('@oclif/command').run() | ||
.then(require('@oclif/command/flush')) | ||
.catch(require('@oclif/errors/handle')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
|
||
node "%~dp0\run" %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Command, { flags } from "@oclif/command"; | ||
|
||
export abstract class BaseCommand extends Command { | ||
public static flags = { | ||
data: flags.string({ | ||
description: "data directory", | ||
}), | ||
config: flags.string({ | ||
description: "network config", | ||
}), | ||
token: flags.string({ | ||
description: "token name", | ||
default: "ark", | ||
}), | ||
network: flags.string({ | ||
description: "token network", | ||
}), | ||
skipCompression: flags.boolean({ | ||
description: "skip gzip compression", | ||
}), | ||
trace: flags.boolean({ | ||
description: "dumps generated queries and settings to console", | ||
}), | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { app } from "@arkecosystem/core-container"; | ||
import { Logger } from "@arkecosystem/core-interfaces"; | ||
import { SnapshotManager } from "@arkecosystem/core-snapshots"; | ||
import { flags } from "@oclif/command"; | ||
import fs from "fs-extra"; | ||
import { setUpLite } from "../utils"; | ||
import { BaseCommand } from "./command"; | ||
|
||
export class DumpCommand extends BaseCommand { | ||
public static description: string = "create a full snapshot of the database"; | ||
|
||
public static flags = { | ||
...BaseCommand.flags, | ||
blocks: flags.string({ | ||
description: "blocks to append to, correlates to folder name", | ||
}), | ||
start: flags.integer({ | ||
description: "start network height to export", | ||
default: -1, | ||
}), | ||
end: flags.integer({ | ||
description: "end network height to export", | ||
default: -1, | ||
}), | ||
codec: flags.string({ | ||
description: "codec name, default is msg-lite binary", | ||
}), | ||
}; | ||
|
||
public async run(): Promise<void> { | ||
// tslint:disable-next-line:no-shadowed-variable | ||
const { flags } = this.parse(DumpCommand); | ||
|
||
await setUpLite(flags); | ||
|
||
await app.resolvePlugin<SnapshotManager>("snapshots").exportData(flags); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { app } from "@arkecosystem/core-container"; | ||
import { EventEmitter } from "@arkecosystem/core-interfaces"; | ||
import { SnapshotManager } from "@arkecosystem/core-snapshots"; | ||
import { flags } from "@oclif/command"; | ||
import _cliProgress from "cli-progress"; | ||
import { setUpLite } from "../utils"; | ||
import { BaseCommand } from "./command"; | ||
|
||
export class RestoreCommand extends BaseCommand { | ||
public static description: string = "import data from specified snapshot"; | ||
|
||
public static flags = { | ||
...BaseCommand.flags, | ||
blocks: flags.string({ | ||
description: "blocks to import, corelates to folder name", | ||
required: true, | ||
}), | ||
codec: flags.string({ | ||
description: "codec name, default is msg-lite binary", | ||
}), | ||
truncate: flags.boolean({ | ||
description: "empty all tables before running import", | ||
}), | ||
skipRestartRound: flags.boolean({ | ||
description: "skip revert to current round", | ||
}), | ||
signatureVerify: flags.boolean({ | ||
description: "signature verification", | ||
}), | ||
}; | ||
|
||
public async run(): Promise<void> { | ||
// tslint:disable-next-line:no-shadowed-variable | ||
const { flags } = this.parse(RestoreCommand); | ||
|
||
await setUpLite(flags); | ||
|
||
const emitter = app.resolvePlugin<EventEmitter.EventEmitter>("event-emitter"); | ||
|
||
const progressBar = new _cliProgress.Bar( | ||
{ | ||
format: "{bar} {percentage}% | ETA: {eta}s | {value}/{total} | Duration: {duration}s", | ||
}, | ||
_cliProgress.Presets.shades_classic, | ||
); | ||
|
||
emitter.on("start", data => { | ||
progressBar.start(data.count, 1); | ||
}); | ||
|
||
emitter.on("progress", data => { | ||
progressBar.update(data.value); | ||
}); | ||
|
||
emitter.on("complete", data => { | ||
progressBar.stop(); | ||
}); | ||
|
||
await app.resolvePlugin<SnapshotManager>("snapshots").importData(flags); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,35 @@ | ||
import { app } from "@arkecosystem/core-container"; | ||
import { Logger } from "@arkecosystem/core-interfaces"; | ||
import { SnapshotManager } from "@arkecosystem/core-snapshots"; | ||
import { flags } from "@oclif/command"; | ||
import { setUpLite } from "../utils"; | ||
import { BaseCommand } from "./command"; | ||
|
||
export async function rollbackSnapshot(options) { | ||
const logger = app.resolvePlugin<Logger.ILogger>("logger"); | ||
const snapshotManager = app.resolvePlugin<SnapshotManager>("snapshots"); | ||
export class RollbackCommand extends BaseCommand { | ||
public static description: string = "rollback chain to specified height"; | ||
|
||
if (options.blockHeight === -1) { | ||
logger.warn("Rollback height is not specified. Rolling back to last completed round."); | ||
} | ||
logger.info( | ||
`Starting the process of blockchain rollback to block height of ${options.blockHeight.toLocaleString()}`, | ||
); | ||
public static flags = { | ||
...BaseCommand.flags, | ||
height: flags.integer({ | ||
description: "block network height number to rollback", | ||
default: -1, | ||
}), | ||
}; | ||
|
||
public async run(): Promise<void> { | ||
// tslint:disable-next-line:no-shadowed-variable | ||
const { flags } = this.parse(RollbackCommand); | ||
|
||
await setUpLite(flags); | ||
|
||
const logger = app.resolvePlugin<Logger.ILogger>("logger"); | ||
|
||
await snapshotManager.rollbackChain(options.blockHeight); | ||
if (flags.height === -1) { | ||
logger.warn("Rollback height is not specified. Rolling back to last completed round."); | ||
} | ||
|
||
logger.info(`Starting the process of blockchain rollback to block height of ${flags.height.toLocaleString()}`); | ||
|
||
await app.resolvePlugin<SnapshotManager>("snapshots").rollbackChain(flags.height); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import { app } from "@arkecosystem/core-container"; | ||
import { SnapshotManager } from "@arkecosystem/core-snapshots"; | ||
import { setUpLite } from "../utils"; | ||
import { BaseCommand } from "./command"; | ||
|
||
export async function truncateSnapshot(options) { | ||
const snapshotManager = app.resolvePlugin<SnapshotManager>("snapshots"); | ||
await snapshotManager.truncateChain(); | ||
export class TruncateCommand extends BaseCommand { | ||
public static description: string = "truncate blockchain database"; | ||
|
||
public async run(): Promise<void> { | ||
// tslint:disable-next-line:no-shadowed-variable | ||
const { flags } = this.parse(TruncateCommand); | ||
|
||
await setUpLite(flags); | ||
|
||
await app.resolvePlugin<SnapshotManager>("snapshots").truncateChain(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,33 @@ | ||
import { app } from "@arkecosystem/core-container"; | ||
import { Logger } from "@arkecosystem/core-interfaces"; | ||
import { SnapshotManager } from "@arkecosystem/core-snapshots"; | ||
import { flags } from "@oclif/command"; | ||
import fs from "fs-extra"; | ||
import { setUpLite } from "../utils"; | ||
import { BaseCommand } from "./command"; | ||
|
||
export async function verifySnapshot(options) { | ||
const logger = app.resolvePlugin<Logger.ILogger>("logger"); | ||
const snapshotManager = app.resolvePlugin<SnapshotManager>("snapshots"); | ||
export class VerifyCommand extends BaseCommand { | ||
public static description: string = "check validity of specified snapshot"; | ||
|
||
if (options.filename && !fs.existsSync(`${process.env.CORE_PATH_DATA}/snapshots/${options.filename}`)) { | ||
logger.error(`Verify not possible. Snapshot ${options.filename} not found.`); | ||
logger.info("Use -f parameter with just the filename and not the full path."); | ||
} else { | ||
await snapshotManager.verifyData(options); | ||
public static flags = { | ||
...BaseCommand.flags, | ||
blocks: flags.string({ | ||
description: "blocks to verify, corelates to folder name", | ||
}), | ||
codec: flags.string({ | ||
description: "codec name, default is msg-lite binary", | ||
}), | ||
signatureVerify: flags.boolean({ | ||
description: "signature verification", | ||
}), | ||
}; | ||
|
||
public async run(): Promise<void> { | ||
// tslint:disable-next-line:no-shadowed-variable | ||
const { flags } = this.parse(VerifyCommand); | ||
|
||
await setUpLite(flags); | ||
|
||
await app.resolvePlugin<SnapshotManager>("snapshots").verifyData(flags); | ||
} | ||
} |
Oops, something went wrong.