Expose snapshot methods in type

This commit is contained in:
Jaco Greeff
2018-09-06 17:52:20 +02:00
parent 052cdbcd33
commit 0369450ff1
2 changed files with 16 additions and 11 deletions
+5 -10
View File
@@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details.
import { TxDb, ProgressCb } from '@polkadot/db/types';
import { TrieDb, Node, NodeBranch, NodeEncodedOrEmpty, NodeKv, NodeNotEmpty, NodeType } from './types';
import { TrieDb, Node, NodeBranch, NodeEncodedOrEmpty, NodeKv, NodeNotEmpty, NodeType, Snapshot } from './types';
import MemoryDb from '@polkadot/db/Memory';
import isNull from '@polkadot/util/is/null';
@@ -18,14 +18,6 @@ import { decodeNibbles, encodeNibbles } from './util/nibbles';
import { getNodeType, decodeNode, encodeNode } from './util/node';
import { EMPTY_HASH, EMPTY_U8A } from './constants';
type Snapshot = {
root: Uint8Array,
kv: Array<{
key: Uint8Array,
value: Uint8Array
}>
};
const l = logger('trie/db');
export default class Trie implements TrieDb {
@@ -145,7 +137,10 @@ export default class Trie implements TrieDb {
createSnapshot (fn: ProgressCb, hash?: Uint8Array, percent: number = 0, depth: number = 0): Snapshot {
const root = hash || this.rootHash || EMPTY_HASH;
l.log('creating current state key/value snapshot');
if (depth === 0) {
l.log('creating current state key/value snapshot');
}
l.debug(() => ['getTrie', { hash }]);
const node = this._getNode(root);
+11 -1
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { TxDb } from '@polkadot/db/types';
import { TxDb, ProgressCb } from '@polkadot/db/types';
export enum NodeType {
EMPTY = 0,
@@ -33,7 +33,17 @@ export type NodeNotEmpty = NodeKv | NodeBranch;
export type Node = NodeEmpty | NodeNotEmpty;
export type Snapshot = {
root: Uint8Array,
kv: Array<{
key: Uint8Array,
value: Uint8Array
}>
};
export interface TrieDb extends TxDb {
getRoot (): Uint8Array;
setRoot (rootHash: Uint8Array): void;
createSnapshot (fn: ProgressCb): Snapshot;
restoreSnapshot (snapshot: Snapshot, fn: ProgressCb): void;
}