Skip to content

Commit

Permalink
refactor(core-snapshot) improve snapshotService interface (#3727)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastijankuzner authored May 25, 2020
1 parent a336694 commit 312a1a7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
26 changes: 23 additions & 3 deletions packages/core-kernel/src/contracts/snapshot/snapshot-service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
export interface SnapshotService {
dump(options: any): Promise<void>;
restore(options: any): Promise<void>;
dump(options: DumpOptions): Promise<void>;
restore(options: RestoreOptions): Promise<void>;
rollbackByHeight(height: number): Promise<void>;
rollbackByNumber(number: number): Promise<void>;
truncate(): Promise<void>;
verify(options: any): Promise<void>;
verify(options: VerifyOptions): Promise<void>;
}

export interface DumpOptions {
network: string;
codec?: string;
skipCompression?: boolean;
start?: number;
end?: number;
}

export interface RestoreOptions {
network: string;
blocks: string;
truncate?: boolean;
verify?: boolean;
}

export interface VerifyOptions {
network: string;
blocks: string;
}
4 changes: 2 additions & 2 deletions packages/core-snapshots/src/contracts/options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface DumpOptions {
network: string;
skipCompression: boolean;
codec: string;
skipCompression?: boolean;
codec?: string;
start?: number;
end?: number;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core-snapshots/src/snapshot-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class SnapshotService implements Contracts.Snapshot.SnapshotService {
@Container.inject(Identifiers.SnapshotDatabaseService)
private readonly database!: Database.DatabaseService;

public async dump(options: any): Promise<void> {
public async dump(options: Contracts.Snapshot.DumpOptions): Promise<void> {
try {
Utils.assert.defined<string>(options.network);

Expand All @@ -33,7 +33,7 @@ export class SnapshotService implements Contracts.Snapshot.SnapshotService {
}
}

public async restore(options: any): Promise<void> {
public async restore(options: Contracts.Snapshot.RestoreOptions): Promise<void> {
try {
Utils.assert.defined<string>(options.network);
Utils.assert.defined<string>(options.blocks);
Expand Down Expand Up @@ -72,7 +72,7 @@ export class SnapshotService implements Contracts.Snapshot.SnapshotService {
}
}

public async verify(options: any): Promise<void> {
public async verify(options: Contracts.Snapshot.RestoreOptions): Promise<void> {
try {
this.logger.info("Running VERIFICATION");

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/commands/snapshot-dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class Command extends Commands.Command {

await app
.get<KernelContracts.Snapshot.SnapshotService>(KernelContainer.Identifiers.SnapshotService)
.dump(flags);
.dump(flags as any);

await app.terminate();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/commands/snapshot-restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class Command extends Commands.Command {

await app
.get<KernelContracts.Snapshot.SnapshotService>(KernelContainer.Identifiers.SnapshotService)
.restore(flags);
.restore(flags as any);

await app.terminate();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/commands/snapshot-verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class Command extends Commands.Command {

await app
.get<KernelContracts.Snapshot.SnapshotService>(KernelContainer.Identifiers.SnapshotService)
.verify(flags);
.verify(flags as any);

await app.terminate();
}
Expand Down

0 comments on commit 312a1a7

Please sign in to comment.